Update change log and spec for wrt-plugins-tizen_0.4.27
[framework/web/wrt-plugins-tizen.git] / src / DataSync / DataSyncManager.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18
19 #include "DataSyncManager.h"
20 #include "SyncInfo.h"
21 #include "SyncServiceInfo.h"
22 #include "SyncProfileInfo.h"
23
24 #include <sync_agent.h>
25 #include <sstream>
26 #include <Logger.h>
27
28 using namespace WrtDeviceApis::Commons;
29
30 namespace DeviceAPI {
31 namespace DataSync {
32
33 int DataSyncManager::m_instanceCount = 0;
34
35 DataSyncManager::DataSyncManager()
36 {
37         LoggerI("Initialize the datasync manager with count: "<<m_instanceCount);
38
39     if (0==m_instanceCount) {
40                 sync_agent_ds_error_e ds_err = sync_agent_ds_init();
41                 if (SYNC_AGENT_DS_SUCCESS!=ds_err) {
42                    LoggerE("Failed to init oma ds.");
43                 }
44         }
45     m_instanceCount++;
46 }
47
48 DataSyncManager::~DataSyncManager()
49 {
50         LoggerI("Deinitialize the datasync manager with count: "<<m_instanceCount);
51
52     m_instanceCount--;
53     if (0==m_instanceCount) {
54                 sync_agent_ds_error_e ds_err = sync_agent_ds_deinit();
55                 if (SYNC_AGENT_DS_SUCCESS!=ds_err) {
56                    LoggerE("Failed to deinit oma ds.");
57                 }
58         }
59 }
60
61 static int datasync_state_changed_cb(sync_agent_event_data_s* request, void *user_data)
62 {
63     LoggerD("DataSync session state changed.");
64
65         char *profileDirName = NULL;
66         int sync_type = 0;
67         char *progress = NULL;
68         char *error = NULL;
69
70     Try
71     {
72         OnDataSyncStateChangedPtr eventPtr(new OnDataSyncStateChanged());
73         DataSyncManager* thisDataSyncManager = (DataSyncManager*) user_data;
74
75                 LoggerD("Get state info.");
76                 sync_agent_get_event_data_param(request, &profileDirName);
77                 sync_agent_get_event_data_param(request, &sync_type);
78                 sync_agent_get_event_data_param(request, &progress);
79                 sync_agent_get_event_data_param(request, &error);
80
81                 LoggerD("profileDirName: "<<profileDirName<<", sync_type: "<<sync_type<<", progress: "<<progress<<", error: "<<error);
82
83                 if(profileDirName) {
84                 eventPtr->setProfileId(profileDirName);
85                 }
86
87                 if(NULL==progress) {
88                         LoggerW("Null status.");
89                         eventPtr->setSessionStatus(OnDataSyncStateChanged::UNDEFINED_STATUS);
90                 } else if(0==strcmp(progress, "DONE")) {
91                         eventPtr->setSessionStatus(OnDataSyncStateChanged::COMPLETE_STATUS);
92                 } else if(0==strcmp(progress, "CANCEL")) {
93                         eventPtr->setSessionStatus(OnDataSyncStateChanged::STOP_STATUS);
94                 } else if(0==strcmp(progress, "ERROR")) {
95                         // Error cases should be redefined and transferred based on the error value.
96                         eventPtr->setSessionStatus(OnDataSyncStateChanged::FAIL_STATUS);
97                 } else {
98                         LoggerW("Wrong status.");
99                         eventPtr->setSessionStatus(OnDataSyncStateChanged::UNDEFINED_STATUS);
100                 }
101
102         eventPtr->setResult(true);
103
104                 if(profileDirName) {
105                 if (thisDataSyncManager->m_changeEmitters[profileDirName]) {
106                     thisDataSyncManager->m_changeEmitters[profileDirName]->emit(eventPtr);
107                 }
108                 }
109     }
110     Catch (Exception)
111     {
112         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
113     }
114
115         if(profileDirName) {
116                 g_free(profileDirName);
117         }
118         if(progress) {
119                 g_free(progress);
120         }
121         if(error) {
122                 g_free(error);
123         }
124
125         if (request != NULL) {
126                 if (request->size != NULL) {
127                         g_free(request->size);
128                 }
129                 g_free(request);
130         }
131
132         return 0;
133 }
134
135 static int datasync_progress_cb(sync_agent_event_data_s* request, void *user_data)
136 {
137     LoggerD("DataSync progress called.");
138
139         char *profileDirName = NULL;
140         int syncType = 0;
141         int uri;
142         char *progressStatus = NULL;
143         char *operationType = NULL;
144
145     Try
146     {
147         OnDataSyncStateChangedPtr eventPtr(new OnDataSyncStateChanged());
148         DataSyncManager* thisDataSyncManager = (DataSyncManager*) user_data;
149
150                 int isFromServer, totalPerOperation, syncedPerOperation, totalPerDb, syncedPerDb;
151
152                 LoggerD("Get progress info.");
153                 sync_agent_get_event_data_param(request, &profileDirName);
154                 sync_agent_get_event_data_param(request, &syncType);
155                 sync_agent_get_event_data_param(request, &uri);
156                 sync_agent_get_event_data_param(request, &progressStatus);
157                 sync_agent_get_event_data_param(request, &operationType);
158
159                 LoggerD("profileDirName: "<<profileDirName<<", syncType: "<<syncType<<", uri: "<<uri<<", progressStatus: "<<progressStatus<<", operationType "<<operationType);
160
161                 sync_agent_get_event_data_param(request, &isFromServer);
162                 sync_agent_get_event_data_param(request, &totalPerOperation);
163                 sync_agent_get_event_data_param(request, &syncedPerOperation);
164                 sync_agent_get_event_data_param(request, &totalPerDb);
165                 sync_agent_get_event_data_param(request, &syncedPerDb);
166
167                 LoggerD("isFromServer: "<<isFromServer<<", totalPerOperation: "<<totalPerOperation<<", syncedPerOperation: "<<syncedPerOperation<<", totalPerDb: "<<totalPerDb<<", syncedPerDb "<<syncedPerDb);
168
169                 if(profileDirName) {
170                 eventPtr->setProfileId(profileDirName);
171                 }
172
173                 eventPtr->setSessionStatus(OnDataSyncStateChanged::PROGRESS_STATUS);
174
175                 if(SYNC_AGENT_SRC_URI_CONTACT==uri) {
176                 eventPtr->setServiceType(SyncServiceInfo::CONTACT_SERVICE_TYPE);
177                 } else if(SYNC_AGENT_SRC_URI_CALENDAR==uri) {
178                 eventPtr->setServiceType(SyncServiceInfo::EVENT_SERVICE_TYPE);
179                 } else {
180                         LoggerW("Wrong service type.");
181                 eventPtr->setServiceType(SyncServiceInfo::UNDEFINED_SERVICE_TYPE);
182                 }
183
184         eventPtr->setIsFromServer(isFromServer);
185                 eventPtr->setSynedPerService(syncedPerDb);
186                 eventPtr->setTotalPerService(totalPerDb);
187
188         eventPtr->setResult(true);
189
190                 if(profileDirName) {
191                 if (thisDataSyncManager->m_changeEmitters[profileDirName]) {
192                     thisDataSyncManager->m_changeEmitters[profileDirName]->emit(eventPtr);
193                 }
194                 }
195     }
196     Catch (Exception)
197     {
198         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
199     }
200
201         if(profileDirName) {
202                 g_free(profileDirName);
203         }
204         if(progressStatus) {
205                 g_free(progressStatus);
206         }
207         if(operationType) {
208                 g_free(operationType);
209         }
210
211         if (request != NULL) {
212                 if (request->size != NULL) {
213                         g_free(request->size);
214                 }
215                 g_free(request);
216         }
217
218         return 0;
219 }
220
221 static sync_agent_ds_sync_mode_e convertToPlatformSyncMode(SyncInfo::SyncMode syncMode)
222 {
223         if(SyncInfo::MANUAL_MODE==syncMode) {
224                 return SYNC_AGENT_SYNC_MODE_MANUAL;
225         } else if(SyncInfo::PERIODIC_MODE==syncMode) {
226                 return SYNC_AGENT_SYNC_MODE_PERIODIC;
227         } else if(SyncInfo::PUSH_MODE==syncMode) {
228                 return SYNC_AGENT_SYNC_MODE_PUSH;
229         } else {
230                 LoggerW("Error while converting a sync mode.");
231         }
232
233         return SYNC_AGENT_SYNC_MODE_MANUAL;
234 }
235
236 static SyncInfo::SyncMode convertToSyncMode(sync_agent_ds_sync_mode_e syncMode)
237 {
238         if(SYNC_AGENT_SYNC_MODE_MANUAL==syncMode) {
239                 return SyncInfo::MANUAL_MODE;
240         } else if(SYNC_AGENT_SYNC_MODE_PERIODIC==syncMode) {
241                 return SyncInfo::PERIODIC_MODE;
242         } else if(SYNC_AGENT_SYNC_MODE_PUSH==syncMode) {
243                 return SyncInfo::PUSH_MODE;
244         } else {
245                 LoggerW("Error while converting a sync mode.");
246         }
247
248         return SyncInfo::UNDEFINED_MODE;
249 }
250
251 static sync_agent_ds_sync_type_e convertToPlatformSyncType(SyncInfo::SyncType syncType)
252 {
253         if(SyncInfo::TWO_WAY_TYPE==syncType) {
254                 return SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH;
255         } else if(SyncInfo::SLOW_TYPE==syncType) {
256                 return SYNC_AGENT_SYNC_TYPE_FULL_SYNC;
257         } else if(SyncInfo::ONE_WAY_FROM_CLIENT_TYPE==syncType) {
258                 return SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER;
259         } else if(SyncInfo::REFRESH_FROM_CLIENT_TYPE==syncType) {
260                 return SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE;
261         } else if(SyncInfo::ONE_WAY_FROM_SERVER_TYPE==syncType) {
262                 return SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE;
263         } else if(SyncInfo::REFRESH_FROM_SERVER_TYPE==syncType) {
264                 return SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER;
265         } else {
266                 LoggerW("Error while converting a sync type.");
267         }
268
269         return SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH;
270 }
271
272 static SyncInfo::SyncType convertToSyncType(sync_agent_ds_sync_type_e syncType)
273 {
274         if(SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH==syncType) {
275                 return SyncInfo::TWO_WAY_TYPE;
276         } else if(SYNC_AGENT_SYNC_TYPE_FULL_SYNC==syncType) {
277                 return SyncInfo::SLOW_TYPE;
278         } else if(SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER==syncType) {
279                 return SyncInfo::ONE_WAY_FROM_CLIENT_TYPE;
280         } else if(SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE==syncType) {
281                 return SyncInfo::REFRESH_FROM_CLIENT_TYPE;
282         } else if(SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE==syncType) {
283                 return SyncInfo::ONE_WAY_FROM_SERVER_TYPE;
284         } else if(SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER==syncType) {
285                 return SyncInfo::REFRESH_FROM_SERVER_TYPE;
286         } else {
287                 LoggerW("Error while converting a sync type.");
288         }
289
290         return SyncInfo::UNDEFINED_TYPE;
291 }
292
293 static sync_agent_ds_sync_interval_e convertToPlatformSyncInterval(SyncInfo::SyncInterval syncInterval)
294 {
295         if(SyncInfo::INTERVAL_5_MINUTES==syncInterval) {
296                 return SYNC_AGENT_SYNC_INTERVAL_5_MINUTES;
297         } else if(SyncInfo::INTERVAL_15_MINUTES==syncInterval) {
298                 return SYNC_AGENT_SYNC_INTERVAL_15_MINUTES;
299         } else if(SyncInfo::INTERVAL_1_HOUR==syncInterval) {
300                 return SYNC_AGENT_SYNC_INTERVAL_1_HOUR;
301         } else if(SyncInfo::INTERVAL_4_HOURS==syncInterval) {
302                 return SYNC_AGENT_SYNC_INTERVAL_4_HOURS;
303         } else if(SyncInfo::INTERVAL_12_HOURS==syncInterval) {
304                 return SYNC_AGENT_SYNC_INTERVAL_12_HOURS;
305         } else if(SyncInfo::INTERVAL_1_DAY==syncInterval) {
306                 return SYNC_AGENT_SYNC_INTERVAL_1_DAY;
307         } else if(SyncInfo::INTERVAL_1_WEEK==syncInterval) {
308                 return SYNC_AGENT_SYNC_INTERVAL_1_WEEK;
309         } else if(SyncInfo::INTERVAL_1_MONTH==syncInterval) {
310                 return SYNC_AGENT_SYNC_INTERVAL_1_MONTH;
311         } else {
312                 LoggerW("Error while converting a sync interval.");
313         }
314
315         return SYNC_AGENT_SYNC_INTERVAL_1_WEEK;
316 }
317
318 static SyncInfo::SyncInterval convertToSyncInterval(sync_agent_ds_sync_interval_e syncInterval)
319 {
320         if(SYNC_AGENT_SYNC_INTERVAL_5_MINUTES==syncInterval) {
321                 return SyncInfo::INTERVAL_5_MINUTES;
322         } else if(SYNC_AGENT_SYNC_INTERVAL_15_MINUTES==syncInterval) {
323                 return SyncInfo::INTERVAL_15_MINUTES;
324         } else if(SYNC_AGENT_SYNC_INTERVAL_1_HOUR==syncInterval) {
325                 return SyncInfo::INTERVAL_1_HOUR;
326         } else if(SYNC_AGENT_SYNC_INTERVAL_4_HOURS==syncInterval) {
327                 return SyncInfo::INTERVAL_4_HOURS;
328         } else if(SYNC_AGENT_SYNC_INTERVAL_12_HOURS==syncInterval) {
329                 return SyncInfo::INTERVAL_12_HOURS;
330         } else if(SYNC_AGENT_SYNC_INTERVAL_1_DAY==syncInterval) {
331                 return SyncInfo::INTERVAL_1_DAY;
332         } else if(SYNC_AGENT_SYNC_INTERVAL_1_WEEK==syncInterval) {
333                 return SyncInfo::INTERVAL_1_WEEK;
334         } else if(SYNC_AGENT_SYNC_INTERVAL_1_MONTH==syncInterval) {
335                 return SyncInfo::INTERVAL_1_MONTH;
336         } else {
337                 LoggerW("Error while converting a sync interval.");
338         }
339
340         return SyncInfo::INTERVAL_UNDEFINED;
341 }
342
343 static sync_agent_ds_service_type_e convertToPlatformSyncServiceType(SyncServiceInfo::SyncServiceType serviceType)
344 {
345         if(SyncServiceInfo::CONTACT_SERVICE_TYPE==serviceType) {
346                 return SYNC_AGENT_CONTACT;
347         } else if(SyncServiceInfo::EVENT_SERVICE_TYPE==serviceType) {
348                 return SYNC_AGENT_CALENDAR;
349         } else {
350                 LoggerW("Error while converting a sync service type.");
351         }
352
353         return SYNC_AGENT_CONTACT;
354 }
355
356 static SyncServiceInfo::SyncServiceType convertToSyncServiceType(sync_agent_ds_service_type_e serviceType)
357 {
358         if(SYNC_AGENT_CONTACT==serviceType) {
359                 return SyncServiceInfo::CONTACT_SERVICE_TYPE;
360         } else if(SYNC_AGENT_CALENDAR==serviceType) {
361                 return SyncServiceInfo::EVENT_SERVICE_TYPE;
362         } else {
363                 LoggerW("Error while converting a sync service type.");
364         }
365
366         return SyncServiceInfo::UNDEFINED_SERVICE_TYPE;
367 }
368
369 static sync_agent_ds_src_uri_e convertToPlatformSourceUri(SyncServiceInfo::SyncServiceType serviceType)
370 {
371         if(SyncServiceInfo::CONTACT_SERVICE_TYPE==serviceType) {
372                 return SYNC_AGENT_SRC_URI_CONTACT;
373         } else if(SyncServiceInfo::EVENT_SERVICE_TYPE==serviceType) {
374                 return SYNC_AGENT_SRC_URI_CALENDAR;
375         } else {
376                 LoggerW("Error while converting a sync service.");
377         }
378
379         return SYNC_AGENT_SRC_URI_CONTACT;
380 }
381
382 static SyncStatistics::SyncStatus convertToSyncStatus(char* status)
383 {
384         if(0==strcmp(status, "success")) {
385                 return SyncStatistics::SUCCESS_STATUS;
386         } else if(0==strcmp(status, "stop")) {
387                 return SyncStatistics::STOP_STATUS;
388         } else if(0==strcmp(status, "fail")) {
389                 return SyncStatistics::FAIL_STATUS;
390         } else if(0==strcmp(status, "No")) {
391                 return SyncStatistics::NONE_STATUS;
392         } else {
393                 LoggerW("Error while converting a sync status.");
394         }
395
396         return SyncStatistics::UNDEFINED_STATUS;
397 }
398
399 void DataSyncManager::OnRequestReceived(const IEventAddProfilePtr &event)
400 {
401         ds_profile_h profile_h = NULL;
402
403     Try
404     {
405         // Check if the quota is full first.
406                 GList *profile_list = NULL;
407                 GList *iter = NULL;
408
409         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
410
411                 ret = sync_agent_ds_get_all_profile(&profile_list);
412                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
413                         ThrowMsg(PlatformException, "Platform error while getting all profiles: "<<ret);
414                 }
415
416                 int numProfiles = g_list_length(profile_list);
417                 for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
418                    sync_agent_ds_free_profile_info((ds_profile_h) iter->data);
419                 }
420                 if(profile_list) {
421                         g_list_free(profile_list);
422                 }
423                 LoggerD("numProfiles: "<<numProfiles);
424                 if(MAX_PROFILES_NUM==numProfiles) {
425                         ThrowMsg(OutOfRangeException, "There are already maximum number of profiles!");
426                 }
427
428         SyncProfileInfoPtr profile;
429         profile = event->getProfile();
430         if (!profile) {
431             ThrowMsg(NullPointerException, "SyncProfileInfo is NULL.");
432         }
433
434                 ret = sync_agent_ds_create_profile_info(&profile_h);
435                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
436                         ThrowMsg(PlatformException, "Platform error while creating a profile: "<<ret);
437                 }
438
439                 ret = sync_agent_ds_set_profile_name(profile_h, (char*)(profile->getProfileName().c_str()));
440                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
441                         ThrowMsg(PlatformException, "Platform error while settting a profile name: "<<ret);
442                 }
443
444                 ret = sync_agent_ds_set_server_info(profile_h, (char*)(profile->getSyncInfo()->getUrl().c_str()),  (char*)(profile->getSyncInfo()->getId().c_str()),  (char*)(profile->getSyncInfo()->getPassword().c_str()));
445                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
446                         ThrowMsg(PlatformException, "Platform error while settting a server info: "<<ret);
447                 }
448
449                 sync_agent_ds_sync_mode_e syncMode = convertToPlatformSyncMode(profile->getSyncInfo()->getSyncMode());
450                 sync_agent_ds_sync_type_e syncType = convertToPlatformSyncType(profile->getSyncInfo()->getSyncType());
451                 sync_agent_ds_sync_interval_e syncInterval = convertToPlatformSyncInterval(profile->getSyncInfo()->getSyncInterval());
452                 LoggerD("syncMode: "<<syncMode<<", syncType: "<<syncType<<", syncInterval: "<<syncInterval);
453
454                 ret = sync_agent_ds_set_sync_info(profile_h, syncMode, syncType, syncInterval);
455                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
456                         ThrowMsg(PlatformException, "Platform error while settting a sync info: "<<ret);
457                 }
458
459                 // Set the sync categories.
460                 SyncServiceInfoListPtr categories = profile->getServiceInfo();
461                 sync_agent_ds_service_type_e serviceType;
462                 sync_agent_ds_src_uri_e srcURI;
463                 std::string tgtURI, id, password;
464                 bool enable;
465                 for(unsigned int i=0; categories->size()>i; i++) {
466                         serviceType = convertToPlatformSyncServiceType(categories->at(i)->getSyncServiceType());
467                         tgtURI = categories->at(i)->getServerDatabaseUri();
468                         srcURI = convertToPlatformSourceUri(categories->at(i)->getSyncServiceType());
469                         id = categories->at(i)->getId();
470                         password = categories->at(i)->getPassword();
471                         enable = categories->at(i)->getEnable();
472
473                         LoggerD("serviceType: "<<serviceType<<", tgtURI: "<<tgtURI<<", id: "<<id<<" for index: "<<i);
474
475                         ret = sync_agent_ds_set_sync_service_info(profile_h, serviceType, enable, srcURI, (char*)(tgtURI.c_str()),
476                                         0==id.size() ? NULL : (char*)(id.c_str()), 0==password.size() ? NULL : (char*)(password.c_str()));
477                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
478                                 ThrowMsg(PlatformException, "Platform error while settting a sync service info: "<<ret);
479                         }
480                 }
481
482                 int profileId;
483                 ret = sync_agent_ds_add_profile(profile_h, &profileId);
484                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
485                         ThrowMsg(PlatformException, "Platform error while adding a profile: "<<ret);
486                 }
487
488         LoggerD("profileId from platform: "<<profileId);
489
490                 char* profileName = NULL;
491                 ret = sync_agent_ds_get_profile_name(profile_h, &profileName);
492                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
493                         ThrowMsg(PlatformException, "Platform error while getting a profile name: "<<ret);
494                 }
495
496         LoggerD("profileName: "<<profileName<<", profileId: "<<profileId);
497
498                 std::stringstream ss;
499                 ss<<profileId;
500                 profile->setProfileId(ss.str());
501
502                 if(profileName) {
503                         free(profileName);
504                 }
505
506         event->setResult(true);
507     }
508     Catch(OutOfRangeException)
509     {
510                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
511         event->setResult(false);
512         event->setExceptionCode(ExceptionCodes::OutOfRangeException);
513     }
514     Catch(Exception)
515     {
516                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
517         event->setResult(false);
518         event->setExceptionCode(ExceptionCodes::PlatformException);
519     }
520
521         if(profile_h) {
522                 sync_agent_ds_free_profile_info(profile_h);
523         }
524 }
525
526 void DataSyncManager::OnRequestReceived(const IEventUpdateProfilePtr &event)
527 {
528         ds_profile_h profile_h = NULL;
529
530     Try
531     {
532         SyncProfileInfoPtr profile;
533         profile = event->getProfile();
534         if (!profile) {
535             ThrowMsg(NullPointerException, "SyncProfileInfo is NULL.");
536         }
537
538         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
539
540                 int profileId = -1;
541                 std::stringstream ss(profile->getProfileId());
542                 ss>>profileId;
543         LoggerD("profileId: "<<profileId);
544                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
545                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
546                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
547                 }
548
549                 ret = sync_agent_ds_set_profile_name(profile_h, (char*)(profile->getProfileName().c_str()));
550                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
551                         ThrowMsg(PlatformException, "Platform error while settting a profile name: "<<ret);
552                 }
553
554                 ret = sync_agent_ds_set_server_info(profile_h, (char*)(profile->getSyncInfo()->getUrl().c_str()),  (char*)(profile->getSyncInfo()->getId().c_str()),  (char*)(profile->getSyncInfo()->getPassword().c_str()));
555                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
556                         ThrowMsg(PlatformException, "Platform error while settting a server info: "<<ret);
557                 }
558
559                 sync_agent_ds_sync_mode_e syncMode = convertToPlatformSyncMode(profile->getSyncInfo()->getSyncMode());
560                 sync_agent_ds_sync_type_e syncType = convertToPlatformSyncType(profile->getSyncInfo()->getSyncType());
561                 sync_agent_ds_sync_interval_e syncInterval = convertToPlatformSyncInterval(profile->getSyncInfo()->getSyncInterval());
562                 LoggerD("syncMode: "<<syncMode<<", syncType: "<<syncType<<", syncInterval: "<<syncInterval);
563
564                 ret = sync_agent_ds_set_sync_info(profile_h, syncMode, syncType, syncInterval);
565                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
566                         ThrowMsg(PlatformException, "Platform error while settting a sync info: "<<ret);
567                 }
568
569                 // Set the sync categories.
570                 SyncServiceInfoListPtr categories = profile->getServiceInfo();
571                 sync_agent_ds_service_type_e serviceType;
572                 sync_agent_ds_src_uri_e srcURI;
573                 std::string tgtURI, id, password;
574                 bool enable;
575                 for(unsigned int i=0; categories->size()<i; i++) {
576                         serviceType = convertToPlatformSyncServiceType(categories->at(i)->getSyncServiceType());
577                         tgtURI = categories->at(i)->getServerDatabaseUri();
578                         srcURI = convertToPlatformSourceUri(categories->at(i)->getSyncServiceType());
579                         id = categories->at(i)->getId();
580                         password = categories->at(i)->getPassword();
581                         enable = categories->at(i)->getEnable();
582
583                         LoggerD("serviceType: "<<serviceType<<", tgtURI: "<<tgtURI<<", id: "<<id<<" for index: "<<i);
584
585                         ret = sync_agent_ds_set_sync_service_info(profile_h, serviceType, enable, srcURI, (char*)(tgtURI.c_str()),
586                                         0==id.size() ? NULL : (char*)(id.c_str()), 0==password.size() ? NULL : (char*)(password.c_str()));
587                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
588                                 ThrowMsg(PlatformException, "Platform error while settting a sync service info: "<<ret);
589                         }
590                 }
591
592                 ret = sync_agent_ds_update_profile(profile_h);
593                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
594                         ThrowMsg(NotFoundException, "Platform error while updating a profile: "<<ret);
595                 }
596
597         event->setResult(true);
598     }
599     Catch(NotFoundException)
600     {
601         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
602         event->setResult(false);
603         event->setExceptionCode(ExceptionCodes::NotFoundException);
604     }
605     Catch(Exception)
606     {
607                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
608         event->setResult(false);
609         event->setExceptionCode(ExceptionCodes::PlatformException);
610     }
611
612         if(profile_h) {
613                 sync_agent_ds_free_profile_info(profile_h);
614         }
615 }
616
617 void DataSyncManager::OnRequestReceived(const IEventRemoveProfilePtr &event)
618 {
619         ds_profile_h profile_h = NULL;
620
621     Try
622     {
623         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
624
625                 int profileId = -1;
626                 std::stringstream ss(event->getProfileId());
627                 ss>>profileId;
628         LoggerD("profileId: "<<profileId);
629                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
630                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
631                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
632                 }
633
634                 ret = sync_agent_ds_delete_profile(profile_h);
635                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
636                         ThrowMsg(PlatformException, "Platform error while deleting a profile: "<<ret);
637                 }
638
639         event->setResult(true);
640     }
641     Catch(NotFoundException)
642     {
643         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
644         event->setResult(false);
645         event->setExceptionCode(ExceptionCodes::NotFoundException);
646     }
647     Catch(Exception)
648     {
649                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
650         event->setResult(false);
651         event->setExceptionCode(ExceptionCodes::PlatformException);
652     }
653
654         if(profile_h) {
655                 sync_agent_ds_free_profile_info(profile_h);
656         }
657 }
658
659 void DataSyncManager::OnRequestReceived(const IEventGetMaxProfilesNumPtr &event)
660 {
661     Try
662     {
663         LoggerD("Return maximum number of supported profiles: "<<MAX_PROFILES_NUM);
664
665                 event->setNumMaxProfiles(MAX_PROFILES_NUM);
666
667         event->setResult(true);
668     }
669     Catch(Exception)
670     {
671                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
672         event->setResult(false);
673         event->setExceptionCode(ExceptionCodes::PlatformException);
674     }
675 }
676
677 void DataSyncManager::OnRequestReceived(const IEventGetProfilesNumPtr &event)
678 {
679         GList *profile_list = NULL;
680         GList *iter = NULL;
681
682     Try
683     {
684         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
685
686                 ret = sync_agent_ds_get_all_profile(&profile_list);
687                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
688                         ThrowMsg(PlatformException, "Platform error while getting all profiles: "<<ret);
689                 }
690
691                 int numProfiles=0;
692                 for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
693                    sync_agent_ds_free_profile_info((ds_profile_h) iter->data);
694                    LoggerD("Free sync_agent_ds_profile_info for index: "<<numProfiles++);
695                 }
696
697                 LoggerD("numProfiles: "<<numProfiles);
698
699                 event->setNumProfiles(numProfiles);
700
701         event->setResult(true);
702     }
703     Catch(Exception)
704     {
705                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
706         event->setResult(false);
707         event->setExceptionCode(ExceptionCodes::PlatformException);
708     }
709 }
710
711 void DataSyncManager::OnRequestReceived(const IEventGetProfilePtr &event)
712 {
713         ds_profile_h profile_h = NULL;
714
715     Try
716     {
717         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
718
719                 int profileId = -1;
720                 std::stringstream ss(event->getProfileId());
721                 ss>>profileId;
722         LoggerD("profileId: "<<profileId);
723                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
724                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
725                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
726                 }
727
728                 SyncProfileInfoPtr profile( new SyncProfileInfo() );
729
730                 profile->setProfileId(event->getProfileId());
731
732                 char *profileName = NULL;
733                 ret = sync_agent_ds_get_profile_name(profile_h, &profileName);
734                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
735                         ThrowMsg(PlatformException, "Platform error while gettting a profile name: "<<ret);
736                 }
737                 profile->setProfileName(profileName);
738
739                 sync_agent_ds_server_info server_info = { NULL };
740                 ret = sync_agent_ds_get_server_info(profile_h, &server_info);
741                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
742                         ThrowMsg(PlatformException, "Platform error while gettting a server info: "<<ret);
743                 }
744                 profile->getSyncInfo()->setUrl(server_info.addr);
745                 profile->getSyncInfo()->setId(server_info.id);
746                 profile->getSyncInfo()->setPassword(server_info.password);
747
748                 sync_agent_ds_sync_info sync_info;
749                 ret = sync_agent_ds_get_sync_info(profile_h, &sync_info);
750                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
751                         ThrowMsg(PlatformException, "Platform error while gettting a sync info: "<<ret);
752                 }
753                 profile->getSyncInfo()->setSyncMode(convertToSyncMode(sync_info.sync_mode));
754                 profile->getSyncInfo()->setSyncType(convertToSyncType(sync_info.sync_type));
755                 profile->getSyncInfo()->setSyncInterval(convertToSyncInterval(sync_info.interval));
756
757                 LoggerD("Sync mode: "<<sync_info.sync_mode<<", type: "<<sync_info.sync_type<<", interval: "<<sync_info.interval);
758
759                 GList *category_list = NULL;
760                 sync_agent_ds_service_info *category_info = NULL;
761                 ret = sync_agent_ds_get_sync_service_info(profile_h, &category_list);
762                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
763                         ThrowMsg(PlatformException, "Platform error while gettting sync categories: "<<ret);
764                 }
765                 int category_count = g_list_length(category_list);
766                 LoggerD("category_count: "<<category_count);
767                 while(category_count--) {
768                         category_info = (sync_agent_ds_service_info *) g_list_nth_data(category_list, category_count);
769                         if(SYNC_AGENT_CALENDAR<category_info->service_type) {
770                                 LoggerD("Skip unsupported sync service type: "<<category_info->service_type);
771                                 continue;
772                         }
773
774                         SyncServiceInfoPtr serviceInfo( new SyncServiceInfo() );
775                         serviceInfo->setEnable(category_info->enabled);
776                         if(category_info->id) {
777                                 serviceInfo->setId(category_info->id);
778                         }
779                         if(category_info->password) {
780                                 serviceInfo->setPassword(category_info->password);
781                         }
782                         serviceInfo->setSyncServiceType(convertToSyncServiceType(category_info->service_type));
783                         if(category_info->tgt_uri) {
784                                 serviceInfo->setServerDatabaseUri(category_info->tgt_uri);
785                         }
786
787                         LoggerD("Service type: "<<serviceInfo->getSyncServiceType());
788                         profile->getServiceInfo()->push_back(serviceInfo);
789                 }
790                 if(category_list) {
791                         g_list_free(category_list);
792                 }
793
794                 event->setProfile(profile);
795
796         event->setResult(true);
797     }
798     Catch(NotFoundException)
799     {
800         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
801         event->setResult(false);
802         event->setExceptionCode(ExceptionCodes::NotFoundException);
803     }
804     Catch(Exception)
805     {
806                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
807         event->setResult(false);
808         event->setExceptionCode(ExceptionCodes::PlatformException);
809     }
810
811         if(profile_h) {
812                 sync_agent_ds_free_profile_info(profile_h);
813         }
814 }
815
816 void DataSyncManager::OnRequestReceived(const IEventGetAllProfilesPtr &event)
817 {
818         GList *profile_list = NULL;
819         GList *iter = NULL;
820
821     Try
822     {
823                 ds_profile_h profile_h = NULL;
824         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
825
826                 ret = sync_agent_ds_get_all_profile(&profile_list);
827                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
828                         ThrowMsg(PlatformException, "Platform error while getting all profiles: "<<ret);
829                 }
830
831                 LoggerD("Number of profiles: "<< g_list_length(profile_list));
832                 for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
833                         profile_h = (ds_profile_h) iter->data;
834                         SyncProfileInfoPtr profile( new SyncProfileInfo() );
835
836                         int profileId;
837                         ret = sync_agent_ds_get_profile_id(profile_h, &profileId);
838                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
839                                 ThrowMsg(PlatformException, "Platform error while gettting a profile id: "<<ret);
840                         }
841
842                         std::stringstream ss;
843                         ss<<profileId;
844                         profile->setProfileId(ss.str());
845
846                         LoggerD("Processing a profile with id: "<<profile->getProfileId());
847
848                         char *profileName = NULL;
849                         ret = sync_agent_ds_get_profile_name(profile_h, &profileName);
850                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
851                                 ThrowMsg(PlatformException, "Platform error while gettting a profile name: "<<ret);
852                         }
853                         profile->setProfileName(profileName);
854
855                         sync_agent_ds_server_info server_info = { NULL };
856                         ret = sync_agent_ds_get_server_info(profile_h, &server_info);
857                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
858                                 ThrowMsg(PlatformException, "Platform error while gettting a server info: "<<ret);
859                         }
860                         profile->getSyncInfo()->setUrl(server_info.addr);
861                         profile->getSyncInfo()->setId(server_info.id);
862                         profile->getSyncInfo()->setPassword(server_info.password);
863
864                         sync_agent_ds_sync_info sync_info;
865                         ret = sync_agent_ds_get_sync_info(profile_h, &sync_info);
866                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
867                                 ThrowMsg(PlatformException, "Platform error while gettting a sync info: "<<ret);
868                         }
869                         profile->getSyncInfo()->setSyncMode(convertToSyncMode(sync_info.sync_mode));
870                         profile->getSyncInfo()->setSyncType(convertToSyncType(sync_info.sync_type));
871                         profile->getSyncInfo()->setSyncInterval(convertToSyncInterval(sync_info.interval));
872
873                         LoggerD("Sync mode: "<<sync_info.sync_mode<<", type: "<<sync_info.sync_type<<", interval: "<<sync_info.interval);
874
875                         GList *category_list = NULL;
876                         sync_agent_ds_service_info *category_info = NULL;
877                         ret = sync_agent_ds_get_sync_service_info(profile_h, &category_list);
878                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
879                                 ThrowMsg(PlatformException, "Platform error while gettting sync categories: "<<ret);
880                         }
881                         int category_count = g_list_length(category_list);
882                         LoggerD("category_count: "<<category_count);
883                         while(category_count--) {
884                                 category_info = (sync_agent_ds_service_info *) g_list_nth_data(category_list, category_count);
885                                 if(SYNC_AGENT_CALENDAR<category_info->service_type) {
886                                         LoggerD("Skip unsupported sync service type: "<<category_info->service_type);
887                                         continue;
888                                 }
889
890                                 SyncServiceInfoPtr serviceInfo( new SyncServiceInfo() );
891                                 serviceInfo->setEnable(category_info->enabled);
892                                 if(category_info->id) {
893                                         serviceInfo->setId(category_info->id);
894                                 }
895                                 if(category_info->password) {
896                                         serviceInfo->setPassword(category_info->password);
897                                 }
898                                 serviceInfo->setSyncServiceType(convertToSyncServiceType(category_info->service_type));
899                                 if(category_info->tgt_uri) {
900                                         serviceInfo->setServerDatabaseUri(category_info->tgt_uri);
901                                 }
902
903                                 LoggerD("Service type: "<<serviceInfo->getSyncServiceType());
904                                 profile->getServiceInfo()->push_back(serviceInfo);
905                         }
906                         if(category_list) {
907                                 g_list_free(category_list);
908                         }
909
910                         LoggerD("Adding a profile to the list.");
911                         event->getProfiles()->push_back(profile);
912                 }
913
914         event->setResult(true);
915     }
916     Catch(Exception)
917     {
918                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
919         event->setResult(false);
920         event->setExceptionCode(ExceptionCodes::PlatformException);
921     }
922
923         LoggerD("Free profiles list.");
924         for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
925                 sync_agent_ds_free_profile_info((ds_profile_h) iter->data);
926         }
927         if(profile_list) {
928                 g_list_free(profile_list);
929         }
930 }
931
932 void DataSyncManager::OnRequestReceived(const IEventStartSyncPtr &event)
933 {
934         ds_profile_h profile_h = NULL;
935
936     Try
937     {
938         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
939                 sync_agent_event_error_e err= SYNC_AGENT_EVENT_FAIL;
940
941                 int profileId = -1;
942                 std::stringstream ss(event->getProfileId());
943                 ss>>profileId;
944         LoggerD("profileId: "<<profileId);
945                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
946                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
947                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
948                 }
949
950         err = sync_agent_set_noti_callback(1, datasync_state_changed_cb, this);
951         if (SYNC_AGENT_EVENT_SUCCESS != err) {
952             ThrowMsg(PlatformException, "Platform error while setting state changed cb: " << err);
953         }
954
955         err = sync_agent_set_noti_callback(2, datasync_progress_cb, this);
956         if (SYNC_AGENT_EVENT_SUCCESS != err) {
957             ThrowMsg(PlatformException, "Platform error while setting progress cb: " << err);
958         }
959
960                 ret = sync_agent_ds_start_sync(profile_h);
961                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
962                         ThrowMsg(PlatformException, "Platform error while starting a profile: "<<ret);
963                 }
964
965         if(event->getEmitter()) {
966             LoggerD("Attaching the emitter with profileId: "<<event->getProfileId());
967             m_changeEmitters[std::string("Sync") + event->getProfileId()] = event->getEmitter();
968         }
969
970         event->setResult(true);
971     }
972     Catch(NotFoundException)
973     {
974         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
975         event->setResult(false);
976         event->setExceptionCode(ExceptionCodes::NotFoundException);
977     }
978     Catch(Exception)
979     {
980                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
981         event->setResult(false);
982         event->setExceptionCode(ExceptionCodes::PlatformException);
983     }
984
985         if(profile_h) {
986                 sync_agent_ds_free_profile_info(profile_h);
987         }
988 }
989
990 void DataSyncManager::OnRequestReceived(const IEventStopSyncPtr &event)
991 {
992         ds_profile_h profile_h = NULL;
993
994     Try
995     {
996         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
997
998                 int profileId = -1;
999                 std::stringstream ss(event->getProfileId());
1000                 ss>>profileId;
1001         LoggerD("profileId: "<<profileId);
1002                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
1003                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
1004                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
1005                 }
1006
1007                 ret = sync_agent_ds_stop_sync(profile_h);
1008                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
1009                         ThrowMsg(PlatformException, "Platform error while stopping a profile: "<<ret);
1010                 }
1011
1012         event->setResult(true);
1013     }
1014     Catch(NotFoundException)
1015     {
1016         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1017         event->setResult(false);
1018         event->setExceptionCode(ExceptionCodes::NotFoundException);
1019     }
1020     Catch(Exception)
1021     {
1022                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1023         event->setResult(false);
1024         event->setExceptionCode(ExceptionCodes::PlatformException);
1025     }
1026
1027         if(profile_h) {
1028                 sync_agent_ds_free_profile_info(profile_h);
1029         }
1030
1031 }
1032
1033 void DataSyncManager::OnRequestReceived(const IEventGetLastSyncStatisticsPtr &event)
1034 {
1035         ds_profile_h profile_h = NULL;
1036
1037     Try
1038     {
1039         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
1040
1041                 int profileId = -1;
1042                 std::stringstream ss(event->getProfileId());
1043                 ss>>profileId;
1044         LoggerD("profileId: "<<profileId);
1045                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
1046                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
1047                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
1048                 }
1049
1050                 SyncStatisticsListPtr statisticsList( new SyncStatisticsList() );
1051
1052                 GList *statistics_list = NULL;
1053                 ret = sync_agent_ds_get_sync_statistics(profile_h, &statistics_list);
1054                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
1055                         ThrowMsg(PlatformException, "Platform error while gettting sync statistics: "<<ret);
1056                 }
1057
1058                 int statistics_count = g_list_length(statistics_list);
1059                 LoggerD("statistics_count: "<<statistics_count);
1060                 sync_agent_ds_statistics_info *statistics = NULL;
1061                 for (int i = 0; i < statistics_count; i++) {
1062                         statistics = (sync_agent_ds_statistics_info *) g_list_nth_data(statistics_list, i);
1063
1064                         SyncStatisticsPtr statisticsPtr( new SyncStatistics() );
1065
1066                         if(0==i) {
1067                                 LoggerD("Statistics for contact.");
1068                                 statisticsPtr->setServiceType(convertToSyncServiceType(SYNC_AGENT_CONTACT));
1069                         } else if(1==i) {
1070                                 LoggerD("Statistics for event.");
1071                                 statisticsPtr->setServiceType(convertToSyncServiceType(SYNC_AGENT_CALENDAR));
1072                         } else {
1073                                 LoggerW("Unsupported category for statistics: "<<i);
1074                                 continue;
1075                         }
1076
1077                         LoggerD("dbsynced: "<<statistics->dbsynced);
1078                         statisticsPtr->setSyncStatus(convertToSyncStatus(statistics->dbsynced));
1079                         statisticsPtr->setClientToServerTotal(statistics->client2server_total);
1080                         statisticsPtr->setClientToServerAdded(statistics->client2server_nrofadd);
1081                         statisticsPtr->setClientToServerUpdated(statistics->client2server_nrofreplace);
1082                         statisticsPtr->setClientToServerRemoved(statistics->client2server_nrofdelete);
1083                         statisticsPtr->setServerToClientTotal(statistics->server2client_total);
1084                         statisticsPtr->setServerToClientAdded(statistics->server2client_nrofadd);
1085                         statisticsPtr->setServerToClientUpdated(statistics->server2client_nrofreplace);
1086                         statisticsPtr->setServerToClientRemoved(statistics->server2client_nrofdelete);
1087
1088                         LoggerD("ClientToServerTotal: "<<statisticsPtr->getClientToServerTotal()<<", ServerToClientTotal: "<<statisticsPtr->getServerToClientTotal());
1089
1090                         statisticsList->push_back(statisticsPtr);
1091                 }
1092                 if(statistics_list) {
1093                         g_list_free(statistics_list);
1094                 }
1095
1096                 event->setSyncStatictics(statisticsList);
1097
1098         event->setResult(true);
1099     }
1100     Catch(NotFoundException)
1101     {
1102         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1103         event->setResult(false);
1104         event->setExceptionCode(ExceptionCodes::NotFoundException);
1105     }
1106     Catch(Exception)
1107     {
1108                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1109         event->setResult(false);
1110         event->setExceptionCode(ExceptionCodes::PlatformException);
1111     }
1112
1113         if(profile_h) {
1114                 sync_agent_ds_free_profile_info(profile_h);
1115         }
1116 }
1117
1118 }
1119 }