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