From 7e2fc1a576034e58efd9b4e4c0da258565eafc6e Mon Sep 17 00:00:00 2001 From: "taekeun.kang" Date: Wed, 20 Apr 2016 21:23:53 +0900 Subject: [PATCH] [IOTCON] update implementation for applying the change of native APIs Change-Id: I98b82bb8f4504814948d447fb6bc83761d6d960f Signed-off-by: taekeun.kang --- src/iotcon/iotcon_client_manager.cc | 35 -------------------- src/iotcon/iotcon_client_manager.h | 1 - src/iotcon/iotcon_instance.cc | 38 ++------------------- src/iotcon/iotcon_server_manager.cc | 51 ----------------------------- src/iotcon/iotcon_server_manager.h | 1 - src/iotcon/iotcon_utils.cc | 1 - 6 files changed, 2 insertions(+), 125 deletions(-) diff --git a/src/iotcon/iotcon_client_manager.cc b/src/iotcon/iotcon_client_manager.cc index 879ce19d..41f9c3b9 100644 --- a/src/iotcon/iotcon_client_manager.cc +++ b/src/iotcon/iotcon_client_manager.cc @@ -43,41 +43,6 @@ IotconClientManager& IotconClientManager::GetInstance() { return instance; } -TizenResult IotconClientManager::RestoreHandles() { - ScopeLogger(); - - for (const auto& it : presence_map_) { - LoggerD("Restoring handle for presence event with id: %lld", it.first); - - PresenceEventPtr presence = it.second; - char* host = nullptr; - char* resource_type = nullptr; - iotcon_connectivity_type_e con_type = IOTCON_CONNECTIVITY_IPV4; - - auto res = IotconUtils::ExtractFromPresenceEvent(presence, &host, - &con_type, &resource_type); - if (!res){ - return res; - } - - const iotcon_presence_h old_handle = presence->handle; - int ret = iotcon_add_presence_cb(host, con_type, resource_type, - PresenceHandler, this,&(presence->handle)); - if (IOTCON_ERROR_NONE != ret || nullptr == presence->handle) { - LogAndReturnTizenError(IotconUtils::ConvertIotconError(ret), - ("iotcon_add_presence_cb() failed: %d (%s)", - ret, get_error_message(ret))); - } - if (old_handle) { - LoggerD("destroy handle which is currently invalid: %p", old_handle); - iotcon_remove_presence_cb(old_handle); - } - LoggerD("new handle: %p", (presence->handle)); - } - - return TizenSuccess(); -} - void IotconClientManager::PresenceHandler(iotcon_presence_h presence, iotcon_error_e err, iotcon_presence_response_h response, diff --git a/src/iotcon/iotcon_client_manager.h b/src/iotcon/iotcon_client_manager.h index e57308d7..8b8fd9f5 100644 --- a/src/iotcon/iotcon_client_manager.h +++ b/src/iotcon/iotcon_client_manager.h @@ -33,7 +33,6 @@ class IotconClientManager { public: static IotconClientManager& GetInstance(); - common::TizenResult RestoreHandles(); common::TizenResult AddPresenceEventListener(const char* host, const iotcon_connectivity_type_e con_type_e, const char* resource_type, diff --git a/src/iotcon/iotcon_instance.cc b/src/iotcon/iotcon_instance.cc index 3344a02b..5eb5a75f 100644 --- a/src/iotcon/iotcon_instance.cc +++ b/src/iotcon/iotcon_instance.cc @@ -17,7 +17,6 @@ #include "iotcon/iotcon_instance.h" #include -#include #include "common/logger.h" #include "common/scope_exit.h" @@ -135,18 +134,11 @@ IotconInstance::IotconInstance() { #undef REGISTER_ASYNC // initialize connection to iotcon service - int ret = iotcon_connect(); + int ret = iotcon_initialize(); if (IOTCON_ERROR_NONE != ret) { LoggerE("Could not connnect to iotcon service: %s", get_error_message(ret)); } else { LoggerD("Iotcon service connected"); - ret = iotcon_add_connection_changed_cb(ConnectionChangedCallback, this); - if (IOTCON_ERROR_NONE != ret) { - LoggerE("Could not add connection changed callback for iotcon service: %s", - get_error_message(ret)); - } else { - LoggerD("Iotcon connection changed callback is registered"); - } ret = iotcon_start_presence(0); if (IOTCON_ERROR_NONE != ret) { @@ -158,37 +150,11 @@ IotconInstance::IotconInstance() { } } -void IotconInstance::ConnectionChangedCallback(bool is_connected, void* user_data) { - ScopeLogger(); - - if (!is_connected) { - LoggerD("Connection lost, need to wait for connection recovery"); - } else { - IotconInstance* instance = static_cast(user_data); - if (!instance) { - LoggerE("instance is NULL"); - return; - } - - LoggerD("Connection recovered, restoring handles"); - auto ret = IotconServerManager::GetInstance().RestoreHandles(); - if (!ret) { - LoggerD("Connection recovered, but restoring handles failed"); - } - - ret = IotconClientManager::GetInstance().RestoreHandles(); - if (!ret) { - LoggerD("Connection recovered, but restoring presence failed"); - } - } -} - IotconInstance::~IotconInstance() { ScopeLogger(); iotcon_stop_presence(); - iotcon_remove_connection_changed_cb(ConnectionChangedCallback, this); - iotcon_disconnect(); + iotcon_deinitialize(); } common::TizenResult IotconInstance::ResourceGetObserverIds(const picojson::object& args) { diff --git a/src/iotcon/iotcon_server_manager.cc b/src/iotcon/iotcon_server_manager.cc index a873cb49..277e52ec 100644 --- a/src/iotcon/iotcon_server_manager.cc +++ b/src/iotcon/iotcon_server_manager.cc @@ -41,57 +41,6 @@ IotconServerManager& IotconServerManager::GetInstance() { return instance; } -TizenResult IotconServerManager::RestoreHandles() { - ScopeLogger(); - - for (const auto& it : resource_map_) { - LoggerD("Restoring handle for resource with id: %lld", it.first); - - ResourceInfoPtr resource = it.second; - char* uri_path = nullptr; - iotcon_resource_types_h res_types = nullptr; - iotcon_resource_interfaces_h ifaces = 0; - int properties = 0; - - auto res = IotconUtils::ExtractFromResource(resource, &uri_path, - &res_types, &ifaces, &properties); - if (!res){ - return res; - } - - const iotcon_resource_h old_handle = resource->handle; - LoggerD("Create resource from backup data, uri: %s, res_types: %p, ifaces: %d, properties: %d", - uri_path, res_types, ifaces, properties); - - int ret = iotcon_resource_create(uri_path, res_types, ifaces, properties, - RequestHandler, // request_callback - this, // user_data - &(resource->handle)); - if (IOTCON_ERROR_NONE != ret || nullptr == resource->handle) { - LogAndReturnTizenError(IotconUtils::ConvertIotconError(ret), - ("iotcon_resource_create() failed: %d (%s)", - ret, get_error_message(ret))); - } - LoggerD("new handle: %p", (resource->handle)); - if (old_handle) { - LoggerD("destroy handle which is currently invalid: %p", old_handle); - iotcon_resource_destroy(old_handle); - } - } - - // rebind children - for (const auto& it : resource_map_) { - for (const auto& child : it.second->children) { - auto result = IotconUtils::ConvertIotconError(iotcon_resource_bind_child_resource(it.second->handle, child->handle)); - if (!result) { - LogAndReturnTizenError(result, ("iotcon_resource_bind_child_resource() failed")); - } - } - } - - return TizenSuccess(); -} - void IotconServerManager::RequestHandler(iotcon_resource_h resource, iotcon_request_h request, void *user_data) { ScopeLogger(); diff --git a/src/iotcon/iotcon_server_manager.h b/src/iotcon/iotcon_server_manager.h index 3f9d8ef8..7b9d347c 100644 --- a/src/iotcon/iotcon_server_manager.h +++ b/src/iotcon/iotcon_server_manager.h @@ -35,7 +35,6 @@ class IotconServerManager { public: static IotconServerManager& GetInstance(); - common::TizenResult RestoreHandles(); common::TizenResult CreateResource(const std::string& uri_path, const picojson::array& interfaces_array, const picojson::array& types_array, diff --git a/src/iotcon/iotcon_utils.cc b/src/iotcon/iotcon_utils.cc index 6fa89bfb..3e8c06b8 100644 --- a/src/iotcon/iotcon_utils.cc +++ b/src/iotcon/iotcon_utils.cc @@ -1988,7 +1988,6 @@ common::TizenResult IotconUtils::ConvertIotconError(int error) { case IOTCON_ERROR_OUT_OF_MEMORY: case IOTCON_ERROR_IOTIVITY: case IOTCON_ERROR_REPRESENTATION: - case IOTCON_ERROR_DBUS: case IOTCON_ERROR_SYSTEM: default: return common::AbortError(error); -- 2.34.1