From: Rafal Galka Date: Wed, 14 Jan 2015 09:53:00 +0000 (+0900) Subject: Revert "[DataSync] add" X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~635 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2c99170f161af20e86b11eb6987df30f1fb911a0;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git Revert "[DataSync] add" This reverts commit f8491291694ae18b4cf64e5bb37f889caa379474. Reason: Runtime error E/WRT_SERVICE( 2458): extension.cpp: Initialize(50) > Error loading extension '/usr/lib/tizen-extensions-crosswalk/libtizen_datasync.so' : undefined symbol: _ZN9extension8datasync15DataSyncManager18platform_enum_map_E Change-Id: Ic192a57643135bc195c7758e919dfd1a183d8657 --- diff --git a/src/datasync/datasync_instance.cc b/src/datasync/datasync_instance.cc index ba1a6547..81650458 100644 --- a/src/datasync/datasync_instance.cc +++ b/src/datasync/datasync_instance.cc @@ -15,8 +15,6 @@ namespace extension { namespace datasync { -using namespace common; - DatasyncInstance::DatasyncInstance() { using namespace std::placeholders; #define REGISTER_SYNC(c, x) \ @@ -72,9 +70,11 @@ void DatasyncInstance::GetLastSyncStatistics(const picojson::value &args, picojs } void DatasyncInstance::Add(const picojson::value &args, picojson::object &out) { - ReportSuccess( - picojson::value(static_cast(DataSyncManager::Instance().Add( - args.get()))), out); +// TODO: implementation + + picojson::value val{picojson::object{}}; + + ReportSuccess(val, out); } void DatasyncInstance::Update(const picojson::value &args, picojson::object &out) { diff --git a/src/datasync/datasync_manager.cc b/src/datasync/datasync_manager.cc index 7ecb990b..bc6d0cf7 100644 --- a/src/datasync/datasync_manager.cc +++ b/src/datasync/datasync_manager.cc @@ -13,82 +13,14 @@ #include "datasync/sync_info.h" #include "datasync/sync_service_info.h" #include "datasync/sync_profile_info.h" -#include "common/converter.h" #include "tizen/tizen.h" namespace extension { namespace datasync { -using namespace common; - const int MAX_PROFILES_NUM = 5; -const std::string kDefaultEnumKey = "_DEFAULT"; -const std::string kSyncMode = "SyncMode"; -const std::string kSyncType = "SyncType"; -const std::string kSyncInterval = "SyncInterval"; -const std::string kSyncServiceType = "SyncServiceType"; -const std::string kSyncServiceTypeToSrcUri = "SyncServiceTypeToSrcUri"; -const std::string kSyncStatus = "SyncStatus"; - -const PlatformEnumMap platform_enum_map_ = { - {kSyncMode, - {{kDefaultEnumKey, SYNC_AGENT_SYNC_MODE_MANUAL}, - {"MANUAL", SYNC_AGENT_SYNC_MODE_MANUAL}, - {"PERIODIC", SYNC_AGENT_SYNC_MODE_PERIODIC}, - {"PUSH", SYNC_AGENT_SYNC_MODE_PUSH}}}, - {kSyncType, - {{kDefaultEnumKey, SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH}, - {"TWO_WAY", SYNC_AGENT_SYNC_TYPE_UPDATE_BOTH}, - {"SLOW", SYNC_AGENT_SYNC_TYPE_FULL_SYNC}, - {"ONE_WAY_FROM_CLIENT", SYNC_AGENT_SYNC_TYPE_UPDATE_TO_SERVER}, - {"REFRESH_FROM_CLIENT", SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_PHONE}, - {"ONE_WAY_FROM_SERVER", SYNC_AGENT_SYNC_TYPE_UPDATE_TO_PHONE}, - {"REFRESH_FROM_SERVER", SYNC_AGENT_SYNC_TYPE_REFRESH_FROM_SERVER}}}, - {kSyncInterval, - {{kDefaultEnumKey, SYNC_AGENT_SYNC_INTERVAL_1_WEEK}, - {"5_MINUTES", SYNC_AGENT_SYNC_INTERVAL_5_MINUTES}, - {"15_MINUTES", SYNC_AGENT_SYNC_INTERVAL_15_MINUTES}, - {"1_HOUR", SYNC_AGENT_SYNC_INTERVAL_1_HOUR}, - {"4_HOURS", SYNC_AGENT_SYNC_INTERVAL_4_HOURS}, - {"12_HOURS", SYNC_AGENT_SYNC_INTERVAL_12_HOURS}, - {"1_DAY", SYNC_AGENT_SYNC_INTERVAL_1_DAY}, - {"1_WEEK", SYNC_AGENT_SYNC_INTERVAL_1_WEEK}, - {"1_MONTH", SYNC_AGENT_SYNC_INTERVAL_1_MONTH}, - {"NONE", SYNC_AGENT_SYNC_INTERVAL_NONE}}}, - {kSyncServiceType, - {{kDefaultEnumKey, SYNC_AGENT_CONTACT}, - {"CONTACT", SYNC_AGENT_CONTACT}, - {"EVENT", SYNC_AGENT_CALENDAR}}}, - {kSyncServiceTypeToSrcUri, - {{kDefaultEnumKey, SYNC_AGENT_SRC_URI_CONTACT}, - {"CONTACT", SYNC_AGENT_SRC_URI_CONTACT}, - {"EVENT", SYNC_AGENT_SRC_URI_CALENDAR}}}}; - -int DataSyncManager::StrToPlatformEnum(const std::string& field, const std::string& value) { - if (platform_enum_map_.find(field) == platform_enum_map_.end()) { - throw UnknownException(std::string("Undefined platform enum type ") + field); - } - - auto def = platform_enum_map_.at(field); - auto def_iter = def.find(value); - if (def_iter != def.end()) { - return def_iter->second; - } - - // default value - if any - def_iter = def.find("_DEFAULT"); - if (def_iter != def.end()) { - return def_iter->second; - } - - std::string message = "Platform enum value " + value + " not found for " + field; - throw InvalidValuesException(message); -} - - - sync_agent_ds_sync_mode_e ConvertToPlatformSyncMode( datasync::SyncInfo::SyncMode sync_mode) { switch (sync_mode) { @@ -366,97 +298,129 @@ DataSyncManager::~DataSyncManager() { // sync-agent should fix it's deinitialization } -void DataSyncManager::Item(ds_profile_h* profile_h, const picojson::object& args) { - sync_agent_ds_error_e ret; +ResultOrError DataSyncManager::Add(SyncProfileInfo& profile_info) { + ds_profile_h profile_h = nullptr; + char* profile_name = nullptr; + + // Check if the quota is full first. + GList* profile_list = nullptr; + GList* iter = nullptr; + + auto exit = common::MakeScopeExit([&profile_name, &profile_h](){ + if (profile_name) { + free(profile_name); + } + + if (profile_h) { + sync_agent_ds_free_profile_info(profile_h); + } + }); + + sync_agent_ds_error_e ret = SYNC_AGENT_DS_FAIL; - std::string profile_name = FromJson(args, "profileName").c_str(); - ret = sync_agent_ds_set_profile_name(profile_h, const_cast(profile_name.c_str())); + ret = sync_agent_ds_get_all_profile(&profile_list); if (SYNC_AGENT_DS_SUCCESS != ret) { - throw UnknownException("Platform error while settting a profile name"); + return Error("Exception", + "Platform error while getting all profiles"); } - const picojson::object& sync_info = FromJson(args, "syncInfo"); - std::string url = FromJson(sync_info, "url").c_str(); - std::string id = FromJson(sync_info, "id").c_str(); - std::string password = FromJson(sync_info, "password").c_str(); - ret = sync_agent_ds_set_server_info(profile_h, const_cast(url.c_str()), - const_cast(id.c_str()), - const_cast(password.c_str())); - if (SYNC_AGENT_DS_SUCCESS != ret) { - throw UnknownException("Platform error while settting a server info"); + int num_profiles = g_list_length(profile_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); + } + LoggerD("numProfiles: %d", num_profiles); + if (MAX_PROFILES_NUM == num_profiles) { + return Error("OutOfRangeException", + "There are already maximum number of profiles!"); } - int sync_mode = StrToPlatformEnum(kSyncMode, FromJson(sync_info, "mode")); - int sync_type = StrToPlatformEnum(kSyncType, FromJson(sync_info, "type")); - int sync_interval = StrToPlatformEnum(kSyncInterval, - FromJson(sync_info, "interval")); - LoggerD("syncMode: %d, syncType: %d, syncInterval: %d", sync_mode, sync_type, sync_interval); - ret = sync_agent_ds_set_sync_info(profile_h, static_cast(sync_mode), - static_cast(sync_type), - static_cast(sync_interval)); + ret = sync_agent_ds_create_profile_info(&profile_h); if (SYNC_AGENT_DS_SUCCESS != ret) { - throw UnknownException("Platform error while settting a sync info"); + return Error("Exception", + "Platform error while creating a profile"); } - // Set the sync categories. - if (IsNull(args, "serviceInfo")) return; - - const picojson::array& service_info = FromJson(args, "serviceInfo"); + ret = sync_agent_ds_set_profile_name( + profile_h, const_cast(profile_info.profile_name().c_str())); + if (SYNC_AGENT_DS_SUCCESS != ret) { + return Error("Exception", + "Platform error while settting a profile name"); + } - for (auto& item : service_info) { - const picojson::object& obj = JsonCast(item); + ret = sync_agent_ds_set_server_info( + profile_h, const_cast(profile_info.sync_info()->url().c_str()), + const_cast(profile_info.sync_info()->id().c_str()), + const_cast(profile_info.sync_info()->password().c_str())); + if (SYNC_AGENT_DS_SUCCESS != ret) { + return Error("Exception", + "Platform error while settting a server info"); + } - bool enable = FromJson(obj, "enable"); - int service_type = - StrToPlatformEnum(kSyncServiceType, FromJson(obj, "serviceType")); - std::string tgt_uri = FromJson(obj, "serverDatabaseUri"); - int src_uri = StrToPlatformEnum(kSyncServiceType, FromJson(obj, "serviceType")); + sync_agent_ds_sync_mode_e sync_mode = + ConvertToPlatformSyncMode(profile_info.sync_info()->sync_mode()); + sync_agent_ds_sync_type_e sync_type = + ConvertToPlatformSyncType(profile_info.sync_info()->sync_type()); + sync_agent_ds_sync_interval_e sync_interval = + ConvertToPlatformSyncInterval(profile_info.sync_info()->sync_interval()); + LoggerD("syncMode: %d, syncType: %d, syncInterval: %d", sync_mode, sync_type, sync_interval); - std::string id = ""; - if (!IsNull(obj, "id")) id = FromJson(obj, "id"); + ret = sync_agent_ds_set_sync_info(profile_h, sync_mode, sync_type, + sync_interval); + if (SYNC_AGENT_DS_SUCCESS != ret) { + return Error("Exception", + "Platform error while settting a sync info"); + } - std::string password = ""; - if (!IsNull(obj, "password")) password = FromJson(obj, "password"); + // Set the sync categories. + SyncServiceInfoListPtr categories = profile_info.service_info(); + for (unsigned int i = 0; categories->size() < i; ++i) { + sync_agent_ds_service_type_e service_type = + ConvertToPlatformSyncServiceType( + categories->at(i)->sync_service_type()); + std::string tgt_uri = categories->at(i)->server_database_uri(); + sync_agent_ds_src_uri_e src_uri = + ConvertToPlatformSourceUri(categories->at(i)->sync_service_type()); + std::string id = categories->at(i)->id(); + std::string password = categories->at(i)->password(); + bool enable = categories->at(i)->enable(); - LoggerI("serviceType: %d, tgtURI: %s, enable: %d", service_type, tgt_uri.c_str(), enable); + LoggerI("serviceType: %d, tgtURI: %s, enable: %d for index: %d", + service_type, tgt_uri.c_str(), enable, i); ret = sync_agent_ds_set_sync_service_info( - profile_h, static_cast(service_type), enable, - static_cast(src_uri), const_cast(tgt_uri.c_str()), + profile_h, service_type, enable, src_uri, + const_cast(tgt_uri.c_str()), 0 == id.size() ? nullptr : const_cast(id.c_str()), 0 == password.size() ? nullptr : const_cast(password.c_str())); if (SYNC_AGENT_DS_SUCCESS != ret) { - throw UnknownException("Platform error while settting a sync service info"); + return Error("Exception", + "Platform error while settting a sync service info"); } } -} - -int DataSyncManager::Add(const picojson::object& args) { - ds_profile_h profile_h = nullptr; - - int num_profiles = GetProfilesNum(); - LoggerD("numProfiles: %d", num_profiles); - - if (MAX_PROFILES_NUM == num_profiles) { - throw QuotaExceededException("There are already maximum number of profiles!"); - } - sync_agent_ds_error_e ret = sync_agent_ds_create_profile_info(&profile_h); + int profile_id; + ret = sync_agent_ds_add_profile(profile_h, &profile_id); if (SYNC_AGENT_DS_SUCCESS != ret) { - throw UnknownException("Platform error while creating a profile"); + return Error("Exception", + "Platform error while adding a profile"); } - Item(&profile_h, args); + LoggerD("profileId from platform: %d", profile_id); - int profile_id; - ret = sync_agent_ds_add_profile(profile_h, &profile_id); + ret = sync_agent_ds_get_profile_name(profile_h, &profile_name); if (SYNC_AGENT_DS_SUCCESS != ret) { - throw UnknownException("Platform error while adding a profile"); + return Error("Exception", + "Platform error while getting a profile name"); } - LoggerD("profileId from platform: %d", profile_id); + LoggerD("profileName: %s, profileId: %d", profile_name, profile_id); + + profile_info.set_profile_id(std::to_string(profile_id)); - return profile_id; + return profile_info.profile_id(); } ResultOrError DataSyncManager::Update(SyncProfileInfo& profile_info) { diff --git a/src/datasync/datasync_manager.h b/src/datasync/datasync_manager.h index 9e205d6d..6ab5cf52 100644 --- a/src/datasync/datasync_manager.h +++ b/src/datasync/datasync_manager.h @@ -18,13 +18,10 @@ #include "datasync/datasync_error.h" #include "datasync/sync_profile_info.h" #include "datasync/sync_statistics.h" -#include "common/picojson.h" namespace extension { namespace datasync { -typedef std::map> PlatformEnumMap; - class DatasyncInstance; class DataSyncManager { @@ -34,7 +31,7 @@ class DataSyncManager { ~DataSyncManager(); - int Add(const picojson::object &args); + ResultOrError Add(SyncProfileInfo& profile_info); ResultOrError Update(SyncProfileInfo& profile_info); ResultOrError Remove(const std::string& id); @@ -55,22 +52,17 @@ class DataSyncManager { static DataSyncManager& Instance(); - static int StrToPlatformEnum(const std::string& field, const std::string& value); - private: DataSyncManager(); int StateChangedCallback(sync_agent_event_data_s* request); int ProgressCallback(sync_agent_event_data_s* request); - void Item(ds_profile_h *profile_h, const picojson::object &args); ProfileIdToCallbackMap callbacks_; static bool sync_agent_initialized_; DISALLOW_COPY_AND_ASSIGN(DataSyncManager); - - static const PlatformEnumMap platform_enum_map_; }; } // namespace datasync