[DataSync] getAll
authorRyszard Matuszyk <r.matuszyk@samsung.com>
Mon, 19 Jan 2015 08:32:54 +0000 (09:32 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Mon, 19 Jan 2015 10:19:11 +0000 (19:19 +0900)
Verification: not available. Platform function sync_agent_ds_init not work

Change-Id: I3bb4488c932c00bdd8efeb6ca9a70a27b94e389d
Signed-off-by: Ryszard Matuszyk <r.matuszyk@samsung.com>
src/datasync/datasync_instance.cc
src/datasync/datasync_manager.cc
src/datasync/datasync_manager.h

index c54e90651bc1a34a190bacbf60930f98eefcbbf0..a05a0e3952c52db529ae8055ccd7186b20cbe20d 100644 (file)
@@ -56,11 +56,10 @@ void DatasyncInstance::Get(const picojson::value &args, picojson::object &out) {
 }
 
 void DatasyncInstance::GetAll(const picojson::value &args, picojson::object &out) {
-//  TODO: implementation
-
-    picojson::value val{picojson::object{}};
+  picojson::value result = picojson::value(picojson::array());
 
-    ReportSuccess(val, out);
+  DataSyncManager::Instance().GetAll(result.get<picojson::array>());
+  ReportSuccess(result, out);
 }
 
 void DatasyncInstance::GetLastSyncStatistics(const picojson::value &args, picojson::object &out) {
index 751d94ea748e4493cea21a698f86417a5b6641c5..0966fdfcb08517a9424a649fe06f072363a75ccd 100644 (file)
@@ -503,127 +503,35 @@ void DataSyncManager::Get(const std::string& id, picojson::object& out) {
   Item(id, &profile_h, out);
 }
 
-ResultOrError<SyncProfileInfoListPtr> DataSyncManager::GetAll() const {
+void DataSyncManager::GetAll(picojson::array &out) {
   GList* profile_list = nullptr;
-  GList* iter = nullptr;
-
-  ds_profile_h profile_h = nullptr;
-
-  auto exit = common::MakeScopeExit([&profile_list, &profile_h, &iter]() {
-    LoggerD("Free profiles list.");
-    for (iter = profile_list; iter != nullptr; iter = g_list_next(iter)) {
-      sync_agent_ds_free_profile_info((ds_profile_h)iter->data);
-    }
-
-    if (profile_list) {
-      g_list_free(profile_list);
-    }
-  });
-
-  SyncProfileInfoListPtr profiles = std::make_shared<SyncProfileInfoList>();
 
-  sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL;
-
-  ret = sync_agent_ds_get_all_profile(&profile_list);
+  sync_agent_ds_error_e ret = sync_agent_ds_get_all_profile(&profile_list);
   if (SYNC_AGENT_DS_SUCCESS != ret) {
-    return Error("Exception",
-        "Platform error while getting all profiles");
+    throw UnknownException("Platform error while getting all profiles");
   }
 
+  ds_profile_h profile_h = nullptr;
+  GList* iter = nullptr;
   int profile_id;
   LoggerD("Number of profiles: %d", g_list_length(profile_list));
+
   for (iter = profile_list; iter != nullptr; iter = g_list_next(iter)) {
-    profile_h = (ds_profile_h)iter->data;
-    SyncProfileInfoPtr profile(new SyncProfileInfo());
+    profile_h = iter->data;
 
     ret = sync_agent_ds_get_profile_id(profile_h, &profile_id);
     if (SYNC_AGENT_DS_SUCCESS != ret) {
-      return Error("Exception",
-          "Platform error while gettting a profile id");
+      throw UnknownException("Platform error while gettting a profile id");
     }
 
-    profile->set_profile_id(std::to_string(profile_id));
+    picojson::value profile = picojson::value(picojson::object());
+    picojson::object& profile_obj = profile.get<picojson::object>();
 
-    LoggerD("Processing a profile with id: %s", profile->profile_id().c_str());
-
-    char* profile_name = nullptr;
-    ret = sync_agent_ds_get_profile_name(profile_h, &profile_name);
-    if (SYNC_AGENT_DS_SUCCESS != ret) {
-      return Error("Exception",
-          "Platform error while gettting a profile name");
-    }
-    profile->set_profile_name(profile_name);
-
-    sync_agent_ds_server_info server_info = {nullptr};
-    ret = sync_agent_ds_get_server_info(profile_h, &server_info);
-    if (SYNC_AGENT_DS_SUCCESS != ret) {
-      return Error("Exception",
-          "Platform error while gettting a server info");
-    }
-    profile->sync_info()->set_url(server_info.addr);
-    profile->sync_info()->set_id(server_info.id);
-    profile->sync_info()->set_password(server_info.password);
-
-    sync_agent_ds_sync_info sync_info;
-    ret = sync_agent_ds_get_sync_info(profile_h, &sync_info);
-    if (SYNC_AGENT_DS_SUCCESS != ret) {
-      return Error("Exception",
-          "Platform error while gettting a sync info");
-    }
-    profile->sync_info()->set_sync_mode(
-        ConvertToSyncMode(sync_info.sync_mode));
-    profile->sync_info()->set_sync_type(
-        ConvertToSyncType(sync_info.sync_type));
-    profile->sync_info()->set_sync_interval(
-        ConvertToSyncInterval(sync_info.interval));
-
-    LoggerD("Sync mode: %d, type: %d, interval: %d",
-            sync_info.sync_mode, sync_info.sync_type, sync_info.interval);
-
-    GList* category_list = nullptr;
-    sync_agent_ds_service_info* category_info = nullptr;
-    ret = sync_agent_ds_get_sync_service_info(profile_h, &category_list);
-    if (SYNC_AGENT_DS_SUCCESS != ret) {
-      return Error(
-          "Exception",
-          "Platform error while gettting sync categories");
-    }
-    int category_count = g_list_length(category_list);
-    LoggerD("category_count: %d", category_count);
-    while (category_count--) {
-      category_info = static_cast<sync_agent_ds_service_info*>(
-          g_list_nth_data(category_list, category_count));
-      if (SYNC_AGENT_CALENDAR < category_info->service_type) {
-        LoggerD("Skip unsupported sync service type: %d", category_info->service_type);
-        continue;
-      }
-
-      SyncServiceInfoPtr service_info(new SyncServiceInfo());
-      service_info->set_enable(category_info->enabled);
-      if (category_info->id) {
-        service_info->set_id(category_info->id);
-      }
-      if (category_info->password) {
-        service_info->set_password(category_info->password);
-      }
-      service_info->set_sync_service_type(
-          ConvertToSyncServiceType(category_info->service_type));
-      if (category_info->tgt_uri) {
-        service_info->set_server_database_uri(category_info->tgt_uri);
-      }
-
-      LoggerD("Service type: %d", service_info->sync_service_type());
-      profile->service_info()->push_back(service_info);
-    }
-    if (category_list) {
-      g_list_free(category_list);
-    }
+    Item(std::to_string(profile_id), &profile_h, profile_obj);
 
     LoggerD("Adding a profile to the list.");
-    profiles->push_back(profile);
+    out.push_back(profile);
   }
-
-  return profiles;
 }
 
 ResultOrError<void> DataSyncManager::StartSync(
index 47759f32a075895056b3b07ad7e98161d31ad08a..8ae308c5daf85f233f88140981ac689496762050 100644 (file)
@@ -42,7 +42,7 @@ class DataSyncManager {
   int GetProfilesNum() const;
 
   void Get(const std::string& id, picojson::object &out);
-  ResultOrError<SyncProfileInfoListPtr> GetAll() const;
+  void GetAll(picojson::array &out);
   void GetLastSyncStatistics(const std::string& id, picojson::array &out);
 
   ResultOrError<void> StartSync(const std::string& profile_id_str,