|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef PUSHDATACONTAINER_H |
|
20 #define PUSHDATACONTAINER_H |
|
21 |
|
22 #include <memory> |
|
23 #include <map> |
|
24 #include <set> |
|
25 #include "pushregdata.h" |
|
26 #include "javastorage.h" |
|
27 #include "javauid.h" |
|
28 #include "pushdbhandler.h" |
|
29 |
|
30 namespace java |
|
31 { |
|
32 namespace captain |
|
33 { |
|
34 class CoreInterface; |
|
35 } |
|
36 namespace push |
|
37 { |
|
38 |
|
39 class PushDBHandler; |
|
40 |
|
41 /** |
|
42 * This is internal class used by PushDataContainer class. |
|
43 */ |
|
44 class PushRegistrationData |
|
45 { |
|
46 public: |
|
47 |
|
48 enum RegistrationType_t {DYNAMIC_REG = 0,STATIC_REG = 1}; |
|
49 |
|
50 PushRegistrationData(const std::wstring& aUri,const std::wstring& aMidletClass, |
|
51 const std::wstring& aFilter,RegistrationType_t aType) |
|
52 : mUri(aUri),mMidletClass(aMidletClass),mFilter(aFilter),mType(aType), |
|
53 mPendingStatus(false) {} |
|
54 |
|
55 virtual ~PushRegistrationData() {} |
|
56 |
|
57 PushRegistrationData &operator=(const PushRegistrationData &x) |
|
58 { |
|
59 mUri = x.mUri; |
|
60 mMidletClass = x.mMidletClass; |
|
61 mFilter = x.mFilter; |
|
62 mType = x.mType; |
|
63 mPendingStatus = x.mPendingStatus; |
|
64 return *this; |
|
65 } |
|
66 |
|
67 PushRegistrationData(const PushRegistrationData& x) |
|
68 { |
|
69 *this = x; |
|
70 } |
|
71 |
|
72 std::wstring mUri; |
|
73 std::wstring mMidletClass; |
|
74 std::wstring mFilter; |
|
75 RegistrationType_t mType; |
|
76 //true' means that message has arrived to the connection. |
|
77 //'false' means that application has started to handle arrived msg of the push connection |
|
78 // or msg has not been arrived to the connection. |
|
79 bool mPendingStatus; |
|
80 |
|
81 }; |
|
82 |
|
83 class PushRegistrationDataWithUid |
|
84 { |
|
85 public: |
|
86 |
|
87 //This class does not take ownership of the aData argument. |
|
88 PushRegistrationDataWithUid(const java::util::Uid& aUid, |
|
89 PushRegistrationData* aData) |
|
90 : mUid(aUid),mPushRegData(aData) {} |
|
91 |
|
92 virtual ~PushRegistrationDataWithUid() {} |
|
93 |
|
94 PushRegistrationDataWithUid &operator=(const PushRegistrationDataWithUid &x) |
|
95 { |
|
96 mUid = x.mUid; |
|
97 mPushRegData = x.mPushRegData; |
|
98 return *this; |
|
99 } |
|
100 |
|
101 PushRegistrationDataWithUid(const PushRegistrationDataWithUid& x) |
|
102 { |
|
103 *this = x; |
|
104 } |
|
105 |
|
106 //MIDlet's uid. |
|
107 java::util::Uid mUid; |
|
108 PushRegistrationData* mPushRegData; |
|
109 }; |
|
110 |
|
111 /** |
|
112 * This class manages push registrations in the Java Captain process. |
|
113 * This class reads all push registrations from the Java Storage and caches |
|
114 * push registrations. Dynamic puush registrations can be register/unregister |
|
115 * via this class. |
|
116 */ |
|
117 |
|
118 class PushDataContainer |
|
119 { |
|
120 public: |
|
121 |
|
122 PushDataContainer(java::captain::CoreInterface& aCore, |
|
123 PushDBHandler& aDbHandler); |
|
124 |
|
125 virtual ~PushDataContainer(); |
|
126 |
|
127 void getIdsOfMidlets(std::set<java::util::Uid>& aUidList); |
|
128 |
|
129 /** |
|
130 * Informs whether MIDlet has push registrations. |
|
131 * @param aUid UID of the MIDlet. |
|
132 * @return 'true' if MIDlet has static and/or dynamic push connedction(s). |
|
133 */ |
|
134 bool isPushConnections(const java::util::Uid& aUid); |
|
135 |
|
136 /** |
|
137 * Returns push registrations of the application. |
|
138 * @param aUid UID of the application. |
|
139 * @param aOutputList Output parameter. Contains push registrations of the application. |
|
140 */ |
|
141 void getPushRegsOfMidlet(const java::util::Uid& aUid,std::list<PushRegData>& aOutputList); |
|
142 |
|
143 /** |
|
144 * This operation stores dynamic push registration to the java storage. |
|
145 * @param aUid UID of the MIDlet. |
|
146 * @param aUri Push connection URI. |
|
147 * @param aMidletName Class name of the MIdlet. |
|
148 * @param aFilter Connection URL indicating which senders are allowed to cause |
|
149 * the MIDlet to be launched. |
|
150 * @throws PushException with following error codes: |
|
151 * PUSH_CONNECTION_ALREADY_EXISTS: |
|
152 * Push connection already exists. |
|
153 * DB_ERROR: |
|
154 * Inserting dynamic push connection to the database failed. |
|
155 */ |
|
156 void storeDynamicPushRegistration(const java::util::Uid& aUid,const std::wstring& aUri, |
|
157 const std::wstring& aMidletName, |
|
158 const std::wstring& aFilter); |
|
159 |
|
160 /** |
|
161 * This operation removes dynamic push connection from the MIDlet. |
|
162 * @throws PushException with following error codes: |
|
163 * NOT_DYNAMIC_PUSH_URI: |
|
164 * URI is static push URI. |
|
165 * URI_BELONGS_TO_OTHER_MIDLET: |
|
166 * Push URI is reserved for other MIDlet. |
|
167 * SRV_CONN_NOT_FOUND: |
|
168 * Server connection is not found from the push registry db. |
|
169 * DB_ERROR: |
|
170 * Database error occurred. |
|
171 */ |
|
172 void unregisterDynamicPushRegistration(const java::util::Uid& aUid,const std::wstring& aUri); |
|
173 |
|
174 /** |
|
175 * This method sets MIDlet to the "do not launch" list. This means that MIDlet |
|
176 * is not try to re-launch in the listening until device has booted next time. |
|
177 * This operation does not throw exceptions. |
|
178 * @param aUid UID of the MIDlet. |
|
179 */ |
|
180 void setMidletDoNotLaunchList(const java::util::Uid& aUid); |
|
181 |
|
182 /** |
|
183 * This method removes MIDlet to the "do not launch" list. |
|
184 * This operation does not throw exceptions. |
|
185 * @param aUid UID of the MIDlet. |
|
186 */ |
|
187 void removeMidletFromDoNotLaunchList(const java::util::Uid& aUid); |
|
188 |
|
189 /** |
|
190 * This operation does not throw exceptions. |
|
191 * @return 'true' if MIDlet is not in the "do not launch" list. |
|
192 */ |
|
193 bool isMidletInDoNotLaunchList(const java::util::Uid& aUid); |
|
194 |
|
195 /** |
|
196 * This operation removes application from all containers. |
|
197 */ |
|
198 void removeApp(const java::util::Uid& aUid); |
|
199 |
|
200 /** |
|
201 * This operation reads application's push registrations from the db and adds |
|
202 * those ones into the internal cache. It also removes application from the |
|
203 * 'do not launch in the push listening mode' list. |
|
204 * @param aUid UID of the application. |
|
205 * @throws This operation does not throw exceptions. |
|
206 */ |
|
207 void readAppDataFromDb(const java::util::Uid& aUid); |
|
208 |
|
209 /** |
|
210 * This method updates pending status of the push connection. Pending status is needed |
|
211 * by PushRegistry.listConnections() operation when this operation is called with 'true' |
|
212 * argument. |
|
213 * @param aUid UID of the application. |
|
214 * @param aUri URI of the push connection. |
|
215 * @param aMsgWaitsHandling status flag of push connection. |
|
216 * - 'true' means that message has arrived to the connection. |
|
217 * - 'false' means that application has started to handle arrived msg |
|
218 * of the push connection. |
|
219 * @throws This operation does not throw exceptions. |
|
220 */ |
|
221 void setPendingStatusOfConn(const java::util::Uid& aUid,const std::wstring& aUri, |
|
222 bool aMsgWaitsHandling); |
|
223 |
|
224 /** |
|
225 * Sets pending status of MIDlet's all push connections to "not active". |
|
226 * @param aMidletUid UID of the application. |
|
227 * @throws This operation does not throw exceptions. |
|
228 */ |
|
229 void clearPendingStatusesOfMidlet(const java::util::Uid& aMidletUid); |
|
230 |
|
231 /** |
|
232 * This method returns push connections of all MIDlets' in the MIDlet suite. |
|
233 * @param aMidletSuiteUid MIDlet suite UID. |
|
234 * @param aAllConnsFlag this flag indicates whether only "pending conns" |
|
235 * are returned: |
|
236 * 'true' => all MIDlets' push connections are returned. |
|
237 * 'false' => only push connections which waiting application's handling. |
|
238 * @param listOfPushUris URIs of push connections. |
|
239 * @throws This operation does not throw exceptions. |
|
240 */ |
|
241 void getPushRegsOfMidletSuite(const java::util::Uid& aMidletSuiteUid,bool aAllConnsFlag, |
|
242 std::list<std::wstring>& aListOfPushUris); |
|
243 |
|
244 /** |
|
245 * Returns filter argument of the push registration. |
|
246 * @param aSuiteUid MIDlet suite UID. |
|
247 * @param aUri push URI. |
|
248 * @throws PushException with following error codes: |
|
249 * SRV_CONN_NOT_FOUND: |
|
250 * - Push connection by URI and suite uid is not found. |
|
251 */ |
|
252 const std::wstring& getFilterOfPushConn(const java::util::Uid& aSuiteUid, |
|
253 const std::wstring& aUri); |
|
254 |
|
255 /** |
|
256 * Returns class name of the push registration. |
|
257 * @param aSuiteUid MIDlet suite UID. |
|
258 * @param aUri push URI. |
|
259 * @throws PushException with following error codes: |
|
260 * SRV_CONN_NOT_FOUND: |
|
261 * - Push connection by URI and suite uid is not found. |
|
262 */ |
|
263 const std::wstring& getClassNameOfPushConn(const java::util::Uid& aSuiteUid, |
|
264 const std::wstring& aUri); |
|
265 |
|
266 /** |
|
267 * This operation returns MIDlet's uid. MIDlet is identified by suite uid and |
|
268 * class name of the MIDlet. |
|
269 * @param aSuiteUid MIDlet suite UID. |
|
270 * @param aClassName Class name of the MIDlet. |
|
271 * @throws PushException with following error code: |
|
272 * INCORRECT_APP_DATA: |
|
273 * - aClassName does not match to any MIDlet in the suite. |
|
274 */ |
|
275 const java::util::Uid& getMidletUid(const java::util::Uid& aSuiteUid, |
|
276 const std::wstring& aClassName); |
|
277 |
|
278 |
|
279 /** |
|
280 * This operation returns suite uid of the push connection retrieved by |
|
281 * base URI. Base URI means "starts with" URI in this context. |
|
282 * Comparison is case insensitive and it assumes that URI contains |
|
283 * only us-ascii characters. |
|
284 * E.g. Match occurs if full URI is "socket://:1234?param1=value1" |
|
285 * and base URI is "socket://:1234". |
|
286 * @param aBaseUri "starts with" URI. |
|
287 * @param aOutputSuiteUid Output parameter. Suite uid of the MIDlet. |
|
288 * @return true if aBaseUri argument match to one push connection URI. |
|
289 */ |
|
290 bool getSuiteUidByBaseUri(const std::wstring& aBaseUri,java::util::Uid& aOutputSuiteUid); |
|
291 |
|
292 /** |
|
293 * This operation returns MIDlet's media uid. |
|
294 * @return MIDlet's media id. Returns -2 if MIDlet by uid is not found. |
|
295 * Returns -1 if "is mmc available" check is not needed to do. |
|
296 */ |
|
297 int getMediaIdByMidletUid(const java::util::Uid& aMidletUid); |
|
298 |
|
299 |
|
300 /** |
|
301 * This operation returns list of MIDlet's uids by media id. |
|
302 * @param aMediaId media id of the drive. |
|
303 * @param aUidList Output argument. List of MIDlet's uids installed to the certain drive. |
|
304 * @throws This operation does not throw exceptions. |
|
305 */ |
|
306 void getMidletUidsByMediaId(unsigned int aMediaId,std::list<java::util::Uid>& aUidList); |
|
307 |
|
308 private: |
|
309 |
|
310 //Datamembers. |
|
311 java::captain::CoreInterface& mCore; |
|
312 PushDBHandler& mPushDbHandler; |
|
313 |
|
314 //Container for push registrations. |
|
315 typedef std::multimap<java::util::Uid,PushRegistrationData> PushRegsContainer_t; |
|
316 typedef std::multimap<java::util::Uid,PushRegistrationData>::iterator PushRegsContainerIter_t; |
|
317 PushRegsContainer_t mPushRegistrations; |
|
318 bool mPushRegsLoaded; |
|
319 |
|
320 typedef std::set<java::util::Uid> DoNotLaunchList_t; |
|
321 typedef std::set<java::util::Uid>::iterator DoNotLaunchListIter_t; |
|
322 DoNotLaunchList_t mDoNotLaunchList; |
|
323 |
|
324 //Container for MIDlet suite info. |
|
325 //Uid is reserved for the suite uid. |
|
326 typedef std::multimap<java::util::Uid,MidletSuiteData> MidletSuiteInfoContainer_t; |
|
327 typedef std::multimap<java::util::Uid,MidletSuiteData>::iterator MidletSuiteInfoContainerIter_t; |
|
328 MidletSuiteInfoContainer_t mMidletSuiteInfo; |
|
329 |
|
330 //Internal operations. |
|
331 void loadPushRegs(); |
|
332 void readPushRegs(const java::util::Uid& aUid); |
|
333 void insertPushRegToInternalContainer(java::storage::JavaStorageApplicationList_t::iterator& aIter); |
|
334 bool pushRegExists(const std::wstring& aUri); |
|
335 void fillConnectionsOfMidlet(const java::util::Uid& aMidletUid,bool aAllConnsFlag, |
|
336 std::list<std::wstring>& aListOfPushUris); |
|
337 bool isMidletPartOfSuite(const java::util::Uid& aSuiteUid, |
|
338 const java::util::Uid& aMidletUid); |
|
339 PushRegistrationData* getPushConnOfSuite(const java::util::Uid& aSuiteUid, |
|
340 const std::wstring& aUri); |
|
341 PushRegistrationData* getPushDataByMidletUidAndUri(const java::util::Uid& aMidletUid, |
|
342 const std::wstring& aUri); |
|
343 PushRegistrationDataWithUid getPushDataByUri(const std::wstring& aUri); |
|
344 |
|
345 bool getSuiteUidByMidletUid(const java::util::Uid& aMidletUid, |
|
346 java::util::Uid& aOutputSuiteUid); |
|
347 /** |
|
348 * This operation compares whether aFullUri starts with value of the aBaseUri |
|
349 * argument. Comparison is case insensitive and both URIs can contains only |
|
350 * us-ascii characters. |
|
351 */ |
|
352 bool isUriStartingWith(const std::string& aFullUri,const std::string& aBaseUri); |
|
353 |
|
354 /** |
|
355 * This operation compares whether two chars are equals. |
|
356 * Comparison is case insensitive. |
|
357 */ |
|
358 static bool caseInsensitiveCompare(const char a1,const char a2); |
|
359 |
|
360 //Not implemented. |
|
361 PushDataContainer(const PushDataContainer &x); |
|
362 PushDataContainer &operator=(const PushDataContainer &x); |
|
363 }; |
|
364 |
|
365 }//end namespace push |
|
366 }//end namespace java |
|
367 |
|
368 #endif // PUSHDATACONTAINER_H |