|
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: Fetches the presence status,the corresponding presence icon |
|
15 and its bitmask. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 //for block list |
|
22 #include <presenceblockinfo.h> |
|
23 |
|
24 // presence cache |
|
25 #include <presencecachereader2.h> |
|
26 #include <mpresencebuddyinfo2.h> |
|
27 |
|
28 #include "clogsextservicehandler.h" |
|
29 #include "clogsextensioncchhandler.h" |
|
30 #include "tlogsextutil.h" |
|
31 #include "logsextconsts.h" |
|
32 #include "clogsextpresentitydata.h" |
|
33 #include "mlogsextservicehandlerobserver.h" |
|
34 |
|
35 #include "simpledebug.h" |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // NewL |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CLogsExtServiceHandler* CLogsExtServiceHandler::NewL( |
|
43 const TUint32 aServiceId, |
|
44 MLogsExtServiceHandlerObserver& aObserver ) |
|
45 { |
|
46 _LOGP("CLogsExtServiceHandler::NewL(): begin %d", aServiceId) |
|
47 CLogsExtServiceHandler* self = |
|
48 CLogsExtServiceHandler::NewLC( aServiceId, aObserver ); |
|
49 CleanupStack::Pop( self ); |
|
50 _LOG("CLogsExtServiceHandler::NewL(): end" ) |
|
51 return self; |
|
52 } |
|
53 |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // NewLC |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CLogsExtServiceHandler* CLogsExtServiceHandler::NewLC( |
|
60 const TUint32 aServiceId, |
|
61 MLogsExtServiceHandlerObserver& aObserver ) |
|
62 { |
|
63 _LOG("CLogsExtServiceHandler::NewLC(): begin" ) |
|
64 CLogsExtServiceHandler* self = |
|
65 new( ELeave ) CLogsExtServiceHandler( aServiceId, aObserver ); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL(); |
|
68 _LOG("CLogsExtServiceHandler::NewLC(): end" ) |
|
69 return self; |
|
70 } |
|
71 |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // ~CLogsExtServiceHandler |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CLogsExtServiceHandler::~CLogsExtServiceHandler() |
|
78 { |
|
79 _LOG("CLogsExtServiceHandler::~CLogsExtServiceHandler(): begin" ) |
|
80 // Trap is easiest approach for this, deletion can occur any time |
|
81 // ( user initiated ) |
|
82 TRAP_IGNORE( UnSubscribePresenceInfosL() ); |
|
83 |
|
84 delete iCacheReader; |
|
85 |
|
86 iPresentityDataArray.ResetAndDestroy(); |
|
87 |
|
88 _LOG("CLogsExtServiceHandler::~CLogsExtServiceHandler(): end" ) |
|
89 } |
|
90 |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CLogsExtServiceHandler |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 CLogsExtServiceHandler::CLogsExtServiceHandler( |
|
97 const TUint32 aServiceId, |
|
98 MLogsExtServiceHandlerObserver& aObserver) : |
|
99 iServiceId( aServiceId ), |
|
100 iPresentityDataArray( KPresenceFetcherArrayGranularity ), |
|
101 iObserver( &aObserver ) |
|
102 { |
|
103 _LOG("CLogsExtServiceHandler::CLogsExtServiceHandler(): begin" ) |
|
104 |
|
105 _LOG("CLogsExtServiceHandler::CLogsExtServiceHandler(): end" ) |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // ConstructL |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void CLogsExtServiceHandler::ConstructL() |
|
114 { |
|
115 _LOG("CLogsExtServiceHandler::ConstructL(): begin" ) |
|
116 |
|
117 iCacheReader = MPresenceCacheReader2::CreateReaderL(); |
|
118 iCacheReader->SetObserverForSubscribedNotifications(this); |
|
119 |
|
120 _LOG("CLogsExtServiceHandler::ConstructL(): end" ) |
|
121 } |
|
122 |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // ServiceId |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 TUint32 CLogsExtServiceHandler::ServiceId() |
|
129 { |
|
130 _LOG("CLogsExtServiceHandler::ServiceId(): start" ) |
|
131 _LOGP("CLogsExtServiceHandler::iServiceId = %d",iServiceId ) |
|
132 _LOG("CLogsExtServiceHandler::ServiceId(): finish" ) |
|
133 return iServiceId; |
|
134 } |
|
135 |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // Tests whether presentity data object exists or not. |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 TBool CLogsExtServiceHandler::PresentityDataExists( |
|
142 const TDesC16& aPresentityId ) |
|
143 { |
|
144 TBool fetcherFound( EFalse ); |
|
145 _LOG("CLogsExtServiceHandler::PresentityDataExists begin" ) |
|
146 |
|
147 // check if there is already a presentity data object for the |
|
148 // speciifed presentityid |
|
149 CLogsExtPresentityData* presData = NULL; |
|
150 |
|
151 if ( KErrNone == GetPresentityData( aPresentityId, presData ) ) |
|
152 { |
|
153 fetcherFound = ETrue; |
|
154 } |
|
155 |
|
156 _LOGP("CLogsExtServiceHandler::PresentityDataExists %d", fetcherFound ); |
|
157 |
|
158 _LOG("CLogsExtServiceHandler::PresentityDataExists end" ) |
|
159 return fetcherFound; |
|
160 } |
|
161 |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // Gets presentity data object of a certain presentity. |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 TInt CLogsExtServiceHandler::GetPresentityData( |
|
168 const TDesC& aPresentityId, |
|
169 CLogsExtPresentityData*& aPresentityData ) |
|
170 { |
|
171 _LOG("CLogsExtServiceHandler::GetPresentityData begin" ) |
|
172 |
|
173 TInt error( KErrNotFound ); |
|
174 TBool dataFound( EFalse ); |
|
175 |
|
176 // check if there is already a fetcher for the brand |
|
177 CLogsExtPresentityData* presData = NULL; |
|
178 |
|
179 for ( TInt i = 0 ; i < iPresentityDataArray.Count() && !dataFound; i++ ) |
|
180 { |
|
181 presData = iPresentityDataArray[i]; |
|
182 if ( presData && aPresentityId == presData->PresentityId() ) |
|
183 { |
|
184 dataFound = ETrue; |
|
185 aPresentityData = presData; |
|
186 } |
|
187 } |
|
188 |
|
189 error = dataFound ? KErrNone : KErrNotFound; |
|
190 _LOGP("CLogsExtServiceHandler::GetPresentityData() error=%d",error ) |
|
191 |
|
192 _LOG("CLogsExtServiceHandler::GetPresentityData end" ) |
|
193 return error; |
|
194 } |
|
195 |
|
196 |
|
197 //--------------------------------------------------------------------------- |
|
198 // Adds the specified presentity to this service handler and starts to |
|
199 // handle subscription/event handling etc. for this presentity. |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CLogsExtServiceHandler::AddPresentityL( const TDesC& aPresentityId ) |
|
203 { |
|
204 _LOG("CLogsExtServiceHandler::HandlePresentityL begin" ) |
|
205 |
|
206 //add presentityData if it not already exists, |
|
207 //and start handling the presentity (make subscription if |
|
208 //needed and so on) |
|
209 DoPresentityDataCreationL( aPresentityId ); |
|
210 |
|
211 _LOG("CLogsExtServiceHandler::HandlePresentityL end" ) |
|
212 } |
|
213 |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CLogsExtServiceHandler::HandlePresenceReadL() |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 void CLogsExtServiceHandler::HandlePresenceReadL(TInt /*aErrorCode*/, |
|
220 RPointerArray<MPresenceBuddyInfo2>& /*aPresenceBuddyInfoList*/) |
|
221 { |
|
222 //intentionally not implemented |
|
223 } |
|
224 |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CLogsExtServiceHandler::HandlePresenceNotificationL() |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void CLogsExtServiceHandler::HandlePresenceNotificationL( TInt aErrorCode, |
|
231 MPresenceBuddyInfo2* aPresenceBuddyInfo ) |
|
232 { |
|
233 if( aErrorCode == KErrNone && aPresenceBuddyInfo ) |
|
234 { |
|
235 CleanupDeletePushL( aPresenceBuddyInfo ); |
|
236 TBool showStatus = EFalse; |
|
237 TInt index = KErrNotFound; |
|
238 MPresenceBuddyInfo2::TAvailabilityValues value = aPresenceBuddyInfo->Availability(); |
|
239 TPtrC presTextValue = aPresenceBuddyInfo->AvailabilityText(); |
|
240 TPtrC buddyId = aPresenceBuddyInfo->BuddyId(); |
|
241 |
|
242 // Presence Cache gives only buddy id and in shown presenties array |
|
243 // is only presentity id... so find index of that presentity which |
|
244 // buddy id is in buddyinfo object for checking shown presentity |
|
245 // from shown presentities array. |
|
246 for ( TInt j = 0 ; j < iPresentityDataArray.Count(); j++ ) |
|
247 { |
|
248 CLogsExtPresentityData* presData = iPresentityDataArray[j]; |
|
249 if ( buddyId == presData->PresentityId() ) |
|
250 { |
|
251 index = j; |
|
252 break; |
|
253 } |
|
254 } |
|
255 |
|
256 if( index != KErrNotFound ) |
|
257 { |
|
258 showStatus = ETrue; |
|
259 |
|
260 if( value == MPresenceBuddyInfo2::EAvailable ) |
|
261 { |
|
262 _LIT( KConvAvailable, "available" ); |
|
263 presTextValue.Set( KConvAvailable ); |
|
264 } |
|
265 |
|
266 else if ( value == MPresenceBuddyInfo2::ENotAvailable /*presTextValue == KConvUnavailable*/ ) |
|
267 { |
|
268 // Presence offline value is modified to match branding |
|
269 _LIT( KConvOffline, "offline" ); |
|
270 presTextValue.Set( KConvOffline ); |
|
271 } |
|
272 |
|
273 iObserver->HandlePresentityPresenceStatusL( |
|
274 iServiceId, |
|
275 iPresentityDataArray[index]->PresentityId(), |
|
276 presTextValue, |
|
277 showStatus ); |
|
278 } |
|
279 |
|
280 CleanupStack::PopAndDestroy( aPresenceBuddyInfo ); |
|
281 } |
|
282 } |
|
283 |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // Create presentity data object for a presentity. |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 void CLogsExtServiceHandler::DoPresentityDataCreationL( |
|
290 const TDesC& aPresentityId ) |
|
291 { |
|
292 _LOG("CLogsExtServiceHandler::DoPresentityDataCreationL begin" ) |
|
293 |
|
294 if ( !PresentityDataExists( aPresentityId ) ) |
|
295 { |
|
296 CLogsExtPresentityData* presData = |
|
297 CLogsExtPresentityData::NewLC( aPresentityId, *this ); |
|
298 iPresentityDataArray.AppendL( presData ); |
|
299 CleanupStack::Pop( presData ); |
|
300 // check the current state, make subscriptions if necessary, etc. |
|
301 CheckServiceHandler(); |
|
302 } |
|
303 |
|
304 _LOG("CLogsExtServiceHandler::DoPresentityDataCreationL end" ) |
|
305 } |
|
306 |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // Subscribe presentity presence |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 void CLogsExtServiceHandler::DoPresentitySubscriptionL( |
|
313 CLogsExtPresentityData& aPresentityData ) |
|
314 { |
|
315 _LOG("CLogsExtServiceHandler::DoPresentitySubscriptionL(): begin" ) |
|
316 |
|
317 const TDesC& presentityId = aPresentityData.PresentityId(); |
|
318 |
|
319 // Watch for changes |
|
320 TInt err = iCacheReader->SubscribePresenceBuddyChangeL( presentityId ); |
|
321 |
|
322 // Synch check |
|
323 MPresenceBuddyInfo2* buddy = iCacheReader->PresenceInfoLC( presentityId ); |
|
324 aPresentityData.SetStatus( CLogsExtPresentityData::ESubscribed ); |
|
325 if ( buddy ) |
|
326 { |
|
327 // Ownership is transferred |
|
328 CleanupStack::Pop(); // buddy |
|
329 HandlePresenceNotificationL( KErrNone, buddy ); |
|
330 } |
|
331 |
|
332 _LOG("CLogsExtServiceHandler::DoPresentitySubscriptionL(): end") |
|
333 } |
|
334 |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // CLogsExtServiceHandler::UnSubscribePresenceInfosL |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 void CLogsExtServiceHandler::UnSubscribePresenceInfosL() |
|
341 { |
|
342 TInt contactsCount = iPresentityDataArray.Count(); |
|
343 TPtrC subUri(KNullDesC); |
|
344 // go through the array of presentityData objects |
|
345 CLogsExtPresentityData* presData = NULL; |
|
346 |
|
347 for(TInt i=0;i<contactsCount;i++) |
|
348 { |
|
349 presData = iPresentityDataArray[i]; |
|
350 if ( presData ) |
|
351 { |
|
352 iCacheReader->UnSubscribePresenceBuddyChangeL( presData->PresentityId() ); |
|
353 } |
|
354 } |
|
355 } |
|
356 |
|
357 // --------------------------------------------------------------------------- |
|
358 // Determines whether the service handler has to make subscriptions |
|
359 // and also initiates those. It also informs the service handler |
|
360 // oberver in case the status of a presentity should not be displayed |
|
361 // (e.g. because the presentity is not found from the subscribed buddy |
|
362 // list anymore) |
|
363 // --------------------------------------------------------------------------- |
|
364 // |
|
365 void CLogsExtServiceHandler::CheckServiceHandler() |
|
366 { |
|
367 _LOG("CLogsExtServiceHandler::CheckServiceHandler() begin" ) |
|
368 |
|
369 _LOG("CLogsExtServiceHandler::CheckServiceHandler() make check!" ) |
|
370 TRAPD( error , DoCheckServiceHandlerL(); ); |
|
371 if ( KErrNone != error ) |
|
372 { |
|
373 _LOGP("CLogsExtServiceHandler::CheckServiceHandler()ERROR! = %d", |
|
374 error ) |
|
375 } |
|
376 |
|
377 _LOG("CLogsExtServiceHandler::CheckServiceHandler() end" ) |
|
378 } |
|
379 |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // DoCheckServiceHandlerL |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 void CLogsExtServiceHandler::DoCheckServiceHandlerL() |
|
386 { |
|
387 _LOG("CLogsExtServiceHandler::DoCheckServiceHandlerL() begin" ) |
|
388 |
|
389 // go through the array of presentityData objects |
|
390 CLogsExtPresentityData* presData = NULL; |
|
391 for ( TInt i(0); i < iPresentityDataArray.Count(); i++ ) |
|
392 { |
|
393 presData = iPresentityDataArray[i]; |
|
394 if ( presData ) |
|
395 { |
|
396 TInt state = presData->Status(); |
|
397 |
|
398 _LOGP("CLogsExtServiceHandler::DoCheckServiceHandlerL():state=%d", |
|
399 state ) |
|
400 |
|
401 // subscribe those presentities which are: |
|
402 // 1) not subcribed |
|
403 if ( state == CLogsExtPresentityData::EUnsubscribed ) |
|
404 { |
|
405 _LOG("CLogsExtServiceHandler::DoCheckServiceHandlerL()...") |
|
406 _LOG("...DoPresentitySubscriptionL( *presData )" ) |
|
407 DoPresentitySubscriptionL( *presData ); |
|
408 } |
|
409 } |
|
410 } |
|
411 |
|
412 _LOG("CLogsExtServiceHandler::DoCheckServiceHandlerL() end" ) |
|
413 } |
|
414 |
|
415 //End of file |