|
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 // DBMS Client/Server architecture |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include "U32STD.H" |
|
20 #include "D32SRV.H" |
|
21 #include "D32DRVR.H" |
|
22 #include <f32file.h> |
|
23 #include <s32mem.h> |
|
24 #include "D32VER.H" |
|
25 #include "D32Map.h" |
|
26 #include "Sd_DbProps.h" |
|
27 #include "Sd_PolicyProxy.h" |
|
28 #include "Sd_DriveSpace.h" |
|
29 |
|
30 // other classes referenced |
|
31 class HDbsColumns; |
|
32 struct TDbProps; |
|
33 |
|
34 // classes defined |
|
35 class TDbsParam; |
|
36 class RDbsObject; |
|
37 class CDbsDatabase; |
|
38 class CDbsIncremental; |
|
39 class CDbsCursor; |
|
40 class CDbsConstraint; |
|
41 class CDbsNotifier; |
|
42 class CDbsSource; |
|
43 class RDbsSources; |
|
44 class CDbsServer; |
|
45 class CDbsSession; |
|
46 class HDbsStream; |
|
47 |
|
48 #if defined(_DEBUG) |
|
49 /** |
|
50 @internalComponent |
|
51 */ |
|
52 #define _SMALL_BUFFER |
|
53 #endif |
|
54 |
|
55 using namespace DBSC; |
|
56 |
|
57 /** |
|
58 @internalComponent |
|
59 */ |
|
60 enum TDbsPanic |
|
61 { |
|
62 EDbsUnimplemented, //0 |
|
63 EDbsInvalidColumn, |
|
64 EDbsWrongType, |
|
65 EDbsNoRowData, |
|
66 EDbsNotInUpdate, |
|
67 EDbsBadDescriptor, |
|
68 EDbsBadHandle, |
|
69 EDbsStreamMarkInvalid, |
|
70 EDbsStreamLocationInvalid, |
|
71 EDbsObserverRequestPending, |
|
72 EDbsInvalidDrive //10 |
|
73 }; |
|
74 |
|
75 /** |
|
76 used by proxy classes |
|
77 @internalComponent |
|
78 */ |
|
79 GLREF_C void Panic(TDbsPanic aPanic); |
|
80 |
|
81 /** |
|
82 @internalComponent |
|
83 */ |
|
84 GLREF_C void ExternalizeL(const TDbCol& aCol,RWriteStream& aStream); |
|
85 GLREF_C void ExternalizeL(const CDbColSet& aColSet,RWriteStream& aStream); |
|
86 GLREF_C void InternalizeL(CDbColSet& aColSet,RReadStream& aStream); |
|
87 GLREF_C void ExternalizeL(const CDbKey& aKey,RWriteStream& aStream); |
|
88 GLREF_C void InternalizeL(CDbKey& aKey,RReadStream& aStream); |
|
89 GLREF_C void ExternalizeL(const CDbNames& aNames,RWriteStream& aStream); |
|
90 GLREF_C void InternalizeL(CDbNames& aNames,RReadStream& aStream); |
|
91 GLREF_C void ExternalizeL(const CDbStrings& aNames,RWriteStream& aStream); |
|
92 GLREF_C void InternalizeL(CDbStrings& aNames,RReadStream& aStream); |
|
93 |
|
94 /** |
|
95 @internalComponent |
|
96 */ |
|
97 _LIT(KDbsServerName,"!DBMS server"); |
|
98 _LIT(KDbsServerImg,"EDBSRV"); // DLL/EXE name |
|
99 const TUid KDbsServerUid3={0x100012a5}; |
|
100 |
|
101 |
|
102 /** |
|
103 @internalComponent |
|
104 */ |
|
105 const TInt KDbsExitDelay=4*0x100000; // ~4 seconds |
|
106 const TInt KDbsLeavePanic=~(1<<20); |
|
107 const TInt KTablePolicyMaskBit = 1024; //Used in RDbs::Get<Obj>Policy() methods |
|
108 |
|
109 /** |
|
110 shared classes |
|
111 @internalComponent |
|
112 */ |
|
113 enum TDbsType {EDbsFree,EDbsDatabase,EDbsIncremental,EDbsCursor,EDbsConstraint,EDbsStream,EDbsObserver,EDbsMaxType=EDbsObserver,EDbsSession=EDbsFree}; |
|
114 |
|
115 /** |
|
116 Make sure that KDbsFunc2SecurityPolicyMask array in SD_PolicyProxy.cpp gets updated if |
|
117 new enum items are going to be added to TDbsFunction. |
|
118 @internalComponent |
|
119 */ |
|
120 enum TDbsFunction |
|
121 { |
|
122 // Session functions |
|
123 EDbsResourceMark, //0 |
|
124 EDbsResourceCheck, |
|
125 EDbsResourceCount, |
|
126 EDbsSetHeapFailure, |
|
127 EDbsOpenDatabase, |
|
128 // common functions |
|
129 EDbsClose, |
|
130 // Database functions |
|
131 EDbsDatabaseAuthenticate, //Not used in SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version |
|
132 EDbsDatabaseDestroy, |
|
133 EDbsDatabaseBegin, |
|
134 EDbsDatabaseCommit, |
|
135 EDbsDatabaseRollback, //10 |
|
136 EDbsDatabaseProperty, |
|
137 EDbsDatabaseCreateTable, |
|
138 EDbsDatabaseTables, |
|
139 EDbsDatabaseColumns, |
|
140 EDbsDatabaseIndexes, |
|
141 EDbsDatabaseKeys, |
|
142 EDbsDatabaseOpenObserver, |
|
143 EDbsDatabaseOpenUtility, |
|
144 EDbsDatabaseOpenDropTable, |
|
145 EDbsDatabaseOpenAlterTable, //20 |
|
146 EDbsDatabaseOpenCreateIndex, |
|
147 EDbsDatabaseOpenDropIndex, |
|
148 EDbsDatabaseExecute, |
|
149 EDbsDatabasePrepareView, |
|
150 EDbsDatabaseOpenTable, |
|
151 // Observer functions |
|
152 EDbsObserverNotify, |
|
153 EDbsObserverCancel, |
|
154 // Incremental functions |
|
155 EDbsIncrementalNext, |
|
156 // Cursor functions |
|
157 EDbsCursorColumnTypes, |
|
158 EDbsCursorReset, //30 |
|
159 EDbsCursorEvaluate, |
|
160 EDbsCursorUnevaluated, |
|
161 EDbsCursorSetIndex, |
|
162 EDbsCursorSeek, |
|
163 EDbsCursorAtBeginning, |
|
164 EDbsCursorAtEnd, |
|
165 EDbsCursorAtRow, |
|
166 EDbsCursorCount, |
|
167 EDbsCursorGotoPos, |
|
168 EDbsCursorBookmark, //40 |
|
169 EDbsCursorGotoBookmark, |
|
170 EDbsCursorGet, |
|
171 EDbsCursorInsert, |
|
172 EDbsCursorUpdate, |
|
173 EDbsCursorRetrieveRow, |
|
174 EDbsCursorCancel, |
|
175 EDbsCursorPut, |
|
176 EDbsCursorDelete, |
|
177 EDbsCursorColumns, |
|
178 EDbsCursorColumnDef, //50 |
|
179 EDbsCursorSetNull, |
|
180 EDbsCursorColumnSize, |
|
181 EDbsCursorColumnSource, |
|
182 EDbsCursorColumnSink, |
|
183 EDbsCursorOpenConstraint, |
|
184 EDbsCursorMatch, |
|
185 EDbsCursorFind, |
|
186 // stream functions |
|
187 EDbsStreamRead, |
|
188 EDbsStreamWrite, |
|
189 EDbsStreamSize, //60 |
|
190 EDbsStreamSynch, |
|
191 // Session functions |
|
192 EDbsCreateDatabase, |
|
193 EDbsDatabaseList, |
|
194 EDbsCopyDatabase, |
|
195 EDbsDeleteDatabase, |
|
196 EDbsGetSecurityPolicy, |
|
197 // reserved disk space handling functions |
|
198 EDbsReserveDriveSpace, |
|
199 EDbsFreeReservedSpace, |
|
200 EDbsReserveGetAccess, |
|
201 EDbsReserveReleaseAccess, //70 |
|
202 // |
|
203 EDbsGetBackupPath, |
|
204 EDbsGetBackupPaths, |
|
205 //Insert new functuions here |
|
206 EDbsLast |
|
207 }; |
|
208 |
|
209 /** |
|
210 @internalComponent |
|
211 */ |
|
212 const TInt KDbsTypeBits=4; |
|
213 const TInt KDbsMagicBits=4; |
|
214 const TInt KDbsIndexBits=14; |
|
215 const TInt KDbsFunctionBits=9; |
|
216 const TInt KDbsHandleBits=KDbsTypeBits+KDbsMagicBits+KDbsIndexBits; |
|
217 const TInt KDbsTypeMask=(1<<KDbsTypeBits)-1; |
|
218 const TInt KDbsMagicMask=(1<<KDbsMagicBits)-1; |
|
219 const TInt KDbsHandleMask=(1<<KDbsHandleBits)-1; |
|
220 const TInt KDbsObjectReturn=1<<(KDbsFunctionBits-1); |
|
221 const TInt KDbsIndexLimit=1<<KDbsIndexBits; |
|
222 |
|
223 /** |
|
224 @internalComponent |
|
225 */ |
|
226 #define KDbsSessionHandle DbsSessionHandle() |
|
227 |
|
228 /** |
|
229 @internalComponent |
|
230 */ |
|
231 inline TInt DbsMessage(TInt aFunction,TInt aHandle); |
|
232 inline TDbsFunction DbsFunction(TInt aMessage); |
|
233 inline TInt DbsHandle(TInt aMessage); |
|
234 inline TDbsType DbsType(TInt aHandle); |
|
235 inline TInt DbsMagic(TInt aHandle); |
|
236 inline TInt DbsObjectIndex(TInt aHandle); |
|
237 inline TInt DbsMakeHandle(TInt aIndex,TInt aMagic,TDbsType aType); |
|
238 inline TInt DbsSessionHandle(); |
|
239 |
|
240 #if !defined(_SMALL_BUFFER) |
|
241 /** |
|
242 @internalComponent |
|
243 */ |
|
244 const TInt KDbsStreamBufSize=0x600; // 1.5K |
|
245 const TInt KDbsStreamIoSize=0xc00; // 3K |
|
246 const TInt KDbsColumnTypesSize=0x200; // .5K |
|
247 #else |
|
248 const TInt KDbsStreamBufSize=2; |
|
249 const TInt KDbsStreamIoSize=32; |
|
250 const TInt KDbsColumnTypesSize=2; |
|
251 #endif |
|
252 |
|
253 /** |
|
254 @internalComponent |
|
255 */ |
|
256 class TDbsStreamBuf |
|
257 { |
|
258 public: |
|
259 enum {ESize=KDbsStreamBufSize}; |
|
260 public: |
|
261 TInt iExt; |
|
262 TUint8 iData[ESize]; |
|
263 }; |
|
264 |
|
265 /** |
|
266 @internalComponent |
|
267 */ |
|
268 class TDbsColumns |
|
269 { |
|
270 public: |
|
271 enum {EMax=KDbsColumnTypesSize}; |
|
272 public: |
|
273 TInt iCount; |
|
274 TUint8 iData[EMax]; |
|
275 }; |
|
276 |
|
277 /** |
|
278 client side classes |
|
279 @internalComponent |
|
280 */ |
|
281 class TDbsParam |
|
282 { |
|
283 public: |
|
284 inline void operator=(const TDesC8& aDes); |
|
285 inline void operator=(const TDesC16& aDes); |
|
286 inline void operator=(TInt aVal); |
|
287 // |
|
288 static TPtrC8 PrepareLC(const CDbColSet& aColSet); |
|
289 static TPtrC8 PrepareLC(const CDbKey& aKey); |
|
290 static TPtrC8 PrepareLC(const TDbLookupKey& aKey); |
|
291 |
|
292 private: |
|
293 union |
|
294 { |
|
295 const TAny* iPtr; |
|
296 TInt iInt; |
|
297 }; |
|
298 }; |
|
299 |
|
300 /** |
|
301 @internalComponent |
|
302 */ |
|
303 typedef TDbsParam TDbsMessage[4]; |
|
304 |
|
305 /** |
|
306 @internalComponent |
|
307 */ |
|
308 class RDbsObject : private RDbs |
|
309 { |
|
310 public: |
|
311 inline RDbsObject(); |
|
312 inline void OpenL(const RDbsObject& aDbs,TDbsFunction aFunction); |
|
313 inline void OpenL(const RDbsObject& aDbs,TDbsFunction aFunction,const TIpcArgs& aArgs); |
|
314 inline void OpenL(const RDbs& aDbs,TDbsFunction aFunction,const TIpcArgs& aArgs); |
|
315 void Close(); |
|
316 // |
|
317 inline TInt Handle() const; |
|
318 // |
|
319 TInt SendReceive(TDbsFunction aFunction) const; |
|
320 inline TInt SendReceive(TDbsFunction aFunction,const TIpcArgs& aArgs) const; |
|
321 TInt SendReceiveL(TDbsFunction aFunction) const; |
|
322 inline TInt SendReceiveL(TDbsFunction aFunction,const TIpcArgs& aArgs) const; |
|
323 inline void SendReceive(TDbsFunction aFunction,TRequestStatus& aStatus) const; |
|
324 inline void SendReceive(TDbsFunction aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus) const; |
|
325 private: |
|
326 inline RDbsObject(const RDbs& aDbs); |
|
327 void SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs,TRequestStatus& aStatus) const; |
|
328 TInt SendReceive(TDbsFunction aFunction,const TIpcArgs* aArgs) const; |
|
329 TInt SendReceiveL(TDbsFunction aFunction,const TIpcArgs* aArgs) const; |
|
330 void OpenL(const RDbsObject& aDbs,TDbsFunction aFunction,const TIpcArgs* aArgs); |
|
331 private: |
|
332 TInt iHandle; |
|
333 }; |
|
334 |
|
335 /** |
|
336 @internalComponent |
|
337 */ |
|
338 NONSHARABLE_CLASS(CDbsDatabase) : public CDbDatabase |
|
339 { |
|
340 friend class CDbsSecureDatabase; |
|
341 public: |
|
342 static CDbsDatabase* NewL(const RDbs& aDbs,const TDesC& aDatabase,const TDesC& aFormat); |
|
343 ~CDbsDatabase(); |
|
344 // |
|
345 private: |
|
346 inline CDbsDatabase(); |
|
347 void ConstructL(const RDbs& aDbs,TIpcArgs& aArgs); |
|
348 // from CDbDatabase |
|
349 TInt Destroy(); |
|
350 TInt Begin(); |
|
351 TInt Commit(); |
|
352 void Rollback(); |
|
353 TInt Property(TProperty aProperty); |
|
354 void CreateTableL(const TDesC& aName,const CDbColSet& aColSet,const CDbKey* aPrimaryKey); |
|
355 void TablesL(CDbTableNames& aNames); |
|
356 void ColumnsL(CDbColSet& aColSet,const TDesC& aName); |
|
357 void IndexesL(CDbIndexNames& aNames,const TDesC& aTable); |
|
358 void KeysL(CDbKey& aKey,const TDesC& aName,const TDesC& aTable); |
|
359 CDbNotifier* OpenNotifierL(); |
|
360 CDbIncremental* OpenUtilityL(TUtility aType,TInt& aStep); |
|
361 CDbIncremental* OpenCompactL(TInt& aStep); |
|
362 CDbIncremental* OpenRecoverL(TInt& aStep); |
|
363 CDbIncremental* OpenDropTableL(const TDesC& aTable,TInt& aStep); |
|
364 CDbIncremental* OpenAlterTableL(const TDesC& aTable,const CDbColSet& aNewDef,TInt& aStep); |
|
365 CDbIncremental* OpenCreateIndexL(const TDesC& aName,const TDesC& aTable,const CDbKey& aKey,TInt& aStep); |
|
366 CDbIncremental* OpenDropIndexL(const TDesC& aName,const TDesC& aTable,TInt& aStep); |
|
367 CDbIncremental* OpenExecuteL(const TDesC& aSql,TDbTextComparison aComparison,TInt& aInit); |
|
368 CDbCursor* PrepareViewL(const TDbQuery& aQuery,const TDbWindow& aWindow,RDbRowSet::TAccess anAccess); |
|
369 CDbCursor* OpenTableL(const TDesC& aName,RDbRowSet::TAccess anAccess); |
|
370 private: |
|
371 RDbsObject iObject; |
|
372 }; |
|
373 |
|
374 //Secure shared database |
|
375 NONSHARABLE_CLASS(CDbsSecureDatabase) : public CDbsDatabase |
|
376 { |
|
377 public: |
|
378 static CDbsSecureDatabase* NewL(const RDbs& aDbs,const TDesC& aDatabase,const TDesC& aFormat); |
|
379 virtual ~CDbsSecureDatabase(); |
|
380 |
|
381 private: |
|
382 inline CDbsSecureDatabase(); |
|
383 void ConstructL(const RDbs& aDbs,TIpcArgs& aArgs); |
|
384 |
|
385 }; |
|
386 |
|
387 /** |
|
388 @internalComponent |
|
389 */ |
|
390 NONSHARABLE_CLASS(CDbsNotifier) : public CDbNotifier |
|
391 { |
|
392 public: |
|
393 static CDbsNotifier* NewL(const RDbsObject& aDatabase); |
|
394 private: |
|
395 inline CDbsNotifier(); |
|
396 ~CDbsNotifier(); |
|
397 // from CDbObserver |
|
398 void Notify(TType aEvent,TRequestStatus& aStatus); |
|
399 void Cancel(); |
|
400 private: |
|
401 RDbsObject iObject; |
|
402 }; |
|
403 |
|
404 /** |
|
405 @internalComponent |
|
406 */ |
|
407 NONSHARABLE_CLASS(CDbsIncremental) : public CDbAsyncIncremental |
|
408 { |
|
409 public: |
|
410 static CDbsIncremental* NewL(const RDbsObject& aDbs,TDbsFunction aFunction,TIpcArgs& aArgs,TInt& aStep); |
|
411 ~CDbsIncremental(); |
|
412 private: |
|
413 inline CDbsIncremental(); |
|
414 // from CDbAsyncIncremental |
|
415 void Next(TPckgBuf<TInt>& aStep,TRequestStatus& aStatus); |
|
416 private: |
|
417 RDbsObject iObject; |
|
418 }; |
|
419 |
|
420 /** |
|
421 @internalComponent |
|
422 */ |
|
423 NONSHARABLE_CLASS(CDbsCursor) : public CDbCursor |
|
424 { |
|
425 public: |
|
426 static CDbsCursor* NewL(const RDbsObject& aDbs,TDbsFunction aFunction,TIpcArgs& aArgs); |
|
427 ~CDbsCursor(); |
|
428 private: |
|
429 CDbsCursor(); |
|
430 void ConstructL(const RDbsObject& aDbs,TDbsFunction aFunction,TIpcArgs& aArgs); |
|
431 // |
|
432 TDbColType Type(TDbColNo aCol) const; |
|
433 void ReplaceBlobL(TDbColumn& aCol); |
|
434 TBool RetrieveL(TDbsFunction aFunction,TInt aArg0=0); |
|
435 // from CDbCursor |
|
436 void Reset(); |
|
437 TBool EvaluateL(); |
|
438 void Evaluate(TRequestStatus& aStatus); |
|
439 TBool Unevaluated(); |
|
440 void SetIndexL(const TDesC* anIndex); |
|
441 TBool SeekL(const TDbLookupKey& aKey,RDbTable::TComparison aComparison); |
|
442 TBool AtBeginning(); |
|
443 TBool AtEnd(); |
|
444 TBool AtRow(); |
|
445 TInt CountL(RDbRowSet::TAccuracy aAccuracy); |
|
446 TBool GotoL(RDbRowSet::TPosition aPosition); |
|
447 void Bookmark(TDbBookmark::TMark& aMark); |
|
448 void GotoL(const TDbBookmark::TMark& aMark); |
|
449 void GetL(); |
|
450 void InsertL(TInsert aClearRow); |
|
451 void UpdateL(); |
|
452 void Cancel(); |
|
453 void PutL(); |
|
454 void DeleteL(); |
|
455 TInt ColumnCount(); |
|
456 void ColumnsL(CDbColSet& aColSet); |
|
457 void ColumnDef(TDbCol& aCol,TDbColNo aColNo); |
|
458 TDbColType ColumnType(TDbColNo aCol); |
|
459 RDbRow* RowBuffer(); |
|
460 TDbColumnC ColumnC(TDbColNo aCol); // non-writeable column |
|
461 TDbColumn Column(TDbColNo aCol); // writeable column |
|
462 void SetNullL(TDbColNo aCol); |
|
463 TInt ColumnSize(TDbColNo aCol); |
|
464 MStreamBuf* ColumnSourceL(TDbColNo aCol); |
|
465 MStreamBuf* ColumnSinkL(TDbColNo aCol); |
|
466 CDbRowConstraint* OpenConstraintL(const TDbQuery& aCriteria); |
|
467 TBool MatchL(CDbRowConstraint& aCursor); |
|
468 TInt FindL(RDbRowSet::TDirection aDirection,const TDbQuery& aCriteria); |
|
469 private: |
|
470 enum TState {EUnknown,EAtBeginning,EAtEnd,EAtRow,ERetrieve,ERead,EWrite}; |
|
471 private: |
|
472 RDbsObject iObject; |
|
473 TState iState; |
|
474 TBool iChangedBlob; |
|
475 HDbsColumns* iColumns; |
|
476 RDbRow iRow; |
|
477 }; |
|
478 |
|
479 /** |
|
480 @internalComponent |
|
481 */ |
|
482 NONSHARABLE_CLASS(CDbsConstraint) : public CDbRowConstraint |
|
483 { |
|
484 friend class CDbsCursor; |
|
485 private: |
|
486 inline CDbsConstraint(); |
|
487 ~CDbsConstraint(); |
|
488 private: |
|
489 RDbsObject iObject; |
|
490 }; |
|
491 |
|
492 /** |
|
493 @internalComponent |
|
494 */ |
|
495 NONSHARABLE_CLASS(HDbsBuf) : public TStreamBuf |
|
496 { |
|
497 public: |
|
498 static HDbsBuf* NewL(const RDbsObject& aObject,TDbsFunction aFunction,TIpcArgs& aArgs); |
|
499 static HDbsBuf* NewLC(const RDbsObject& aObject,TDbsFunction aFunction,TIpcArgs& aArgs); |
|
500 static HDbsBuf* NewLC(const RDbs& aDbSession, TDbsFunction aFunction, TIpcArgs& aArgs); |
|
501 virtual inline ~HDbsBuf(); |
|
502 private: |
|
503 inline HDbsBuf(); |
|
504 void ConstructL(const RDbsObject& aObject,TDbsFunction aFunction,TIpcArgs& aArgs); |
|
505 void ConstructL(const RDbs& aDbSession, TDbsFunction aFunction, TIpcArgs& aArgs); |
|
506 // from TStreamBuf |
|
507 TInt UnderflowL(TInt aMaxLength); |
|
508 void OverflowL(); |
|
509 void DoRelease(); |
|
510 void DoSynchL(); |
|
511 TInt DoReadL(TAny* aPtr,TInt aMaxLength); |
|
512 void DoWriteL(const TAny* aPtr,TInt aLength); |
|
513 TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset); |
|
514 private: |
|
515 inline void SetPos(TRead,TInt aPos); |
|
516 inline void SetPos(TWrite,TInt aPos); |
|
517 inline TInt Pos(TRead) const; |
|
518 inline TInt Pos(TWrite) const; |
|
519 inline TInt MovePos(TRead,TInt anOffset); |
|
520 inline TInt MovePos(TWrite,TInt anOffset); |
|
521 TInt IpcReadL(TAny* aPtr,TInt aMaxLength); |
|
522 void IpcWriteL(const TAny* aPtr,TInt aLength); |
|
523 TInt EndL(); |
|
524 // |
|
525 inline TInt Lag(TRead) const; |
|
526 inline TInt Lag(TWrite) const; |
|
527 inline TInt Mark(TRead) const; |
|
528 inline TInt Mark(TWrite) const; |
|
529 private: |
|
530 RDbsObject iIpc; |
|
531 TInt iRPos; |
|
532 TInt iWPos; |
|
533 TDbsStreamBuf iBuf; |
|
534 }; |
|
535 |
|
536 /** |
|
537 @internalComponent |
|
538 */ |
|
539 NONSHARABLE_CLASS(HDbsReadBuf) : public TMemBuf |
|
540 { |
|
541 public: |
|
542 static HDbsReadBuf* NewL(const TDesC8& aDes); |
|
543 protected: |
|
544 inline HDbsReadBuf(const TDesC8& aDes); |
|
545 void DoRelease(); |
|
546 }; |
|
547 |
|
548 /** |
|
549 @internalComponent |
|
550 */ |
|
551 NONSHARABLE_CLASS(CDbsObserver) : public CActive |
|
552 { |
|
553 public: |
|
554 /** |
|
555 @internalComponent |
|
556 */ |
|
557 class HObserver |
|
558 { |
|
559 friend class CDbsObserver; |
|
560 public: |
|
561 ~HObserver(); |
|
562 void Notify(const RMessage2& aMessage); |
|
563 void Cancel(); |
|
564 private: |
|
565 inline HObserver(); |
|
566 void Complete(TInt aStatus); |
|
567 void Event(TInt aEvent); |
|
568 private: |
|
569 TDblQueLink iLink; |
|
570 TInt iPending; |
|
571 RMessagePtr2 iMessage; |
|
572 }; |
|
573 friend class HObserver; |
|
574 public: |
|
575 static CDbsObserver* NewL(CDbsSource& aSource); |
|
576 static CDbsObserver* Collect(CDbsObserver* aNotifier); |
|
577 HObserver* ObserverL(); |
|
578 private: |
|
579 inline CDbsObserver(CDbsSource& aSource); |
|
580 ~CDbsObserver(); |
|
581 // |
|
582 void Queue(); |
|
583 // from CActive |
|
584 void RunL(); |
|
585 void DoCancel(); |
|
586 private: |
|
587 CDbsSource& iSource; |
|
588 CDbNotifier* iNotifier; |
|
589 TDblQue<HObserver> iQueue; |
|
590 }; |
|
591 |
|
592 /** |
|
593 @internalComponent |
|
594 */ |
|
595 NONSHARABLE_CLASS(CDbsConnection) : public CDbContext |
|
596 { |
|
597 friend class RDbsSources; |
|
598 public: |
|
599 inline CDbsSource& Source() const; |
|
600 static inline const CDbsConnection& Connection(const CDbObject& aObject); |
|
601 static inline CDbsSource& Source(const CDbObject& aObject); |
|
602 private: |
|
603 inline CDbsConnection() {} |
|
604 ~CDbsConnection(); |
|
605 inline void Set(CDbsSource& aSource); |
|
606 private: |
|
607 CDbsSource* iSource; |
|
608 }; |
|
609 |
|
610 /** |
|
611 @internalComponent |
|
612 */ |
|
613 class CDbsDatabaseStub : public CDbObject |
|
614 { |
|
615 public: |
|
616 static CDbsDatabaseStub* NewL(); |
|
617 CDbDatabase* AuthenticateL(); |
|
618 private: |
|
619 inline CDbsDatabaseStub(); |
|
620 }; |
|
621 |
|
622 /** |
|
623 @internalComponent |
|
624 */ |
|
625 NONSHARABLE_CLASS(CDbsSource) : public CBase |
|
626 { |
|
627 friend class CDbsConnection; |
|
628 friend class CDbsObserver; |
|
629 public: |
|
630 static CDbsSource* NewL(RFs& aFs,const TDesC& aSource); |
|
631 // |
|
632 static inline TInt LinkOffset(); |
|
633 TBool Is(const TDesC& aSource) const; |
|
634 // |
|
635 inline CDbSource& Source(); |
|
636 CDbsObserver::HObserver* ObserverL(); |
|
637 private: |
|
638 inline CDbsSource(const TDbFormat& aFormat); |
|
639 ~CDbsSource(); |
|
640 void Closed(); |
|
641 // |
|
642 inline void Open(); |
|
643 void Close(); |
|
644 private: |
|
645 TDblQueLink iLink; |
|
646 HBufC* iName; |
|
647 const TDbFormat& iFormat; |
|
648 TInt iConnections; |
|
649 CDbSource* iSource; |
|
650 CDbsObserver* iObserver; |
|
651 }; |
|
652 |
|
653 /** |
|
654 @internalComponent |
|
655 */ |
|
656 class RDbsSources |
|
657 { |
|
658 private: |
|
659 typedef TDblQueIter<CDbsSource> TIter; |
|
660 public: |
|
661 inline RDbsSources(RDbCache& aCache); |
|
662 inline void Close(); |
|
663 // |
|
664 CDbsConnection* OpenLC(RFs& aFs,const TDesC& aSource,const TDesC& aFormat); |
|
665 private: |
|
666 TDblQue<CDbsSource> iSources; |
|
667 RDbCache iDrivers; |
|
668 }; |
|
669 |
|
670 /** |
|
671 @internalComponent |
|
672 */ |
|
673 NONSHARABLE_CLASS(CDbsServer) : public CServer2 |
|
674 { |
|
675 public: |
|
676 static CDbsServer* NewL(); |
|
677 // |
|
678 inline TDes& Name0(); |
|
679 inline TDes& Name1(); |
|
680 inline TDes& FileName(); |
|
681 inline RDbsSources& Sources(); |
|
682 inline RFs& Fs(); |
|
683 inline RDriveSpaceCol& DriveSpaceCol(); |
|
684 void RemoveSession(); |
|
685 // |
|
686 static CDbsServer* Instance(); |
|
687 void Panic(const TDesC& aCategory,TInt aCode); // .. panic client! |
|
688 |
|
689 inline CPolicyProxy& PolicyProxy() const; |
|
690 inline RDbPropsFactory& DbPropsFactory(); |
|
691 |
|
692 private: |
|
693 inline CDbsServer(); |
|
694 ~CDbsServer(); |
|
695 void ConstructL(); |
|
696 // from CServer |
|
697 CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const; |
|
698 private: |
|
699 enum {ECacheSize=8}; |
|
700 enum {EServerPriority=0}; |
|
701 private: |
|
702 RDbCache iCache; |
|
703 RDbsSources iSources; |
|
704 TDbName iName0; // used for message servicing |
|
705 TDbName iName1; |
|
706 TFileName iFileName; |
|
707 RFs iFs; |
|
708 CPolicyProxy* iPolicyProxy; |
|
709 RDbPropsFactory iDbPropsFactory; |
|
710 RDriveSpaceCol iDriveSpaceCol; |
|
711 }; |
|
712 |
|
713 /** |
|
714 @internalComponent |
|
715 */ |
|
716 NONSHARABLE_CLASS(CDbsSession) : public CSession2 |
|
717 { |
|
718 private: |
|
719 #if !defined(_SMALL_BUFFER) |
|
720 enum {EIndexGranularity=8}; |
|
721 #else |
|
722 enum {EIndexGranularity=1}; |
|
723 #endif |
|
724 struct TEntry |
|
725 { |
|
726 union |
|
727 { |
|
728 TAny* iObject; |
|
729 TInt iNext; |
|
730 }; |
|
731 TUint8 iType; |
|
732 const MPolicy* iPolicy; |
|
733 TUint8 iMagic; |
|
734 public: |
|
735 void Release(); |
|
736 DECLARE_DB_DUMP3(aFile) |
|
737 // |
|
738 inline TDbsType Type() const; |
|
739 inline CDbsDatabaseStub& DatabaseStub(); |
|
740 inline CDbDatabase& Database(); |
|
741 inline CDbIncremental& Incremental(); |
|
742 inline CDbCursor& Cursor(); |
|
743 inline CDbRowConstraint& Constraint(); |
|
744 inline HDbsStream& Stream(); |
|
745 inline CDbsObserver::HObserver& Observer(); |
|
746 }; |
|
747 public: |
|
748 CDbsSession(); |
|
749 virtual ~CDbsSession(); |
|
750 private: |
|
751 //From CSession2 |
|
752 virtual void CreateL(); |
|
753 // from CSession |
|
754 void ServiceL(const RMessage2& aMessage); |
|
755 TInt ExtServiceL(const RMessage2& aMessage, TDbsFunction aDbsFunction); |
|
756 void ServiceError(const RMessage2& aMessage,TInt aError); |
|
757 TInt CountResources(); |
|
758 // |
|
759 inline CDbsServer& Server() const; |
|
760 inline RDbsSources& Sources(); |
|
761 // |
|
762 const TDesC& ReadName0L(TInt aIndex,const RMessage2& aMessage); |
|
763 const TDesC& ReadName1L(TInt aIndex,const RMessage2& aMessage); |
|
764 const TDesC& ReadFileNameL(TInt aIndex, const RMessage2& aMessage); |
|
765 HBufC* ReadHBufLC(TInt aIndex,const RMessage2& aMessage); |
|
766 HBufC8* ReadHBuf8LC(TInt aIndex,const RMessage2& aMessage); |
|
767 CDbColSet* ColSetLC(TInt aIndex,const RMessage2& aMessage); |
|
768 CDbKey* KeyLC(TInt aIndex,const RMessage2& aMessage); |
|
769 TDbLookupKey* LookupKeyLC(TInt aIndex,TInt aSize,const RMessage2& aMessage); |
|
770 CDbObject* DoAuthenticateL(CDbsConnection* aDbsConnection, const RMessage2& aMessage); |
|
771 TInt DoOpenDatabaseL(const RMessage2& aMessage, const TDbProps& aDbProps); |
|
772 |
|
773 TDbProps* ExtractDbPropsLC(const RMessage2& aMessage); |
|
774 TInt OpenDatabaseL(const RMessage2& aMessage); |
|
775 TInt CreateDatabaseL(const RMessage2& aMessage); |
|
776 TInt DoCreateDatabaseL(const RMessage2& aMessage, const TDbProps& aDbProps); |
|
777 void CopyDatabaseL(const RMessage2& aMessage); |
|
778 void DeleteDatabaseL(const RMessage2& aMessage); |
|
779 TInt GetDatabaseListL(const RMessage2& aMessage); |
|
780 void GetSecurityPolicyL(const RMessage2& aMessage); |
|
781 void ReadRowL(RDbRow& aRow,TInt aSize,const RMessage2& aMessage); |
|
782 void PutRowL(CDbCursor& aCursor,const RMessage2& aMessage); |
|
783 TInt WriteRowL(const RDbRow& aRow,const RMessage2& aMessage); |
|
784 TInt RetrieveRowL(CDbCursor& aCursor,const RMessage2& aMessage); |
|
785 TInt NewCursorL(CDbCursor* aCursor,const RMessage2& aMessage,const MPolicy* aTblSecurityPolicy); |
|
786 TInt NewIncrementalL(CDbIncremental* aCursor,TInt& aInit,const RMessage2& aMessage,const MPolicy* aPolicy); |
|
787 TInt NewStreamL(MStreamBuf* aHost,const RMessage2& aMessage,const MPolicy* aPolicy,TInt aExtent=-1); |
|
788 TInt NewStreamL(TAny* aPtr,TExternalizeFunction aExter,const RMessage2& aMessage,const MPolicy* aPolicy); |
|
789 void NewDbEntryL(CDbObject* aDbObject, const TDbPolicyRequest& aDbPolicyRequest, TInt& aDbHandle); |
|
790 |
|
791 #ifdef __DBDUMP__ |
|
792 void Dump(); |
|
793 #endif |
|
794 |
|
795 void ReserveDriveSpaceL(TDriveNumber aDrive); |
|
796 void FreeReservedSpace(TDriveNumber aDrive); |
|
797 void GetReserveAccessL(TDriveNumber aDrive); |
|
798 void ReleaseReserveAccess(TDriveNumber aDrive); |
|
799 |
|
800 void GetBackupPathL(const RMessage2& aMessage); |
|
801 TInt GetBackupPathsL(const RMessage2& aMessage); |
|
802 |
|
803 inline TInt Add(CDbIncremental* aIncremental, const MPolicy* aPolicy); |
|
804 inline TInt Add(CDbCursor* aCursor, const MPolicy* aPolicy); |
|
805 inline TInt Add(CDbRowConstraint* aConstraint, const MPolicy* aPolicy); |
|
806 inline TInt Add(HDbsStream* aStream, const MPolicy* aPolicy); |
|
807 inline TInt Add(CDbsObserver::HObserver* aObserver, const MPolicy* aPolicy); |
|
808 |
|
809 TEntry& Object(TInt aHandle); |
|
810 void AllocL(); |
|
811 TInt DoAdd(TAny* aObject,TDbsType aType, const MPolicy* aPolicy); |
|
812 void Free(TEntry& aEntry); |
|
813 |
|
814 private: |
|
815 TEntry* iIx; |
|
816 TInt iSize; |
|
817 TInt iFree; |
|
818 RMap<TInt, TDbPolicyRequest> iDbPolicyRqColl; |
|
819 CDbsSessDriveSpace* iSessDriveSpace; |
|
820 }; |
|
821 |
|
822 /** |
|
823 @internalComponent |
|
824 */ |
|
825 class HDbsStream |
|
826 { |
|
827 public: |
|
828 inline HDbsStream(MStreamBuf* aHost,TInt aReadPos); |
|
829 inline ~HDbsStream(); |
|
830 // |
|
831 TInt ReadL(const RMessage2& aMessage); |
|
832 void WriteL(const RMessage2& aMessage); |
|
833 inline TInt SizeL(); |
|
834 inline void SynchL(); |
|
835 private: |
|
836 MStreamBuf& iHost; |
|
837 TInt iRPos; |
|
838 TInt iWPos; |
|
839 }; |
|
840 |
|
841 /** |
|
842 @internalComponent |
|
843 */ |
|
844 NONSHARABLE_CLASS(HBufBuf) : public TBufBuf |
|
845 { |
|
846 enum {EGranularity=512}; |
|
847 public: |
|
848 static HBufBuf* NewLC(); |
|
849 private: |
|
850 inline HBufBuf(); |
|
851 virtual inline ~HBufBuf(); |
|
852 void DoRelease(); |
|
853 private: |
|
854 CBufBase* iBuf; |
|
855 }; |
|
856 |
|
857 #include "SD_STD.INL" |
|
858 |
|
859 |
|
860 |