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