c1c8c9de28a3f71ee23df1a556fe3d833a7e1034
[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         LoggerD("id: "<<profile->getProfileId());
539
540         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
541
542                 int profileId;
543                 std::stringstream ss(profile->getProfileId());
544                 ss>>profileId;
545                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
546                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
547                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
548                 }
549
550                 ret = sync_agent_ds_set_profile_name(profile_h, (char*)(profile->getProfileName().c_str()));
551                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
552                         ThrowMsg(PlatformException, "Platform error while settting a profile name: "<<ret);
553                 }
554
555                 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()));
556                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
557                         ThrowMsg(PlatformException, "Platform error while settting a server info: "<<ret);
558                 }
559
560                 sync_agent_ds_sync_mode_e syncMode = convertToPlatformSyncMode(profile->getSyncInfo()->getSyncMode());
561                 sync_agent_ds_sync_type_e syncType = convertToPlatformSyncType(profile->getSyncInfo()->getSyncType());
562                 sync_agent_ds_sync_interval_e syncInterval = convertToPlatformSyncInterval(profile->getSyncInfo()->getSyncInterval());
563                 LoggerD("syncMode: "<<syncMode<<", syncType: "<<syncType<<", syncInterval: "<<syncInterval);
564
565                 ret = sync_agent_ds_set_sync_info(profile_h, syncMode, syncType, syncInterval);
566                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
567                         ThrowMsg(PlatformException, "Platform error while settting a sync info: "<<ret);
568                 }
569
570                 // Set the sync categories.
571                 SyncServiceInfoListPtr categories = profile->getServiceInfo();
572                 sync_agent_ds_service_type_e serviceType;
573                 sync_agent_ds_src_uri_e srcURI;
574                 std::string tgtURI, id, password;
575                 bool enable;
576                 for(unsigned int i=0; categories->size()<i; i++) {
577                         serviceType = convertToPlatformSyncServiceType(categories->at(i)->getSyncServiceType());
578                         tgtURI = categories->at(i)->getServerDatabaseUri();
579                         srcURI = convertToPlatformSourceUri(categories->at(i)->getSyncServiceType());
580                         id = categories->at(i)->getId();
581                         password = categories->at(i)->getPassword();
582                         enable = categories->at(i)->getEnable();
583
584                         LoggerD("serviceType: "<<serviceType<<", tgtURI: "<<tgtURI<<", id: "<<id<<" for index: "<<i);
585
586                         ret = sync_agent_ds_set_sync_service_info(profile_h, serviceType, enable, srcURI, (char*)(tgtURI.c_str()),
587                                         0==id.size() ? NULL : (char*)(id.c_str()), 0==password.size() ? NULL : (char*)(password.c_str()));
588                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
589                                 ThrowMsg(PlatformException, "Platform error while settting a sync service info: "<<ret);
590                         }
591                 }
592
593                 ret = sync_agent_ds_update_profile(profile_h);
594                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
595                         ThrowMsg(NotFoundException, "Platform error while updating a profile: "<<ret);
596                 }
597
598         event->setResult(true);
599     }
600     Catch(NotFoundException)
601     {
602         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
603         event->setResult(false);
604         event->setExceptionCode(ExceptionCodes::NotFoundException);
605     }
606     Catch(Exception)
607     {
608                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
609         event->setResult(false);
610         event->setExceptionCode(ExceptionCodes::PlatformException);
611     }
612
613         if(profile_h) {
614                 sync_agent_ds_free_profile_info(profile_h);
615         }
616 }
617
618 void DataSyncManager::OnRequestReceived(const IEventRemoveProfilePtr &event)
619 {
620         ds_profile_h profile_h = NULL;
621
622     Try
623     {
624         LoggerD("id: "<<event->getProfileId());
625
626         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
627
628                 int profileId;
629                 std::stringstream ss(event->getProfileId());
630                 ss>>profileId;
631                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
632                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
633                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
634                 }
635
636                 ret = sync_agent_ds_delete_profile(profile_h);
637                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
638                         ThrowMsg(PlatformException, "Platform error while deleting a profile: "<<ret);
639                 }
640
641         event->setResult(true);
642     }
643     Catch(NotFoundException)
644     {
645         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
646         event->setResult(false);
647         event->setExceptionCode(ExceptionCodes::NotFoundException);
648     }
649     Catch(Exception)
650     {
651                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
652         event->setResult(false);
653         event->setExceptionCode(ExceptionCodes::PlatformException);
654     }
655
656         if(profile_h) {
657                 sync_agent_ds_free_profile_info(profile_h);
658         }
659 }
660
661 void DataSyncManager::OnRequestReceived(const IEventGetMaxProfilesNumPtr &event)
662 {
663     Try
664     {
665         LoggerD("Return maximum number of supported profiles: "<<MAX_PROFILES_NUM);
666
667                 event->setNumMaxProfiles(MAX_PROFILES_NUM);
668
669         event->setResult(true);
670     }
671     Catch(Exception)
672     {
673                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
674         event->setResult(false);
675         event->setExceptionCode(ExceptionCodes::PlatformException);
676     }
677 }
678
679 void DataSyncManager::OnRequestReceived(const IEventGetProfilesNumPtr &event)
680 {
681         GList *profile_list = NULL;
682         GList *iter = NULL;
683
684     Try
685     {
686         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
687
688                 ret = sync_agent_ds_get_all_profile(&profile_list);
689                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
690                         ThrowMsg(PlatformException, "Platform error while getting all profiles: "<<ret);
691                 }
692
693                 int numProfiles=0;
694                 for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
695                    sync_agent_ds_free_profile_info((ds_profile_h) iter->data);
696                    LoggerD("Free sync_agent_ds_profile_info for index: "<<numProfiles++);
697                 }
698
699                 LoggerD("numProfiles: "<<numProfiles);
700
701                 event->setNumProfiles(numProfiles);
702
703         event->setResult(true);
704     }
705     Catch(Exception)
706     {
707                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
708         event->setResult(false);
709         event->setExceptionCode(ExceptionCodes::PlatformException);
710     }
711 }
712
713 void DataSyncManager::OnRequestReceived(const IEventGetProfilePtr &event)
714 {
715         ds_profile_h profile_h = NULL;
716
717     Try
718     {
719         LoggerD("id: "<<event->getProfileId());
720
721         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
722
723                 int profileId;
724                 std::stringstream ss(event->getProfileId());
725                 ss>>profileId;
726                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
727                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
728                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
729                 }
730
731                 SyncProfileInfoPtr profile( new SyncProfileInfo() );
732
733                 profile->setProfileId(event->getProfileId());
734
735                 char *profileName = NULL;
736                 ret = sync_agent_ds_get_profile_name(profile_h, &profileName);
737                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
738                         ThrowMsg(PlatformException, "Platform error while gettting a profile name: "<<ret);
739                 }
740                 profile->setProfileName(profileName);
741
742                 sync_agent_ds_server_info server_info = { NULL };
743                 ret = sync_agent_ds_get_server_info(profile_h, &server_info);
744                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
745                         ThrowMsg(PlatformException, "Platform error while gettting a server info: "<<ret);
746                 }
747                 profile->getSyncInfo()->setUrl(server_info.addr);
748                 profile->getSyncInfo()->setId(server_info.id);
749                 profile->getSyncInfo()->setPassword(server_info.password);
750
751                 sync_agent_ds_sync_info sync_info;
752                 ret = sync_agent_ds_get_sync_info(profile_h, &sync_info);
753                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
754                         ThrowMsg(PlatformException, "Platform error while gettting a sync info: "<<ret);
755                 }
756                 profile->getSyncInfo()->setSyncMode(convertToSyncMode(sync_info.sync_mode));
757                 profile->getSyncInfo()->setSyncType(convertToSyncType(sync_info.sync_type));
758                 profile->getSyncInfo()->setSyncInterval(convertToSyncInterval(sync_info.interval));
759
760                 LoggerD("Sync mode: "<<sync_info.sync_mode<<", type: "<<sync_info.sync_type<<", interval: "<<sync_info.interval);
761
762                 GList *category_list = NULL;
763                 sync_agent_ds_service_info *category_info = NULL;
764                 ret = sync_agent_ds_get_sync_service_info(profile_h, &category_list);
765                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
766                         ThrowMsg(PlatformException, "Platform error while gettting sync categories: "<<ret);
767                 }
768                 int category_count = g_list_length(category_list);
769                 LoggerD("category_count: "<<category_count);
770                 while(category_count--) {
771                         category_info = (sync_agent_ds_service_info *) g_list_nth_data(category_list, category_count);
772                         if(SYNC_AGENT_CALENDAR<category_info->service_type) {
773                                 LoggerD("Skip unsupported sync service type: "<<category_info->service_type);
774                                 continue;
775                         }
776
777                         SyncServiceInfoPtr serviceInfo( new SyncServiceInfo() );
778                         serviceInfo->setEnable(category_info->enabled);
779                         if(category_info->id) {
780                                 serviceInfo->setId(category_info->id);
781                         }
782                         if(category_info->password) {
783                                 serviceInfo->setPassword(category_info->password);
784                         }
785                         serviceInfo->setSyncServiceType(convertToSyncServiceType(category_info->service_type));
786                         if(category_info->tgt_uri) {
787                                 serviceInfo->setServerDatabaseUri(category_info->tgt_uri);
788                         }
789
790                         LoggerD("Service type: "<<serviceInfo->getSyncServiceType());
791                         profile->getServiceInfo()->push_back(serviceInfo);
792                 }
793                 if(category_list) {
794                         g_list_free(category_list);
795                 }
796
797                 event->setProfile(profile);
798
799         event->setResult(true);
800     }
801     Catch(NotFoundException)
802     {
803         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
804         event->setResult(false);
805         event->setExceptionCode(ExceptionCodes::NotFoundException);
806     }
807     Catch(Exception)
808     {
809                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
810         event->setResult(false);
811         event->setExceptionCode(ExceptionCodes::PlatformException);
812     }
813
814         if(profile_h) {
815                 sync_agent_ds_free_profile_info(profile_h);
816         }
817 }
818
819 void DataSyncManager::OnRequestReceived(const IEventGetAllProfilesPtr &event)
820 {
821         GList *profile_list = NULL;
822         GList *iter = NULL;
823
824     Try
825     {
826                 ds_profile_h profile_h = NULL;
827         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
828
829                 ret = sync_agent_ds_get_all_profile(&profile_list);
830                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
831                         ThrowMsg(PlatformException, "Platform error while getting all profiles: "<<ret);
832                 }
833
834                 LoggerD("Number of profiles: "<< g_list_length(profile_list));
835                 for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
836                         profile_h = (ds_profile_h) iter->data;
837                         SyncProfileInfoPtr profile( new SyncProfileInfo() );
838
839                         int profileId;
840                         ret = sync_agent_ds_get_profile_id(profile_h, &profileId);
841                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
842                                 ThrowMsg(PlatformException, "Platform error while gettting a profile id: "<<ret);
843                         }
844
845                         std::stringstream ss;
846                         ss<<profileId;
847                         profile->setProfileId(ss.str());
848
849                         LoggerD("Processing a profile with id: "<<profile->getProfileId());
850
851                         char *profileName = NULL;
852                         ret = sync_agent_ds_get_profile_name(profile_h, &profileName);
853                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
854                                 ThrowMsg(PlatformException, "Platform error while gettting a profile name: "<<ret);
855                         }
856                         profile->setProfileName(profileName);
857
858                         sync_agent_ds_server_info server_info = { NULL };
859                         ret = sync_agent_ds_get_server_info(profile_h, &server_info);
860                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
861                                 ThrowMsg(PlatformException, "Platform error while gettting a server info: "<<ret);
862                         }
863                         profile->getSyncInfo()->setUrl(server_info.addr);
864                         profile->getSyncInfo()->setId(server_info.id);
865                         profile->getSyncInfo()->setPassword(server_info.password);
866
867                         sync_agent_ds_sync_info sync_info;
868                         ret = sync_agent_ds_get_sync_info(profile_h, &sync_info);
869                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
870                                 ThrowMsg(PlatformException, "Platform error while gettting a sync info: "<<ret);
871                         }
872                         profile->getSyncInfo()->setSyncMode(convertToSyncMode(sync_info.sync_mode));
873                         profile->getSyncInfo()->setSyncType(convertToSyncType(sync_info.sync_type));
874                         profile->getSyncInfo()->setSyncInterval(convertToSyncInterval(sync_info.interval));
875
876                         LoggerD("Sync mode: "<<sync_info.sync_mode<<", type: "<<sync_info.sync_type<<", interval: "<<sync_info.interval);
877
878                         GList *category_list = NULL;
879                         sync_agent_ds_service_info *category_info = NULL;
880                         ret = sync_agent_ds_get_sync_service_info(profile_h, &category_list);
881                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
882                                 ThrowMsg(PlatformException, "Platform error while gettting sync categories: "<<ret);
883                         }
884                         int category_count = g_list_length(category_list);
885                         LoggerD("category_count: "<<category_count);
886                         while(category_count--) {
887                                 category_info = (sync_agent_ds_service_info *) g_list_nth_data(category_list, category_count);
888                                 if(SYNC_AGENT_CALENDAR<category_info->service_type) {
889                                         LoggerD("Skip unsupported sync service type: "<<category_info->service_type);
890                                         continue;
891                                 }
892
893                                 SyncServiceInfoPtr serviceInfo( new SyncServiceInfo() );
894                                 serviceInfo->setEnable(category_info->enabled);
895                                 if(category_info->id) {
896                                         serviceInfo->setId(category_info->id);
897                                 }
898                                 if(category_info->password) {
899                                         serviceInfo->setPassword(category_info->password);
900                                 }
901                                 serviceInfo->setSyncServiceType(convertToSyncServiceType(category_info->service_type));
902                                 if(category_info->tgt_uri) {
903                                         serviceInfo->setServerDatabaseUri(category_info->tgt_uri);
904                                 }
905
906                                 LoggerD("Service type: "<<serviceInfo->getSyncServiceType());
907                                 profile->getServiceInfo()->push_back(serviceInfo);
908                         }
909                         if(category_list) {
910                                 g_list_free(category_list);
911                         }
912
913                         LoggerD("Adding a profile to the list.");
914                         event->getProfiles()->push_back(profile);
915                 }
916
917         event->setResult(true);
918     }
919     Catch(Exception)
920     {
921                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
922         event->setResult(false);
923         event->setExceptionCode(ExceptionCodes::PlatformException);
924     }
925
926         LoggerD("Free profiles list.");
927         for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
928                 sync_agent_ds_free_profile_info((ds_profile_h) iter->data);
929         }
930         if(profile_list) {
931                 g_list_free(profile_list);
932         }
933 }
934
935 void DataSyncManager::OnRequestReceived(const IEventStartSyncPtr &event)
936 {
937         ds_profile_h profile_h = NULL;
938
939     Try
940     {
941         LoggerD("id: "<<event->getProfileId());
942
943         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
944                 sync_agent_event_error_e err= SYNC_AGENT_EVENT_FAIL;
945
946                 int profileId;
947                 std::stringstream ss(event->getProfileId());
948                 ss>>profileId;
949                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
950                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
951                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
952                 }
953
954         err = sync_agent_set_noti_callback(1, datasync_state_changed_cb, this);
955         if (SYNC_AGENT_EVENT_SUCCESS != err) {
956             ThrowMsg(PlatformException, "Platform error while setting state changed cb: " << err);
957         }
958
959         err = sync_agent_set_noti_callback(2, datasync_progress_cb, this);
960         if (SYNC_AGENT_EVENT_SUCCESS != err) {
961             ThrowMsg(PlatformException, "Platform error while setting progress cb: " << err);
962         }
963
964                 ret = sync_agent_ds_start_sync(profile_h);
965                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
966                         ThrowMsg(PlatformException, "Platform error while starting a profile: "<<ret);
967                 }
968
969         if(event->getEmitter()) {
970             LoggerD("Attaching the emitter with profileId: "<<event->getProfileId());
971             m_changeEmitters[std::string("Sync") + event->getProfileId()] = event->getEmitter();
972         }
973
974         event->setResult(true);
975     }
976     Catch(NotFoundException)
977     {
978         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
979         event->setResult(false);
980         event->setExceptionCode(ExceptionCodes::NotFoundException);
981     }
982     Catch(Exception)
983     {
984                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
985         event->setResult(false);
986         event->setExceptionCode(ExceptionCodes::PlatformException);
987     }
988
989         if(profile_h) {
990                 sync_agent_ds_free_profile_info(profile_h);
991         }
992 }
993
994 void DataSyncManager::OnRequestReceived(const IEventStopSyncPtr &event)
995 {
996         ds_profile_h profile_h = NULL;
997
998     Try
999     {
1000         LoggerD("id: "<<event->getProfileId());
1001
1002         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
1003
1004                 int profileId;
1005                 std::stringstream ss(event->getProfileId());
1006                 ss>>profileId;
1007                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
1008                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
1009                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
1010                 }
1011
1012                 ret = sync_agent_ds_stop_sync(profile_h);
1013                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
1014                         ThrowMsg(PlatformException, "Platform error while stopping a profile: "<<ret);
1015                 }
1016
1017         event->setResult(true);
1018     }
1019     Catch(NotFoundException)
1020     {
1021         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1022         event->setResult(false);
1023         event->setExceptionCode(ExceptionCodes::NotFoundException);
1024     }
1025     Catch(Exception)
1026     {
1027                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1028         event->setResult(false);
1029         event->setExceptionCode(ExceptionCodes::PlatformException);
1030     }
1031
1032         if(profile_h) {
1033                 sync_agent_ds_free_profile_info(profile_h);
1034         }
1035
1036 }
1037
1038 void DataSyncManager::OnRequestReceived(const IEventGetLastSyncStatisticsPtr &event)
1039 {
1040         ds_profile_h profile_h = NULL;
1041
1042     Try
1043     {
1044         LoggerD("id: "<<event->getProfileId());
1045
1046         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
1047
1048                 int profileId;
1049                 std::stringstream ss(event->getProfileId());
1050                 ss>>profileId;
1051                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
1052                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
1053                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
1054                 }
1055
1056                 SyncStatisticsListPtr statisticsList( new SyncStatisticsList() );
1057
1058                 GList *statistics_list = NULL;
1059                 ret = sync_agent_ds_get_sync_statistics(profile_h, &statistics_list);
1060                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
1061                         ThrowMsg(PlatformException, "Platform error while gettting sync statistics: "<<ret);
1062                 }
1063
1064                 int statistics_count = g_list_length(statistics_list);
1065                 LoggerD("statistics_count: "<<statistics_count);
1066                 sync_agent_ds_statistics_info *statistics = NULL;
1067                 for (int i = 0; i < statistics_count; i++) {
1068                         statistics = (sync_agent_ds_statistics_info *) g_list_nth_data(statistics_list, i);
1069
1070                         SyncStatisticsPtr statisticsPtr( new SyncStatistics() );
1071
1072                         if(0==i) {
1073                                 LoggerD("Statistics for contact.");
1074                                 statisticsPtr->setServiceType(convertToSyncServiceType(SYNC_AGENT_CONTACT));
1075                         } else if(1==i) {
1076                                 LoggerD("Statistics for event.");
1077                                 statisticsPtr->setServiceType(convertToSyncServiceType(SYNC_AGENT_CALENDAR));
1078                         } else {
1079                                 LoggerW("Unsupported category for statistics: "<<i);
1080                                 continue;
1081                         }
1082
1083                         LoggerD("dbsynced: "<<statistics->dbsynced);
1084                         statisticsPtr->setSyncStatus(convertToSyncStatus(statistics->dbsynced));
1085                         statisticsPtr->setClientToServerTotal(statistics->client2server_total);
1086                         statisticsPtr->setClientToServerAdded(statistics->client2server_nrofadd);
1087                         statisticsPtr->setClientToServerUpdated(statistics->client2server_nrofreplace);
1088                         statisticsPtr->setClientToServerRemoved(statistics->client2server_nrofdelete);
1089                         statisticsPtr->setServerToClientTotal(statistics->server2client_total);
1090                         statisticsPtr->setServerToClientAdded(statistics->server2client_nrofadd);
1091                         statisticsPtr->setServerToClientUpdated(statistics->server2client_nrofreplace);
1092                         statisticsPtr->setServerToClientRemoved(statistics->server2client_nrofdelete);
1093
1094                         LoggerD("ClientToServerTotal: "<<statisticsPtr->getClientToServerTotal()<<", ServerToClientTotal: "<<statisticsPtr->getServerToClientTotal());
1095
1096                         statisticsList->push_back(statisticsPtr);
1097                 }
1098                 if(statistics_list) {
1099                         g_list_free(statistics_list);
1100                 }
1101
1102                 event->setSyncStatictics(statisticsList);
1103
1104         event->setResult(true);
1105     }
1106     Catch(NotFoundException)
1107     {
1108         LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1109         event->setResult(false);
1110         event->setExceptionCode(ExceptionCodes::NotFoundException);
1111     }
1112     Catch(Exception)
1113     {
1114                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1115         event->setResult(false);
1116         event->setExceptionCode(ExceptionCodes::PlatformException);
1117     }
1118
1119         if(profile_h) {
1120                 sync_agent_ds_free_profile_info(profile_h);
1121         }
1122 }
1123
1124 }
1125 }