[Iotcon] getDeviceInfo implemented
authorLukasz Bardeli <l.bardeli@samsung.com>
Wed, 10 Feb 2016 08:51:43 +0000 (09:51 +0100)
committerLukasz Bardeli <l.bardeli@samsung.com>
Wed, 10 Feb 2016 10:56:00 +0000 (19:56 +0900)
Change-Id: I4e77c21f289a6f7935e6d83bec4b259bc90db9fb
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
src/iotcon/iotcon_instance.cc
src/iotcon/iotcon_utils.cc
src/iotcon/iotcon_utils.h

index ae48cf213743148fd714cc262157ab2f5c024d6d..73243eab9346f65a32527deaa30085c888bf4807 100644 (file)
@@ -383,10 +383,47 @@ common::TizenResult IotconInstance::ClientRemovePresenceEventListener(const pico
   return common::UnknownError("Not implemented");
 }
 
+void IotconPDeviceInfoCb(iotcon_device_info_h device_info,
+                          iotcon_error_e result, void *user_data) {
+  ScopeLogger();
+
+  CallbackData* data = static_cast<CallbackData*>(user_data);
+  picojson::value v{picojson::object{}};
+  common::TizenResult ret = common::TizenSuccess();
+
+  if (IOTCON_ERROR_NONE != result) {
+    ret = IotconUtils::ConvertIotconError(result);
+  } else {
+    auto ret = IotconUtils::DeviceInfoToJson(device_info,&v.get<picojson::object>());
+  }
+
+  data->fun(ret, v);
+  delete data;
+}
+
 common::TizenResult IotconInstance::ClientGetDeviceInfo(const picojson::object& args,
                                                         const common::AsyncToken& token) {
   ScopeLogger();
-  return common::UnknownError("Not implemented");
+
+  CHECK_EXIST(args, kHostAddress);
+  CHECK_EXIST(args, kConnectivityType);
+
+  std::string host = args.find(kHostAddress)->second.get<std::string>();
+  std::string con_type = args.find(kConnectivityType)->second.get<std::string>();
+  iotcon_connectivity_type_e con_type_e = IotconUtils::ToConnectivityType(con_type);
+
+  CallbackData* data = new CallbackData{SimplePost(token)};
+
+  auto result = IotconUtils::ConvertIotconError(
+       iotcon_get_device_info(host.c_str(), con_type_e, IotconPDeviceInfoCb,
+                                data));
+
+  if (!result) {
+    delete data;
+    LogAndReturnTizenError(result);
+  }
+
+  return common::TizenSuccess();
 }
 
 void IotconPlatformInfoCb(iotcon_platform_info_h platform_info,
index a22704a3923f4deaab6e201a6e63d348a075c6f8..b91060e5c649a35b833b13cc958be54d79f6d5e1 100644 (file)
@@ -112,6 +112,11 @@ const std::string kFirmwareVersion = "firmwareVersion";
 const std::string kSupportUrl = "supportUrl";
 const std::string kSystemTime = "systemTime";
 
+const std::string kDeviceName = "deviceName";
+const std::string kSpecVersion = "specVersion";
+const std::string kOicDeviceId = "oicDeviceId";
+const std::string kDataModelVersion = "dataModelVersion";
+
 using common::TizenResult;
 using common::TizenSuccess;
 
@@ -1236,6 +1241,67 @@ common::TizenResult IotconUtils::PlatformInfoToJson(iotcon_platform_info_h platf
   return TizenSuccess();
 }
 
+common::TizenResult IotconUtils::DeviceInfoGetProperty(iotcon_device_info_h device,
+                                                       iotcon_device_info_e property_e,
+                                                       const std::string& name,
+                                                       picojson::object* out) {
+  ScopeLogger();
+
+  char* property = nullptr;
+  auto result = ConvertIotconError(iotcon_device_info_get_property(device,
+                                                                   property_e,
+                                                                   &property));
+  if (!result || !property) {
+    LogAndReturnTizenError(result, ("iotcon_device_info_get_property() failed"));
+  }
+  out->insert(std::make_pair(name, picojson::value{property}));
+
+  return TizenSuccess();
+}
+
+common::TizenResult IotconUtils::DeviceInfoToJson(iotcon_device_info_h device,
+                                                  picojson::object* out) {
+  ScopeLogger();
+
+  {
+    // deviceName
+    auto result = DeviceInfoGetProperty(device, IOTCON_DEVICE_INFO_NAME,
+                                        kDeviceName, out);
+    if (!result) {
+      return result;
+    }
+  }
+
+  {
+    // specVersion
+    auto result = DeviceInfoGetProperty(device, IOTCON_DEVICE_INFO_SPEC_VER,
+                                        kSpecVersion, out);
+    if (!result) {
+      return result;
+    }
+  }
+
+  {
+    // oicDeviceId
+    auto result = DeviceInfoGetProperty(device, IOTCON_DEVICE_INFO_ID,
+                                        kOicDeviceId, out);
+    if (!result) {
+      return result;
+    }
+  }
+
+  {
+    // dataModelVersion
+    auto result = DeviceInfoGetProperty(device, IOTCON_DEVICE_INFO_DATA_MODEL_VER,
+                                        kDataModelVersion, out);
+    if (!result) {
+      return result;
+    }
+  }
+
+  return TizenSuccess();
+}
+
 common::TizenResult IotconUtils::ConvertIotconError(int error) {
   switch (error) {
     case IOTCON_ERROR_NONE:
index 780bfe5cecaacfdeadaa7bff2a8c0e10c6c5844e..efe13f23526cf5551b27952496c2ef3eef2a71d0 100644 (file)
@@ -99,6 +99,12 @@ class IotconUtils {
                                                      iotcon_platform_info_e property,
                                                      const std::string& name,
                                                      picojson::object* out);
+  static common::TizenResult DeviceInfoToJson(iotcon_device_info_h device,
+                                                picojson::object* out);
+  static common::TizenResult DeviceInfoGetProperty(iotcon_device_info_h platform,
+                                                   iotcon_device_info_e  property,
+                                                   const std::string& name,
+                                                   picojson::object* out);
 
   static common::TizenResult RepresentationFromResource(const ResourceInfoPtr& resource,
                                                         const picojson::value& states,