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