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,
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;
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:
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,