From a3c7e1ef4c83a647f19d6df8704f894c07911d92 Mon Sep 17 00:00:00 2001 From: Piotr Kosko Date: Tue, 16 Feb 2016 13:41:45 +0100 Subject: [PATCH] [Iotcon] startCaching(), stopCaching(), res.cachedRepresentation [Verification] Code compiles, functionalities tested in console. Change-Id: I6ebf9a650b661c5c3dcc9857d96f9a58fe8edc36 Signed-off-by: Piotr Kosko --- src/iotcon/iotcon_api.js | 4 +++ src/iotcon/iotcon_instance.cc | 53 +++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) 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) { -- 2.34.1