[IOTCON] apply changed api name and revise options behavior (readonly -> writable)
authortaekeun.kang <taekeun.kang@samsung.com>
Thu, 28 Apr 2016 23:31:56 +0000 (08:31 +0900)
committertaekeun.kang <taekeun.kang@samsung.com>
Fri, 29 Apr 2016 05:28:47 +0000 (14:28 +0900)
[version] 0.73

Change-Id: I6994856ae5dd9c88549aa9f320a943d817504faf
Signed-off-by: taekeun.kang <taekeun.kang@samsung.com>
packaging/webapi-plugins.spec
src/iotcon/iotcon_api.js
src/iotcon/iotcon_instance.cc
src/iotcon/iotcon_utils.cc

index f045b88897cd3243d2ac910f4e5f56a405daac14..debd9356e71c9cf8eaf7e4206609b208541da01a 100644 (file)
@@ -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
index ed8776db323c65c658c82c693fd8603d40e7b650..fa5899b0720cd185290486caf1047b48678b6071 100644 (file)
@@ -595,6 +595,11 @@ function RemoteResource(data) {
       }.bind(this),
       set: function() {},
       enumerable: true
+    },
+    options: {
+      value: null,
+      writable: true,
+      enumerable: true
     }
   });
 
index 5eb5a75f58b56dd3f7468c5f480ba234a78b6005..380f9f087cea88b1da3c71d4954ebb608783cd7d 100644 (file)
@@ -537,6 +537,26 @@ common::TizenResult IotconInstance::RemoteResourceMethodGet(const picojson::obje
 
   std::unique_ptr<CallbackData> data{new CallbackData{PostForMethodCall(token, resource)}};
 
+  // set options to the remote resource
+  const auto& js_options = IotconUtils::GetArg(args, kOptions);
+
+  if (js_options.is<picojson::array>()) {
+    iotcon_options_h options = nullptr;
+
+    result = IotconUtils::OptionsFromJson(js_options.get<picojson::array>(), &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<CallbackData> data{new CallbackData{PostForMethodCall(token, resource)}};
 
+  // set options to the remote resource
+  const auto& js_options = IotconUtils::GetArg(args, kOptions);
+
+  if (js_options.is<picojson::array>()) {
+    iotcon_options_h options = nullptr;
+
+    result = IotconUtils::OptionsFromJson(js_options.get<picojson::array>(), &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<CallbackData> data{new CallbackData{PostForMethodCall(token, resource)}};
 
+  // set options to the remote resource
+  const auto& js_options = IotconUtils::GetArg(args, kOptions);
+
+  if (js_options.is<picojson::array>()) {
+    iotcon_options_h options = nullptr;
+
+    result = IotconUtils::OptionsFromJson(js_options.get<picojson::array>(), &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<CallbackData> data{new CallbackData{PostForMethodCall(token, resource)}};
 
+  // set options to the remote resource
+  const auto& js_options = IotconUtils::GetArg(args, kOptions);
+
+  if (js_options.is<picojson::array>()) {
+    iotcon_options_h options = nullptr;
+
+    result = IotconUtils::OptionsFromJson(js_options.get<picojson::array>(), &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<picojson::array>()) {
+    iotcon_options_h options = nullptr;
+
+    result = IotconUtils::OptionsFromJson(js_options.get<picojson::array>(), &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<picojson::array>()) {
+    iotcon_options_h options = nullptr;
+
+    result = IotconUtils::OptionsFromJson(js_options.get<picojson::array>(), &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;
index 3e8c06b80af65d13baf95605032f15e9e58d1f31..b0a2c7ee715e73e77839759a6f1b6f648f1cf809 100644 (file)
@@ -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<picojson::array>());
-    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<picojson::object>());
@@ -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) {