1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/udbms/UD_DRVR.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,273 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "UD_STD.H"
1.20 +#include <f32file.h>
1.21 +#include <e32uid.h>
1.22 +
1.23 +// Class CDbContext
1.24 +
1.25 +inline void CDbContext::Open()
1.26 + {
1.27 + ++iRef;
1.28 + }
1.29 +
1.30 +//
1.31 +// Attach an object to this context
1.32 +//
1.33 +void CDbContext::Attach(CDbObject* aObject)
1.34 + {
1.35 + if (aObject && aObject->iContext!=this)
1.36 + {
1.37 + __ASSERT(!aObject->iContext);
1.38 + aObject->iContext=this;
1.39 + Open();
1.40 + }
1.41 + }
1.42 +
1.43 +//
1.44 +// self destruct when we are no longer referenced
1.45 +//
1.46 +void CDbContext::Close()
1.47 + {
1.48 + __ASSERT(iRef>0);
1.49 + if (--iRef==0)
1.50 + Idle();
1.51 + }
1.52 +
1.53 +//
1.54 +// default implementation is to delete ourself
1.55 +//
1.56 +void CDbContext::Idle()
1.57 + {
1.58 + delete this;
1.59 + }
1.60 +
1.61 +// Class CDbObject
1.62 +
1.63 +//
1.64 +// Attach aObject to the same context as it's factory
1.65 +//
1.66 +CDbObject* CDbObject::Attach(CDbObject* aObject)
1.67 + {
1.68 + CDbContext* context=iContext;
1.69 + if (context)
1.70 + context->Attach(aObject);
1.71 + return aObject;
1.72 + }
1.73 +
1.74 +//
1.75 +// Library safe destruction of a implementation object
1.76 +// This ensures that all objects from a Driver are deleted BEFORE the library is unloaded
1.77 +//
1.78 +void CDbObject::Destroy(CDbObject* aObject)
1.79 + {
1.80 + if (aObject)
1.81 + {
1.82 + CDbContext* context=aObject->iContext;
1.83 + delete aObject;
1.84 + if (context)
1.85 + context->Close();
1.86 + }
1.87 + }
1.88 +
1.89 +//
1.90 +// Library safe cleanup-stack function
1.91 +//
1.92 +void CDbObject::PushL()
1.93 + {
1.94 + CleanupStack::PushL(TCleanupItem(TCleanupOperation(Destroy),this));
1.95 + }
1.96 +
1.97 +
1.98 +// Class CDbSource
1.99 +
1.100 +//SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version of the method.
1.101 +// Encapsulate the 2-phase construction for client access
1.102 +//
1.103 +CDbDatabase* CDbSource::OpenL()
1.104 + {
1.105 + return AuthenticateL();
1.106 + }
1.107 +
1.108 +// Class RDbNamedDatabase
1.109 +
1.110 +//SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version of the method.
1.111 +LOCAL_C CDbDatabase* OpenDatabaseL(TDbFormat::TOpen aMode, RFs& aFs, const TDesC& aSource,
1.112 + const TDesC& /*aFormat*/)
1.113 + {
1.114 + CDbSource* source=KBuiltinDriver.iFormats[0].OpenL(aFs,aSource,aMode);
1.115 + CleanupStack::PushL(source);
1.116 + CDbDatabase* db=source->OpenL();
1.117 + CleanupStack::PopAndDestroy(); // source (not needed)
1.118 + return db;
1.119 + }
1.120 +
1.121 +//SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version of the method.
1.122 +//The method may be used in the other cpp files too
1.123 +CDbDatabase* CreateDatabaseL(TDbFormat::TCreate aMode, RFs& aFs, const TDesC& aSource,
1.124 + const TDesC& aFormat)
1.125 + {
1.126 + const TDbFormat& fmt=KBuiltinDriver.iFormats[0];
1.127 +
1.128 + TUid policyId = KNullUid;
1.129 + TPtrC uidName;
1.130 +
1.131 + ::ExtractUidAndName(aFormat, policyId, uidName);
1.132 +
1.133 + CDbDatabase* db=fmt.CreateL(aFs,aSource,aMode,
1.134 + TUidType(TUid::Uid(fmt.iUid[0]),TUid::Uid(fmt.iUid[1]),policyId));
1.135 +
1.136 + return db;
1.137 + }
1.138 +
1.139 +
1.140 +/**
1.141 +Creates a new non-secure database.
1.142 +
1.143 +In this "single client" mode, the database cannot be shared with the other clients.
1.144 +The database server is not involved in the operations with the database, the client side
1.145 +database library (edbms.dll) will be used.
1.146 +If the database has to be shared, the following example shows how this may be accomplished:
1.147 +@code
1.148 +RFs fs;
1.149 +TInt err = fs.Connect();
1.150 +<process the error>
1.151 +_LIT(KDatabaseName, _L("C:\\A.DB"));
1.152 +RDbNamedDatabase db;
1.153 +err = db.Create(fs, KDatabaseName); //Step 1 - create the database using the RFs object
1.154 +<process the error>
1.155 +db.Close(); //Step 2 - close the database
1.156 +RDbs dbs;
1.157 +err = dbs.Connect();
1.158 +<process the error>
1.159 +err = db.Open(dbs, KDatabaseName); //Step 3 - reopen the database using the RDbs object
1.160 +<process the error>
1.161 +...
1.162 +@endcode
1.163 +
1.164 +Max allowed database name length (with the extension) is KDbMaxName symbols.
1.165 +
1.166 +For creating a new secure shared database, see RDbNamedDatabase::Create(), which first argument
1.167 +is a RDbs reference.
1.168 +
1.169 +@param aFs Handle to a file server session.
1.170 +@param aSource Database file name.
1.171 +@param aFormat Database format string. It can be omitted in which case the default parameter
1.172 + value (TPtrC()) will be used.
1.173 +@return KErrNone if successful otherwise one of the system-wide error codes, including:
1.174 + KErrAlreadyExists - the database already exists;
1.175 + KErrArgument - bad argument, including null/invaluid uids, the database name includes a null;
1.176 +
1.177 +@see RDbNamedDatabase::Create(RDbs& aDbs, const TDesC& aDatabase, const TDesC& aFormat)
1.178 +
1.179 +@publishedAll
1.180 +@released
1.181 +*/
1.182 +EXPORT_C TInt RDbNamedDatabase::Create(RFs& aFs, const TDesC& aSource, const TDesC& aFormat)
1.183 + {
1.184 + TRAPD(r,iDatabase=CreateDatabaseL(TDbFormat::ECreate,aFs,aSource,aFormat));
1.185 + return r;
1.186 + }
1.187 +
1.188 +
1.189 +/**
1.190 +Creates a new non-secure database.
1.191 +If a database with the same file name exists, it will be replased.
1.192 +
1.193 +In this "single client" mode, the database cannot be shared with the other clients.
1.194 +The database server is not involved in the operations with the database, the client side
1.195 +database library (edbms.dll) will be used.
1.196 +If the database has to be shared, the following example shows how this may be accomplished:
1.197 +@code
1.198 +RFs fs;
1.199 +TInt err = fs.Connect();
1.200 +<process the error>
1.201 +_LIT(KDatabaseName, _L("C:\\A.DB"));
1.202 +RDbNamedDatabase db;
1.203 +err = db.Replace(fs, KDatabaseName); //Step 1 - create the database using the RFs object
1.204 +<process the error>
1.205 +db.Close(); //Step 2 - close the database
1.206 +RDbs dbs;
1.207 +err = dbs.Connect();
1.208 +<process the error>
1.209 +err = db.Open(dbs, KDatabaseName); //Step 3 - reopen the database using the RDbs object
1.210 +<process the error>
1.211 +...
1.212 +@endcode
1.213 +
1.214 +Max allowed database name length (with the extension) is KDbMaxName symbols.
1.215 +
1.216 +For creating a new secure shared database, see RDbNamedDatabase::Create(), which first argument
1.217 +is a RDbs reference.
1.218 +
1.219 +@param aFs Handle to a file server session.
1.220 +@param aSource Database name. The name format is: <drive>:<path><name>.<ext>
1.221 +@param aFormat Database format string. It can be omitted in which case the default parameter
1.222 + value (TPtrC()) will be used.
1.223 +@return KErrNone if successful otherwise one of the system-wide error codes, including:
1.224 + KErrArgument - bad argument, including null/invaluid uids, the database name includes a null;
1.225 +
1.226 +@see RDbNamedDatabase::Create(RDbs& aDbs, const TDesC& aDatabase, const TDesC& aFormat)
1.227 +
1.228 +@publishedAll
1.229 +@released
1.230 +*/
1.231 +EXPORT_C TInt RDbNamedDatabase::Replace(RFs& aFs, const TDesC& aSource, const TDesC& aFormat)
1.232 + {
1.233 + TRAPD(r,iDatabase=CreateDatabaseL(TDbFormat::EReplace,aFs,aSource,aFormat));
1.234 + return r;
1.235 + }
1.236 +
1.237 +/**
1.238 +Opens an existing non-secure database.
1.239 +
1.240 +In this "single client" mode, the database cannot be shared with the other clients.
1.241 +The database server is not involved in the operations with the database, the client side
1.242 +database library (edbms.dll) will be used.
1.243 +
1.244 +For opening a new secure shared database, see RDbNamedDatabase::Open(), which first argument
1.245 +is a RDbs reference.
1.246 +
1.247 +@param aFs Handle to a file server session.
1.248 +@param aSource Database name. The name format is: <drive>:<path><name>.<ext>
1.249 +@param aFormat Database format string. It can be omitted in which case the default parameter
1.250 + value (TPtrC()) will be used.
1.251 +@param aMode The mode in which the database is to be accessed. The mode is
1.252 +defined by the TAccess type.
1.253 +@return KErrNone if successful otherwise one of the system-wide error codes, including:
1.254 + KErrNotFound - the database is not found;
1.255 + KErrPathNotFound - the path of database is not found
1.256 + KErrNotSupported - the format is not supported.
1.257 + KErrArgument - bad argument,including null/invaluid uids,the database name is null;
1.258 + KErrPermissionDenied - the caller has not enough rights to do the operation;
1.259 +
1.260 +@see RDbNamedDatabase::Open(RDbs& aDbs, const TDesC& aDatabase, const TDesC& aFormat)
1.261 +
1.262 +@publishedAll
1.263 +@released
1.264 +*/
1.265 +EXPORT_C TInt RDbNamedDatabase::Open(RFs& aFs, const TDesC& aSource, const TDesC& aFormat,
1.266 + TAccess aMode)
1.267 + {
1.268 + TRAPD(r,iDatabase=OpenDatabaseL(TDbFormat::TOpen(aMode),aFs,aSource,aFormat));
1.269 + return r;
1.270 + }
1.271 +
1.272 +
1.273 +CDbNotifier* CDbSource::NotifierL()
1.274 + {
1.275 + return AttachContext(this,OpenNotifierL());
1.276 + }