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