From: Pawel Andruszkiewicz Date: Thu, 18 Feb 2016 10:51:11 +0000 (+0100) Subject: [iotcon] Implementation of RemoteResource.methodPost(). X-Git-Tag: submit/tizen/20160222.104327^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9cdc8b389c7a2a92df98e89874603855c58d0ad1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [iotcon] Implementation of RemoteResource.methodPost(). Change-Id: Icfcf820ef4a2627d9fe3e47b8a6584c876d886e6 Signed-off-by: Pawel Andruszkiewicz --- 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,