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

index 06531959e553fbecb8a8f9aafe8de33fefc4c831..43ed6fbe1a47146d694d1c9ebf98b39394c018cb 100644 (file)
@@ -715,18 +715,21 @@ RemoteResource.prototype.methodPost = 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_methodPost', callArgs, callback);
 
   if (native.isFailure(result)) {
     throw native.getErrorObject(result);
+  } else {
+    manageId(this, native.getResultObject(result));
   }
 };
 
index 0fe32dba64c8d047e070da590762cee6fe2255f3..4b6b0de6a3a52701bf423eed61befbcb26ede012 100644 (file)
@@ -623,7 +623,45 @@ common::TizenResult IotconInstance::RemoteResourceMethodPut(const picojson::obje
 common::TizenResult IotconInstance::RemoteResourceMethodPost(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_post(resource->handle, representation, query, RemoteResourceResponseCallback, data.get()));
+  if (!result) {
+    LogAndReturnTizenError(result, ("iotcon_remote_resource_post() failed"));
+  }
+
+  // release memory ownership
+  data.release();
+
+  return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(resource)};
 }
 
 common::TizenResult IotconInstance::RemoteResourceMethodDelete(const picojson::object& args,