|
1 // Copyright (c) 2006-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 /** |
|
17 @file |
|
18 @internalTechnology |
|
19 */ |
|
20 |
|
21 #ifndef CMTPHANDLEALLOCATOR_H |
|
22 #define CMTPHANDLEALLOCATOR_H |
|
23 |
|
24 #include <e32base.h> |
|
25 |
|
26 class CMTPObjectStore; |
|
27 /** |
|
28 Defines the handle allocator which centralize the allocation of object handles |
|
29 |
|
30 @internalTechnology |
|
31 |
|
32 */ |
|
33 class CMTPHandleAllocator : public CBase |
|
34 { |
|
35 public: |
|
36 static CMTPHandleAllocator* NewL( CMTPObjectStore& aObjectStore ); |
|
37 ~CMTPHandleAllocator(); |
|
38 |
|
39 TUint32 NextIdL(TUint aDataProviderId); |
|
40 void SetIdL( TUint32 aHandleID, TInt64 aPOUID ); |
|
41 TInt64 NextPOUIDL(); |
|
42 |
|
43 TBool AppendHandleBlockL( TUint aDataProviderId, TUint aNextID, TInt aSpace ); |
|
44 |
|
45 private: |
|
46 CMTPHandleAllocator( CMTPObjectStore& aObjectStore ); |
|
47 void ConstructL(); |
|
48 void ExtendArrayL(TUint aDataProviderId); |
|
49 |
|
50 TUint32 NextIDFromPoolL( TUint aDataProviderId ); |
|
51 |
|
52 /* |
|
53 * Defines the HandleID cache of one data provider. The HandleIDs have been allocated, but now |
|
54 * they are available because the corresponding Object have been deleted or ... |
|
55 * |
|
56 * When the HandleID of one data provider is over flow, we have to search the DB to get the available |
|
57 * HandleIDs that are not registed in DB. |
|
58 * |
|
59 */ |
|
60 class CDPHandleCache : public CBase |
|
61 { |
|
62 public: |
|
63 |
|
64 class THandleBlock |
|
65 { |
|
66 public: |
|
67 THandleBlock( TUint aNextID, TInt aSpace ); |
|
68 public: |
|
69 TUint iNextID; |
|
70 TInt iSpace; |
|
71 }; |
|
72 |
|
73 public: |
|
74 static TInt HanldeCacheOrderFromAscending( const CDPHandleCache& aL, const CDPHandleCache& aR); |
|
75 static TInt HanldeCacheOrderFromKeyAscending( const TUint* aL, const CDPHandleCache& aR); |
|
76 |
|
77 public: |
|
78 static CDPHandleCache* NewLC( TUint aDataProviderId ); |
|
79 |
|
80 ~CDPHandleCache(); |
|
81 |
|
82 TUint32 NextHandleID(); |
|
83 void AppendL( const THandleBlock& aBlock ); |
|
84 |
|
85 inline TUint DPID() const |
|
86 { |
|
87 return iDPID; |
|
88 } |
|
89 |
|
90 inline TBool HasCache() const |
|
91 { |
|
92 return (iBlocks.Count() != 0); |
|
93 } |
|
94 |
|
95 inline TInt BlocksCount() const |
|
96 { |
|
97 return iBlocks.Count(); |
|
98 } |
|
99 |
|
100 static inline TInt MaxNumOfBlocks() |
|
101 { |
|
102 return iNumOfBlocks; |
|
103 } |
|
104 |
|
105 private: |
|
106 CDPHandleCache(TUint aDataProviderId); |
|
107 void ConstructL(); |
|
108 |
|
109 private: |
|
110 /* |
|
111 * The number of blocks |
|
112 */ |
|
113 static const TInt iNumOfBlocks = 10; |
|
114 |
|
115 /* |
|
116 * Data Provider ID |
|
117 */ |
|
118 TUint iDPID; |
|
119 |
|
120 /* |
|
121 * HandleID Blocks |
|
122 */ |
|
123 RArray<THandleBlock> iBlocks; |
|
124 }; |
|
125 |
|
126 private: |
|
127 CMTPObjectStore& iObjectStore; |
|
128 |
|
129 RArray<TUint> iNextIds; |
|
130 |
|
131 TInt64 iNextPOUID; |
|
132 |
|
133 //For ObjectID overflow |
|
134 RPointerArray<CDPHandleCache> iNextIDPool; |
|
135 }; |
|
136 #endif //CMTPHANDLEALLOCATOR_H |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |