|
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 #include "cmscontact.h" |
|
20 #include "cmssession.h" |
|
21 #include "cmscontactfield.h" |
|
22 #include "cmscontactfieldinfo.h" |
|
23 #include "cmscommondefines.h" |
|
24 #include "cmscontactnotifier.h" |
|
25 |
|
26 // ---------------------------------------------------- |
|
27 // RCmsContact::RCmsContact |
|
28 // |
|
29 // ---------------------------------------------------- |
|
30 // |
|
31 EXPORT_C RCmsContact::RCmsContact() : iContactIdentifierPtr( NULL, 0 ) |
|
32 { |
|
33 } |
|
34 |
|
35 // ---------------------------------------------------- |
|
36 // RCmsContact::~RCmsContact |
|
37 // |
|
38 // ---------------------------------------------------- |
|
39 // |
|
40 EXPORT_C RCmsContact::~RCmsContact() |
|
41 { |
|
42 iNotifiers.ResetAndDestroy(); |
|
43 } |
|
44 |
|
45 // ---------------------------------------------------- |
|
46 // RCmsContact::Open |
|
47 // |
|
48 // ---------------------------------------------------- |
|
49 // |
|
50 EXPORT_C TInt RCmsContact::Open( RCmsSession& aSession, |
|
51 TInt32 aContactId ) |
|
52 { |
|
53 #ifdef _DEBUG |
|
54 RCmsSession::WriteToLog( _L8( "RCmsContact::Open( ID )" ) ); |
|
55 RCmsSession::WriteToLog( _L8( " Contact ID: %d" ), aContactId ); |
|
56 #endif |
|
57 return CreateSubSession( aSession, ECmsOpenID, TIpcArgs( aContactId ) ); |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------- |
|
61 // RCmsContact::Open |
|
62 // |
|
63 // ---------------------------------------------------- |
|
64 // |
|
65 EXPORT_C TInt RCmsContact::Open( RCmsSession& aSession, |
|
66 const TDesC8& aPackedLink ) |
|
67 { |
|
68 #ifdef _DEBUG |
|
69 RCmsSession::WriteToLog( _L8( "RCmsContact::Open( LINK )" ) ); |
|
70 #endif |
|
71 return CreateSubSession( aSession, ECmsOpenLink, TIpcArgs( &aPackedLink ) ); |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------- |
|
75 // RCmsContact::Open |
|
76 // |
|
77 // ---------------------------------------------------- |
|
78 // |
|
79 EXPORT_C TInt RCmsContact::Open( RCmsSession& aSession, |
|
80 const TDesC& aPhoneNbr ) |
|
81 { |
|
82 #ifdef _DEBUG |
|
83 HBufC8* phoneBuf = HBufC8::NewLC( aPhoneNbr.Length() ); |
|
84 phoneBuf->Des().Copy( aPhoneNbr ); |
|
85 TPtrC8 phoneDesc( phoneBuf->Des() ); |
|
86 RCmsSession::WriteToLog( _L8( "RCmsContact::Open( MSISDN )" ) ); |
|
87 RCmsSession::WriteToLog( _L8( " Phone number: %S" ), &phoneDesc ); |
|
88 CleanupStack::PopAndDestroy(); //phoneBuf |
|
89 #endif |
|
90 return CreateSubSession( aSession, ECmsOpenPhoneNbr, TIpcArgs( &aPhoneNbr ) ); |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------- |
|
94 // RCmsContact::FieldDataL |
|
95 // |
|
96 // ---------------------------------------------------- |
|
97 // |
|
98 EXPORT_C CCmsContactField* RCmsContact::FieldDataL( TRequestStatus& aStatus, |
|
99 CCmsContactFieldItem::TCmsContactField aFieldType ) |
|
100 { |
|
101 #ifdef _DEBUG |
|
102 RCmsSession::WriteToLog( _L8( "RCmsContact::FieldDataL( SINGLE ): %d" ), aFieldType ); |
|
103 #endif |
|
104 CCmsContactField* field = CCmsContactField::NewL( *this, aStatus, aFieldType ); |
|
105 SendMessage( ECmsFetchContactField, *field, aFieldType ); |
|
106 return field; |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------- |
|
110 // RCmsContact::EnabledFields |
|
111 // |
|
112 // ---------------------------------------------------- |
|
113 // |
|
114 EXPORT_C CCmsContactFieldInfo* RCmsContact::EnabledFieldsL( TRequestStatus& aStatus ) |
|
115 { |
|
116 #ifdef _DEBUG |
|
117 RCmsSession::WriteToLog( _L8( "RCmsContact::EnabledFieldsL()" ) ); |
|
118 #endif |
|
119 CCmsContactFieldInfo* info = CCmsContactFieldInfo::NewL( *this, aStatus ); |
|
120 TIpcArgs arguments( info->StreamDesc8() ); |
|
121 SendMessage( ECmsFetchEnabledFields, arguments, info->Activate() ); |
|
122 return info; |
|
123 } |
|
124 |
|
125 // ---------------------------------------------------- |
|
126 // RCmsContact::IsServiceAvailable |
|
127 // |
|
128 // ---------------------------------------------------- |
|
129 // |
|
130 EXPORT_C TInt RCmsContact::IsServiceAvailable( VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aServiceType ) const |
|
131 { |
|
132 #ifdef _DEBUG |
|
133 RCmsSession::WriteToLog( _L8( "RCmsContact::IsServiceAvailable() - Field: %d" ), aServiceType ); |
|
134 #endif |
|
135 return SendReceive( ECmsFetchServiceAvailability, TIpcArgs( aServiceType ) ); |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------- |
|
139 // RCmsContact::ContactStore |
|
140 // |
|
141 // ---------------------------------------------------- |
|
142 // |
|
143 EXPORT_C TCmsContactStore RCmsContact::ContactStore() const |
|
144 { |
|
145 #ifdef _DEBUG |
|
146 RCmsSession::WriteToLog( _L8( "RCmsContact::ContactStore()" ) ); |
|
147 #endif |
|
148 TInt result = SendReceive( ECmsFindParentStore, TIpcArgs() ); |
|
149 return ( TCmsContactStore )result; |
|
150 } |
|
151 |
|
152 // ---------------------------------------------------- |
|
153 // RCmsContact::FindExternalContact |
|
154 // |
|
155 // ---------------------------------------------------- |
|
156 // |
|
157 EXPORT_C void RCmsContact::FindExternalContact( TRequestStatus& aStatus ) const |
|
158 { |
|
159 #ifdef _DEBUG |
|
160 RCmsSession::WriteToLog( _L8( "RCmsContact::FindExternalStore()" ) ); |
|
161 #endif |
|
162 SendReceive( ECmsFindExternalContact, TIpcArgs(), aStatus ); |
|
163 } |
|
164 |
|
165 // ---------------------------------------------------- |
|
166 // RCmsContact::GetContactIdentifierL |
|
167 // |
|
168 // ---------------------------------------------------- |
|
169 // |
|
170 EXPORT_C HBufC8* RCmsContact::GetContactIdentifierL() |
|
171 { |
|
172 #ifdef _DEBUG |
|
173 RCmsSession::WriteToLog( _L8( "RCmsContact::GetContactIdentifierL()" ) ); |
|
174 #endif |
|
175 |
|
176 HBufC8* identifierbuffer = HBufC8::NewL( KStreamBufferDefaultSizeText ); |
|
177 iContactIdentifierPtr.Set( identifierbuffer->Des() ); |
|
178 |
|
179 //Currently only MVPbkContactLinkArray is supported. |
|
180 SendReceive(ECmsFetchContactIdentifier, TIpcArgs(&iContactIdentifierPtr)); |
|
181 |
|
182 return identifierbuffer; |
|
183 } |
|
184 |
|
185 |
|
186 // ---------------------------------------------------- |
|
187 // RCmsContact::Cancel |
|
188 // |
|
189 // ---------------------------------------------------- |
|
190 // |
|
191 EXPORT_C void RCmsContact::Cancel( CCmsContactBase& aContactBase ) |
|
192 { |
|
193 #ifdef _DEBUG |
|
194 RCmsSession::WriteToLog( _L8( "RCmsContact::Cancel()" ) ); |
|
195 #endif |
|
196 aContactBase.Cancel(); |
|
197 Send(ECmsCancelOperation , TIpcArgs() ); |
|
198 } |
|
199 |
|
200 // ---------------------------------------------------- |
|
201 // RCmsContact::CancelExternalContactFind |
|
202 // |
|
203 // ---------------------------------------------------- |
|
204 // |
|
205 EXPORT_C void RCmsContact::CancelExternalContactFind() const |
|
206 { |
|
207 #ifdef _DEBUG |
|
208 RCmsSession::WriteToLog( _L8( "RCmsContact::CancelExternalContactFind()" ) ); |
|
209 #endif |
|
210 Send( ECmsCancelExternalContactFind, TIpcArgs() ); |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------- |
|
214 // RCmsContact::Close |
|
215 // |
|
216 // ---------------------------------------------------- |
|
217 // |
|
218 EXPORT_C void RCmsContact::Close() |
|
219 { |
|
220 #ifdef _DEBUG |
|
221 RCmsSession::WriteToLog( _L8( "RCmsContact::Close()" ) ); |
|
222 #endif |
|
223 |
|
224 iNotifiers.ResetAndDestroy(); |
|
225 |
|
226 RSubSessionBase::CloseSubSession( ECmsCloseSubsession ); |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------- |
|
230 // RCmsContact::Subscribe |
|
231 // |
|
232 // ---------------------------------------------------- |
|
233 // |
|
234 EXPORT_C void RCmsContact::OrderNotificationsL( |
|
235 MCmsNotificationHandlerAPI* aHandler, |
|
236 CCmsContactFieldItem::TCmsContactNotification aNotificationType ) |
|
237 { |
|
238 #ifdef _DEBUG |
|
239 RCmsSession::WriteToLog( _L8( "RCmsContact::OrderNotificationsL()" ) ); |
|
240 #endif |
|
241 // We have to create separate notifiers for Presence and Phonebook events. |
|
242 // There are two separate queues in the CSM server, that's why. |
|
243 if ( aNotificationType & CCmsContactFieldItem::ECmsPresenceAllNotification ) |
|
244 { |
|
245 // mask phonebook bits off. |
|
246 TUint myMask = aNotificationType & CCmsContactFieldItem::ECmsPresenceAllNotification; |
|
247 CCmsContactNotifier* notifier = CreateNotifierL( aHandler, (CCmsContactFieldItem::TCmsContactNotification)myMask ); |
|
248 notifier->StartOrderL(); |
|
249 } |
|
250 |
|
251 if ( aNotificationType & CCmsContactFieldItem::ECmsPhonebookNotification ) |
|
252 { |
|
253 CCmsContactNotifier* notifier = CreateNotifierL( aHandler, CCmsContactFieldItem::ECmsPhonebookNotification ); |
|
254 notifier->StartOrderL(); |
|
255 } |
|
256 } |
|
257 |
|
258 // ---------------------------------------------------- |
|
259 // RCmsContact::UnSubscribe |
|
260 // |
|
261 // ---------------------------------------------------- |
|
262 // |
|
263 |
|
264 EXPORT_C void RCmsContact::CancelNotifications( |
|
265 CCmsContactFieldItem::TCmsContactNotification aNotificationType ) |
|
266 { |
|
267 #ifdef _DEBUG |
|
268 RCmsSession::WriteToLog( _L8( "RCmsContact::CancelNotifications()" ) ); |
|
269 #endif |
|
270 DeleteNotifier( aNotificationType ); |
|
271 } |
|
272 |
|
273 // ---------------------------------------------------- |
|
274 // RCmsContact::UnSubscribe |
|
275 // |
|
276 // ---------------------------------------------------- |
|
277 // |
|
278 EXPORT_C TInt RCmsContact::GetContactActionFieldCount( |
|
279 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aContactAction) |
|
280 { |
|
281 return SendReceive( ECmsGetContactActionFieldCount, TIpcArgs( aContactAction ) ); |
|
282 } |
|
283 |
|
284 // ---------------------------------------------------- |
|
285 // RCmsContact::SendMessage |
|
286 // |
|
287 // ---------------------------------------------------- |
|
288 // |
|
289 void RCmsContact::SendMessage( TInt aServerMessage, |
|
290 CCmsContactBase& aContactField, |
|
291 CCmsContactFieldItem::TCmsContactField aFieldType ) |
|
292 { |
|
293 #ifdef _DEBUG |
|
294 RCmsSession::WriteToLog( _L8( "RCmsContact::SendMessage()" ) ); |
|
295 #endif |
|
296 if( aContactField.IsBinary() ) |
|
297 { |
|
298 SendReceive( aServerMessage, TIpcArgs( |
|
299 aFieldType, aContactField.StreamDesc8() ), aContactField.Activate() ); |
|
300 } |
|
301 else |
|
302 { |
|
303 SendReceive( aServerMessage, TIpcArgs( |
|
304 aFieldType, aContactField.StreamDesc16() ), aContactField.Activate() ); |
|
305 } |
|
306 } |
|
307 |
|
308 // ---------------------------------------------------- |
|
309 // RCmsContact::SendMessage |
|
310 // |
|
311 // ---------------------------------------------------- |
|
312 // |
|
313 void RCmsContact::SendMessage( TInt aServerMessage, |
|
314 CCmsContactBase& aContactField, |
|
315 CCmsContactFieldItem::TCmsContactFieldGroup aFieldGroup ) |
|
316 { |
|
317 #ifdef _DEBUG |
|
318 RCmsSession::WriteToLog( _L8( "RCmsContact::SendMessage()" ) ); |
|
319 #endif |
|
320 if( aContactField.IsBinary() ) |
|
321 { |
|
322 SendReceive( aServerMessage, TIpcArgs( |
|
323 aFieldGroup, aContactField.StreamDesc8() ), aContactField.Activate() ); |
|
324 } |
|
325 else |
|
326 { |
|
327 SendReceive( aServerMessage, TIpcArgs( |
|
328 aFieldGroup, aContactField.StreamDesc16() ), aContactField.Activate() ); |
|
329 } |
|
330 } |
|
331 |
|
332 // ---------------------------------------------------- |
|
333 // RCmsContact::SendMessage |
|
334 // |
|
335 // ---------------------------------------------------- |
|
336 // |
|
337 void RCmsContact::SendMessage( TInt aServerMessage, |
|
338 TIpcArgs& aArguments, |
|
339 TRequestStatus& aStatus ) |
|
340 { |
|
341 #ifdef _DEBUG |
|
342 RCmsSession::WriteToLog( _L8( "RCmsContact::SendMessage()" ) ); |
|
343 #endif |
|
344 SendReceive( aServerMessage, aArguments, aStatus ); |
|
345 } |
|
346 |
|
347 // ---------------------------------------------------- |
|
348 // RCmsContact::SendMessage |
|
349 // |
|
350 // ---------------------------------------------------- |
|
351 // |
|
352 void RCmsContact::SendMessage( TInt aServerMessage, |
|
353 TIpcArgs& aArguments ) |
|
354 { |
|
355 #ifdef _DEBUG |
|
356 RCmsSession::WriteToLog( _L8( "RCmsContact::SendMessage()" ) ); |
|
357 #endif |
|
358 SendReceive( aServerMessage, aArguments ); |
|
359 } |
|
360 |
|
361 // ---------------------------------------------------- |
|
362 // RCmsContact::ResendReceive |
|
363 // |
|
364 // ---------------------------------------------------- |
|
365 // |
|
366 void RCmsContact::ResendReceive( TInt aOperation ) |
|
367 { |
|
368 #ifdef _DEBUG |
|
369 RCmsSession::WriteToLog( _L8( "RCmsContact::ResendReceive()" ) ); |
|
370 #endif |
|
371 SendReceive( aOperation, TIpcArgs() ); |
|
372 } |
|
373 |
|
374 // ---------------------------------------------------- |
|
375 // RCmsContact::ResendReceive |
|
376 // |
|
377 // ---------------------------------------------------- |
|
378 // |
|
379 void RCmsContact::ResendReceive( TInt aOperation, |
|
380 TRequestStatus& aStatus, |
|
381 const TIpcArgs& aArguments ) |
|
382 { |
|
383 #ifdef _DEBUG |
|
384 RCmsSession::WriteToLog( _L8( "RCmsContact::ResendReceive()" ) ); |
|
385 #endif |
|
386 SendReceive( aOperation, aArguments, aStatus ); |
|
387 } |
|
388 |
|
389 // ---------------------------------------------------- |
|
390 // RCmsContact::CreateNotifierL |
|
391 // |
|
392 // ---------------------------------------------------- |
|
393 // |
|
394 CCmsContactNotifier* RCmsContact::CreateNotifierL( |
|
395 MCmsNotificationHandlerAPI* aHandler, |
|
396 CCmsContactFieldItem::TCmsContactNotification aNotificationType ) |
|
397 { |
|
398 CCmsContactNotifier* current = NULL; |
|
399 TInt count = iNotifiers.Count(); |
|
400 for ( TInt i = 0; i < count; ++i ) |
|
401 { |
|
402 current = iNotifiers[i]; |
|
403 if ( current->Type() == aNotificationType ) |
|
404 { |
|
405 User::Leave( KErrAlreadyExists ); |
|
406 } |
|
407 } |
|
408 // create a new notifier |
|
409 current = CCmsContactNotifier::NewL( *this, *aHandler, aNotificationType); |
|
410 User::LeaveIfError( iNotifiers.Append( current ) ); |
|
411 return current; |
|
412 } |
|
413 |
|
414 // ---------------------------------------------------- |
|
415 // RCmsContact::DeleteNotifier |
|
416 // |
|
417 // ---------------------------------------------------- |
|
418 // |
|
419 void RCmsContact::DeleteNotifier( |
|
420 CCmsContactFieldItem::TCmsContactNotification aNotificationType ) |
|
421 { |
|
422 CCmsContactNotifier* current = NULL; |
|
423 TInt count = iNotifiers.Count(); |
|
424 for ( TInt i = count-1; i >= 0; i-- ) |
|
425 { |
|
426 current = iNotifiers[i]; |
|
427 if ( current->Type() & aNotificationType ) |
|
428 { |
|
429 iNotifiers.Remove(i); |
|
430 iNotifiers.Compress(); |
|
431 delete current; |
|
432 } |
|
433 } |
|
434 } |
|
435 |
|
436 |