os/persistentdata/persistentstorage/dbms/sdbms/SD_STD.H
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/dbms/sdbms/SD_STD.H	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,860 @@
     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 +// DBMS Client/Server architecture
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +
    1.22 +#include "U32STD.H"
    1.23 +#include "D32SRV.H"
    1.24 +#include "D32DRVR.H"
    1.25 +#include <f32file.h>
    1.26 +#include <s32mem.h>
    1.27 +#include "D32VER.H"
    1.28 +#include "D32Map.h"
    1.29 +#include "Sd_DbProps.h"
    1.30 +#include "Sd_PolicyProxy.h"
    1.31 +#include "Sd_DriveSpace.h"
    1.32 +
    1.33 +// other classes referenced
    1.34 +class HDbsColumns;
    1.35 +struct TDbProps;
    1.36 +
    1.37 +// classes defined
    1.38 +class TDbsParam;
    1.39 +class RDbsObject;
    1.40 +class CDbsDatabase;
    1.41 +class CDbsIncremental;
    1.42 +class CDbsCursor;
    1.43 +class CDbsConstraint;
    1.44 +class CDbsNotifier;
    1.45 +class CDbsSource;
    1.46 +class RDbsSources;
    1.47 +class CDbsServer;
    1.48 +class CDbsSession;
    1.49 +class HDbsStream;
    1.50 +
    1.51 +#if defined(_DEBUG)
    1.52 +/**
    1.53 +@internalComponent
    1.54 +*/
    1.55 +#define _SMALL_BUFFER
    1.56 +#endif
    1.57 +
    1.58 +using namespace DBSC;
    1.59 +
    1.60 +/**
    1.61 +@internalComponent
    1.62 +*/
    1.63 +enum TDbsPanic
    1.64 +	{
    1.65 +	EDbsUnimplemented,              //0
    1.66 +	EDbsInvalidColumn,
    1.67 +	EDbsWrongType,
    1.68 +	EDbsNoRowData,
    1.69 +	EDbsNotInUpdate,
    1.70 +	EDbsBadDescriptor,
    1.71 +	EDbsBadHandle,
    1.72 +	EDbsStreamMarkInvalid,
    1.73 +	EDbsStreamLocationInvalid,
    1.74 +	EDbsObserverRequestPending,
    1.75 +    EDbsInvalidDrive                //10
    1.76 +	};
    1.77 +
    1.78 +/**
    1.79 +used by proxy classes
    1.80 +@internalComponent
    1.81 +*/
    1.82 +GLREF_C void Panic(TDbsPanic aPanic);	
    1.83 +
    1.84 +/**
    1.85 +@internalComponent
    1.86 +*/
    1.87 +GLREF_C void ExternalizeL(const TDbCol& aCol,RWriteStream& aStream);
    1.88 +GLREF_C void ExternalizeL(const CDbColSet& aColSet,RWriteStream& aStream);
    1.89 +GLREF_C void InternalizeL(CDbColSet& aColSet,RReadStream& aStream);
    1.90 +GLREF_C void ExternalizeL(const CDbKey& aKey,RWriteStream& aStream);
    1.91 +GLREF_C void InternalizeL(CDbKey& aKey,RReadStream& aStream);
    1.92 +GLREF_C void ExternalizeL(const CDbNames& aNames,RWriteStream& aStream);
    1.93 +GLREF_C void InternalizeL(CDbNames& aNames,RReadStream& aStream);
    1.94 +GLREF_C void ExternalizeL(const CDbStrings& aNames,RWriteStream& aStream);
    1.95 +GLREF_C void InternalizeL(CDbStrings& aNames,RReadStream& aStream);
    1.96 +
    1.97 +/**
    1.98 +@internalComponent
    1.99 +*/
   1.100 +_LIT(KDbsServerName,"!DBMS server");
   1.101 +_LIT(KDbsServerImg,"EDBSRV");		// DLL/EXE name
   1.102 +const TUid KDbsServerUid3={0x100012a5};
   1.103 +
   1.104 +
   1.105 +/**
   1.106 +@internalComponent
   1.107 +*/
   1.108 +const TInt KDbsExitDelay=4*0x100000;	// ~4 seconds
   1.109 +const TInt KDbsLeavePanic=~(1<<20);
   1.110 +const TInt KTablePolicyMaskBit = 1024;	//Used in RDbs::Get<Obj>Policy() methods
   1.111 +
   1.112 +/**
   1.113 +shared classes
   1.114 +@internalComponent
   1.115 +*/
   1.116 +enum TDbsType {EDbsFree,EDbsDatabase,EDbsIncremental,EDbsCursor,EDbsConstraint,EDbsStream,EDbsObserver,EDbsMaxType=EDbsObserver,EDbsSession=EDbsFree};
   1.117 +
   1.118 +/**
   1.119 +Make sure that KDbsFunc2SecurityPolicyMask array in SD_PolicyProxy.cpp gets updated if 
   1.120 +new enum items are going to be added to TDbsFunction.
   1.121 +@internalComponent
   1.122 +*/
   1.123 +enum TDbsFunction
   1.124 +	{
   1.125 +// Session functions
   1.126 +	EDbsResourceMark,					//0
   1.127 +	EDbsResourceCheck,
   1.128 +	EDbsResourceCount,
   1.129 +	EDbsSetHeapFailure,
   1.130 +	EDbsOpenDatabase,
   1.131 +// common functions
   1.132 +	EDbsClose,
   1.133 +// Database functions
   1.134 +	EDbsDatabaseAuthenticate,           //Not used in SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version
   1.135 +	EDbsDatabaseDestroy,
   1.136 +	EDbsDatabaseBegin,
   1.137 +	EDbsDatabaseCommit,
   1.138 +	EDbsDatabaseRollback,				//10
   1.139 +	EDbsDatabaseProperty,
   1.140 +	EDbsDatabaseCreateTable,
   1.141 +	EDbsDatabaseTables,
   1.142 +	EDbsDatabaseColumns,
   1.143 +	EDbsDatabaseIndexes,
   1.144 +	EDbsDatabaseKeys,
   1.145 +	EDbsDatabaseOpenObserver,
   1.146 +	EDbsDatabaseOpenUtility,
   1.147 +	EDbsDatabaseOpenDropTable,
   1.148 +	EDbsDatabaseOpenAlterTable,			//20
   1.149 +	EDbsDatabaseOpenCreateIndex,
   1.150 +	EDbsDatabaseOpenDropIndex,
   1.151 +	EDbsDatabaseExecute,
   1.152 +	EDbsDatabasePrepareView,
   1.153 +	EDbsDatabaseOpenTable,
   1.154 +// Observer functions
   1.155 +	EDbsObserverNotify,
   1.156 +	EDbsObserverCancel,
   1.157 +// Incremental functions
   1.158 +	EDbsIncrementalNext,
   1.159 +// Cursor functions
   1.160 +	EDbsCursorColumnTypes,
   1.161 +	EDbsCursorReset,					//30
   1.162 +	EDbsCursorEvaluate,
   1.163 +	EDbsCursorUnevaluated,
   1.164 +	EDbsCursorSetIndex,
   1.165 +	EDbsCursorSeek,
   1.166 +	EDbsCursorAtBeginning,
   1.167 +	EDbsCursorAtEnd,
   1.168 +	EDbsCursorAtRow,
   1.169 +	EDbsCursorCount,
   1.170 +	EDbsCursorGotoPos,
   1.171 +	EDbsCursorBookmark,					//40
   1.172 +	EDbsCursorGotoBookmark,
   1.173 +	EDbsCursorGet,
   1.174 +	EDbsCursorInsert,
   1.175 +	EDbsCursorUpdate,
   1.176 +	EDbsCursorRetrieveRow,
   1.177 +	EDbsCursorCancel,
   1.178 +	EDbsCursorPut,
   1.179 +	EDbsCursorDelete,
   1.180 +	EDbsCursorColumns,
   1.181 +	EDbsCursorColumnDef,				//50
   1.182 +	EDbsCursorSetNull,
   1.183 +	EDbsCursorColumnSize,
   1.184 +	EDbsCursorColumnSource,
   1.185 +	EDbsCursorColumnSink,
   1.186 +	EDbsCursorOpenConstraint,
   1.187 +	EDbsCursorMatch,
   1.188 +	EDbsCursorFind,
   1.189 +// stream functions
   1.190 +	EDbsStreamRead,
   1.191 +	EDbsStreamWrite,
   1.192 +	EDbsStreamSize,						//60
   1.193 +	EDbsStreamSynch,
   1.194 +// Session functions
   1.195 +	EDbsCreateDatabase,
   1.196 +	EDbsDatabaseList,
   1.197 +	EDbsCopyDatabase,
   1.198 +	EDbsDeleteDatabase,
   1.199 +	EDbsGetSecurityPolicy,
   1.200 +// reserved disk space handling functions
   1.201 +	EDbsReserveDriveSpace,
   1.202 +	EDbsFreeReservedSpace,
   1.203 +	EDbsReserveGetAccess,
   1.204 +	EDbsReserveReleaseAccess,			//70
   1.205 +//
   1.206 +	EDbsGetBackupPath,	
   1.207 +	EDbsGetBackupPaths,	
   1.208 +	//Insert new functuions here
   1.209 +	EDbsLast
   1.210 +	};
   1.211 +
   1.212 +/**
   1.213 +@internalComponent
   1.214 +*/
   1.215 +const TInt KDbsTypeBits=4;
   1.216 +const TInt KDbsMagicBits=4;
   1.217 +const TInt KDbsIndexBits=14;
   1.218 +const TInt KDbsFunctionBits=9;
   1.219 +const TInt KDbsHandleBits=KDbsTypeBits+KDbsMagicBits+KDbsIndexBits;
   1.220 +const TInt KDbsTypeMask=(1<<KDbsTypeBits)-1;
   1.221 +const TInt KDbsMagicMask=(1<<KDbsMagicBits)-1;
   1.222 +const TInt KDbsHandleMask=(1<<KDbsHandleBits)-1;
   1.223 +const TInt KDbsObjectReturn=1<<(KDbsFunctionBits-1);
   1.224 +const TInt KDbsIndexLimit=1<<KDbsIndexBits;
   1.225 +
   1.226 +/**
   1.227 +@internalComponent
   1.228 +*/
   1.229 +#define KDbsSessionHandle DbsSessionHandle()
   1.230 +
   1.231 +/**
   1.232 +@internalComponent
   1.233 +*/
   1.234 +inline TInt DbsMessage(TInt aFunction,TInt aHandle);
   1.235 +inline TDbsFunction DbsFunction(TInt aMessage);
   1.236 +inline TInt DbsHandle(TInt aMessage);
   1.237 +inline TDbsType DbsType(TInt aHandle);
   1.238 +inline TInt DbsMagic(TInt aHandle);
   1.239 +inline TInt DbsObjectIndex(TInt aHandle);
   1.240 +inline TInt DbsMakeHandle(TInt aIndex,TInt aMagic,TDbsType aType);
   1.241 +inline TInt DbsSessionHandle();
   1.242 +
   1.243 +#if !defined(_SMALL_BUFFER)
   1.244 +/**
   1.245 +@internalComponent
   1.246 +*/
   1.247 +const TInt KDbsStreamBufSize=0x600;		// 1.5K
   1.248 +const TInt KDbsStreamIoSize=0xc00;		// 3K
   1.249 +const TInt KDbsColumnTypesSize=0x200;	// .5K
   1.250 +#else
   1.251 +const TInt KDbsStreamBufSize=2;
   1.252 +const TInt KDbsStreamIoSize=32;
   1.253 +const TInt KDbsColumnTypesSize=2;
   1.254 +#endif
   1.255 +
   1.256 +/**
   1.257 +@internalComponent
   1.258 +*/
   1.259 +class TDbsStreamBuf
   1.260 +	{
   1.261 +public:
   1.262 +	enum {ESize=KDbsStreamBufSize};
   1.263 +public:
   1.264 +	TInt iExt;
   1.265 +	TUint8 iData[ESize];
   1.266 +	};
   1.267 +
   1.268 +/**
   1.269 +@internalComponent
   1.270 +*/
   1.271 +class TDbsColumns
   1.272 +	{
   1.273 +public:
   1.274 +	enum {EMax=KDbsColumnTypesSize};
   1.275 +public:
   1.276 +	TInt iCount;
   1.277 +	TUint8 iData[EMax];
   1.278 +	};
   1.279 +
   1.280 +/**
   1.281 +client side classes
   1.282 +@internalComponent
   1.283 +*/
   1.284 +class TDbsParam
   1.285 +	{
   1.286 +public:
   1.287 +	inline void operator=(const TDesC8& aDes);
   1.288 +	inline void operator=(const TDesC16& aDes);
   1.289 +	inline void operator=(TInt aVal);
   1.290 +//
   1.291 +	static TPtrC8 PrepareLC(const CDbColSet& aColSet);
   1.292 +	static TPtrC8 PrepareLC(const CDbKey& aKey);
   1.293 +	static TPtrC8 PrepareLC(const TDbLookupKey& aKey);
   1.294 +	
   1.295 +private:
   1.296 +	union
   1.297 +		{
   1.298 +		const TAny* iPtr;
   1.299 +		TInt iInt;
   1.300 +		};
   1.301 +	};
   1.302 +
   1.303 +/**
   1.304 +@internalComponent
   1.305 +*/
   1.306 +typedef TDbsParam TDbsMessage[4];
   1.307 +
   1.308 +/**
   1.309 +@internalComponent
   1.310 +*/
   1.311 +class RDbsObject : private RDbs
   1.312 +	{
   1.313 +public:
   1.314 +	inline RDbsObject();
   1.315 +	inline void OpenL(const RDbsObject& aDbs,TDbsFunction aFunction);
   1.316 +	inline void OpenL(const RDbsObject& aDbs,TDbsFunction aFunction,const TIpcArgs& aArgs);
   1.317 +	inline void OpenL(const RDbs& aDbs,TDbsFunction aFunction,const TIpcArgs& aArgs);
   1.318 +	void Close();
   1.319 +//
   1.320 +	inline TInt Handle() const;
   1.321 +//
   1.322 +	TInt SendReceive(TDbsFunction aFunction) const;
   1.323 +	inline TInt SendReceive(TDbsFunction aFunction,const TIpcArgs& aArgs) const;
   1.324 +	TInt SendReceiveL(TDbsFunction aFunction) const;
   1.325 +	inline TInt SendReceiveL(TDbsFunction aFunction,const TIpcArgs& aArgs) const;
   1.326 +	inline void SendReceive(TDbsFunction aFunction,TRequestStatus& aStatus) const;
   1.327 +	inline void SendReceive(TDbsFunction aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus) const;
   1.328 +private:
   1.329 +	inline RDbsObject(const RDbs& aDbs);
   1.330 +	void SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs,TRequestStatus& aStatus) const;
   1.331 +	TInt SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs) const;
   1.332 +	TInt SendReceiveL(TDbsFunction aFunction,const TIpcArgs* aArgs) const;
   1.333 +	void OpenL(const RDbsObject& aDbs,TDbsFunction aFunction,const TIpcArgs* aArgs);
   1.334 +private:
   1.335 +	TInt iHandle;
   1.336 +	};
   1.337 +
   1.338 +/**
   1.339 +@internalComponent
   1.340 +*/
   1.341 +NONSHARABLE_CLASS(CDbsDatabase) : public CDbDatabase
   1.342 +	{
   1.343 +	friend class CDbsSecureDatabase;
   1.344 +public:
   1.345 +	static CDbsDatabase* NewL(const RDbs& aDbs,const TDesC& aDatabase,const TDesC& aFormat);
   1.346 +	~CDbsDatabase();
   1.347 +//
   1.348 +private:
   1.349 +	inline CDbsDatabase();
   1.350 +	void ConstructL(const RDbs& aDbs,TIpcArgs& aArgs);
   1.351 +// from CDbDatabase
   1.352 +	TInt Destroy();
   1.353 +	TInt Begin();
   1.354 +	TInt Commit();
   1.355 +	void Rollback();
   1.356 +	TInt Property(TProperty aProperty);
   1.357 +	void CreateTableL(const TDesC& aName,const CDbColSet& aColSet,const CDbKey* aPrimaryKey);
   1.358 +	void TablesL(CDbTableNames& aNames);
   1.359 +	void ColumnsL(CDbColSet& aColSet,const TDesC& aName);
   1.360 +	void IndexesL(CDbIndexNames& aNames,const TDesC& aTable);
   1.361 +	void KeysL(CDbKey& aKey,const TDesC& aName,const TDesC& aTable);
   1.362 +	CDbNotifier* OpenNotifierL();
   1.363 +	CDbIncremental* OpenUtilityL(TUtility aType,TInt& aStep);
   1.364 +	CDbIncremental* OpenCompactL(TInt& aStep);
   1.365 +	CDbIncremental* OpenRecoverL(TInt& aStep);
   1.366 +	CDbIncremental* OpenDropTableL(const TDesC& aTable,TInt& aStep);
   1.367 +	CDbIncremental* OpenAlterTableL(const TDesC& aTable,const CDbColSet& aNewDef,TInt& aStep);
   1.368 +	CDbIncremental* OpenCreateIndexL(const TDesC& aName,const TDesC& aTable,const CDbKey& aKey,TInt& aStep);
   1.369 +	CDbIncremental* OpenDropIndexL(const TDesC& aName,const TDesC& aTable,TInt& aStep);
   1.370 +	CDbIncremental* OpenExecuteL(const TDesC& aSql,TDbTextComparison aComparison,TInt& aInit);
   1.371 +	CDbCursor* PrepareViewL(const TDbQuery& aQuery,const TDbWindow& aWindow,RDbRowSet::TAccess anAccess);
   1.372 +	CDbCursor* OpenTableL(const TDesC& aName,RDbRowSet::TAccess anAccess);
   1.373 +private:
   1.374 +	RDbsObject iObject;
   1.375 +	};
   1.376 +
   1.377 +//Secure shared database
   1.378 +NONSHARABLE_CLASS(CDbsSecureDatabase) : public CDbsDatabase
   1.379 +	{
   1.380 +public:
   1.381 +	static CDbsSecureDatabase* NewL(const RDbs& aDbs,const TDesC& aDatabase,const TDesC& aFormat);
   1.382 +	virtual ~CDbsSecureDatabase();
   1.383 +
   1.384 +private:
   1.385 +	inline CDbsSecureDatabase();
   1.386 +	void ConstructL(const RDbs& aDbs,TIpcArgs& aArgs);
   1.387 +
   1.388 +	};
   1.389 +
   1.390 +/**
   1.391 +@internalComponent
   1.392 +*/
   1.393 +NONSHARABLE_CLASS(CDbsNotifier) : public CDbNotifier
   1.394 +	{
   1.395 +public:
   1.396 +	static CDbsNotifier* NewL(const RDbsObject& aDatabase);
   1.397 +private:
   1.398 +	inline CDbsNotifier();
   1.399 +	~CDbsNotifier();
   1.400 +// from CDbObserver
   1.401 +	void Notify(TType aEvent,TRequestStatus& aStatus);
   1.402 +	void Cancel();
   1.403 +private:
   1.404 +	RDbsObject iObject;
   1.405 +	};
   1.406 +
   1.407 +/**
   1.408 +@internalComponent
   1.409 +*/
   1.410 +NONSHARABLE_CLASS(CDbsIncremental) : public CDbAsyncIncremental
   1.411 +	{
   1.412 +public:
   1.413 +	static CDbsIncremental* NewL(const RDbsObject& aDbs,TDbsFunction aFunction,TIpcArgs& aArgs,TInt& aStep);
   1.414 +	~CDbsIncremental();
   1.415 +private:
   1.416 +	inline CDbsIncremental();
   1.417 +// from CDbAsyncIncremental
   1.418 +	void Next(TPckgBuf<TInt>& aStep,TRequestStatus& aStatus);
   1.419 +private:
   1.420 +	RDbsObject iObject;
   1.421 +	};
   1.422 +
   1.423 +/**
   1.424 +@internalComponent
   1.425 +*/
   1.426 +NONSHARABLE_CLASS(CDbsCursor) : public CDbCursor
   1.427 +	{
   1.428 +public:
   1.429 +	static CDbsCursor* NewL(const RDbsObject& aDbs,TDbsFunction aFunction,TIpcArgs& aArgs);
   1.430 +	~CDbsCursor();
   1.431 +private:
   1.432 +	CDbsCursor();
   1.433 +	void ConstructL(const RDbsObject& aDbs,TDbsFunction aFunction,TIpcArgs& aArgs);
   1.434 +//
   1.435 +	TDbColType Type(TDbColNo aCol) const;
   1.436 +	void ReplaceBlobL(TDbColumn& aCol);
   1.437 +	TBool RetrieveL(TDbsFunction aFunction,TInt aArg0=0);
   1.438 +// from CDbCursor
   1.439 +	void Reset();
   1.440 +	TBool EvaluateL();
   1.441 +	void Evaluate(TRequestStatus& aStatus);
   1.442 +	TBool Unevaluated();
   1.443 +	void SetIndexL(const TDesC* anIndex);
   1.444 +	TBool SeekL(const TDbLookupKey& aKey,RDbTable::TComparison aComparison);
   1.445 +	TBool AtBeginning();
   1.446 +	TBool AtEnd();
   1.447 +	TBool AtRow();
   1.448 +	TInt CountL(RDbRowSet::TAccuracy aAccuracy);
   1.449 +	TBool GotoL(RDbRowSet::TPosition aPosition);
   1.450 +	void Bookmark(TDbBookmark::TMark& aMark);
   1.451 +	void GotoL(const TDbBookmark::TMark& aMark);
   1.452 +	void GetL();
   1.453 +	void InsertL(TInsert aClearRow);
   1.454 +	void UpdateL();
   1.455 +	void Cancel();
   1.456 +	void PutL();
   1.457 +	void DeleteL();
   1.458 +	TInt ColumnCount();
   1.459 +	void ColumnsL(CDbColSet& aColSet);
   1.460 +	void ColumnDef(TDbCol& aCol,TDbColNo aColNo);
   1.461 +	TDbColType ColumnType(TDbColNo aCol);
   1.462 +	RDbRow* RowBuffer();
   1.463 +	TDbColumnC ColumnC(TDbColNo aCol);	// non-writeable column
   1.464 +	TDbColumn Column(TDbColNo aCol);		// writeable column
   1.465 +	void SetNullL(TDbColNo aCol);
   1.466 +	TInt ColumnSize(TDbColNo aCol);
   1.467 +	MStreamBuf* ColumnSourceL(TDbColNo aCol);
   1.468 +	MStreamBuf* ColumnSinkL(TDbColNo aCol);
   1.469 +	CDbRowConstraint* OpenConstraintL(const TDbQuery& aCriteria);
   1.470 +	TBool MatchL(CDbRowConstraint& aCursor);
   1.471 +	TInt FindL(RDbRowSet::TDirection aDirection,const TDbQuery& aCriteria);
   1.472 +private:
   1.473 +	enum TState {EUnknown,EAtBeginning,EAtEnd,EAtRow,ERetrieve,ERead,EWrite};
   1.474 +private:
   1.475 +	RDbsObject iObject;
   1.476 +	TState iState;
   1.477 +	TBool iChangedBlob;
   1.478 +	HDbsColumns* iColumns;
   1.479 +	RDbRow iRow;
   1.480 +	};
   1.481 +
   1.482 +/**
   1.483 +@internalComponent
   1.484 +*/
   1.485 +NONSHARABLE_CLASS(CDbsConstraint) : public CDbRowConstraint
   1.486 +	{
   1.487 +	friend class CDbsCursor;
   1.488 +private:
   1.489 +	inline CDbsConstraint();
   1.490 +	~CDbsConstraint();
   1.491 +private:
   1.492 +	RDbsObject iObject;
   1.493 +	};
   1.494 +
   1.495 +/**
   1.496 +@internalComponent
   1.497 +*/
   1.498 +NONSHARABLE_CLASS(HDbsBuf) : public TStreamBuf
   1.499 +	{
   1.500 +public:
   1.501 +	static HDbsBuf* NewL(const RDbsObject& aObject,TDbsFunction aFunction,TIpcArgs& aArgs);
   1.502 +	static HDbsBuf* NewLC(const RDbsObject& aObject,TDbsFunction aFunction,TIpcArgs& aArgs);
   1.503 +	static HDbsBuf* NewLC(const RDbs& aDbSession, TDbsFunction aFunction, TIpcArgs& aArgs);
   1.504 +	virtual inline ~HDbsBuf();
   1.505 +private:
   1.506 +	inline HDbsBuf();
   1.507 +	void ConstructL(const RDbsObject& aObject,TDbsFunction aFunction,TIpcArgs& aArgs);
   1.508 +	void ConstructL(const RDbs& aDbSession, TDbsFunction aFunction, TIpcArgs& aArgs);
   1.509 +// from TStreamBuf
   1.510 +	TInt UnderflowL(TInt aMaxLength);
   1.511 +	void OverflowL();
   1.512 +	void DoRelease();
   1.513 +	void DoSynchL();
   1.514 +	TInt DoReadL(TAny* aPtr,TInt aMaxLength);
   1.515 +	void DoWriteL(const TAny* aPtr,TInt aLength);
   1.516 +	TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
   1.517 +private:
   1.518 +	inline void SetPos(TRead,TInt aPos);
   1.519 +	inline void SetPos(TWrite,TInt aPos);
   1.520 +	inline TInt Pos(TRead) const;
   1.521 +	inline TInt Pos(TWrite) const;
   1.522 +	inline TInt MovePos(TRead,TInt anOffset);
   1.523 +	inline TInt MovePos(TWrite,TInt anOffset);
   1.524 +	TInt IpcReadL(TAny* aPtr,TInt aMaxLength);
   1.525 +	void IpcWriteL(const TAny* aPtr,TInt aLength);
   1.526 +	TInt EndL();
   1.527 +//
   1.528 +	inline TInt Lag(TRead) const;
   1.529 +	inline TInt Lag(TWrite) const;
   1.530 +	inline TInt Mark(TRead) const;
   1.531 +	inline TInt Mark(TWrite) const;
   1.532 +private:
   1.533 +	RDbsObject iIpc;
   1.534 +	TInt iRPos;
   1.535 +	TInt iWPos;
   1.536 +	TDbsStreamBuf iBuf;
   1.537 +	};
   1.538 +
   1.539 +/**
   1.540 +@internalComponent
   1.541 +*/
   1.542 +NONSHARABLE_CLASS(HDbsReadBuf) : public TMemBuf
   1.543 +	{
   1.544 +public:
   1.545 +	static HDbsReadBuf* NewL(const TDesC8& aDes);
   1.546 +protected:
   1.547 +	inline HDbsReadBuf(const TDesC8& aDes);
   1.548 +	void DoRelease();
   1.549 +	};
   1.550 +
   1.551 +/**
   1.552 +@internalComponent
   1.553 +*/
   1.554 +NONSHARABLE_CLASS(CDbsObserver) : public CActive
   1.555 +	{
   1.556 +public:
   1.557 +	/**
   1.558 +	@internalComponent
   1.559 +	*/
   1.560 +	class HObserver
   1.561 +		{
   1.562 +		friend class CDbsObserver;
   1.563 +	public:
   1.564 +		~HObserver();
   1.565 +		void Notify(const RMessage2& aMessage);		
   1.566 +		void Cancel();
   1.567 +	private:
   1.568 +		inline HObserver();
   1.569 +		void Complete(TInt aStatus);
   1.570 +		void Event(TInt aEvent);
   1.571 +	private:
   1.572 +		TDblQueLink iLink;
   1.573 +		TInt iPending;
   1.574 +		RMessagePtr2 iMessage;
   1.575 +		};
   1.576 +	friend class HObserver;
   1.577 +public:
   1.578 +	static CDbsObserver* NewL(CDbsSource& aSource);
   1.579 +	static CDbsObserver* Collect(CDbsObserver* aNotifier);
   1.580 +	HObserver* ObserverL();
   1.581 +private:
   1.582 +	inline CDbsObserver(CDbsSource& aSource);
   1.583 +	~CDbsObserver();
   1.584 +//
   1.585 +	void Queue();
   1.586 +// from CActive
   1.587 +	void RunL();
   1.588 +	void DoCancel();
   1.589 +private:
   1.590 +	CDbsSource& iSource;
   1.591 +	CDbNotifier* iNotifier;
   1.592 +	TDblQue<HObserver> iQueue;
   1.593 +	};
   1.594 +
   1.595 +/**
   1.596 +@internalComponent
   1.597 +*/
   1.598 +NONSHARABLE_CLASS(CDbsConnection) : public CDbContext
   1.599 +	{
   1.600 +	friend class RDbsSources;
   1.601 +public:
   1.602 +	inline CDbsSource& Source() const;
   1.603 +	static inline const CDbsConnection& Connection(const CDbObject& aObject);
   1.604 +	static inline CDbsSource& Source(const CDbObject& aObject);
   1.605 +private:
   1.606 +	inline CDbsConnection() {}
   1.607 +	~CDbsConnection();
   1.608 +	inline void Set(CDbsSource& aSource);
   1.609 +private:
   1.610 +	CDbsSource* iSource;
   1.611 +	};
   1.612 +
   1.613 +/**
   1.614 +@internalComponent
   1.615 +*/
   1.616 +class CDbsDatabaseStub : public CDbObject
   1.617 +	{
   1.618 +public:
   1.619 +	static CDbsDatabaseStub* NewL();
   1.620 +	CDbDatabase* AuthenticateL();
   1.621 +private:
   1.622 +	inline CDbsDatabaseStub();
   1.623 +	};
   1.624 +
   1.625 +/**
   1.626 +@internalComponent
   1.627 +*/
   1.628 +NONSHARABLE_CLASS(CDbsSource) : public CBase
   1.629 +	{
   1.630 +	friend class CDbsConnection;
   1.631 +	friend class CDbsObserver;
   1.632 +public:
   1.633 +	static CDbsSource* NewL(RFs& aFs,const TDesC& aSource);
   1.634 +//
   1.635 +	static inline TInt LinkOffset();
   1.636 +	TBool Is(const TDesC& aSource) const;
   1.637 +//
   1.638 +	inline CDbSource& Source();
   1.639 +	CDbsObserver::HObserver* ObserverL();
   1.640 +private:
   1.641 +	inline CDbsSource(const TDbFormat& aFormat);
   1.642 +	~CDbsSource();
   1.643 +	void Closed();
   1.644 +//
   1.645 +	inline void Open();
   1.646 +	void Close();
   1.647 +private:
   1.648 +	TDblQueLink iLink;
   1.649 +	HBufC* iName;
   1.650 +	const TDbFormat& iFormat;
   1.651 +	TInt iConnections;
   1.652 +	CDbSource* iSource;
   1.653 +	CDbsObserver* iObserver;
   1.654 +	};
   1.655 +
   1.656 +/**
   1.657 +@internalComponent
   1.658 +*/
   1.659 +class RDbsSources
   1.660 +	{
   1.661 +private:
   1.662 +	typedef TDblQueIter<CDbsSource> TIter;
   1.663 +public:
   1.664 +	inline RDbsSources(RDbCache& aCache);
   1.665 +	inline void Close();
   1.666 +//
   1.667 +	CDbsConnection* OpenLC(RFs& aFs,const TDesC& aSource,const TDesC& aFormat);
   1.668 +private:
   1.669 +	TDblQue<CDbsSource> iSources;
   1.670 +	RDbCache iDrivers;
   1.671 +	};
   1.672 +
   1.673 +/**
   1.674 +@internalComponent
   1.675 +*/
   1.676 +NONSHARABLE_CLASS(CDbsServer) : public CServer2
   1.677 +	{
   1.678 +public:
   1.679 +	static CDbsServer* NewL();
   1.680 +//
   1.681 +	inline TDes& Name0();
   1.682 +	inline TDes& Name1();
   1.683 +	inline TDes& FileName();
   1.684 +	inline RDbsSources& Sources();
   1.685 +	inline RFs& Fs();
   1.686 +	inline RDriveSpaceCol& DriveSpaceCol();
   1.687 +	void RemoveSession();
   1.688 +//
   1.689 +	static CDbsServer* Instance();
   1.690 +	void Panic(const TDesC& aCategory,TInt aCode);	// .. panic client!
   1.691 +
   1.692 +	inline CPolicyProxy& PolicyProxy() const;
   1.693 +	inline RDbPropsFactory& DbPropsFactory();
   1.694 +
   1.695 +private:
   1.696 +	inline CDbsServer();
   1.697 +	~CDbsServer();
   1.698 +	void ConstructL();
   1.699 +// from CServer
   1.700 +	CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
   1.701 +private:
   1.702 +	enum {ECacheSize=8};
   1.703 +	enum {EServerPriority=0};
   1.704 +private:
   1.705 +	RDbCache iCache;
   1.706 +	RDbsSources iSources;
   1.707 +	TDbName iName0;		// used for message servicing
   1.708 +	TDbName iName1;
   1.709 +	TFileName iFileName;
   1.710 +	RFs iFs;
   1.711 +	CPolicyProxy* iPolicyProxy;
   1.712 +	RDbPropsFactory iDbPropsFactory;
   1.713 +	RDriveSpaceCol iDriveSpaceCol;
   1.714 +};
   1.715 +
   1.716 +/**
   1.717 +@internalComponent
   1.718 +*/
   1.719 +NONSHARABLE_CLASS(CDbsSession) : public CSession2
   1.720 +	{
   1.721 +private:
   1.722 +#if !defined(_SMALL_BUFFER)
   1.723 +	enum {EIndexGranularity=8};
   1.724 +#else
   1.725 +	enum {EIndexGranularity=1};
   1.726 +#endif
   1.727 +	struct TEntry
   1.728 +		{
   1.729 +		union
   1.730 +			{
   1.731 +			TAny* iObject;
   1.732 +			TInt iNext;
   1.733 +			};
   1.734 +		TUint8 iType;
   1.735 +		const MPolicy* iPolicy;
   1.736 +		TUint8 iMagic;
   1.737 +	public:
   1.738 +		void Release();
   1.739 +		DECLARE_DB_DUMP3(aFile)
   1.740 +	//
   1.741 +		inline TDbsType Type() const;
   1.742 +		inline CDbsDatabaseStub& DatabaseStub();
   1.743 +		inline CDbDatabase& Database();
   1.744 +		inline CDbIncremental& Incremental();
   1.745 +		inline CDbCursor& Cursor();
   1.746 +		inline CDbRowConstraint& Constraint();
   1.747 +		inline HDbsStream& Stream();
   1.748 +		inline CDbsObserver::HObserver& Observer();
   1.749 +		};
   1.750 +public:
   1.751 +	CDbsSession();
   1.752 +	virtual ~CDbsSession();
   1.753 +private:
   1.754 +//From CSession2
   1.755 +	virtual void CreateL();
   1.756 +// from CSession
   1.757 +	void ServiceL(const RMessage2& aMessage);	
   1.758 +	TInt ExtServiceL(const RMessage2& aMessage, TDbsFunction aDbsFunction);
   1.759 +	void ServiceError(const RMessage2& aMessage,TInt aError);
   1.760 +	TInt CountResources();
   1.761 +//
   1.762 +	inline CDbsServer& Server() const;
   1.763 +	inline RDbsSources& Sources();
   1.764 +//
   1.765 +	const TDesC& ReadName0L(TInt aIndex,const RMessage2& aMessage);
   1.766 +	const TDesC& ReadName1L(TInt aIndex,const RMessage2& aMessage);
   1.767 +	const TDesC& ReadFileNameL(TInt aIndex, const RMessage2& aMessage);
   1.768 +	HBufC* ReadHBufLC(TInt aIndex,const RMessage2& aMessage);
   1.769 +	HBufC8* ReadHBuf8LC(TInt aIndex,const RMessage2& aMessage);
   1.770 +	CDbColSet* ColSetLC(TInt aIndex,const RMessage2& aMessage);
   1.771 +	CDbKey* KeyLC(TInt aIndex,const RMessage2& aMessage);
   1.772 +	TDbLookupKey* LookupKeyLC(TInt aIndex,TInt aSize,const RMessage2& aMessage);
   1.773 +	CDbObject* DoAuthenticateL(CDbsConnection* aDbsConnection, const RMessage2& aMessage);
   1.774 +	TInt DoOpenDatabaseL(const RMessage2& aMessage, const TDbProps& aDbProps);
   1.775 +
   1.776 +	TDbProps* ExtractDbPropsLC(const RMessage2& aMessage);
   1.777 +	TInt OpenDatabaseL(const RMessage2& aMessage);	
   1.778 +	TInt CreateDatabaseL(const RMessage2& aMessage);
   1.779 +	TInt DoCreateDatabaseL(const RMessage2& aMessage, const TDbProps& aDbProps);
   1.780 +	void CopyDatabaseL(const RMessage2& aMessage);
   1.781 +	void DeleteDatabaseL(const RMessage2& aMessage);
   1.782 +	TInt GetDatabaseListL(const RMessage2& aMessage);	
   1.783 +	void GetSecurityPolicyL(const RMessage2& aMessage);	
   1.784 +	void ReadRowL(RDbRow& aRow,TInt aSize,const RMessage2& aMessage);
   1.785 +	void PutRowL(CDbCursor& aCursor,const RMessage2& aMessage);
   1.786 +	TInt WriteRowL(const RDbRow& aRow,const RMessage2& aMessage);
   1.787 +	TInt RetrieveRowL(CDbCursor& aCursor,const RMessage2& aMessage);
   1.788 +	TInt NewCursorL(CDbCursor* aCursor,const RMessage2& aMessage,const MPolicy* aTblSecurityPolicy);
   1.789 +	TInt NewIncrementalL(CDbIncremental* aCursor,TInt& aInit,const RMessage2& aMessage,const MPolicy* aPolicy);
   1.790 +	TInt NewStreamL(MStreamBuf* aHost,const RMessage2& aMessage,const MPolicy* aPolicy,TInt aExtent=-1);
   1.791 +	TInt NewStreamL(TAny* aPtr,TExternalizeFunction aExter,const RMessage2& aMessage,const MPolicy* aPolicy);
   1.792 +	void NewDbEntryL(CDbObject* aDbObject, const TDbPolicyRequest& aDbPolicyRequest, TInt& aDbHandle);
   1.793 +	
   1.794 +#ifdef __DBDUMP__
   1.795 +	void Dump();
   1.796 +#endif	
   1.797 +
   1.798 +	void ReserveDriveSpaceL(TDriveNumber aDrive);
   1.799 +	void FreeReservedSpace(TDriveNumber aDrive);
   1.800 +	void GetReserveAccessL(TDriveNumber aDrive);
   1.801 +	void ReleaseReserveAccess(TDriveNumber aDrive);
   1.802 +	
   1.803 +	void GetBackupPathL(const RMessage2& aMessage);
   1.804 +	TInt GetBackupPathsL(const RMessage2& aMessage);
   1.805 +
   1.806 +	inline TInt Add(CDbIncremental* aIncremental, const MPolicy* aPolicy);
   1.807 +	inline TInt Add(CDbCursor* aCursor, const MPolicy* aPolicy);
   1.808 +	inline TInt Add(CDbRowConstraint* aConstraint, const MPolicy* aPolicy);
   1.809 +	inline TInt Add(HDbsStream* aStream, const MPolicy* aPolicy);
   1.810 +	inline TInt Add(CDbsObserver::HObserver* aObserver, const MPolicy* aPolicy);
   1.811 +
   1.812 +	TEntry& Object(TInt aHandle);
   1.813 +	void AllocL();
   1.814 +	TInt DoAdd(TAny* aObject,TDbsType aType, const MPolicy* aPolicy);
   1.815 +	void Free(TEntry& aEntry);
   1.816 +
   1.817 +private:
   1.818 +	TEntry* iIx;
   1.819 +	TInt iSize;
   1.820 +	TInt iFree;
   1.821 +	RMap<TInt, TDbPolicyRequest> iDbPolicyRqColl;
   1.822 +    CDbsSessDriveSpace* iSessDriveSpace;
   1.823 +	};
   1.824 +
   1.825 +/**
   1.826 +@internalComponent
   1.827 +*/
   1.828 +class HDbsStream
   1.829 +	{
   1.830 +public:
   1.831 +	inline HDbsStream(MStreamBuf* aHost,TInt aReadPos);
   1.832 +	inline ~HDbsStream();
   1.833 +//
   1.834 +	TInt ReadL(const RMessage2& aMessage);	
   1.835 +	void WriteL(const RMessage2& aMessage);	
   1.836 +	inline TInt SizeL();
   1.837 +	inline void SynchL();
   1.838 +private:
   1.839 +	MStreamBuf& iHost;
   1.840 +	TInt iRPos;
   1.841 +	TInt iWPos;
   1.842 +	};
   1.843 +
   1.844 +/**
   1.845 +@internalComponent
   1.846 +*/
   1.847 +NONSHARABLE_CLASS(HBufBuf) : public TBufBuf
   1.848 +	{
   1.849 +	enum {EGranularity=512};
   1.850 +public:
   1.851 +	static HBufBuf* NewLC();
   1.852 +private:
   1.853 +	inline HBufBuf();
   1.854 +	virtual inline ~HBufBuf();
   1.855 +	void DoRelease();
   1.856 +private:
   1.857 +	CBufBase* iBuf;
   1.858 +	};
   1.859 +
   1.860 +#include "SD_STD.INL"
   1.861 +
   1.862 +
   1.863 +