[IOTCON] update implementation for applying the change of native APIs
authortaekeun.kang <taekeun.kang@samsung.com>
Wed, 20 Apr 2016 12:23:53 +0000 (21:23 +0900)
committertaekeun.kang <taekeun.kang@samsung.com>
Thu, 21 Apr 2016 02:01:34 +0000 (11:01 +0900)
Change-Id: I98b82bb8f4504814948d447fb6bc83761d6d960f
Signed-off-by: taekeun.kang <taekeun.kang@samsung.com>
src/iotcon/iotcon_client_manager.cc
src/iotcon/iotcon_client_manager.h
src/iotcon/iotcon_instance.cc
src/iotcon/iotcon_server_manager.cc
src/iotcon/iotcon_server_manager.h
src/iotcon/iotcon_utils.cc

index 879ce19d4f589790e02c687be6bd2546d309f781..41f9c3b9b2192da51785be683dec126cbe5e6ac3 100644 (file)
@@ -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,
index e57308d76405a8218ee52f0045899d25d67cc343..8b8fd9f56755543bc2109ce6cb6cb24e8de1bc8c 100644 (file)
@@ -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,
index 3344a02bc2688fcd58b889d7603f8bb7eab6ebea..5eb5a75f58b56dd3f7468c5f480ba234a78b6005 100644 (file)
@@ -17,7 +17,6 @@
 #include "iotcon/iotcon_instance.h"
 
 #include <thread>
-#include <iotcon-internal.h>
 
 #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<IotconInstance*>(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) {
index a873cb494869b165c43f1b8d5c9b5f8b6a5b5058..277e52ec877556f4ed3b6f1c76be9f41112e57b5 100644 (file)
@@ -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();
index 3f9d8ef8ffef6e278293bfda179aa4298e1591a3..7b9d347c7636b63d3556d6021ce1f319116e0f25 100644 (file)
@@ -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,
index 6fa89bfbfb0be82da1bc88ad4987987a8a211554..3e8c06b80af65d13baf95605032f15e9e58d1f31 100644 (file)
@@ -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);