os/persistentdata/persistentstorage/dbms/tdbms/t_dbfilestore.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "D32DBX.H"
sl@0
    17
#include "D32STOR.H"
sl@0
    18
#include <s32file.h>
sl@0
    19
sl@0
    20
const TInt32 KTestUidValue=0x01234567u;
sl@0
    21
sl@0
    22
NONSHARABLE_CLASS(COplDatabase) : public CDbFileStoreDatabase
sl@0
    23
	{
sl@0
    24
public:
sl@0
    25
	static CDbDatabase* CreateL(RFs& aFs,const TDesC& aName,TDbFormat::TCreate aMode,const TUidType& aType);
sl@0
    26
	static CDbSource* OpenL(RFs& aFs,const TDesC& aName,TDbFormat::TOpen aMode);
sl@0
    27
private:
sl@0
    28
	inline COplDatabase(RFs& aFs) :CDbFileStoreDatabase(aFs) {}
sl@0
    29
	static COplDatabase* NewLC(RFs& aFs);
sl@0
    30
	TStreamId CreateRootL(TStreamId aDatabaseId);
sl@0
    31
	TStreamId DatabaseIdL(TStreamId aRootId);	// override
sl@0
    32
	};
sl@0
    33
sl@0
    34
const TInt32 KUidOplDocValue=268435573;
sl@0
    35
const TInt32 KUidExternalOplFileValue=268435594;
sl@0
    36
const TInt32 KUidOplInterpreterValue=268435816;
sl@0
    37
const TUid KUidOplInterpreter={KUidOplInterpreterValue};
sl@0
    38
sl@0
    39
// Class OplDatabase
sl@0
    40
// this supports the "opl" and "opl.doc" formats
sl@0
    41
sl@0
    42
COplDatabase* COplDatabase::NewLC(RFs& aFs)
sl@0
    43
	{
sl@0
    44
	COplDatabase* self=new(ELeave) COplDatabase(aFs);
sl@0
    45
	CleanupStack::PushL(self);
sl@0
    46
	return self;
sl@0
    47
	}
sl@0
    48
sl@0
    49
CDbDatabase* COplDatabase::CreateL(RFs& aFs,const TDesC& aName,TDbFormat::TCreate aMode,const TUidType& aType)
sl@0
    50
	{
sl@0
    51
	COplDatabase* self=NewLC(aFs);
sl@0
    52
	self->CDbFileStoreDatabase::CreateL(aName,aMode,aType);
sl@0
    53
	CDbDatabase* db=self->InterfaceL();
sl@0
    54
	CleanupStack::Pop();			// self
sl@0
    55
	return db;
sl@0
    56
	}
sl@0
    57
sl@0
    58
TStreamId COplDatabase::CreateRootL(TStreamId aDatabaseId)
sl@0
    59
	{
sl@0
    60
	RStoreWriteStream root;
sl@0
    61
	TStreamId id=root.CreateLC(*iStore);
sl@0
    62
	root<<KUidOplInterpreter<<aDatabaseId;
sl@0
    63
	root.CommitL();
sl@0
    64
	CleanupStack::PopAndDestroy();	// root
sl@0
    65
	return id;
sl@0
    66
	}
sl@0
    67
sl@0
    68
CDbSource* COplDatabase::OpenL(RFs& aFs,const TDesC& aName,TDbFormat::TOpen aMode)
sl@0
    69
	{
sl@0
    70
	COplDatabase* self=NewLC(aFs);
sl@0
    71
	self->CDbFileStoreDatabase::OpenL(aName,aMode);
sl@0
    72
	CDbSource* src=self->SourceL();
sl@0
    73
	CleanupStack::Pop();			// self
sl@0
    74
	return src;
sl@0
    75
	}
sl@0
    76
sl@0
    77
TStreamId COplDatabase::DatabaseIdL(TStreamId aRootId)
sl@0
    78
	{
sl@0
    79
    RStoreReadStream read;
sl@0
    80
    read.OpenLC(*iStore,aRootId);
sl@0
    81
	TUid ignore;
sl@0
    82
    read>>ignore>>aRootId;
sl@0
    83
    CleanupStack::PopAndDestroy(); // read
sl@0
    84
    return aRootId;
sl@0
    85
	}
sl@0
    86
sl@0
    87
// data
sl@0
    88
sl@0
    89
