|
1 /* |
|
2 * Copyright (c) 2007 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 |
|
20 #ifndef __CMSSERVERCONTACT__ |
|
21 #define __CMSSERVERCONTACT__ |
|
22 |
|
23 // INCLUDES |
|
24 #include "cmscontact.h" |
|
25 #include <VPbkEng.rsg> |
|
26 #include "bpasobserver.h" |
|
27 #include "cmscontactinterface.h" |
|
28 #include "mpresencetrafficlightsobs.h" |
|
29 #include "cmsserver.h" |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KDefaultBinaryBufferSize = 1024; |
|
33 const TInt KPresenceFieldGroup[] = { |
|
34 R_VPBK_FIELD_TYPE_IMPP }; |
|
35 |
|
36 // FORWARD DECLARATIONS |
|
37 class CVPbkContactManager; |
|
38 class CBPAS; |
|
39 class CCmsNotifyEvent; |
|
40 class CCmsServerSession; |
|
41 class CCmsServerAsyncContact; |
|
42 class CCmsServerXSPContactHandler; |
|
43 class MVPbkContactOperationBase; |
|
44 |
|
45 /** |
|
46 * CCmsServerContact is responsible for retrieving contact information |
|
47 */ |
|
48 NONSHARABLE_CLASS( CCmsServerContact ) : public CBase, |
|
49 public MBPASObserver, |
|
50 public MCmsContactInterface, |
|
51 public MPresenceIconNotifier |
|
52 { |
|
53 public: |
|
54 |
|
55 /** |
|
56 * Creates a new instance of CCmsServerContact |
|
57 * |
|
58 * @param aSession Reference to the session instance. |
|
59 * @param aCmsServer Reference to the server instance. |
|
60 * @return Pointer to CCmsServerContact |
|
61 */ |
|
62 static CCmsServerContact* NewL( CCmsServerSession& aSession, |
|
63 CCmsServer& aCmsServer ); |
|
64 |
|
65 /** |
|
66 * Starts fetching enabled fields |
|
67 * |
|
68 * @param Kernel message with client's data |
|
69 */ |
|
70 void FetchEnabledFields( const RMessage2& aMessage ); |
|
71 |
|
72 /** |
|
73 * Starts fetching contact info |
|
74 * |
|
75 * @param aMessage Kernel message with client's data |
|
76 */ |
|
77 void FetchContactData( const RMessage2& aMessage ); |
|
78 |
|
79 /** |
|
80 * Packs iPackedContactLinkArray and sends to client |
|
81 * |
|
82 * @param aMessage Kernel message with client's data |
|
83 */ |
|
84 void FetchContactLinkArrayL( const RMessage2& aMessage ); |
|
85 |
|
86 /** |
|
87 * Starts searching for xSP contacts |
|
88 * |
|
89 * @param aMessage Kernel message with client's data |
|
90 */ |
|
91 void FindXSPContactL( const RMessage2& aMessage ); |
|
92 |
|
93 /** |
|
94 * Cancels xSP contacts search |
|
95 */ |
|
96 void CancelXspContactFind() const; |
|
97 |
|
98 /** |
|
99 * Cancels active async request |
|
100 */ |
|
101 void CancelOperation(); |
|
102 |
|
103 /** |
|
104 * Saves data into internal cache |
|
105 * |
|
106 * @param a16BitData Data to be cached. Ownership is taken. |
|
107 */ |
|
108 void CacheData( HBufC* a16BitData ); |
|
109 |
|
110 /** |
|
111 * Saves data into internal cache |
|
112 * |
|
113 * @param a8BitData Data to be cached. Ownership is taken. |
|
114 */ |
|
115 void CacheData( HBufC8* a8BitData ); |
|
116 |
|
117 /** |
|
118 * Destructor |
|
119 */ |
|
120 ~CCmsServerContact(); |
|
121 |
|
122 /** |
|
123 * Activates notifications |
|
124 * |
|
125 * @param aMessage Kernel message with client's data |
|
126 * @param aAskMore If ETrue, returns current presence status imemdiately |
|
127 * from the presence cache and notify later about any changes |
|
128 */ |
|
129 void OrderNotifyL( const RMessage2& aMessage, TBool aAskMore ); |
|
130 |
|
131 /** |
|
132 * Completes notification request |
|
133 * |
|
134 * @param aMessage Kernel message with client's data |
|
135 * @param aStatus Status to complete notification with |
|
136 */ |
|
137 void CompleteNotify( const RMessage2& aMessage, TInt aStatus ); |
|
138 |
|
139 /** |
|
140 * @return ETrue if contact was deleted |
|
141 */ |
|
142 TBool IsDeleted() const; |
|
143 |
|
144 /** |
|
145 * @return Contact store type, see TCmsContactStore |
|
146 */ |
|
147 TInt ContactStore() const; |
|
148 |
|
149 /** |
|
150 * @param Contact store URI. |
|
151 */ |
|
152 TPtrC StoreUri(); |
|
153 |
|
154 /** |
|
155 * @return Reference to BPAS handle. Ownership is not transfered. |
|
156 */ |
|
157 CBPAS& BPASHandle(); |
|
158 |
|
159 /** |
|
160 * @return Reference to async contact. Ownership is not transfered. |
|
161 */ |
|
162 CCmsServerAsyncContact& AsyncContact(); |
|
163 |
|
164 /** |
|
165 * @return Pointer to xSP contact handle. Ownership is not transfered |
|
166 */ |
|
167 CCmsServerXSPContactHandler* XSPHandler() const; |
|
168 |
|
169 /** |
|
170 * Check voip support |
|
171 * |
|
172 * @return Bitmask of TCmsVoIPSupport, see cmscontactfield.h |
|
173 */ |
|
174 TInt ParseVoIPAvailabilityL(); |
|
175 |
|
176 /** |
|
177 * Start next find operation |
|
178 * |
|
179 * @param aNextFindStringPos Position of next string to find in the iIdArray |
|
180 */ |
|
181 void StartNextFindOperationL( TInt aNextFindStringPos ); |
|
182 |
|
183 private: |
|
184 |
|
185 /** |
|
186 * Default contructor |
|
187 * |
|
188 * @param aSession Reference to the session instance. |
|
189 * @param aCmsServer Reference to the server instance. |
|
190 */ |
|
191 CCmsServerContact( CCmsServerSession& aSession, |
|
192 CCmsServer& aCmsServer ); |
|
193 |
|
194 /** |
|
195 * Second phase constructor |
|
196 */ |
|
197 void ConstructL(); |
|
198 |
|
199 /** |
|
200 * Sends cached data to the client |
|
201 * |
|
202 * @param aMessageParam Slot in the message to use for sending data |
|
203 */ |
|
204 void CachedDataSend8( TInt aMessageParam ); |
|
205 |
|
206 /** |
|
207 * @return ETrue if some contact data was cached |
|
208 */ |
|
209 TBool CachedData(); |
|
210 |
|
211 /** |
|
212 * Sends cached data to the client |
|
213 * |
|
214 * @param aMessageParam Slot in the message to use for sending data |
|
215 */ |
|
216 void CachedDataSend16( TInt aMessageParam ); |
|
217 |
|
218 /** |
|
219 * Handles contact presence info. |
|
220 * |
|
221 * @param aInfos IM contacts info |
|
222 */ |
|
223 void DeliverPresenceDataL( RPointerArray<CBPASInfo>& aInfos ); |
|
224 |
|
225 /** |
|
226 * Packs icon info, language and notification type into one buffer |
|
227 * |
|
228 * @param aBrandId Brand id |
|
229 * @param aElementId Element id |
|
230 * @param aImageId Image Id |
|
231 * @param aLangId Language Id |
|
232 * @param aServiceTypeId Notification type |
|
233 * @return Packed info |
|
234 */ |
|
235 HBufC8* ConstructIconInfoL( const TDesC8& aBrandId, const TDesC8& aTextId, |
|
236 const TDesC8& aImageId, TInt aLangId, |
|
237 CCmsContactFieldItem::TCmsContactNotification aServiceTypeId ); |
|
238 |
|
239 /** |
|
240 * Utility method for creating contactlink array of the contact. |
|
241 */ |
|
242 void CreateContactLinkArrayL(); |
|
243 |
|
244 /** |
|
245 * Saves info about contact store. |
|
246 * |
|
247 * @param aStoreUri Store URI |
|
248 */ |
|
249 void ParseContactStore( const TDesC& aStoreUri ); |
|
250 |
|
251 /** |
|
252 * Notifies client about presence status changes or |
|
253 * saves notification to the queue. |
|
254 * |
|
255 * @param aData Packed branded icon info |
|
256 */ |
|
257 void SendOrQueueBrandedDataL( const TDesC8& aData ); |
|
258 |
|
259 /** |
|
260 * Clears array with presence notifications |
|
261 */ |
|
262 void EmptyPresenceQueue(); |
|
263 |
|
264 /** |
|
265 * Clears array with contact event notifications |
|
266 */ |
|
267 void EmptyPhonebookQueue(); |
|
268 |
|
269 /** |
|
270 * Packs branded icon info into one buffer |
|
271 * |
|
272 * @param aBrandId Brand id |
|
273 * @param aElementId Element id |
|
274 * @return Packed branded icon info |
|
275 */ |
|
276 HBufC8* CompileBrandInfoDataLC( const TDesC8& aBrandId, const TDesC8& aElementId ); |
|
277 |
|
278 /** |
|
279 * Starts listening for contact events |
|
280 */ |
|
281 void StartPhonebookNotificationL(); |
|
282 |
|
283 /** |
|
284 * Starts listening to presence notifications |
|
285 * |
|
286 * @param aMessage Kernel message with client's data |
|
287 * @param aAskMore If ETrue, returns current presence status imemdiately |
|
288 * from the presence cache and notify later about any changes |
|
289 */ |
|
290 void StartPresenceNotificationL( const RMessage2& aMessage, TBool aAskMore ); |
|
291 |
|
292 /** |
|
293 * Gets length of the client's data |
|
294 * |
|
295 * @param aMessageSlot Slot in kernel message to be checked for data length |
|
296 * @param aMessage Kernel message with client's data |
|
297 * @return TInt Length of client's data |
|
298 */ |
|
299 TInt ClientDesLength( TInt aMessageSlot, RMessage2*& aMessage ); |
|
300 |
|
301 /** |
|
302 * Start VoIP notifications |
|
303 */ |
|
304 void StartPresenceVoipNotificationL( ); |
|
305 |
|
306 /** |
|
307 * Start Chat notifications |
|
308 */ |
|
309 void StartPresenceChatNotificationL( ); |
|
310 |
|
311 /** |
|
312 * Add Voip enabled fields |
|
313 * |
|
314 * @param aArray Contains Voip fields on return |
|
315 * @param aResourceId Field types to be used in search |
|
316 */ |
|
317 void AddVoipFieldL( CDesCArrayFlat& aArray, TInt aResourceId ); |
|
318 |
|
319 /** |
|
320 * Add Voip enabled fields |
|
321 * |
|
322 * @param aBitmask Contains updated flag for Voip support on return, |
|
323 * if supported |
|
324 */ |
|
325 void CheckServiceProviderSupportL( TInt& aBitmask ); |
|
326 |
|
327 /** |
|
328 * Handle NewIconForContact method call |
|
329 * |
|
330 * @param aBrandId Brand id |
|
331 * @param aElementId Element id |
|
332 * @param aId Id given in SubscribeBrandingForContactL |
|
333 * @param aBrandLanguage - Brand Language ID |
|
334 */ |
|
335 void DoNewIconForContactL( |
|
336 const TDesC8& aBrandId, |
|
337 const TDesC8& aElementId, |
|
338 TInt aId, |
|
339 TInt aBrandLanguage ); |
|
340 /** |
|
341 * Custom TCleaupItem callback function called by the CleanupStack |
|
342 * |
|
343 * @param aItem Item to be cleaned up by the cleanup stack |
|
344 */ |
|
345 |
|
346 static void CleanupResetAndDestroy(TAny* aItem); |
|
347 |
|
348 |
|
349 private: //From MCmsContactInterface |
|
350 |
|
351 void ContactReadyL( TInt aError, MVPbkStoreContact* aContact ); |
|
352 TBool OfferContactEventL( TCmsPhonebookEvent aEventType, |
|
353 const MVPbkContactLink* aContactLink ); |
|
354 const MVPbkStoreContact& Contact() const; |
|
355 TBool HandleField( HBufC* aFieldData ); |
|
356 TBool HandleField( HBufC8* aFieldData ); |
|
357 TBool HandleEnabledFields( HBufC* aEnabledFields ); |
|
358 void HandleError( TInt aError ); |
|
359 |
|
360 private: //From MBPASObserver |
|
361 |
|
362 void HandleInfosL( TInt aErrorCode, RPointerArray<CBPASInfo>& aInfos ); |
|
363 void HandleSubscribedInfoL( CBPASInfo* aInfo ); |
|
364 |
|
365 private: //From MPresenceIconNotifier |
|
366 |
|
367 void NewIconForContact( |
|
368 MVPbkContactLink* aLink, |
|
369 const TDesC8& aBrandId, |
|
370 const TDesC8& aElementId, |
|
371 TInt aId, |
|
372 TInt aBrandLanguage ); |
|
373 void NewIconsForContact( |
|
374 MVPbkContactLink* aLink, |
|
375 RPointerArray <MPresenceServiceIconInfo>& aInfoArray, |
|
376 TInt aId ); |
|
377 |
|
378 private: //Data |
|
379 |
|
380 /// ETrue, if contact was deleted. |
|
381 TBool iContactDeleted; |
|
382 |
|
383 /// ETrue, if presence notificattion is active |
|
384 TBool iPresenceNotifySubscribed; |
|
385 |
|
386 /// Handle to BPAS to get presence info. Oowned. |
|
387 CBPAS* iBrandedPresence; |
|
388 |
|
389 /// Contact's store URI. Owned. |
|
390 HBufC* iStoreUri; |
|
391 |
|
392 /// Cache for field content. Owned. |
|
393 HBufC* iCachedField16; |
|
394 |
|
395 /// Cache for field content. Owned. |
|
396 HBufC8* iCachedField8; |
|
397 |
|
398 /// Packed contant link array whicvh contains iContact. Owned. |
|
399 HBufC8* iPackedContactLinkArray; |
|
400 |
|
401 /// Kernel message to be completed later for async requests |
|
402 RMessage2 iMessage; |
|
403 |
|
404 /// Kernel message to be completed for contact notifications |
|
405 RMessage2 iPbkNotifyMessage; |
|
406 |
|
407 /// Kernel message to be completed for presence notifications |
|
408 RMessage2 iPresenceNotifyMessage; |
|
409 |
|
410 /// Type of contact store. |
|
411 TCmsContactStore iContactStore; |
|
412 |
|
413 /// Reference to session instance. Not owned. |
|
414 CCmsServerSession& iSession; |
|
415 |
|
416 /// Store contact. Owned. |
|
417 MVPbkStoreContact* iContact; |
|
418 |
|
419 /// Contact manager. Not owned. |
|
420 CVPbkContactManager* iContactManager; |
|
421 |
|
422 /// Contact object for async requests. Owned. |
|
423 CCmsServerAsyncContact* iAsyncContact; |
|
424 |
|
425 /// xSPContact handle. Owned. |
|
426 CCmsServerXSPContactHandler* iXSPContactHandler; |
|
427 |
|
428 /// Array for keeping presence events. Owned. |
|
429 RPointerArray<CCmsNotifyEvent> iPresenceEvents; |
|
430 |
|
431 /// Array for keeping contact events. Owned. |
|
432 RPointerArray<CCmsNotifyEvent> iPhonebookEvents; |
|
433 |
|
434 /// Conact link of iContact. Owned. |
|
435 MVPbkContactLink* iContactLink; |
|
436 |
|
437 /// Voip handler to get voip presence status. Owned. |
|
438 MPresenceTrafficLights* iVoipHandler; |
|
439 |
|
440 /// Chat handler to get chat presence status. Owned. |
|
441 MPresenceTrafficLights* iChatHandler; |
|
442 |
|
443 /// Array for keeping all contact's IMPP fields. Owned. |
|
444 CDesCArrayFlat* iIdArray; |
|
445 |
|
446 /// Reference to CCmsServer instance. Not owned. |
|
447 CCmsServer& iCmsServer; |
|
448 |
|
449 /// Array of find operations in xSP stores. Owned. |
|
450 RPointerArray<MVPbkContactOperationBase> iXSPFindOperationsArray; |
|
451 }; |
|
452 |
|
453 #endif //__CMSSERVERCONTACT__ |
|
454 |
|
455 |
|
456 // End of File |