|
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 the License "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: Implementation of the sync api's of the contact sapi's. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //user includes |
|
21 #include "contactservice.h" |
|
22 #include "contactsynccallback.h" |
|
23 |
|
24 |
|
25 /* |
|
26 ----------------------------------------------------------------------------- |
|
27 CContactService :: GetListL |
|
28 Description : synchronous implementation of GetList api. |
|
29 Return values : CContactIter* |
|
30 ----------------------------------------------------------------------------- |
|
31 */ |
|
32 EXPORT_C |
|
33 CContactIter* CContactService::GetListL(Ttype atype, |
|
34 const TDesC8& aContactId, |
|
35 const TDesC& aSearchVal, |
|
36 CSearchFields* aSearchFields, |
|
37 TOrder aSortOrder, |
|
38 const TDesC& aStoreUri) |
|
39 { |
|
40 //create the callback object internally |
|
41 CContactSyncCallback* callback = new(ELeave) CContactSyncCallback(); |
|
42 CleanupStack::PushL(callback); |
|
43 //create the wait scheduler instance |
|
44 CActiveSchedulerWait* waitScheduler = new(ELeave) CActiveSchedulerWait(); |
|
45 CleanupStack::PushL(waitScheduler); |
|
46 //needed to stop the scheduler by the callback instance |
|
47 callback->SetWaitScheduler(waitScheduler); |
|
48 //call the asynch sapi with all the params |
|
49 TRAPD(err,GetListL(callback, |
|
50 0, |
|
51 atype, |
|
52 aContactId, |
|
53 aSearchVal, |
|
54 aSearchFields, |
|
55 aSortOrder, |
|
56 aStoreUri)); |
|
57 //TRAP harness is used to unset the sync flag in leaving condition |
|
58 //since we r using the same async apis for sync implementation |
|
59 if(KErrNone != err) |
|
60 { |
|
61 User::Leave(err); |
|
62 } |
|
63 //start the wait scheduler and wait untill the operation finishes |
|
64 waitScheduler->Start(); |
|
65 //Unset the callbak pointer |
|
66 callback->SetWaitScheduler(NULL); |
|
67 //check for any errors |
|
68 TInt error = callback->GetErrorCode(); |
|
69 if(KErrNone != error) |
|
70 { |
|
71 User::Leave(error); |
|
72 } |
|
73 CContactIter* tempIter = callback->GetIter(); |
|
74 CleanupStack::PopAndDestroy(waitScheduler); |
|
75 CleanupStack::PopAndDestroy(callback); |
|
76 return tempIter; |
|
77 } |
|
78 |
|
79 |
|
80 |
|
81 /* |
|
82 ----------------------------------------------------------------------------- |
|
83 CContactService :: AddL |
|
84 Description : synchronous implementation of AddL api. |
|
85 Return values : CContactIter* |
|
86 ----------------------------------------------------------------------------- |
|
87 */ |
|
88 |
|
89 EXPORT_C |
|
90 void CContactService:: AddL( CSingleContact* aContact, |
|
91 const TDesC8& aGroupId, |
|
92 const TDesC& aGroupLabel, |
|
93 const TDesC& aStoreUri) |
|
94 { |
|
95 iErrKey = 0; |
|
96 //create the callback object internally |
|
97 CContactSyncCallback* callback = new(ELeave) CContactSyncCallback(); |
|
98 CleanupStack::PushL(callback); |
|
99 //create the wait scheduler instance |
|
100 CActiveSchedulerWait* waitScheduler = new(ELeave) CActiveSchedulerWait(); |
|
101 CleanupStack::PushL(waitScheduler); |
|
102 //needed to stop the scheduler by the callback instance |
|
103 callback->SetWaitScheduler(waitScheduler); |
|
104 //call the asynch sapi with all the params |
|
105 TRAPD(err,AddL(callback, |
|
106 0, |
|
107 aContact, |
|
108 aGroupId, |
|
109 aGroupLabel, |
|
110 aStoreUri)); |
|
111 //TRAP harness is used to unset the sync flag in leaving condition |
|
112 //since we are using the same async apis for sync implementation |
|
113 if(err!= KErrNone) |
|
114 { |
|
115 User::Leave(err); |
|
116 } |
|
117 //start the wait scheduler and wait untill the operation finishes |
|
118 waitScheduler->Start(); |
|
119 //Unset the callbak pointer |
|
120 callback->SetWaitScheduler(NULL); |
|
121 //check for any errors |
|
122 TInt error = callback->GetErrorCode(); |
|
123 if( error!= KErrNone ) |
|
124 { |
|
125 if(error == KErrNotSupported && callback->iErrKey != 0) |
|
126 { |
|
127 iErrKey = callback->iErrKey; |
|
128 } |
|
129 User::Leave(error); |
|
130 } |
|
131 CleanupStack::PopAndDestroy(waitScheduler); |
|
132 CleanupStack::PopAndDestroy(callback); |
|
133 } |
|
134 |
|
135 |
|
136 /* |
|
137 ----------------------------------------------------------------------------- |
|
138 CContactService :: DeleteL |
|
139 Description : synchronous implementation of DeleteL api. |
|
140 Return values : CContactIter* |
|
141 ----------------------------------------------------------------------------- |
|
142 */ |
|
143 |
|
144 |
|
145 EXPORT_C void CContactService:: DeleteL(RPointerArray<TDesC8>& aContactIdArray, |
|
146 const TDesC& aStoreUri) |
|
147 { |
|
148 //create the callback object internally |
|
149 CContactSyncCallback* callback = new(ELeave) CContactSyncCallback(); |
|
150 CleanupStack::PushL(callback); |
|
151 //create the wait scheduler instance |
|
152 CActiveSchedulerWait* waitScheduler = new(ELeave) CActiveSchedulerWait(); |
|
153 CleanupStack::PushL(waitScheduler); |
|
154 //needed to stop the scheduler by the callback instance |
|
155 callback->SetWaitScheduler(waitScheduler); |
|
156 //call the asynch sapi with all the params |
|
157 TRAPD(err,DeleteL(callback, |
|
158 0, |
|
159 aContactIdArray, |
|
160 aStoreUri)); |
|
161 //TRAP harness is used to unset the sync flag in leaving condition |
|
162 //since we r using the same async apis for sync implementation |
|
163 if(err!= KErrNone) |
|
164 { |
|
165 User::Leave(err); |
|
166 } |
|
167 //start the wait scheduler and wait untill the operation finishes |
|
168 waitScheduler->Start(); |
|
169 //Unset the callbak pointer |
|
170 callback->SetWaitScheduler(NULL); |
|
171 //check for any errors |
|
172 TInt error = callback->GetErrorCode(); |
|
173 if( error!= KErrNone ) |
|
174 { |
|
175 User::Leave(error); |
|
176 } |
|
177 CleanupStack::PopAndDestroy(waitScheduler); |
|
178 CleanupStack::PopAndDestroy(callback); |
|
179 } |
|
180 |
|
181 |
|
182 |
|
183 /* |
|
184 ----------------------------------------------------------------------------- |
|
185 CContactService :: OrganiseGroupsL |
|
186 Description : synchronous implementation of OrganiseGroupsL api. |
|
187 Return values : CContactIter* |
|
188 ----------------------------------------------------------------------------- |
|
189 */ |
|
190 |
|
191 |
|
192 EXPORT_C void CContactService:: OrganiseGroupsL( const TDesC8& aGroupId, |
|
193 RPointerArray<TDesC8>& aContactIdArray, |
|
194 TBool aAssociateFlag, |
|
195 const TDesC& aStoreUri) |
|
196 { |
|
197 //create the callback object internally |
|
198 CContactSyncCallback* callback = new(ELeave) CContactSyncCallback(); |
|
199 CleanupStack::PushL(callback); |
|
200 //create the wait scheduler instance |
|
201 CActiveSchedulerWait* waitScheduler = new(ELeave) CActiveSchedulerWait(); |
|
202 CleanupStack::PushL(waitScheduler); |
|
203 //needed to stop the scheduler by the callback instance |
|
204 callback->SetWaitScheduler(waitScheduler); |
|
205 //call the asynch sapi with all the params |
|
206 //TInt err = KErrNone; |
|
207 TRAPD(err,OrganiseGroupsL(callback, |
|
208 0, |
|
209 aGroupId, |
|
210 aContactIdArray, |
|
211 aAssociateFlag, |
|
212 aStoreUri)); |
|
213 //TRAP harness is used to unset the sync flag in leaving condition |
|
214 //since we r using the same async apis for sync implementation |
|
215 if(err!= KErrNone) |
|
216 { |
|
217 User::Leave(err); |
|
218 } |
|
219 //start the wait scheduler and wait untill the operation finishes |
|
220 waitScheduler->Start(); |
|
221 //Unset the callbak pointer |
|
222 callback->SetWaitScheduler(NULL); |
|
223 //check for any errors |
|
224 TInt error = callback->GetErrorCode(); |
|
225 if(error!= KErrNone) |
|
226 { |
|
227 User::Leave(error); |
|
228 } |
|
229 CleanupStack::PopAndDestroy(waitScheduler); |
|
230 CleanupStack::PopAndDestroy(callback); |
|
231 } |
|
232 |
|
233 |
|
234 /* |
|
235 ----------------------------------------------------------------------------- |
|
236 CContactService :: ExportVCardL |
|
237 Description : synchronous implementation of ExportVCardL api. |
|
238 Return values : CContactIter* |
|
239 ----------------------------------------------------------------------------- |
|
240 */ |
|
241 |
|
242 |
|
243 EXPORT_C void CContactService::ExportVCardL(const TFileName& aFileName, |
|
244 const TDesC8& aContactId, |
|
245 const TDesC& aStoreUri) |
|
246 |
|
247 { |
|
248 //create the callback object internally |
|
249 CContactSyncCallback* callback = new(ELeave) CContactSyncCallback(); |
|
250 CleanupStack::PushL(callback); |
|
251 //create the wait scheduler instance |
|
252 CActiveSchedulerWait* waitScheduler = new(ELeave) CActiveSchedulerWait(); |
|
253 CleanupStack::PushL(waitScheduler); |
|
254 //needed to stop the scheduler by the callback instance |
|
255 callback->SetWaitScheduler(waitScheduler); |
|
256 //call the asynch sapi with all the params |
|
257 TRAPD(err,ExportVCardL(callback, |
|
258 0, |
|
259 aFileName, |
|
260 aContactId, |
|
261 aStoreUri)); |
|
262 //TRAP harness is used to unset the sync flag in leaving condition |
|
263 //since we r using the same async apis for sync implementation |
|
264 if(err!= KErrNone) |
|
265 { |
|
266 User::Leave(err); |
|
267 } |
|
268 //start the wait scheduler and wait untill the operation finishes |
|
269 waitScheduler->Start(); |
|
270 //Unset the callbak pointer |
|
271 callback->SetWaitScheduler(NULL); |
|
272 //check for any errors |
|
273 TInt error = callback->GetErrorCode(); |
|
274 if( error!= KErrNone ) |
|
275 { |
|
276 User::Leave(error); |
|
277 } |
|
278 CleanupStack::PopAndDestroy(waitScheduler); |
|
279 CleanupStack::PopAndDestroy(callback); |
|
280 } |
|
281 |
|
282 /* |
|
283 ----------------------------------------------------------------------------- |
|
284 CContactService :: ImportVCardToStoreL |
|
285 Description : synchronous implementation of ImportVCardToStoreL api. |
|
286 Return values : CContactIter* |
|
287 ----------------------------------------------------------------------------- |
|
288 */ |
|
289 |
|
290 EXPORT_C void CContactService::ImportVCardToStoreL(const TFileName& aFilename, |
|
291 const TDesC& aStoreUri) |
|
292 { |
|
293 //create the callback object internally |
|
294 CContactSyncCallback* callback = new(ELeave) CContactSyncCallback(); |
|
295 CleanupStack::PushL(callback); |
|
296 //create the wait scheduler instance |
|
297 CActiveSchedulerWait* waitScheduler = new(ELeave) CActiveSchedulerWait(); |
|
298 CleanupStack::PushL(waitScheduler); |
|
299 //needed to stop the scheduler by the callback instance |
|
300 callback->SetWaitScheduler(waitScheduler); |
|
301 //call the asynch sapi with all the params |
|
302 TRAPD(err,ImportVCardToStoreL(callback, |
|
303 0, |
|
304 aFilename, |
|
305 aStoreUri)); |
|
306 //TRAP harness is used to unset the sync flag in leaving condition |
|
307 //since we r using the same async apis for sync implementation |
|
308 if(err!= KErrNone) |
|
309 { |
|
310 User::Leave(err); |
|
311 } |
|
312 //start the wait scheduler and wait untill the operation finishes |
|
313 waitScheduler->Start(); |
|
314 //Unset the callbak pointer |
|
315 callback->SetWaitScheduler(NULL); |
|
316 //check for any errors |
|
317 TInt error = callback->GetErrorCode(); |
|
318 if( error!= KErrNone ) |
|
319 { |
|
320 User::Leave(error); |
|
321 } |
|
322 CleanupStack::PopAndDestroy(waitScheduler); |
|
323 CleanupStack::PopAndDestroy(callback); |
|
324 } |
|
325 |