From 9cdc8b389c7a2a92df98e89874603855c58d0ad1 Mon Sep 17 00:00:00 2001
From: Pawel Andruszkiewicz
Date: Thu, 18 Feb 2016 11:51:11 +0100
Subject: [PATCH] [iotcon] Implementation of RemoteResource.methodPost().
Change-Id: Icfcf820ef4a2627d9fe3e47b8a6584c876d886e6
Signed-off-by: Pawel Andruszkiewicz
---
src/iotcon/iotcon_api.js | 11 ++++++----
src/iotcon/iotcon_instance.cc | 40 ++++++++++++++++++++++++++++++++++-
2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/src/iotcon/iotcon_api.js b/src/iotcon/iotcon_api.js
index 06531959..43ed6fbe 100644
--- a/src/iotcon/iotcon_api.js
+++ b/src/iotcon/iotcon_api.js
@@ -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));
}
};
diff --git a/src/iotcon/iotcon_instance.cc b/src/iotcon/iotcon_instance.cc
index 0fe32dba..4b6b0de6 100644
--- a/src/iotcon/iotcon_instance.cc
+++ b/src/iotcon/iotcon_instance.cc
@@ -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(), &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(), &query);
+ if (!result) {
+ LogAndReturnTizenError(result, ("QueryFromJson() failed"));
+ }
+ SCOPE_EXIT {
+ iotcon_query_destroy(query);
+ };
+
+ std::unique_ptr 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,
--
2.34.1