From: taekeun.kang Date: Thu, 28 Apr 2016 23:31:56 +0000 (+0900) Subject: [IOTCON] apply changed api name and revise options behavior (readonly -> writable) X-Git-Tag: submit/tizen/20160502.015917^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6053cef2665370554debf52fa2aa6f0d514ea86b;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [IOTCON] apply changed api name and revise options behavior (readonly -> writable) [version] 0.73 Change-Id: I6994856ae5dd9c88549aa9f320a943d817504faf Signed-off-by: taekeun.kang --- diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index f045b888..debd9356 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -10,7 +10,7 @@ %define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions} Name: webapi-plugins -Version: 0.72 +Version: 0.73 Release: 0 License: Apache-2.0 and BSD-2.0 and MIT Group: Development/Libraries diff --git a/src/iotcon/iotcon_api.js b/src/iotcon/iotcon_api.js index ed8776db..fa5899b0 100644 --- a/src/iotcon/iotcon_api.js +++ b/src/iotcon/iotcon_api.js @@ -595,6 +595,11 @@ function RemoteResource(data) { }.bind(this), set: function() {}, enumerable: true + }, + options: { + value: null, + writable: true, + enumerable: true } }); diff --git a/src/iotcon/iotcon_instance.cc b/src/iotcon/iotcon_instance.cc index 5eb5a75f..380f9f08 100644 --- a/src/iotcon/iotcon_instance.cc +++ b/src/iotcon/iotcon_instance.cc @@ -537,6 +537,26 @@ common::TizenResult IotconInstance::RemoteResourceMethodGet(const picojson::obje std::unique_ptr data{new CallbackData{PostForMethodCall(token, resource)}}; + // set options to the remote resource + const auto& js_options = IotconUtils::GetArg(args, kOptions); + + if (js_options.is()) { + iotcon_options_h options = nullptr; + + result = IotconUtils::OptionsFromJson(js_options.get(), &options); + if (!result) { + LogAndReturnTizenError(result, ("OptionsFromJson() failed")); + } + SCOPE_EXIT { + iotcon_options_destroy(options); + }; + + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_set_options(resource->handle, options)); + if (!result) { + LogAndReturnTizenError(result, ("iotcon_response_set_options() failed")); + } + } + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_get(resource->handle, query, RemoteResourceResponseCallback, data.get())); if (!result) { LogAndReturnTizenError(result, ("iotcon_remote_resource_get() failed")); @@ -581,6 +601,26 @@ common::TizenResult IotconInstance::RemoteResourceMethodPut(const picojson::obje std::unique_ptr data{new CallbackData{PostForMethodCall(token, resource)}}; + // set options to the remote resource + const auto& js_options = IotconUtils::GetArg(args, kOptions); + + if (js_options.is()) { + iotcon_options_h options = nullptr; + + result = IotconUtils::OptionsFromJson(js_options.get(), &options); + if (!result) { + LogAndReturnTizenError(result, ("OptionsFromJson() failed")); + } + SCOPE_EXIT { + iotcon_options_destroy(options); + }; + + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_set_options(resource->handle, options)); + if (!result) { + LogAndReturnTizenError(result, ("iotcon_response_set_options() failed")); + } + } + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_put(resource->handle, representation, query, RemoteResourceResponseCallback, data.get())); if (!result) { LogAndReturnTizenError(result, ("iotcon_remote_resource_put() failed")); @@ -625,6 +665,26 @@ common::TizenResult IotconInstance::RemoteResourceMethodPost(const picojson::obj std::unique_ptr data{new CallbackData{PostForMethodCall(token, resource)}}; + // set options to the remote resource + const auto& js_options = IotconUtils::GetArg(args, kOptions); + + if (js_options.is()) { + iotcon_options_h options = nullptr; + + result = IotconUtils::OptionsFromJson(js_options.get(), &options); + if (!result) { + LogAndReturnTizenError(result, ("OptionsFromJson() failed")); + } + SCOPE_EXIT { + iotcon_options_destroy(options); + }; + + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_set_options(resource->handle, options)); + if (!result) { + LogAndReturnTizenError(result, ("iotcon_response_set_options() failed")); + } + } + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_post(resource->handle, representation, query, RemoteResourceResponseCallback, data.get())); if (!result) { LogAndReturnTizenError(result, ("iotcon_remote_resource_post() failed")); @@ -648,6 +708,26 @@ common::TizenResult IotconInstance::RemoteResourceMethodDelete(const picojson::o std::unique_ptr data{new CallbackData{PostForMethodCall(token, resource)}}; + // set options to the remote resource + const auto& js_options = IotconUtils::GetArg(args, kOptions); + + if (js_options.is()) { + iotcon_options_h options = nullptr; + + result = IotconUtils::OptionsFromJson(js_options.get(), &options); + if (!result) { + LogAndReturnTizenError(result, ("OptionsFromJson() failed")); + } + SCOPE_EXIT { + iotcon_options_destroy(options); + }; + + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_set_options(resource->handle, options)); + if (!result) { + LogAndReturnTizenError(result, ("iotcon_response_set_options() failed")); + } + } + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_delete(resource->handle, RemoteResourceResponseCallback, data.get())); if (!result) { LogAndReturnTizenError(result, ("iotcon_remote_resource_delete() failed")); @@ -708,6 +788,26 @@ common::TizenResult IotconInstance::RemoteResourceSetStateChangeListener(const p Post(kRemoteResourceStateChangeListener, common::TizenSuccess{response}); }; + // set options to the remote resource + const auto& js_options = IotconUtils::GetArg(args, kOptions); + + if (js_options.is()) { + iotcon_options_h options = nullptr; + + result = IotconUtils::OptionsFromJson(js_options.get(), &options); + if (!result) { + LogAndReturnTizenError(result, ("OptionsFromJson() failed")); + } + SCOPE_EXIT { + iotcon_options_destroy(options); + }; + + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_set_options(ptr->handle, options)); + if (!result) { + LogAndReturnTizenError(result, ("iotcon_response_set_options() failed")); + } + } + result = IotconUtils::ConvertIotconError( iotcon_remote_resource_observe_register(ptr->handle, observe_policy, query, ObserveCallback, ptr.get())); @@ -724,6 +824,27 @@ common::TizenResult IotconInstance::RemoteResourceUnsetStateChangeListener(const if (!result) { LogAndReturnTizenError(result, ("Failed to create remote resource handle")); } + + // set options to the remote resource + const auto& js_options = IotconUtils::GetArg(args, kOptions); + + if (js_options.is()) { + iotcon_options_h options = nullptr; + + result = IotconUtils::OptionsFromJson(js_options.get(), &options); + if (!result) { + LogAndReturnTizenError(result, ("OptionsFromJson() failed")); + } + SCOPE_EXIT { + iotcon_options_destroy(options); + }; + + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_set_options(ptr->handle, options)); + if (!result) { + LogAndReturnTizenError(result, ("iotcon_response_set_options() failed")); + } + } + result = IotconUtils::ConvertIotconError(iotcon_remote_resource_observe_deregister(ptr->handle)); if (!result) { return result; diff --git a/src/iotcon/iotcon_utils.cc b/src/iotcon/iotcon_utils.cc index 3e8c06b8..b0a2c7ee 100644 --- a/src/iotcon/iotcon_utils.cc +++ b/src/iotcon/iotcon_utils.cc @@ -398,12 +398,6 @@ TizenResult IotconUtils::ExtractFromRemoteResource(RemoteResourceInfo* resource) LogAndReturnTizenError(result, ("Gathering properties failed")); } - result = ConvertIotconError( - iotcon_remote_resource_get_options(resource->resource, &resource->options)); - if (!result) { - LogAndReturnTizenError(result, ("Gathering options failed")); - } - result = ConvertIotconError( iotcon_remote_resource_get_cached_representation(resource->resource, &resource->representation)); if (!result) { @@ -448,15 +442,6 @@ TizenResult IotconUtils::RemoteResourceToJson(iotcon_remote_resource_h handle, IotconUtils::PropertiesToJson(remote_res.properties, res); - if (remote_res.options) { - picojson::value opt_json{picojson::array{}}; - result = OptionsToJson(remote_res.options, &opt_json.get()); - if (!result) { - LogAndReturnTizenError(result, ("OptionsToJson() failed")); - } - res->insert(std::make_pair(kOptions, opt_json)); - } - if (remote_res.representation) { picojson::value repr_json{picojson::object{}}; result = RepresentationToJson(remote_res.representation, &repr_json.get()); @@ -650,7 +635,7 @@ common::TizenResult IotconUtils::RepresentationToJson(iotcon_representation_h re if (representation) { { - // hostAddress + // uriPath char* uri_path = nullptr; auto result = ConvertIotconError(iotcon_representation_get_uri_path(representation, &uri_path)); if (!result || !uri_path) { @@ -1261,13 +1246,13 @@ common::TizenResult IotconUtils::RepresentationFromResource(const ResourceInfoPt } { - int children = 0; - result = IotconUtils::ConvertIotconError(iotcon_resource_get_number_of_children(resource->handle, &children)); + unsigned int children = 0; + result = IotconUtils::ConvertIotconError(iotcon_resource_get_child_count(resource->handle, &children)); if (!result) { - LogAndReturnTizenError(result, ("iotcon_resource_get_number_of_children() failed")); + LogAndReturnTizenError(result, ("iotcon_resource_get_child_count() failed")); } - for (int i = 0; i < children; ++i) { + for (unsigned int i = 0; i < children; ++i) { iotcon_resource_h child = nullptr; result = IotconUtils::ConvertIotconError(iotcon_resource_get_nth_child(resource->handle, i, &child)); if (!result) {