From: Piotr Kosko Date: Tue, 16 Feb 2016 12:41:45 +0000 (+0100) Subject: [Iotcon] startCaching(), stopCaching(), res.cachedRepresentation X-Git-Tag: submit/tizen/20160222.104327^2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a3c7e1ef4c83a647f19d6df8704f894c07911d92;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Iotcon] startCaching(), stopCaching(), res.cachedRepresentation [Verification] Code compiles, functionalities tested in console. Change-Id: I6ebf9a650b661c5c3dcc9857d96f9a58fe8edc36 Signed-off-by: Piotr Kosko --- diff --git a/src/iotcon/iotcon_api.js b/src/iotcon/iotcon_api.js index a97da630..7548ac05 100644 --- a/src/iotcon/iotcon_api.js +++ b/src/iotcon/iotcon_api.js @@ -817,6 +817,8 @@ RemoteResource.prototype.startCaching = function() { if (native.isFailure(result)) { throw native.getErrorObject(result); + } else { + manageId(this, native.getResultObject(result)); } }; @@ -827,6 +829,8 @@ RemoteResource.prototype.stopCaching = function() { 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 5f18e9ba..8634735a 100644 --- a/src/iotcon/iotcon_instance.cc +++ b/src/iotcon/iotcon_instance.cc @@ -486,7 +486,27 @@ common::TizenResult IotconInstance::ResponseSend(const picojson::object& args) { common::TizenResult IotconInstance::RemoteResourceGetCachedRepresentation(const picojson::object& args) { ScopeLogger(); - return common::UnknownError("Not implemented"); + + FoundRemoteInfoPtr ptr; + auto res = IotconUtils::RemoteResourceFromJson(args, &ptr); + if (!res) { + LogAndReturnTizenError(res, ("Failed to build resource using json data")); + } + iotcon_representation_h representation = nullptr; + res = IotconUtils::ConvertIotconError( + iotcon_remote_resource_get_cached_representation(ptr->handle, &representation)); + if (!res) { + LogAndReturnTizenError(res, ("Gathering cached representation failed")); + } + if (representation) { + picojson::value repr_json{picojson::object{}}; + res = IotconUtils::RepresentationToJson(representation, &repr_json.get()); + if (!res) { + LogAndReturnTizenError(res, ("RepresentationToJson() failed")); + } + return common::TizenSuccess{repr_json}; + } + return common::UnknownError("Failed to gather cached representation"); } common::TizenResult IotconInstance::RemoteResourceMethodGet(const picojson::object& args, @@ -523,14 +543,41 @@ common::TizenResult IotconInstance::RemoteResourceUnsetStateChangeListener(const return common::UnknownError("Not implemented"); } +static void RepresentationChangedCallback(iotcon_remote_resource_h resource, + iotcon_representation_h representation, + void *user_data) { + LoggerD("Entered"); + //TODO probably should be handled +} + common::TizenResult IotconInstance::RemoteResourceStartCaching(const picojson::object& args) { ScopeLogger(); - return common::UnknownError("Not implemented"); + FoundRemoteInfoPtr ptr; + auto result = IotconUtils::RemoteResourceFromJson(args, &ptr); + if (!result) { + LogAndReturnTizenError(result, ("Failed to create remote resource handle")); + } + result = IotconUtils::ConvertIotconError( + iotcon_remote_resource_start_caching(ptr->handle, RepresentationChangedCallback, nullptr)); + if (!result) { + return result; + } + return common::TizenSuccess{IotconClientManager::GetInstance().StoreRemoteResource(ptr)}; } common::TizenResult IotconInstance::RemoteResourceStopCaching(const picojson::object& args) { ScopeLogger(); - return common::UnknownError("Not implemented"); + FoundRemoteInfoPtr ptr; + auto result = IotconUtils::RemoteResourceFromJson(args, &ptr); + if (!result) { + LogAndReturnTizenError(result, ("Failed to create remote resource handle")); + } + result = IotconUtils::ConvertIotconError( + iotcon_remote_resource_stop_caching(ptr->handle)); + if (!result) { + return result; + } + return common::TizenSuccess{IotconClientManager::GetInstance().RemoveRemoteResource(ptr)}; } common::TizenResult IotconInstance::RemoteResourceSetConnectionChangeListener(const picojson::object& args) {