[iotcon] Implementation of Resource.observerIds.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 10 Feb 2016 11:49:06 +0000 (12:49 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 15 Feb 2016 13:48:07 +0000 (22:48 +0900)
Change-Id: I51c53da71b7af05d92a2617c37789d5a7993be6e
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/iotcon/iotcon_api.js
src/iotcon/iotcon_instance.cc

index 5a8a331..e51b588 100644 (file)
@@ -284,10 +284,10 @@ function Resource(data) {
     observerIds: {
       get: function() {
         var callArgs = {};
-        callArgs.id = data.id;
+        callArgs.id = this[kIdKey];
         var result = native.callSync('IotconResource_getObserverIds', callArgs);
         return native.getResultObject(result);
-      },
+      }.bind(this),
       set: function() {},
       enumerable: true
     }
@@ -550,10 +550,10 @@ function RemoteResource(data) {
     cachedRepresentation: {
       get: function() {
         var callArgs = {};
-        callArgs.id = data.id;
+        callArgs.id = this[kIdKey];
         var result = native.callSync('IotconRemoteResource_getCachedRepresentation', callArgs);
         return createRepresentation(native.getResultObject(result));
-      },
+      }.bind(this),
       set: function() {},
       enumerable: true
     }
index 092ae13..1fac061 100644 (file)
@@ -154,7 +154,24 @@ IotconInstance::~IotconInstance() {
 
 common::TizenResult IotconInstance::ResourceGetObserverIds(const picojson::object& args) {
   ScopeLogger();
-  return common::UnknownError("Not implemented");
+
+  CHECK_EXIST(args, kId);
+
+  ResourceInfoPtr resource;
+  auto result = IotconServerManager::GetInstance().GetResourceById(GetId(args), &resource);
+
+  if (!result) {
+    LogAndReturnTizenError(result, ("GetResourceById() failed"));
+  }
+
+  picojson::value value{picojson::array{}};
+  auto& arr = value.get<picojson::array>();
+
+  for (auto id : resource->observers) {
+    arr.push_back(picojson::value{static_cast<double>(id)});
+  }
+
+  return common::TizenSuccess(value);
 }
 
 common::TizenResult IotconInstance::ResourceNotify(const picojson::object& args) {