|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef MCSTORAGEMANAGER_H |
|
20 #define MCSTORAGEMANAGER_H |
|
21 |
|
22 #include "ncddatabasestorage.h" |
|
23 #include "ncdstoragebase.h" |
|
24 |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <bamdesca.h> |
|
28 |
|
29 |
|
30 class CNcdStorageBase; |
|
31 |
|
32 |
|
33 |
|
34 class CNcdDbStorageManager : |
|
35 public CNcdStorageBaseListener, |
|
36 public MNcdDatabaseStorage |
|
37 { |
|
38 class CNcdDbStorageManagerData; |
|
39 |
|
40 public: |
|
41 |
|
42 static CNcdDbStorageManager* NewLC( |
|
43 RFs& aFs, |
|
44 const TDesC& aStorageUid, |
|
45 const TDesC& aStorageFolder, |
|
46 const TDesC& aStorageName ); |
|
47 |
|
48 ~CNcdDbStorageManager(); |
|
49 |
|
50 |
|
51 public: // New methods |
|
52 |
|
53 |
|
54 TInt CommitCachedItems(); |
|
55 |
|
56 void RollbackItems(); |
|
57 |
|
58 |
|
59 public: // From MNcdDatabaseStorage |
|
60 |
|
61 |
|
62 /** |
|
63 * Returns ponter to storage item. If storage item doesn't exist |
|
64 * it is created. Ownerhip of the storage item is not transferred |
|
65 * to caller. |
|
66 */ |
|
67 MNcdStorageItem* StorageItemL( const TDesC& aUid, TInt aType ); |
|
68 |
|
69 /** |
|
70 * Gets all storage items from storage. This method doens't create |
|
71 * new items to storage but returns all items being currently stored |
|
72 * to it. |
|
73 * |
|
74 * @param aItems An array where to storage items will be added. |
|
75 */ |
|
76 void StorageItemsL( RPointerArray<MNcdStorageItem>& aItems ); |
|
77 |
|
78 |
|
79 void RemoveItemsL( |
|
80 const RArray<RNcdDatabaseItems>& aDoNotRemoveItems ); |
|
81 |
|
82 |
|
83 /** |
|
84 * Begins transaction into storage. |
|
85 */ |
|
86 void Begin(); |
|
87 |
|
88 /** |
|
89 * Commits changes to storage. |
|
90 */ |
|
91 void CommitL(); |
|
92 |
|
93 /** |
|
94 * Discards changes and restores storage to state it was before |
|
95 * transaction was started. |
|
96 */ |
|
97 void Rollback(); |
|
98 |
|
99 /** |
|
100 * Ensures that given storage item exists in storage. |
|
101 * |
|
102 * NOTE: It is possible that storage item is created and exists |
|
103 * but it is not stored to storage. |
|
104 * |
|
105 * @param aStorageItem The item to be checked |
|
106 * @return Boolean value indicating whether the item exsists in |
|
107 * storage. |
|
108 */ |
|
109 TBool ItemExistsInStorageL( MNcdStorageItem& aStorageItem ); |
|
110 |
|
111 /** |
|
112 * Ensures that given storage item exists in storage. |
|
113 * |
|
114 * NOTE: It is possible that storage item is created and exists |
|
115 * but it is not stored to storage. |
|
116 * |
|
117 * @param aUid Uid of the item to be checked |
|
118 * @param aType Type of the item to be checked |
|
119 * @return Boolean value indicating whether the item exsists in |
|
120 * storage. |
|
121 */ |
|
122 TBool ItemExistsInStorageL( const TDesC& aUid, TInt aType ); |
|
123 |
|
124 |
|
125 /** |
|
126 * Storage UID getter |
|
127 * @return Storage UID |
|
128 */ |
|
129 const TDesC& Uid() const; |
|
130 |
|
131 |
|
132 /** |
|
133 * @see MNcdDatabaseStorage::Size() |
|
134 */ |
|
135 TNcdDatabaseSize Size() const; |
|
136 |
|
137 |
|
138 /** |
|
139 * @see MNcdDatabaseStorage::Compact() |
|
140 */ |
|
141 void Compact(); |
|
142 |
|
143 |
|
144 public: // From CNcdStorageBaseListener |
|
145 |
|
146 void CacheOpened(); |
|
147 |
|
148 void CacheReadyL(); |
|
149 |
|
150 void NotifyRollback(); |
|
151 |
|
152 |
|
153 private: |
|
154 |
|
155 CNcdDbStorageManager(); |
|
156 |
|
157 void ConstructL( |
|
158 RFs& aFs, |
|
159 const TDesC& aStorageUid, |
|
160 const TDesC& aStorageFolder, |
|
161 const TDesC& aStorageName ); |
|
162 |
|
163 |
|
164 private: |
|
165 |
|
166 class CNcdDbStorageManagerData : public CBase |
|
167 { |
|
168 public: |
|
169 |
|
170 CNcdDbStorageManagerData( CNcdDbStorageManager* aRoot ); |
|
171 |
|
172 ~CNcdDbStorageManagerData(); |
|
173 |
|
174 public: |
|
175 |
|
176 void StorageOpened(); |
|
177 |
|
178 |
|
179 void StorageClosedL(); |
|
180 |
|
181 TInt OpenStorages(); |
|
182 |
|
183 void Rollback(); |
|
184 |
|
185 |
|
186 private: |
|
187 |
|
188 CNcdDbStorageManager* iRoot; |
|
189 |
|
190 TInt iOpenStorages; |
|
191 |
|
192 }; |
|
193 |
|
194 |
|
195 private: |
|
196 |
|
197 CNcdDbStorageManagerData* iData; |
|
198 |
|
199 CNcdStorageBase* iStorage; |
|
200 |
|
201 TInt iLocallyOpenCount; |
|
202 |
|
203 TBool iForceOpen; |
|
204 |
|
205 }; |
|
206 |
|
207 |
|
208 #endif |