[iotcon] Implementation of RemoteResource.methodPut().
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 18 Feb 2016 10:48:16 +0000 (11:48 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 18 Feb 2016 14:34:52 +0000 (23:34 +0900)
Change-Id: I93c9853fcfc7cecb4c2fad2e2735b2502fcaa22e
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/iotcon/iotcon_api.js
src/iotcon/iotcon_instance.cc

index bf6b312069b7e882d05379e61449c116c6e0829b..06531959e553fbecb8a8f9aafe8de33fefc4c831 100644 (file)
@@ -674,18 +674,21 @@ RemoteResource.prototype.methodPut = function() {
   callArgs.query = args.query;
 
   var callback = function(result) {
-    if (native.isFailure(result)) {
+    result = native.getResultObject(result);
+    manageId(this, result);
+    if (!result.data) {
       native.callIfPossible(args.errorCallback, native.getErrorObject(result));
     } else {
-      // TODO: implement
-      args.responseCallback();
+      args.responseCallback(new RemoteResponse(result.data));
     }
-  };
+  }.bind(this);
 
   var result = native.call('IotconRemoteResource_methodPut', callArgs, callback);
 
   if (native.isFailure(result)) {
     throw native.getErrorObject(result);
+  } else {
+    manageId(this, native.getResultObject(result));
   }
 };
 
index c25042f35f9a119321cea924d3c76875dfd26858..0fe32dba64c8d047e070da590762cee6fe2255f3 100644 (file)
@@ -579,7 +579,45 @@ common::TizenResult IotconInstance::RemoteResourceMethodGet(const picojson::obje
 common::TizenResult IotconInstance::RemoteResourceMethodPut(const picojson::object& args,
                                                             const common::AsyncToken& token) {
   ScopeLogger();
-  return common::UnknownError("Not implemented");
+
+  CHECK_EXIST(args, kRepresentation);
+  CHECK_EXIST(args, kQuery);
+
+  FoundRemoteInfoPtr resource;
+  auto result = IotconUtils::RemoteResourceFromJson(args, &resource);
+  if (!result) {
+    LogAndReturnTizenError(result, ("RemoteResourceFromJson() failed"));
+  }
+
+  iotcon_representation_h representation = nullptr;
+  result = IotconUtils::RepresentationFromJson(IotconUtils::GetArg(args, kRepresentation).get<picojson::object>(), &representation);
+  if (!result) {
+    LogAndReturnTizenError(result, ("RepresentationFromJson() failed"));
+  }
+  SCOPE_EXIT {
+    iotcon_representation_destroy(representation);
+  };
+
+  iotcon_query_h query = nullptr;
+  result = IotconUtils::QueryFromJson(IotconUtils::GetArg(args, kQuery).get<picojson::object>(), &query);
+  if (!result) {
+    LogAndReturnTizenError(result, ("QueryFromJson() failed"));
+  }
+  SCOPE_EXIT {
+    iotcon_query_destroy(query);
+  };
+
+  std::unique_ptr<CallbackData> data{new CallbackData{PostForMethodCall(token, resource)}};
+
+  result = IotconUtils::ConvertIotconError(iotcon_remote_resource_put(resource->handle, representation, query, RemoteResourceResponseCallback, data.get()));
+  if (!result) {
+    LogAndReturnTizenError(result, ("iotcon_remote_resource_put() failed"));
+  }
+
+  // release memory ownership
+  data.release();
+
+  return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(resource)};
 }
 
 common::TizenResult IotconInstance::RemoteResourceMethodPost(const picojson::object& args,