Update change log and spec for wrt-plugins-tizen_0.4.13
[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 <dpl/log/log.h>
25
26 #include <sync_agent.h>
27
28 #include <sstream>
29
30 using namespace WrtDeviceApis::Commons;
31
32 namespace DeviceAPI {
33 namespace DataSync {
34
35 DataSyncManager::DataSyncManager()
36 {
37         LogInfo("Initialize the datasync manager.");
38
39         sync_agent_ds_error_e ds_err = sync_agent_ds_init();
40         if (SYNC_AGENT_DS_SUCCESS!=ds_err) {
41            LogError("Failed to init oma ds.");
42         }
43 }
44
45 DataSyncManager::~DataSyncManager()
46 {
47         LogInfo("Deinitialize the datasync manager.");
48
49         sync_agent_ds_error_e ds_err = sync_agent_ds_deinit();
50         if (SYNC_AGENT_DS_SUCCESS!=ds_err) {
51            LogError("Failed to deinit oma ds.");
52         }
53 }
54
55 static int datasync_state_changed_cb(sync_agent_event_data_s* request, void *user_data)
56 {
57     LogDebug("DataSync session state changed.");
58
59         char *profileDirName = NULL;
60         int sync_type = 0;
61         char *progress = NULL;
62         char *error = NULL;
63
64     Try
65     {
66         OnDataSyncStateChangedPtr eventPtr(new OnDataSyncStateChanged());
67         DataSyncManager* thisDataSyncManager = (DataSyncManager*) user_data;
68
69                 LogDebug("Get state info.");
70                 sync_agent_get_event_data_param(request, &profileDirName);
71                 sync_agent_get_event_data_param(request, &sync_type);
72                 sync_agent_get_event_data_param(request, &progress);
73                 sync_agent_get_event_data_param(request, &error);
74
75                 LogDebug("profileDirName: "<<profileDirName<<", sync_type: "<<sync_type<<", progress: "<<progress<<", error: "<<error);
76
77                 if(profileDirName) {
78                 eventPtr->setProfileId(profileDirName);
79                 }
80
81                 if(NULL==progress) {
82                         LogWarning("Null status.");
83                         eventPtr->setSessionStatus(OnDataSyncStateChanged::UNDEFINED_STATUS);
84                 } else if(0==strcmp(progress, "DONE")) {
85                         eventPtr->setSessionStatus(OnDataSyncStateChanged::COMPLETE_STATUS);
86                 } else if(0==strcmp(progress, "CANCEL")) {
87                         eventPtr->setSessionStatus(OnDataSyncStateChanged::STOP_STATUS);
88                 } else if(0==strcmp(progress, "ERROR")) {
89                         // Error cases should be redefined and transferred based on the error value.
90                         eventPtr->setSessionStatus(OnDataSyncStateChanged::FAIL_STATUS);
91                 } else {
92                         LogWarning("Wrong status.");
93                         eventPtr->setSessionStatus(OnDataSyncStateChanged::UNDEFINED_STATUS);
94                 }
95
96         eventPtr->setResult(true);
97
98                 if(profileDirName) {
99                 if (thisDataSyncManager->m_changeEmitters[profileDirName]) {
100                     thisDataSyncManager->m_changeEmitters[profileDirName]->emit(eventPtr);
101                 }
102                 }
103     }
104     Catch (Exception)
105     {
106         LogWarning("Exception: "<<_rethrown_exception.GetMessage());
107     }
108
109         if(profileDirName) {
110                 g_free(profileDirName);
111         }
112         if(progress) {
113                 g_free(progress);
114         }
115         if(error) {
116                 g_free(error);
117         }
118
119         if (request != NULL) {
120                 if (request->size != NULL) {
121                         g_free(request->size);
122                 }
123                 g_free(request);
124         }
125
126         return 0;
127 }
128
129 static int datasync_progress_cb(sync_agent_event_data_s* request, void *user_data)
130 {
131     LogDebug("DataSync progress called.");
132
133         char *profileDirName = NULL;
134         int syncType = 0;
135         int uri;
136         char *progressStatus = NULL;
137         char *operationType = NULL;
138
139     Try
140     {
141         OnDataSyncStateChangedPtr eventPtr(new OnDataSyncStateChanged());
142         DataSyncManager* thisDataSyncManager = (DataSyncManager*) user_data;
143
144                 int isFromServer, totalPerOperation, syncedPerOperation, totalPerDb, syncedPerDb;
145
146                 LogDebug("Get progress info.");
147                 sync_agent_get_event_data_param(request, &profileDirName);
148                 sync_agent_get_event_data_param(request, &syncType);
149                 sync_agent_get_event_data_param(request, &uri);
150                 sync_agent_get_event_data_param(request, &progressStatus);
151                 sync_agent_get_event_data_param(request, &operationType);
152
153                 LogDebug("profileDirName: "<<profileDirName<<", syncType: "<<syncType<<", uri: "<<uri<<", progressStatus: "<<progressStatus<<", operationType "<<operationType);
154
155                 sync_agent_get_event_data_param(request, &isFromServer);
156                 sync_agent_get_event_data_param(request, &totalPerOperation);
157                 sync_agent_get_event_data_param(request, &syncedPerOperation);
158                 sync_agent_get_event_data_param(request, &totalPerDb);
159                 sync_agent_get_event_data_param(request, &syncedPerDb);
160
161                 LogDebug("isFromServer: "<<isFromServer<<", totalPerOperation: "<<totalPerOperation<<", syncedPerOperation: "<<syncedPerOperation<<", totalPerDb: "<<totalPerDb<<", syncedPerDb "<<syncedPerDb);
162
163                 if(profileDirName) {
164                 eventPtr->setProfileId(profileDirName);
165                 }
166
167                 eventPtr->setSessionStatus(OnDataSyncStateChanged::PROGRESS_STATUS);
168
169                 if(SYNC_AGENT_SRC_URI_CONTACT==uri) {
170                 eventPtr->setServiceType(SyncServiceInfo::CONTACT_SERVICE_TYPE);
171                 } else if(SYNC_AGENT_SRC_URI_CALENDAR==uri) {
172                 eventPtr->setServiceType(SyncServiceInfo::EVENT_SERVICE_TYPE);
173                 } else {
174                         LogWarning("Wrong service type.");
175                 eventPtr->setServiceType(SyncServiceInfo::UNDEFINED_SERVICE_TYPE);
176                 }
177
178         eventPtr->setIsFromServer(isFromServer);
179                 eventPtr->setSynedPerService(syncedPerDb);
180                 eventPtr->setTotalPerService(totalPerDb);
181
182         eventPtr->setResult(true);
183
184                 if(profileDirName) {
185                 if (thisDataSyncManager->m_changeEmitters[profileDirName]) {
186                     thisDataSyncManager->m_changeEmitters[profileDirName]->emit(eventPtr);
187                 }
188                 }
189     }
190     Catch (Exception)
191     {
192         LogWarning("Exception: "<<_rethrown_exception.GetMessage());
193     }
194
195         if(profileDirName) {
196                 g_free(profileDirName);
197         }
198         if(progressStatus) {
199                 g_free(progressStatus);
200         }
201         if(operationType) {
202                 g_free(operationType);
203         }
204
205         if (request != NULL) {
206                 if (request->size != NULL) {
207                         g_free(request->size);
208                 }
209                 g_free(request);
210         }
211
212         return 0;
213 }
214
215 static sync_agent_ds_sync_mode_e convertToPlatformSyncMode(SyncInfo::SyncMode syncMode)
216 {
217         if(SyncInfo::MANUAL_MODE==syncMode) {
218                 return SYNC_AGENT_SYNC_MODE_MANUAL;
219         } else if(SyncInfo::PERIODIC_MODE==syncMode) {
220                 return SYNC_AGENT_SYNC_MODE_PERIODIC;
221         } else if(SyncInfo::PUSH_MODE==syncMode) {
222                 return SYNC_AGENT_SYNC_MODE_PUSH;
223         } else {
224                 LogWarning("Error while converting a sync mode.");
225         }
226
227         return SYNC_AGENT_SYNC_MODE_MANUAL;
228 }
229
230 static SyncInfo::SyncMode convertToSyncMode(sync_agent_ds_sync_mode_e syncMode)
231 {
232         if(SYNC_AGENT_SYNC_MODE_MANUAL==syncMode) {
233                 return SyncInfo::MANUAL_MODE;
234         } else if(SYNC_AGENT_SYNC_MODE_PERIODIC==syncMode) {
235                 return SyncInfo::PERIODIC_MODE;
236         } else if(SYNC_AGENT_SYNC_MODE_PUSH==syncMode) {
237                 return SyncInfo::PUSH_MODE;
238         } else {
239                 LogWarning("Error while converting a sync mode.");
240         }
241
242         return SyncInfo::UNDEFINED_MODE;
243 }
244
245 static sync_agent_ds_sync_type_e convertToPlatformSyncType(SyncInfo::SyncType syncType)
246 {
247         if(SyncInfo::TWO_WAY_TYPE==syncType) {
248                 return SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH;
249         } else if(SyncInfo::SLOW_TYPE==syncType) {
250                 return SYNC_AGENT_SYNC_TYPE_FULL_SYNC;
251         } else if(SyncInfo::ONE_WAY_FROM_CLIENT_TYPE==syncType) {
252                 return SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER;
253         } else if(SyncInfo::REFRESH_FROM_CLIENT_TYPE==syncType) {
254                 return SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE;
255         } else if(SyncInfo::ONE_WAY_FROM_SERVER_TYPE==syncType) {
256                 return SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE;
257         } else if(SyncInfo::REFRESH_FROM_SERVER_TYPE==syncType) {
258                 return SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER;
259         } else {
260                 LogWarning("Error while converting a sync type.");
261         }
262
263         return SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH;
264 }
265
266 static SyncInfo::SyncType convertToSyncType(sync_agent_ds_sync_type_e syncType)
267 {
268         if(SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH==syncType) {
269                 return SyncInfo::TWO_WAY_TYPE;
270         } else if(SYNC_AGENT_SYNC_TYPE_FULL_SYNC==syncType) {
271                 return SyncInfo::SLOW_TYPE;
272         } else if(SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER==syncType) {
273                 return SyncInfo::ONE_WAY_FROM_CLIENT_TYPE;
274         } else if(SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE==syncType) {
275                 return SyncInfo::REFRESH_FROM_CLIENT_TYPE;
276         } else if(SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE==syncType) {
277                 return SyncInfo::ONE_WAY_FROM_SERVER_TYPE;
278         } else if(SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER==syncType) {
279                 return SyncInfo::REFRESH_FROM_SERVER_TYPE;
280         } else {
281                 LogWarning("Error while converting a sync type.");
282         }
283
284         return SyncInfo::UNDEFINED_TYPE;
285 }
286
287 static sync_agent_ds_sync_interval_e convertToPlatformSyncInterval(SyncInfo::SyncInterval syncInterval)
288 {
289         if(SyncInfo::INTERVAL_5_MINUTES==syncInterval) {
290                 return SYNC_AGENT_SYNC_INTERVAL_5_MINUTES;
291         } else if(SyncInfo::INTERVAL_15_MINUTES==syncInterval) {
292                 return SYNC_AGENT_SYNC_INTERVAL_15_MINUTES;
293         } else if(SyncInfo::INTERVAL_1_HOUR==syncInterval) {
294                 return SYNC_AGENT_SYNC_INTERVAL_1_HOUR;
295         } else if(SyncInfo::INTERVAL_4_HOURS==syncInterval) {
296                 return SYNC_AGENT_SYNC_INTERVAL_4_HOURS;
297         } else if(SyncInfo::INTERVAL_12_HOURS==syncInterval) {
298                 return SYNC_AGENT_SYNC_INTERVAL_12_HOURS;
299         } else if(SyncInfo::INTERVAL_1_DAY==syncInterval) {
300                 return SYNC_AGENT_SYNC_INTERVAL_1_DAY;
301         } else if(SyncInfo::INTERVAL_1_WEEK==syncInterval) {
302                 return SYNC_AGENT_SYNC_INTERVAL_1_WEEK;
303         } else if(SyncInfo::INTERVAL_1_MONTH==syncInterval) {
304                 return SYNC_AGENT_SYNC_INTERVAL_1_MONTH;
305         } else {
306                 LogWarning("Error while converting a sync interval.");
307         }
308
309         return SYNC_AGENT_SYNC_INTERVAL_1_WEEK;
310 }
311
312 static SyncInfo::SyncInterval convertToSyncInterval(sync_agent_ds_sync_interval_e syncInterval)
313 {
314         if(SYNC_AGENT_SYNC_INTERVAL_5_MINUTES==syncInterval) {
315                 return SyncInfo::INTERVAL_5_MINUTES;
316         } else if(SYNC_AGENT_SYNC_INTERVAL_15_MINUTES==syncInterval) {
317                 return SyncInfo::INTERVAL_15_MINUTES;
318         } else if(SYNC_AGENT_SYNC_INTERVAL_1_HOUR==syncInterval) {
319                 return SyncInfo::INTERVAL_1_HOUR;
320         } else if(SYNC_AGENT_SYNC_INTERVAL_4_HOURS==syncInterval) {
321                 return SyncInfo::INTERVAL_4_HOURS;
322         } else if(SYNC_AGENT_SYNC_INTERVAL_12_HOURS==syncInterval) {
323                 return SyncInfo::INTERVAL_12_HOURS;
324         } else if(SYNC_AGENT_SYNC_INTERVAL_1_DAY==syncInterval) {
325                 return SyncInfo::INTERVAL_1_DAY;
326         } else if(SYNC_AGENT_SYNC_INTERVAL_1_WEEK==syncInterval) {
327                 return SyncInfo::INTERVAL_1_WEEK;
328         } else if(SYNC_AGENT_SYNC_INTERVAL_1_MONTH==syncInterval) {
329                 return SyncInfo::INTERVAL_1_MONTH;
330         } else {
331                 LogWarning("Error while converting a sync interval.");
332         }
333
334         return SyncInfo::INTERVAL_UNDEFINED;
335 }
336
337 static sync_agent_ds_service_type_e convertToPlatformSyncServiceType(SyncServiceInfo::SyncServiceType serviceType)
338 {
339         if(SyncServiceInfo::CONTACT_SERVICE_TYPE==serviceType) {
340                 return SYNC_AGENT_CONTACT;
341         } else if(SyncServiceInfo::EVENT_SERVICE_TYPE==serviceType) {
342                 return SYNC_AGENT_CALENDAR;
343         } else {
344                 LogWarning("Error while converting a sync service type.");
345         }
346
347         return SYNC_AGENT_CONTACT;
348 }
349
350 static SyncServiceInfo::SyncServiceType convertToSyncServiceType(sync_agent_ds_service_type_e serviceType)
351 {
352         if(SYNC_AGENT_CONTACT==serviceType) {
353                 return SyncServiceInfo::CONTACT_SERVICE_TYPE;
354         } else if(SYNC_AGENT_CALENDAR==serviceType) {
355                 return SyncServiceInfo::EVENT_SERVICE_TYPE;
356         } else {
357                 LogWarning("Error while converting a sync service type.");
358         }
359
360         return SyncServiceInfo::UNDEFINED_SERVICE_TYPE;
361 }
362
363 static sync_agent_ds_src_uri_e convertToPlatformSourceUri(SyncServiceInfo::SyncServiceType serviceType)
364 {
365         if(SyncServiceInfo::CONTACT_SERVICE_TYPE==serviceType) {
366                 return SYNC_AGENT_SRC_URI_CONTACT;
367         } else if(SyncServiceInfo::EVENT_SERVICE_TYPE==serviceType) {
368                 return SYNC_AGENT_SRC_URI_CALENDAR;
369         } else {
370                 LogWarning("Error while converting a sync service.");
371         }
372
373         return SYNC_AGENT_SRC_URI_CONTACT;
374 }
375
376 static SyncStatistics::SyncStatus convertToSyncStatus(char* status)
377 {
378         if(0==strcmp(status, "success")) {
379                 return SyncStatistics::SUCCESS_STATUS;
380         } else if(0==strcmp(status, "stop")) {
381                 return SyncStatistics::STOP_STATUS;
382         } else if(0==strcmp(status, "fail")) {
383                 return SyncStatistics::FAIL_STATUS;
384         } else if(0==strcmp(status, "No")) {
385                 return SyncStatistics::NONE_STATUS;
386         } else {
387                 LogWarning("Error while converting a sync status.");
388         }
389
390         return SyncStatistics::UNDEFINED_STATUS;
391 }
392
393 void DataSyncManager::OnRequestReceived(const IEventAddProfilePtr &event)
394 {
395         ds_profile_h profile_h = NULL;
396
397     Try
398     {
399         // Check if the quota is full first.
400                 GList *profile_list = NULL;
401                 GList *iter = NULL;
402
403         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
404
405                 ret = sync_agent_ds_get_all_profile(&profile_list);
406                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
407                         ThrowMsg(PlatformException, "Platform error while getting all profiles: "<<ret);
408                 }
409
410                 int numProfiles = g_list_length(profile_list);
411                 for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
412                    sync_agent_ds_free_profile_info((ds_profile_h) iter->data);
413                 }
414                 if(profile_list) {
415                         g_list_free(profile_list);
416                 }
417                 LogDebug("numProfiles: "<<numProfiles);
418                 if(MAX_PROFILES_NUM==numProfiles) {
419                         ThrowMsg(OutOfRangeException, "There are already maximum number of profiles!");
420                 }
421
422         SyncProfileInfoPtr profile;
423         profile = event->getProfile();
424         if (!profile) {
425             ThrowMsg(NullPointerException, "SyncProfileInfo is NULL.");
426         }
427
428         LogDebug("url: "<<profile->getSyncInfo()->getUrl());
429
430                 ret = sync_agent_ds_create_profile_info(&profile_h);
431                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
432                         ThrowMsg(PlatformException, "Platform error while creating a profile: "<<ret);
433                 }
434
435                 ret = sync_agent_ds_set_profile_name(profile_h, (char*)(profile->getProfileName().c_str()));
436                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
437                         ThrowMsg(PlatformException, "Platform error while settting a profile name: "<<ret);
438                 }
439
440                 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()));
441                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
442                         ThrowMsg(PlatformException, "Platform error while settting a server info: "<<ret);
443                 }
444
445                 sync_agent_ds_sync_mode_e syncMode = convertToPlatformSyncMode(profile->getSyncInfo()->getSyncMode());
446                 sync_agent_ds_sync_type_e syncType = convertToPlatformSyncType(profile->getSyncInfo()->getSyncType());
447                 sync_agent_ds_sync_interval_e syncInterval = convertToPlatformSyncInterval(profile->getSyncInfo()->getSyncInterval());
448                 LogDebug("syncMode: "<<syncMode<<", syncType: "<<syncType<<", syncInterval: "<<syncInterval);
449
450                 ret = sync_agent_ds_set_sync_info(profile_h, syncMode, syncType, syncInterval);
451                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
452                         ThrowMsg(PlatformException, "Platform error while settting a sync info: "<<ret);
453                 }
454
455                 // Set the sync categories.
456                 SyncServiceInfoListPtr categories = profile->getServiceInfo();
457                 sync_agent_ds_service_type_e serviceType;
458                 sync_agent_ds_src_uri_e srcURI;
459                 std::string tgtURI, id, password;
460                 bool enable;
461                 for(unsigned int i=0; categories->size()>i; i++) {
462                         serviceType = convertToPlatformSyncServiceType(categories->at(i)->getSyncServiceType());
463                         tgtURI = categories->at(i)->getServerDatabaseUri();
464                         srcURI = convertToPlatformSourceUri(categories->at(i)->getSyncServiceType());
465                         id = categories->at(i)->getId();
466                         password = categories->at(i)->getPassword();
467                         enable = categories->at(i)->getEnable();
468
469                         LogDebug("serviceType: "<<serviceType<<", tgtURI: "<<tgtURI<<", id: "<<id<<" for index: "<<i);
470
471                         ret = sync_agent_ds_set_sync_service_info(profile_h, serviceType, enable, srcURI, (char*)(tgtURI.c_str()),
472                                         0==id.size() ? NULL : (char*)(id.c_str()), 0==password.size() ? NULL : (char*)(password.c_str()));
473                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
474                                 ThrowMsg(PlatformException, "Platform error while settting a sync service info: "<<ret);
475                         }
476                 }
477
478                 int profileId;
479                 ret = sync_agent_ds_add_profile(profile_h, &profileId);
480                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
481                         ThrowMsg(PlatformException, "Platform error while adding a profile: "<<ret);
482                 }
483
484         LogDebug("profileId from platform: "<<profileId);
485
486                 char* profileName = NULL;
487                 ret = sync_agent_ds_get_profile_name(profile_h, &profileName);
488                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
489                         ThrowMsg(PlatformException, "Platform error while getting a profile name: "<<ret);
490                 }
491
492         LogDebug("profileName: "<<profileName<<", profileId: "<<profileId);
493
494                 std::stringstream ss;
495                 ss<<profileId;
496                 profile->setProfileId(ss.str());
497
498                 if(profileName) {
499                         free(profileName);
500                 }
501
502         event->setResult(true);
503     }
504     Catch(OutOfRangeException)
505     {
506                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
507         event->setResult(false);
508         event->setExceptionCode(ExceptionCodes::OutOfRangeException);
509     }
510     Catch(Exception)
511     {
512                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
513         event->setResult(false);
514         event->setExceptionCode(ExceptionCodes::PlatformException);
515     }
516
517         if(profile_h) {
518                 sync_agent_ds_free_profile_info(profile_h);
519         }
520 }
521
522 void DataSyncManager::OnRequestReceived(const IEventUpdateProfilePtr &event)
523 {
524         ds_profile_h profile_h = NULL;
525
526     Try
527     {
528         SyncProfileInfoPtr profile;
529         profile = event->getProfile();
530         if (!profile) {
531             ThrowMsg(NullPointerException, "SyncProfileInfo is NULL.");
532         }
533
534         LogDebug("id: "<<profile->getProfileId());
535
536         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
537
538                 int profileId;
539                 std::stringstream ss(profile->getProfileId());
540                 ss>>profileId;
541                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
542                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
543                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
544                 }
545
546                 ret = sync_agent_ds_set_profile_name(profile_h, (char*)(profile->getProfileName().c_str()));
547                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
548                         ThrowMsg(PlatformException, "Platform error while settting a profile name: "<<ret);
549                 }
550
551                 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()));
552                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
553                         ThrowMsg(PlatformException, "Platform error while settting a server info: "<<ret);
554                 }
555
556                 sync_agent_ds_sync_mode_e syncMode = convertToPlatformSyncMode(profile->getSyncInfo()->getSyncMode());
557                 sync_agent_ds_sync_type_e syncType = convertToPlatformSyncType(profile->getSyncInfo()->getSyncType());
558                 sync_agent_ds_sync_interval_e syncInterval = convertToPlatformSyncInterval(profile->getSyncInfo()->getSyncInterval());
559                 LogDebug("syncMode: "<<syncMode<<", syncType: "<<syncType<<", syncInterval: "<<syncInterval);
560
561                 ret = sync_agent_ds_set_sync_info(profile_h, syncMode, syncType, syncInterval);
562                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
563                         ThrowMsg(PlatformException, "Platform error while settting a sync info: "<<ret);
564                 }
565
566                 // Set the sync categories.
567                 SyncServiceInfoListPtr categories = profile->getServiceInfo();
568                 sync_agent_ds_service_type_e serviceType;
569                 sync_agent_ds_src_uri_e srcURI;
570                 std::string tgtURI, id, password;
571                 bool enable;
572                 for(unsigned int i=0; categories->size()<i; i++) {
573                         serviceType = convertToPlatformSyncServiceType(categories->at(i)->getSyncServiceType());
574                         tgtURI = categories->at(i)->getServerDatabaseUri();
575                         srcURI = convertToPlatformSourceUri(categories->at(i)->getSyncServiceType());
576                         id = categories->at(i)->getId();
577                         password = categories->at(i)->getPassword();
578                         enable = categories->at(i)->getEnable();
579
580                         LogDebug("serviceType: "<<serviceType<<", tgtURI: "<<tgtURI<<", id: "<<id<<" for index: "<<i);
581
582                         ret = sync_agent_ds_set_sync_service_info(profile_h, serviceType, enable, srcURI, (char*)(tgtURI.c_str()),
583                                         0==id.size() ? NULL : (char*)(id.c_str()), 0==password.size() ? NULL : (char*)(password.c_str()));
584                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
585                                 ThrowMsg(PlatformException, "Platform error while settting a sync service info: "<<ret);
586                         }
587                 }
588
589                 ret = sync_agent_ds_update_profile(profile_h);
590                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
591                         ThrowMsg(NotFoundException, "Platform error while updating a profile: "<<ret);
592                 }
593
594         event->setResult(true);
595     }
596     Catch(NotFoundException)
597     {
598         LogWarning("Exception: "<<_rethrown_exception.GetMessage());
599         event->setResult(false);
600         event->setExceptionCode(ExceptionCodes::NotFoundException);
601     }
602     Catch(Exception)
603     {
604                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
605         event->setResult(false);
606         event->setExceptionCode(ExceptionCodes::PlatformException);
607     }
608
609         if(profile_h) {
610                 sync_agent_ds_free_profile_info(profile_h);
611         }
612 }
613
614 void DataSyncManager::OnRequestReceived(const IEventRemoveProfilePtr &event)
615 {
616         ds_profile_h profile_h = NULL;
617
618     Try
619     {
620         LogDebug("id: "<<event->getProfileId());
621
622         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
623
624                 int profileId;
625                 std::stringstream ss(event->getProfileId());
626                 ss>>profileId;
627                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
628                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
629                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
630                 }
631
632                 ret = sync_agent_ds_delete_profile(profile_h);
633                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
634                         ThrowMsg(PlatformException, "Platform error while deleting a profile: "<<ret);
635                 }
636
637         event->setResult(true);
638     }
639     Catch(NotFoundException)
640     {
641         LogWarning("Exception: "<<_rethrown_exception.GetMessage());
642         event->setResult(false);
643         event->setExceptionCode(ExceptionCodes::NotFoundException);
644     }
645     Catch(Exception)
646     {
647                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
648         event->setResult(false);
649         event->setExceptionCode(ExceptionCodes::PlatformException);
650     }
651
652         if(profile_h) {
653                 sync_agent_ds_free_profile_info(profile_h);
654         }
655 }
656
657 void DataSyncManager::OnRequestReceived(const IEventGetMaxProfilesNumPtr &event)
658 {
659     Try
660     {
661         LogDebug("Return maximum number of supported profiles: "<<MAX_PROFILES_NUM);
662
663                 event->setNumMaxProfiles(MAX_PROFILES_NUM);
664
665         event->setResult(true);
666     }
667     Catch(Exception)
668     {
669                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
670         event->setResult(false);
671         event->setExceptionCode(ExceptionCodes::PlatformException);
672     }
673 }
674
675 void DataSyncManager::OnRequestReceived(const IEventGetProfilesNumPtr &event)
676 {
677         GList *profile_list = NULL;
678         GList *iter = NULL;
679
680     Try
681     {
682         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
683
684                 ret = sync_agent_ds_get_all_profile(&profile_list);
685                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
686                         ThrowMsg(PlatformException, "Platform error while getting all profiles: "<<ret);
687                 }
688
689                 int numProfiles=0;
690                 for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
691                    sync_agent_ds_free_profile_info((ds_profile_h) iter->data);
692                    LogDebug("Free sync_agent_ds_profile_info for index: "<<numProfiles++);
693                 }
694
695                 LogDebug("numProfiles: "<<numProfiles);
696
697                 event->setNumProfiles(numProfiles);
698
699         event->setResult(true);
700     }
701     Catch(Exception)
702     {
703                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
704         event->setResult(false);
705         event->setExceptionCode(ExceptionCodes::PlatformException);
706     }
707 }
708
709 void DataSyncManager::OnRequestReceived(const IEventGetProfilePtr &event)
710 {
711         ds_profile_h profile_h = NULL;
712
713     Try
714     {
715         LogDebug("id: "<<event->getProfileId());
716
717         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
718
719                 int profileId;
720                 std::stringstream ss(event->getProfileId());
721                 ss>>profileId;
722                 ret = sync_agent_ds_get_profile(profileId, &profile_h);
723                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
724                         ThrowMsg(NotFoundException, "Platform error while getting a profile: "<<ret);
725                 }
726
727                 SyncProfileInfoPtr profile( new SyncProfileInfo() );
728
729                 profile->setProfileId(event->getProfileId());
730
731                 char *profileName = NULL;
732                 ret = sync_agent_ds_get_profile_name(profile_h, &profileName);
733                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
734                         ThrowMsg(PlatformException, "Platform error while gettting a profile name: "<<ret);
735                 }
736                 profile->setProfileName(profileName);
737
738                 sync_agent_ds_server_info server_info = { NULL };
739                 ret = sync_agent_ds_get_server_info(profile_h, &server_info);
740                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
741                         ThrowMsg(PlatformException, "Platform error while gettting a server info: "<<ret);
742                 }
743                 profile->getSyncInfo()->setUrl(server_info.addr);
744                 profile->getSyncInfo()->setId(server_info.id);
745                 profile->getSyncInfo()->setPassword(server_info.password);
746
747                 LogDebug("Url: "<<profile->getSyncInfo()->getUrl());
748
749                 sync_agent_ds_sync_info sync_info;
750                 ret = sync_agent_ds_get_sync_info(profile_h, &sync_info);
751                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
752                         ThrowMsg(PlatformException, "Platform error while gettting a sync info: "<<ret);
753                 }
754                 profile->getSyncInfo()->setSyncMode(convertToSyncMode(sync_info.sync_mode));
755                 profile->getSyncInfo()->setSyncType(convertToSyncType(sync_info.sync_type));
756                 profile->getSyncInfo()->setSyncInterval(convertToSyncInterval(sync_info.interval));
757
758                 LogDebug("Sync mode: "<<sync_info.sync_mode<<", type: "<<sync_info.sync_type<<", interval: "<<sync_info.interval);
759
760                 GList *category_list = NULL;
761                 sync_agent_ds_service_info *category_info = NULL;
762                 ret = sync_agent_ds_get_sync_service_info(profile_h, &category_list);
763                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
764                         ThrowMsg(PlatformException, "Platform error while gettting sync categories: "<<ret);
765                 }
766                 int category_count = g_list_length(category_list);
767                 LogDebug("category_count: "<<category_count);
768                 while(category_count--) {
769                         category_info = (sync_agent_ds_service_info *) g_list_nth_data(category_list, category_count);
770                         if(SYNC_AGENT_CALENDAR<category_info->service_type) {
771                                 LogDebug("Skip unsupported sync service type: "<<category_info->service_type);
772                                 continue;
773                         }
774
775                         SyncServiceInfoPtr serviceInfo( new SyncServiceInfo() );
776                         serviceInfo->setEnable(category_info->enabled);
777                         if(category_info->id) {
778                                 serviceInfo->setId(category_info->id);
779                         }
780                         if(category_info->password) {
781                                 serviceInfo->setPassword(category_info->password);
782                         }
783                         serviceInfo->setSyncServiceType(convertToSyncServiceType(category_info->service_type));
784                         if(category_info->tgt_uri) {
785                                 serviceInfo->setServerDatabaseUri(category_info->tgt_uri);
786                         }
787
788                         LogDebug("Service type: "<<serviceInfo->getSyncServiceType()<<", DB URI: "<<serviceInfo->getServerDatabaseUri());
789                         profile->getServiceInfo()->push_back(serviceInfo);
790                 }
791                 if(category_list) {
792                         g_list_free(category_list);
793                 }
794
795                 event->setProfile(profile);
796
797         event->setResult(true);
798     }
799     Catch(NotFoundException)
800     {
801         LogWarning("Exception: "<<_rethrown_exception.GetMessage());
802         event->setResult(false);
803         event->setExceptionCode(ExceptionCodes::NotFoundException);
804     }
805     Catch(Exception)
806     {
807                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
808         event->setResult(false);
809         event->setExceptionCode(ExceptionCodes::PlatformException);
810     }
811
812         if(profile_h) {
813                 sync_agent_ds_free_profile_info(profile_h);
814         }
815 }
816
817 void DataSyncManager::OnRequestReceived(const IEventGetAllProfilesPtr &event)
818 {
819         GList *profile_list = NULL;
820         GList *iter = NULL;
821
822     Try
823     {
824                 ds_profile_h profile_h = NULL;
825         sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
826
827                 ret = sync_agent_ds_get_all_profile(&profile_list);
828                 if (SYNC_AGENT_DS_SUCCESS!=ret) {
829                         ThrowMsg(PlatformException, "Platform error while getting all profiles: "<<ret);
830                 }
831
832                 LogDebug("Number of profiles: "<< g_list_length(profile_list));
833                 for (iter = profile_list; iter != NULL; iter = g_list_next(iter)) {
834                         profile_h = (ds_profile_h) iter->data;
835                         SyncProfileInfoPtr profile( new SyncProfileInfo() );
836
837                         int profileId;
838                         ret = sync_agent_ds_get_profile_id(profile_h, &profileId);
839                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
840                                 ThrowMsg(PlatformException, "Platform error while gettting a profile id: "<<ret);
841                         }
842
843                         std::stringstream ss;
844                         ss<<profileId;
845                         profile->setProfileId(ss.str());
846
847                         LogDebug("Processing a profile with id: "<<profile->getProfileId());
848
849                         char *profileName = NULL;
850                         ret = sync_agent_ds_get_profile_name(profile_h, &profileName);
851                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
852                                 ThrowMsg(PlatformException, "Platform error while gettting a profile name: "<<ret);
853                         }
854                         profile->setProfileName(profileName);
855
856                         sync_agent_ds_server_info server_info = { NULL };
857                         ret = sync_agent_ds_get_server_info(profile_h, &server_info);
858                         if (SYNC_AGENT_DS_SUCCESS!=ret) {
859                                 ThrowMsg(PlatformException, "Platform error while gettting a server info: "<<ret);
860                         }
861                         profile->getSyncInfo()->setUrl(server_info.addr);
862                         profile->getSyncInfo()->setId(server_info.id);
863                         profile->getSyncInfo()->setPassword(server_info.password);
864
865                         LogDebug("Url: "<<profile->getSyncInfo()->getUrl());
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                         LogDebug("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                         LogDebug("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                                         LogDebug("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                                 LogDebug("Service type: "<<serviceInfo->getSyncServiceType()<<", DB URI: "<<serviceInfo->getServerDatabaseUri());
907                                 profile->getServiceInfo()->push_back(serviceInfo);
908                         }
909                         if(category_list) {
910                                 g_list_free(category_list);
911                         }
912
913                         LogDebug("Adding a profile to the list.");
914                         event->getProfiles()->push_back(profile);
915                 }
916
917         event->setResult(true);
918     }
919     Catch(Exception)
920     {
921                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
922         event->setResult(false);
923         event->setExceptionCode(ExceptionCodes::PlatformException);
924     }
925
926         LogDebug("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         LogDebug("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             LogDebug("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         LogWarning("Exception: "<<_rethrown_exception.GetMessage());
979         event->setResult(false);
980         event->setExceptionCode(ExceptionCodes::NotFoundException);
981     }
982     Catch(Exception)
983     {
984                 LogWarning("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         LogDebug("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         LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1022         event->setResult(false);
1023         event->setExceptionCode(ExceptionCodes::NotFoundException);
1024     }
1025     Catch(Exception)
1026     {
1027                 LogWarning("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         LogDebug("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                 LogDebug("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                                 LogDebug("Statistics for contact.");
1074                                 statisticsPtr->setServiceType(convertToSyncServiceType(SYNC_AGENT_CONTACT));
1075                         } else if(1==i) {
1076                                 LogDebug("Statistics for event.");
1077                                 statisticsPtr->setServiceType(convertToSyncServiceType(SYNC_AGENT_CALENDAR));
1078                         } else {
1079                                 LogWarning("Unsupported category for statistics: "<<i);
1080                                 continue;
1081                         }
1082
1083                         LogDebug("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                         LogDebug("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         LogWarning("Exception: "<<_rethrown_exception.GetMessage());
1109         event->setResult(false);
1110         event->setExceptionCode(ExceptionCodes::NotFoundException);
1111     }
1112     Catch(Exception)
1113     {
1114                 LogWarning("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 }