From ebbc5ee339c7b304da1af0a2523a8d435cb6d46c Mon Sep 17 00:00:00 2001 From: Pawel Andruszkiewicz Date: Thu, 18 Feb 2016 08:36:14 +0100 Subject: [PATCH] [iotcon] Adjustments to latest WIDL. Change-Id: I80f7af6b5fb51ab06d99d465c959b47d36dc9eeb Signed-off-by: Pawel Andruszkiewicz --- src/iotcon/iotcon_api.js | 18 +++++++++--------- src/iotcon/iotcon_instance.cc | 18 +++++++++++------- src/iotcon/iotcon_instance.h | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/iotcon/iotcon_api.js b/src/iotcon/iotcon_api.js index 7bf89403..450b6d52 100644 --- a/src/iotcon/iotcon_api.js +++ b/src/iotcon/iotcon_api.js @@ -340,23 +340,24 @@ Resource.prototype.notify = function() { } }; -Resource.prototype.addResourceType = function() { +Resource.prototype.addResourceTypes = function() { var args = validator.validateMethod(arguments, [{ - name: 'type', - type: types.STRING + name: 'types', + type: types.ARRAY, + values: types.STRING }]); var callArgs = {}; callArgs.id = this[kIdKey]; - callArgs.type = args.type; + callArgs.types = args.types; - var result = native.callSync('IotconResource_addResourceType', callArgs); + var result = native.callSync('IotconResource_addResourceTypes', callArgs); if (native.isFailure(result)) { throw native.getErrorObject(result); } else { var t = this.resourceTypes; - t.push(args.type); + t = t.concat(args.types); updateWithInternalData({ resourceTypes: t }, this); } }; @@ -597,10 +598,9 @@ function RemoteResource(data) { var result = native.callSync('IotconRemoteResource_getCachedRepresentation', callArgs); if (native.isSuccess(result)) { return createRepresentation(native.getResultObject(result)); + } else { + return null; } - // TODO check what should be returned - console.log("returning empty Object"); - return {}; }.bind(this), set: function() {}, enumerable: true diff --git a/src/iotcon/iotcon_instance.cc b/src/iotcon/iotcon_instance.cc index 10250149..6b8276ca 100644 --- a/src/iotcon/iotcon_instance.cc +++ b/src/iotcon/iotcon_instance.cc @@ -79,7 +79,7 @@ const common::ListenerToken kRemoteResourceStateChangeListener const std::string kObserverIds = "observerIds"; const std::string kQos = "qos"; const std::string kChildId = "childId"; -const std::string kType = "type"; +const std::string kTypes = "types"; const std::string kInterface = "iface"; const std::string kResult = "result"; const std::string kTimeout = "timeout"; @@ -98,7 +98,7 @@ IotconInstance::IotconInstance() { REGISTER_SYNC("IotconResource_getObserverIds", ResourceGetObserverIds); REGISTER_SYNC("IotconResource_notify", ResourceNotify); - REGISTER_SYNC("IotconResource_addResourceType", ResourceAddResourceType); + REGISTER_SYNC("IotconResource_addResourceTypes", ResourceAddResourceTypes); REGISTER_SYNC("IotconResource_addResourceInterface", ResourceAddResourceInterface); REGISTER_SYNC("IotconResource_addChildResource", ResourceAddChildResource); REGISTER_SYNC("IotconResource_removeChildResource", ResourceRemoveChildResource); @@ -291,11 +291,11 @@ common::TizenResult IotconInstance::ResourceNotify(const picojson::object& args) return common::TizenSuccess(); } -common::TizenResult IotconInstance::ResourceAddResourceType(const picojson::object& args) { +common::TizenResult IotconInstance::ResourceAddResourceTypes(const picojson::object& args) { ScopeLogger(); CHECK_EXIST(args, kId); - CHECK_EXIST(args, kType); + CHECK_EXIST(args, kTypes); ResourceInfoPtr resource; auto result = IotconServerManager::GetInstance().GetResourceById(GetId(args), &resource); @@ -303,9 +303,13 @@ common::TizenResult IotconInstance::ResourceAddResourceType(const picojson::obje LogAndReturnTizenError(result, ("GetResourceById() failed")); } - result = IotconUtils::ConvertIotconError(iotcon_resource_bind_type(resource->handle, IotconUtils::GetArg(args, kType).get().c_str())); - if (!result) { - LogAndReturnTizenError(result, ("iotcon_resource_bind_type() failed")); + const auto& types = IotconUtils::GetArg(args, kTypes).get(); + + for (const auto& type : types) { + result = IotconUtils::ConvertIotconError(iotcon_resource_bind_type(resource->handle, type.get().c_str())); + if (!result) { + LogAndReturnTizenError(result, ("iotcon_resource_bind_type() failed")); + } } return common::TizenSuccess(); diff --git a/src/iotcon/iotcon_instance.h b/src/iotcon/iotcon_instance.h index 58d9327d..528abdb9 100644 --- a/src/iotcon/iotcon_instance.h +++ b/src/iotcon/iotcon_instance.h @@ -37,7 +37,7 @@ class IotconInstance : public common::TizenInstance { common::TizenResult ResourceGetObserverIds(const picojson::object& args); common::TizenResult ResourceNotify(const picojson::object& args); - common::TizenResult ResourceAddResourceType(const picojson::object& args); + common::TizenResult ResourceAddResourceTypes(const picojson::object& args); common::TizenResult ResourceAddResourceInterface(const picojson::object& args); common::TizenResult ResourceAddChildResource(const picojson::object& args); common::TizenResult ResourceRemoveChildResource(const picojson::object& args); -- 2.34.1