|
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: This header file describes the class that handles the storage |
|
15 * of triggers in database. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef C_LBTCONTAINER_DBTRIGGERS_MANAGER_H |
|
21 #define C_LBTCONTAINER_DBTRIGGERS_MANAGER_H |
|
22 |
|
23 // system includes |
|
24 #include <e32base.h> |
|
25 #include <d32dbms.h> |
|
26 |
|
27 // user includes |
|
28 #include "lbttriggerstoreinterface.h" |
|
29 |
|
30 // forward declaration |
|
31 class CLbtDbOperationAO; |
|
32 class MLbtTriggerStoreObserver; |
|
33 class CLbtContainerFilterBase; |
|
34 |
|
35 /** |
|
36 * This class provides an abstraction to store and retrieve triggers |
|
37 * from a symbian database. |
|
38 * |
|
39 * It internally utilizes the database client side API to store and |
|
40 * retrieve information from the database. It also contians a cache |
|
41 * mechanism to provide for faster access to the information from the |
|
42 * database. |
|
43 */ |
|
44 NONSHARABLE_CLASS( CLbtDbTriggersManager ) : public CActive, |
|
45 public MLbtTriggerStore |
|
46 { |
|
47 enum TDbOperation |
|
48 { |
|
49 EDbOpNone = 0, |
|
50 EDbOpCreateTrigger, |
|
51 EDbOpGetTriggers, |
|
52 EDbOpListTriggers, |
|
53 EDbOpUpdateTrigger, |
|
54 EDbOpUpdateTriggersState, |
|
55 EDbOpUpdateTriggersValidity, |
|
56 EDbOpUpdateTriggers, |
|
57 EDbOpDeleteTriggers |
|
58 }; |
|
59 |
|
60 enum TOperationState |
|
61 { |
|
62 EOpStateNone, |
|
63 EOpStateQuery, |
|
64 EOpStateIterating, |
|
65 EOpCompaction |
|
66 }; |
|
67 |
|
68 public: |
|
69 /** |
|
70 * The Symbian 2 phase constructor. |
|
71 * This method creates a new instance of CLbtDbTriggersManager |
|
72 * |
|
73 * @return An instance of this class |
|
74 */ |
|
75 static CLbtDbTriggersManager* NewL( ); |
|
76 |
|
77 /** |
|
78 * Destructor. |
|
79 */ |
|
80 virtual ~CLbtDbTriggersManager(); |
|
81 |
|
82 /** |
|
83 * This method signals the completion of an asynchronous SQL Query |
|
84 * Operation on the database |
|
85 * @return any symbian error code. |
|
86 */ |
|
87 void DbSqlOperationCompletedL(TInt error); |
|
88 |
|
89 /** |
|
90 * This method signals the completion of an asynchronous |
|
91 * Operation on the database like database compaction or recovery. |
|
92 * @return any symbian error code. |
|
93 */ |
|
94 void DbIncrementalOperationCompleted(TInt error); |
|
95 |
|
96 /** |
|
97 * This method returns the list of triggers modified for a given operation |
|
98 * @param[out] aIdArray Contains the list of triggers modified for a given operation. |
|
99 */ |
|
100 void TriggersModified(RArray<TLbtTriggerModifiedInfo>& aArray); |
|
101 |
|
102 TInt GetCountOfEnabledAndValidTriggers(); |
|
103 |
|
104 protected: // from base class MLbtTriggerStore |
|
105 |
|
106 TTriggerTypeMask SupportedTriggerTypes(); |
|
107 |
|
108 void CreateTriggerL( CLbtContainerTriggerEntry &aEntry, |
|
109 TRequestStatus& aStatus ); |
|
110 |
|
111 void GetTriggersL( RArray<TLbtTriggerId>& aTriggerIds, |
|
112 RPointerArray<CLbtContainerTriggerEntry>& aTriggers, |
|
113 TLbtSecurityPolicy& aSecurityPolicy, |
|
114 TRequestStatus &aStatus ); |
|
115 void ListTriggersL( CLbtContainerListOptions* aFilter, |
|
116 RPointerArray<CLbtContainerTriggerEntry>& aTriggers, |
|
117 TLbtSecurityPolicy& aSecurityPolicy, |
|
118 TRequestStatus &aStatus); |
|
119 |
|
120 void UpdateTriggerL( CLbtContainerTriggerEntry& aEntry, |
|
121 TLbtTriggerDataMask aDataMask, |
|
122 TLbtTriggerAttributeFieldsMask aAttrMask, |
|
123 TLbtSecurityPolicy& aSecurityPolicy, |
|
124 TRequestStatus& aStatus ); |
|
125 |
|
126 void UpdateTriggersStateL( CLbtTriggerEntry::TLbtTriggerState aState, |
|
127 CLbtContainerUpdateFilter* aFilter, |
|
128 TLbtFireOnUpdate aFireOnUpdate, |
|
129 TLbtSecurityPolicy& aSecurityPolicy, |
|
130 TRequestStatus& aStatus); |
|
131 |
|
132 void UpdateTriggersValidityL( TLbtTriggerDynamicInfo::TLbtTriggerValidity aValidity, |
|
133 RArray<TLbtTriggerId>& aTriggerIds, |
|
134 TLbtSecurityPolicy& aSecurityPolicy, |
|
135 TRequestStatus& aStatus); |
|
136 |
|
137 void UpdateTriggerFiredStateL( RArray<TLbtTriggerId>& aTriggerIds, |
|
138 TBool aFireBool, |
|
139 TRequestStatus& aStatus ); |
|
140 |
|
141 void DeleteTriggersL( CLbtContainerUpdateFilter* /*aFilter*/, |
|
142 TLbtSecurityPolicy& aSecurityPolicy, |
|
143 TRequestStatus& /*aStatus*/ ); |
|
144 |
|
145 TBool IsStoreBusy(); |
|
146 |
|
147 void SetStoreChangeObserver(MLbtTriggerStoreObserver* aObserver); |
|
148 TInt CancelCurrentOperation(); |
|
149 |
|
150 private: // From CActive |
|
151 void RunL(); |
|
152 TInt RunError(TInt aError); |
|
153 void DoCancel(); |
|
154 |
|
155 private: // Other private functions |
|
156 CLbtContainerTriggerEntry* RetrieveTriggerEntryFromDbL( RDbView& aMainView ); |
|
157 void DeleteTriggerL(TLbtTriggerId aTriggerId); |
|
158 void AppendTriggerInfo(CLbtContainerTriggerEntry* aEntry); |
|
159 void SetTimeTillCompaction(TTime aTime); |
|
160 void RemoveTriggerConditionFromDb( TLbtTriggerId aTriggerId, |
|
161 CLbtGeoAreaBase::TGeoAreaType aAreaType ); |
|
162 void AddGeoCellIntoDbL( CLbtTriggerEntry* aTriggerEntry ); |
|
163 void AddGeoCircleIntoDbL( CLbtTriggerEntry* aTriggerEntry ); |
|
164 void AddGeoHybridIntoDbL( CLbtTriggerEntry* aTriggerEntry ); |
|
165 void SelfComplete(); |
|
166 |
|
167 private: // All active asynch operation handlers |
|
168 /** |
|
169 * Handles trigger creation async event |
|
170 */ |
|
171 void HandleTriggerCreationEventL(); |
|
172 void HandleTriggersDeletionEventL(); |
|
173 void HandleListTriggersEventL(); |
|
174 void HandleTriggerStateUpdationEventL(); |
|
175 void HandleTriggerUpdationEventL(); |
|
176 void HandleGetTriggersEventL(); |
|
177 |
|
178 private: |
|
179 /** |
|
180 * C++ constructor |
|
181 */ |
|
182 CLbtDbTriggersManager(); |
|
183 |
|
184 /** |
|
185 * Symbian 2nd phase of construction |
|
186 */ |
|
187 void ConstructL(); |
|
188 |
|
189 /** |
|
190 * C++ Copy Constructor |
|
191 * The private copy constructor prevents the usage of copy constructors |
|
192 * with this class. |
|
193 */ |
|
194 CLbtDbTriggersManager(const CLbtDbTriggersManager& aDbTriggersManager); |
|
195 |
|
196 /** |
|
197 * Overload equality operator |
|
198 * The private overload of the equality operator prevents the usage of |
|
199 * equality operator with this class. |
|
200 */ |
|
201 CLbtDbTriggersManager& operator =( |
|
202 const CLbtDbTriggersManager& aDbTriggersManager); |
|
203 |
|
204 /** |
|
205 * Create the Table in the Database |
|
206 */ |
|
207 void CreateTablesInDbL(); |
|
208 |
|
209 /** |
|
210 * Helper method to create a trigger entry in the Db View |
|
211 */ |
|
212 void CreateTriggerInViewL(); |
|
213 |
|
214 void ProcessListTriggers( CLbtContainerTriggerEntry* aEntry, |
|
215 TLbtTriggerAttributeFieldsMask aAttrMask, |
|
216 TLbtTriggerDynamicInfoFieldsMask aDynInfoMask, |
|
217 TLbtTriggerDataMask aDataMask ); |
|
218 |
|
219 /** |
|
220 * Checks if the DB requires compaction and does the compaction |
|
221 */ |
|
222 void CompactDbIfRequiredL(); |
|
223 |
|
224 /** |
|
225 * |
|
226 */ |
|
227 void CompleteClientRequest( TInt aError ); |
|
228 |
|
229 /** |
|
230 * |
|
231 */ |
|
232 void ResetCurrentStates(); |
|
233 |
|
234 /** |
|
235 * Prepares view for list operation. The view is prepared |
|
236 * such that all the tuples required for the list operation |
|
237 * is prepared |
|
238 */ |
|
239 void PrepareViewForListingL( RDbView& aView ); |
|
240 |
|
241 /** |
|
242 * Prepare view for the common db such that only the tuples that |
|
243 * match the trigger ids supplied are present in the view. |
|
244 */ |
|
245 void PrepareViewForTriggersL( const RArray<TLbtTriggerId>& aTriggerIds, RDbView& aView ); |
|
246 |
|
247 /** |
|
248 * |
|
249 */ |
|
250 TInt AsyncPrepareViewForTriggers( const RArray<TLbtTriggerId>& aTriggerIds, RDbView& aView ); |
|
251 |
|
252 /** |
|
253 * Prepares the main view for creation of a trigger |
|
254 */ |
|
255 TInt AsyncPrepareViewOfCommonTable(); |
|
256 |
|
257 /** |
|
258 * Checks if the filter supplied matches the type of triggers stored in |
|
259 * the database |
|
260 * |
|
261 * @return ETrue if the filter matches for DB, EFalse otherwise |
|
262 */ |
|
263 TBool IsFilterForDBTriggersL( CLbtTriggerFilterBase* aFilter ); |
|
264 |
|
265 /** |
|
266 * Creates Cell triggers table in DB |
|
267 */ |
|
268 void CreateCellTriggersTableL( ); |
|
269 |
|
270 /** |
|
271 * Creates Co-ordinate triggers table in DB |
|
272 */ |
|
273 void CreateCoordinateTriggersTableL(); |
|
274 |
|
275 /** |
|
276 * Creates triggers common attribute table in DB |
|
277 */ |
|
278 void CreateCommonTriggerAttributesTableL(); |
|
279 /** |
|
280 * Creates triggers common attribute table in DB |
|
281 */ |
|
282 void CreateHybridTriggersTableL(); |
|
283 |
|
284 private: |
|
285 // File Server Client Side handle |
|
286 RFs iFs; |
|
287 |
|
288 // The Database Handle |
|
289 RDbNamedDatabase iDb; |
|
290 |
|
291 // The operation executioner |
|
292 CLbtDbOperationAO* iDbOperation; |
|
293 |
|
294 // SQL query to be executed |
|
295 HBufC* iSqlQuery; |
|
296 |
|
297 /** The current operation being executed */ |
|
298 TDbOperation iCurrentOperation; |
|
299 |
|
300 // The state of the current operation being handled |
|
301 TOperationState iOperationState; |
|
302 |
|
303 /** |
|
304 * The Database view which provides the interface to execute |
|
305 * the db operations |
|
306 */ |
|
307 RDbView iView; |
|
308 |
|
309 /** |
|
310 * The trigger entry on which the create trigger operation is performed. |
|
311 * This object is not owned by container and should NOT BE deleted by |
|
312 * container |
|
313 */ |
|
314 CLbtContainerTriggerEntry* iEntry; |
|
315 |
|
316 /** The status variable used for a create trigger request */ |
|
317 TRequestStatus* iClientReqStatus; |
|
318 |
|
319 /** |
|
320 * Pointer to CLbtContainerListOptions used in List Triggers operation |
|
321 * This is a reference parameter and is valid only when the |
|
322 * List Triggers operation is being executed. |
|
323 * Db Triggers Manager should NEVER DELETE this member variable. |
|
324 */ |
|
325 CLbtContainerListOptions* iFilter; |
|
326 |
|
327 /** |
|
328 * Owned by container |
|
329 */ |
|
330 CLbtContainerFilterBase* iFilterBase; |
|
331 |
|
332 /** |
|
333 * |
|
334 */ |
|
335 TLbtSecurityPolicy iClientSecurityPolicy; |
|
336 |
|
337 /** |
|
338 * Pointer to array of CLbtContainerTriggerEntry. |
|
339 * This is a reference to the array which is filled up |
|
340 * with the triggers to be returned to CLbtContainer class. |
|
341 * This object should not NEVER BE deleted by container |
|
342 */ |
|
343 RPointerArray<CLbtContainerTriggerEntry>* iTriggers; |
|
344 |
|
345 // Array to hold of list of trigger ids modified by an operation |
|
346 RArray<TLbtTriggerModifiedInfo> iIdArray; |
|
347 |
|
348 // Count of enabled and valid trigger in the db |
|
349 TInt iCountOfEnabledAndValidTrigger; |
|
350 |
|
351 // The time which can be provided untill compaction can proceed |
|
352 TTime iTimeTillCompaction; |
|
353 |
|
354 // Refernce to trigger store observer |
|
355 MLbtTriggerStoreObserver* iObserver; |
|
356 |
|
357 // Flag to check if the db has been opened successfully |
|
358 TBool iIsDbOpened; |
|
359 |
|
360 //It is used to store new state of the trigger to be modified. |
|
361 // It is used in RunL to do the actual modification |
|
362 CLbtTriggerEntry::TLbtTriggerState iState; |
|
363 |
|
364 //It is used to store new fireonupdate flag of the trigger to be modified. |
|
365 // It is used in RunL to do the actual modification. |
|
366 TLbtFireOnUpdate iFireOnUpdate; |
|
367 |
|
368 // It is used to store datamask of trigger to be modified. |
|
369 // It is used in RunL to do the actual modification of trigger. |
|
370 TLbtTriggerDataMask iDataMask; |
|
371 |
|
372 // It is used to store attrmask of trigger to be modified. |
|
373 // It is used in RunL to do the actual modification. |
|
374 TLbtTriggerAttributeFieldsMask iAttrMask; |
|
375 |
|
376 // It is used to store id of triggers to be retrived. |
|
377 // It is used in RunL to do the actual modification. |
|
378 RArray<TLbtTriggerId>* iTriggerIds; |
|
379 }; |
|
380 |
|
381 |
|
382 #endif // C_LBTCONTAINER_DBTRIGGERS_MANAGER_H |