|
1 /* |
|
2 * Copyright (c) 2008 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: Used by sessions for handling data related requests |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CPDATA_MANAGER_H |
|
20 #define C_CPDATA_MANAGER_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include "cpstorage.h" |
|
24 |
|
25 // FORWARD DECLARATIONS |
|
26 #ifdef CONTENT_PUBLISHER_DEBUG |
|
27 class CCPDebug; |
|
28 #endif |
|
29 class CLiwMap; |
|
30 class CCPLiwMap; |
|
31 class CCpStorage; |
|
32 class CCPServerSession; |
|
33 class CCPNotificationHandler; |
|
34 class TLiwVariant; |
|
35 |
|
36 /** |
|
37 * Content publisher data manager. |
|
38 * |
|
39 * Used to add, modify and remove data and actions. |
|
40 * @since S60 v5.0 |
|
41 */ |
|
42 class CCPDataManager : public CBase, MCPChangeNotifier |
|
43 { |
|
44 public: |
|
45 // exported |
|
46 |
|
47 /** |
|
48 * C++ destructor |
|
49 */ |
|
50 ~CCPDataManager(); |
|
51 |
|
52 /** |
|
53 * Two-phased constructor. |
|
54 */ |
|
55 static CCPDataManager* NewL( TBool aTBool = EFalse ); |
|
56 |
|
57 /** |
|
58 * Two-phased constructor. |
|
59 */ |
|
60 static CCPDataManager* NewLC( TBool aTBool = EFalse ); |
|
61 |
|
62 /** |
|
63 * Add a new data to database |
|
64 * |
|
65 * @param aData Data to be added. |
|
66 * @return Id of a newly created data item |
|
67 */ |
|
68 TUint AddDataL( CCPLiwMap& aMap ); |
|
69 |
|
70 /** |
|
71 * Data is not added to database. Only notification is send to observers. |
|
72 * |
|
73 * @param aData Data to be added. |
|
74 * @return Id of a newly created data item |
|
75 */ |
|
76 void AddNonPersistentDataL( const CCPLiwMap* aMap ); |
|
77 |
|
78 /** |
|
79 * Fetches data from database |
|
80 * @param aInParamList filter and sorting criteria |
|
81 * @param aOutParamList results |
|
82 */ |
|
83 void GetListL( const CCPLiwMap& aMa, CLiwGenericParamList& aOutParamList ); |
|
84 /** |
|
85 * Fetches action from database |
|
86 * @param aInParamList filter and sorting criteria |
|
87 * @param aOutParamList results |
|
88 * @param aNotificationList change info list (for notifications) |
|
89 * @return KErrNotFound if data was not found |
|
90 */ |
|
91 TInt GetActionL( const CCPLiwMap& aMa, |
|
92 CLiwGenericParamList& aOutParamList, |
|
93 CLiwDefaultList* aNotificationList = NULL ); |
|
94 |
|
95 /** |
|
96 * Fetches all activated publishers |
|
97 * @param aInParamList filter and sorting criteria |
|
98 * @param aOutParamList results |
|
99 */ |
|
100 void GetActivePublishersL( CLiwGenericParamList* aResultList ); |
|
101 |
|
102 /** |
|
103 * Removes data from database |
|
104 * @param aInParamList filter criteria |
|
105 */ |
|
106 void RemoveDataL( const CCPLiwMap& aMa ); |
|
107 |
|
108 /** |
|
109 * Adds observer to database |
|
110 * @param new observer |
|
111 */ |
|
112 void AddObserverL( CCPNotificationHandler* aNotificationHandler ); |
|
113 |
|
114 /** |
|
115 * Removes observer from database |
|
116 * @param aNotificationHandler observer to remove |
|
117 */ |
|
118 void RemoveObserver( CCPNotificationHandler* aNotificationHandler ); |
|
119 |
|
120 // from MCPChangeNotifier |
|
121 /** |
|
122 * @param Map containing change information |
|
123 * @return |
|
124 */ |
|
125 void HandleChangeL( CLiwDefaultList* aListOfMaps ); |
|
126 |
|
127 /** |
|
128 * Close database |
|
129 * @return |
|
130 */ |
|
131 void CloseDatabase(); |
|
132 /** |
|
133 * Open database |
|
134 * @return |
|
135 */ |
|
136 void OpenDatabaseL(); |
|
137 |
|
138 private: |
|
139 // methods |
|
140 |
|
141 /** |
|
142 * Standard C++ constructor. |
|
143 */ |
|
144 CCPDataManager(); |
|
145 |
|
146 /** |
|
147 * Standard 2nd phase constructor. |
|
148 */ |
|
149 void ConstructL( TBool aTBool ); |
|
150 |
|
151 /** |
|
152 * Fetches action bound to provided trigger. |
|
153 * |
|
154 * @param aOutParamList of all actions |
|
155 * @param aMap for found action |
|
156 * @param aTrigger |
|
157 */ |
|
158 void ExtractTriggerL( CLiwGenericParamList& aOutParamList, |
|
159 const CLiwDefaultMap* aMap, const TDesC8& aTrigger ); |
|
160 /** |
|
161 * Sends notifications to observers stored in iNotificationsArray |
|
162 * |
|
163 * @param List of change information |
|
164 * @param index od data item |
|
165 */ |
|
166 void SendNotificationL( CLiwDefaultList* aListOfMaps, TInt aIndex ); |
|
167 |
|
168 /** |
|
169 * Exctracts action from input parameters |
|
170 * |
|
171 * @param aParam for data |
|
172 * @param aAction for action |
|
173 */ |
|
174 void ExtractActionL( const TLiwGenericParam* aParam, RBuf8& aAction ); |
|
175 |
|
176 /** |
|
177 * Fills aOutParamList with parameters for action. |
|
178 * |
|
179 * @param aOutParamList parsed list of items |
|
180 * @param aParamList list of items from data base |
|
181 * @param aActionTrigger action trigger |
|
182 */ |
|
183 void FillActionParamListL( |
|
184 CLiwGenericParamList & aOutParamList, |
|
185 const TLiwGenericParam* aParam, |
|
186 RBuf8 & aActionTrigger); |
|
187 |
|
188 /** |
|
189 * Creates map for GetList request - publisher, content_type |
|
190 * and content_id are copied from aMap to returned map |
|
191 * @param aMap - input map |
|
192 * @return input map for GetList request |
|
193 */ |
|
194 CCPLiwMap* CreateMapForGetlistLC( const CCPLiwMap& aMap ); |
|
195 |
|
196 |
|
197 /** |
|
198 * Gets Flag for specified item from DB and returns activate |
|
199 * info |
|
200 * @param aMap - input map |
|
201 * @return activate flag |
|
202 */ |
|
203 TBool GetActivateInfoL( const CCPLiwMap* aMap ); |
|
204 |
|
205 /** |
|
206 * Builds change info list based on query result to database |
|
207 * @param aMap - map containing parameters needed to build change info list |
|
208 * @param aParam - param from getlist result |
|
209 * @param aChangeInfoList - output list containing change info list sent |
|
210 * as notification |
|
211 */ |
|
212 void BuildChangeInfoL( |
|
213 const CCPLiwMap* aMap, |
|
214 const TLiwGenericParam* aParam, |
|
215 CLiwDefaultList* aChangeInfoList ); |
|
216 /** |
|
217 * Builds change info list when query to database returned nothing |
|
218 * @param aMap - map containing parameters needed to build change info list |
|
219 * @param aChangeInfoList - output list containing change info list sent |
|
220 * as notification |
|
221 */ |
|
222 void BuildDefaultChangeInfoL( |
|
223 const CCPLiwMap* aMap, |
|
224 CLiwDefaultList* aChangeInfoList ); |
|
225 /** |
|
226 * Builds change info list when query to database returned nothing |
|
227 * @param aMap - map containing parameters needed to build change info list |
|
228 * @param aChangeInfoList - output list containing change info list sent |
|
229 * as notification |
|
230 */ |
|
231 void BuildChangeInfoForAddL( |
|
232 const CCPLiwMap* aMap, |
|
233 CLiwDefaultList* aChangeInfoList ); |
|
234 |
|
235 /** |
|
236 * Copies variant from in to out map if entry with provided key exists |
|
237 * @param aKey a key |
|
238 * @param aInMap input map |
|
239 * @param aOutMap output map |
|
240 */ |
|
241 void CopyVariantL(const TDesC8& aKey, const CLiwMap* aInMap, |
|
242 CLiwDefaultMap* aOutMap ); |
|
243 |
|
244 /** |
|
245 * Copies variant from in map for key KActionTrigger to out map with key KActionTrigger16 |
|
246 * and formated type(from TDesC8 to TDesC) |
|
247 * @param aInMap input map |
|
248 * @param aOutMap output map |
|
249 */ |
|
250 void CopyActionTrigger16L( const CLiwMap* aInMap, |
|
251 CLiwDefaultMap* aOutMap ); |
|
252 |
|
253 private: |
|
254 // data |
|
255 |
|
256 /* |
|
257 * Storage database |
|
258 * Own. |
|
259 */ |
|
260 CCpStorage* iStorage; |
|
261 |
|
262 /* |
|
263 * Array of registered notification handlers. |
|
264 * Own. |
|
265 */ |
|
266 RPointerArray<CCPNotificationHandler> iNotificationsArray; |
|
267 |
|
268 #ifdef CONTENT_PUBLISHER_DEBUG |
|
269 CCPDebug* iDebug; |
|
270 #endif |
|
271 }; |
|
272 |
|
273 #endif // C_CPDATA_MANAGER_H |
|
274 // end of file |