NONSHARABLE_CLASS(CDataDocument) : public CDbFileStoreDatabase
sl@0
    90
	{
sl@0
    91
public:
sl@0
    92
	static CDbDatabase* CreateL(RFs& aFs,const TDesC& aName,TDbFormat::TCreate aMode,const TUidType& aType);
sl@0
    93
	static CDbSource* OpenL(RFs& aFs,const TDesC& aName,TDbFormat::TOpen aMode);
sl@0
    94
private:
sl@0
    95
	inline CDataDocument(RFs& aFs) :CDbFileStoreDatabase(aFs) {}
sl@0
    96
	TStreamId DatabaseIdL(TStreamId aRootId);	// override
sl@0
    97
	};
sl@0
    98
sl@0
    99
const TInt32 KUidAppDllDocValue=0x1000006d;
sl@0
   100
const TInt32 KUidDataAppValue=0x10000086;
sl@0
   101
const TUid KUidDataHeadStream={0x1000012e};
sl@0
   102
sl@0
   103
// Class DataDocument
sl@0
   104
sl@0
   105
//
sl@0
   106
// Cannot do this
sl@0
   107
//
sl@0
   108
CDbDatabase* CDataDocument::CreateL(RFs&,const TDesC&,TDbFormat::TCreate,const TUidType&)
sl@0
   109
	{
sl@0
   110
	User::Leave(KErrNotSupported);
sl@0
   111
	return 0;
sl@0
   112
	}
sl@0
   113
sl@0
   114
//
sl@0
   115
// read-only!
sl@0
   116
//
sl@0
   117
CDbSource* CDataDocument::OpenL(RFs& aFs,const TDesC& aName,TDbFormat::TOpen aMode)
sl@0
   118
	{
sl@0
   119
	if (aMode!=TDbFormat::EReadOnly)
sl@0
   120
		User::Leave(KErrNotSupported);
sl@0
   121
	CDataDocument* self=new(ELeave) CDataDocument(aFs);
sl@0
   122
	CleanupStack::PushL(self);
sl@0
   123
	self->CDbFileStoreDatabase::OpenL(aName,aMode);
sl@0
   124
	CDbSource* src=self->SourceL();
sl@0
   125
	CleanupStack::Pop();			// self
sl@0
   126
	return src;
sl@0
   127
	}
sl@0
   128
sl@0
   129
TStreamId CDataDocument::DatabaseIdL(TStreamId aRootId)
sl@0
   130
	{
sl@0
   131
    CStreamDictionary* dict=CStreamDictionary::NewLC();
sl@0
   132
    RStoreReadStream read;
sl@0
   133
    read.OpenLC(*iStore,aRootId);
sl@0
   134
    read>>*dict;
sl@0
   135
    CleanupStack::PopAndDestroy(); // read
sl@0
   136
    TStreamId id=dict->At(KUidDataHeadStream);
sl@0
   137
    CleanupStack::PopAndDestroy();  // dict
sl@0
   138
    read.OpenLC(*iStore,id); 
sl@0
   139
    read>>id;
sl@0
   140
    CleanupStack::PopAndDestroy(); // read
sl@0
   141
	return id;
sl@0
   142
	}
sl@0
   143
sl@0
   144
const TDbFormat KFormats[]=
sl@0
   145
	{
sl@0
   146
	{
sl@0
   147
	_S("test"),&CDbFileStoreDatabase::CreateL,&CDbFileStoreDatabase::OpenL,
sl@0
   148
	{KPermanentFileStoreLayoutUidValue,KTestUidValue}
sl@0
   149
	},
sl@0
   150
	{
sl@0
   151
	_S("data"),&CDataDocument::CreateL,&CDataDocument::OpenL,
sl@0
   152
	{KPermanentFileStoreLayoutUidValue,KUidAppDllDocValue,KUidDataAppValue}
sl@0
   153
	},
sl@0
   154
	{
sl@0
   155
	_S("opl"),&COplDatabase::CreateL,&COplDatabase::OpenL,
sl@0
   156
	{KPermanentFileStoreLayoutUidValue,KUidExternalOplFileValue}
sl@0
   157
	},
sl@0
   158
	{
sl@0
   159
	_S("opl.doc"),&COplDatabase::CreateL,&COplDatabase::OpenL,
sl@0
   160
	{KPermanentFileStoreLayoutUidValue,KUidOplDocValue}
sl@0
   161
	}
sl@0
   162
	};
sl@0
   163
sl@0
   164
const TDbDriver KDriver={4,KFormats};
sl@0
   165
sl@0
   166
EXPORT_C const TDbDriver& DbmsDriver()
sl@0
   167
	{
sl@0
   168
	return KDriver;
sl@0
   169
	}
sl@0
   170