|
1 /* |
|
2 * Copyright (c) 2007, 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: Header file for Presence Cache Server session |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef PRESENCECACHESESSION_H |
|
20 #define PRESENCECACHESESSION_H |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <e32base.h> |
|
24 |
|
25 #include "presencecachedefs.h" |
|
26 |
|
27 /** |
|
28 * Presence cache server session class. |
|
29 * @ingroup ximpprescacheserver |
|
30 * @since S60 v3.2 |
|
31 */ |
|
32 // FORWARD DECLARATIONS |
|
33 class CPresenceCacheServer; |
|
34 class MPresenceInfo; |
|
35 class MPresenceBuddyInfo; |
|
36 class CPresenceBuddyInfoListImp; |
|
37 class CPresenceBuddyInfoImp; |
|
38 class CCacheSessionActiveHelper; |
|
39 class CPresenceCacheBuddyStore; |
|
40 |
|
41 //Include Cache server namespace |
|
42 using namespace NCacheSrv; |
|
43 |
|
44 class CPresenceCacheSession : public CSession2 |
|
45 { |
|
46 friend class CCacheSessionActiveHelper; |
|
47 public: // Constructors and destructors |
|
48 |
|
49 /** |
|
50 * Two-phased constructor. |
|
51 * @param aServer The server. |
|
52 * @return Pointer to created CPresenceCacheSession object. |
|
53 */ |
|
54 static CPresenceCacheSession* NewL( CPresenceCacheServer& aServer ); |
|
55 |
|
56 /** |
|
57 * Two-phased constructor. |
|
58 * @param aServer The server. |
|
59 * @return Pointer to created CPresenceCacheSession object. |
|
60 */ |
|
61 static CPresenceCacheSession* NewLC( CPresenceCacheServer& aServer ); |
|
62 |
|
63 /** |
|
64 * ~CPresenceCacheSession. |
|
65 * Destructor. |
|
66 */ |
|
67 virtual ~CPresenceCacheSession(); |
|
68 |
|
69 public: // Functions from base classes |
|
70 |
|
71 /** |
|
72 * From CSession |
|
73 */ |
|
74 void ServiceL( const RMessage2& aMessage ); |
|
75 |
|
76 public: // own |
|
77 |
|
78 /** |
|
79 * This is called by some other session to inform this session that given |
|
80 * buddy's presence has been changed. The informing session first make |
|
81 * sure that this session has subscribed for the changes in given buddy. |
|
82 * |
|
83 *@param pointer to CPresenceBuddyInfoImp, ownership doesnt transfer. |
|
84 */ |
|
85 void NotifyPresenceChangeL(const CPresenceBuddyInfoImp* aPresenceBuddyInfo); |
|
86 |
|
87 private: // Constructors and destructors |
|
88 |
|
89 /** |
|
90 * C++ default constructor. |
|
91 * @param aServer The server. |
|
92 */ |
|
93 CPresenceCacheSession( CPresenceCacheServer& aServer ); |
|
94 |
|
95 /** |
|
96 * Construct. |
|
97 * 2nd phase constructor |
|
98 */ |
|
99 void ConstructL(); |
|
100 |
|
101 private: // New methods |
|
102 |
|
103 /** |
|
104 * Packs PresenceInfo object into a data packet. |
|
105 * @param aPresInfo PresenceInfo object. |
|
106 * @return HBufC* data packet. |
|
107 */ |
|
108 HBufC8* PackPresenceInfoLC(const MPresenceInfo& aPresInfo); |
|
109 |
|
110 /** |
|
111 * Cancels the async request, this is called by docancel of active helper |
|
112 */ |
|
113 void Cancel(); |
|
114 |
|
115 /** |
|
116 * Tries writing given buddy to presence cache |
|
117 * @param aBuddyPresInfo object to write. |
|
118 * @return TInt error code |
|
119 */ |
|
120 TInt TryWriteBuddyToCacheL(MPresenceBuddyInfo* aBuddyPresInfo); |
|
121 |
|
122 /** |
|
123 * Packs services array |
|
124 * |
|
125 * @param CArrayFixFlat aArray |
|
126 * @return packed object |
|
127 */ |
|
128 //HBufC8* PackServicesL(CArrayFixFlat<TUid>* aArray ); |
|
129 |
|
130 /** |
|
131 * Removes all subscriptions stored by this session in iSubscribedStores |
|
132 */ |
|
133 void RemoveMySubscriptions(); |
|
134 |
|
135 /** |
|
136 * Notify to subscribers in given buddy store's presence change. This method |
|
137 * goes through all subscribed sessions and call their NotifyPresenceChangeL |
|
138 * methods. Ownership of store is not transferred. |
|
139 * |
|
140 * @param aBuddyStore pointer to changed CPresenceCacheBuddyStore |
|
141 */ |
|
142 void NotifyAllSubscribersL(CPresenceCacheBuddyStore* aBuddyStore); |
|
143 |
|
144 /** |
|
145 * Pack buddy's presence info into descriptor. |
|
146 * |
|
147 * @param aBuddyPresInfo buddy's presence info, ownership doesnt transfer |
|
148 * @param HBufC8* packed presence info |
|
149 */ |
|
150 HBufC8* PackBuddyPresenceInfoLC( |
|
151 const CPresenceBuddyInfoImp* aBuddyPresInfo); |
|
152 |
|
153 |
|
154 private: // New Massage processors, these are called to process messages. |
|
155 void HandlePrepReadPresenceInfoSyncL(const RMessage2& aMessage ); |
|
156 |
|
157 void HandleWritePresenceInfoSyncL(const RMessage2& aMessage ); |
|
158 |
|
159 void HandleGetLastPreparedPacketL( const RMessage2& aMessage ); |
|
160 |
|
161 void HandleGetLastPreparedAsyncPacketL( const RMessage2& aMessage ); |
|
162 |
|
163 void HandleBuddyCountInAllServices(const RMessage2& aMessage ); |
|
164 |
|
165 void HandleBuddyCountInService(const RMessage2& aMessage ); |
|
166 |
|
167 void HandleWritePresenceInfoAsyncL(const RMessage2& aMessage ); |
|
168 |
|
169 void HandlePrepReadAllBuddiesPresenceInService(const RMessage2& aMessage ); |
|
170 |
|
171 //void HandleGetAllServicesL(const RMessage2& aMessage ); |
|
172 |
|
173 void HandleGetServiceCount(const RMessage2& aMessage ); |
|
174 |
|
175 void HandleDeleteService(const RMessage2& aMessage ); |
|
176 |
|
177 void HandleCancel(const RMessage2& aMessage ); |
|
178 |
|
179 void HandleDeletePresence(const RMessage2& aMessage ); |
|
180 |
|
181 |
|
182 // subscribe notification related |
|
183 void HandleSubscribeBuddyPresenceChange(const RMessage2& aMessage ); |
|
184 |
|
185 void HandleUnSubscribeBuddyPresenceChange(const RMessage2& aMessage ); |
|
186 |
|
187 void HandleGetLastNotifiedtPacketL(const RMessage2& aMessage ); |
|
188 |
|
189 void HandleWaitingForNotification(const RMessage2& aMessage ); |
|
190 |
|
191 void HandleCancelWaitingForNotification(const RMessage2& aMessage ); |
|
192 |
|
193 |
|
194 private: |
|
195 |
|
196 /** |
|
197 * Writes Presence info async. to cache, its called on each runl cycle |
|
198 * and it takes data to write from member data holders. |
|
199 */ |
|
200 void WritePresenceInfoAsyncL(); |
|
201 |
|
202 /** |
|
203 * Reads all buddies presence info in given service. It takes data from |
|
204 * stored message. |
|
205 */ |
|
206 void ReadAllBuddiesPresenceInServiceL(); |
|
207 |
|
208 /** |
|
209 * Get Service name from given xsp id |
|
210 * |
|
211 * @param aXspId xsp id e.g. ovi:xyz@nokia.com |
|
212 * @return ServiceName returned here |
|
213 */ |
|
214 TPtrC GetServiceName(const TDesC& aXspId); |
|
215 |
|
216 |
|
217 private: // Data |
|
218 |
|
219 /** |
|
220 * iMessage, the message exchange data with the server. |
|
221 */ |
|
222 RMessage2 iMessage; |
|
223 |
|
224 /** |
|
225 * iMessage, the message holder for notification wating. |
|
226 * This is always pending when some client subscribe for notifications. |
|
227 */ |
|
228 RMessage2 iMessageForNoti; |
|
229 |
|
230 /** |
|
231 * iServer, reference to the server. |
|
232 */ |
|
233 CPresenceCacheServer& iServer; |
|
234 |
|
235 /** |
|
236 * Own: used for sync messages |
|
237 */ |
|
238 HBufC8* iDataPack; |
|
239 |
|
240 /** |
|
241 * Own: used for async messages |
|
242 */ |
|
243 HBufC8* iDataPackAsync; |
|
244 |
|
245 /** |
|
246 * Own: used for subscribe notify message |
|
247 */ |
|
248 HBufC8* iDataPackNotifier; |
|
249 |
|
250 /** |
|
251 * Own: used for ansync requests |
|
252 */ |
|
253 NRequest::TOpAsyncCodes iAsyncReq; |
|
254 |
|
255 /** |
|
256 *Own |
|
257 */ |
|
258 CPresenceBuddyInfoListImp* iBuddypresInfoList; |
|
259 |
|
260 /** |
|
261 * |
|
262 */ |
|
263 TInt iLastServiceCount; |
|
264 |
|
265 |
|
266 /** |
|
267 *Own |
|
268 */ |
|
269 CCacheSessionActiveHelper* iActiveHelper; |
|
270 |
|
271 /** |
|
272 * Pointers not owned. |
|
273 */ |
|
274 RPointerArray<CPresenceCacheBuddyStore> iSubscribedStores; |
|
275 |
|
276 }; |
|
277 |
|
278 /** |
|
279 * This class is used by CPresenceCacheSession for dividing long running async. |
|
280 * tasks into smaller units. The CPresenceCacheSession itself was not made |
|
281 * active, since that results in c++ ambiguousness problems in CPresenceCacheSession |
|
282 * because of inheriting twice from CBase. |
|
283 * |
|
284 * @since S60 v3.2 |
|
285 */ |
|
286 class CCacheSessionActiveHelper : public CActive |
|
287 { |
|
288 public: // public functions |
|
289 |
|
290 /** |
|
291 * Default 1st phase factory method. |
|
292 * Creates an instance of CCacheSessionActiveHelper |
|
293 * |
|
294 * @return created instance of the CCacheSessionActiveHelper |
|
295 */ |
|
296 static CCacheSessionActiveHelper* NewL(CPresenceCacheSession* aSession ); |
|
297 |
|
298 /** |
|
299 * Destructor |
|
300 */ |
|
301 ~CCacheSessionActiveHelper( ); |
|
302 |
|
303 /** |
|
304 * Active object start |
|
305 */ |
|
306 void Start(); |
|
307 |
|
308 private: // private functions |
|
309 |
|
310 /** |
|
311 * Constructor |
|
312 */ |
|
313 CCacheSessionActiveHelper(CPresenceCacheSession* aSession); |
|
314 |
|
315 /** |
|
316 * Active object RunL |
|
317 */ |
|
318 void RunL(); |
|
319 |
|
320 /** |
|
321 * Active object DoCancel |
|
322 */ |
|
323 void DoCancel(); |
|
324 |
|
325 /** |
|
326 * ConstructL |
|
327 */ |
|
328 void ConstructL(); |
|
329 |
|
330 |
|
331 /** |
|
332 * pointer to CPresenceCacheSession doesnt own |
|
333 */ |
|
334 CPresenceCacheSession* iCacheSession; |
|
335 |
|
336 }; |
|
337 |
|
338 #endif // PRESENCECACHESESSION_H |
|
339 |
|
340 // End of File |
|
341 |