From c0b2af33007ccf889d3d1f787b9234c0aa1f2618 Mon Sep 17 00:00:00 2001 From: "sung.goo.kim" Date: Mon, 19 Oct 2015 14:01:53 +0900 Subject: [PATCH] (ACR) Integrate notify_list and notify_all Change-Id: I3d1f75d4263bc372d0ff15c0d9cf4ac8f2e697cc --- common/ic-dbus.xml | 6 +---- daemon/icd-dbus.c | 30 +++++------------------- daemon/icd-ioty.c | 42 +++++++++++---------------------- daemon/icd-ioty.h | 5 +--- doc/iotcon_doc.h | 8 ++----- lib/icl-resource.c | 60 +++++++++++++++++++----------------------------- lib/icl-resource.h | 1 + lib/include/iotcon.h | 46 ++++++++++--------------------------- packaging/iotcon.conf.in | 3 --- test/crud-test-server.c | 4 ++-- 10 files changed, 62 insertions(+), 143 deletions(-) diff --git a/common/ic-dbus.xml b/common/ic-dbus.xml index 261dab9..a649bcf 100644 --- a/common/ic-dbus.xml +++ b/common/ic-dbus.xml @@ -31,16 +31,12 @@ - + - - - - diff --git a/daemon/icd-dbus.c b/daemon/icd-dbus.c index 1092e90..030d2da 100644 --- a/daemon/icd-dbus.c +++ b/daemon/icd-dbus.c @@ -552,7 +552,7 @@ static gboolean _dbus_handle_observer_stop(icDbus *object, } -static gboolean _dbus_handle_notify_list_of_observers(icDbus *object, +static gboolean _dbus_handle_notify(icDbus *object, GDBusMethodInvocation *invocation, gint64 resource, GVariant *notify_msg, @@ -560,27 +560,11 @@ static gboolean _dbus_handle_notify_list_of_observers(icDbus *object, { int ret; - ret = icd_ioty_notify_list_of_observers(ICD_INT64_TO_POINTER(resource), notify_msg, - observers); + ret = icd_ioty_notify(ICD_INT64_TO_POINTER(resource), notify_msg, observers); if (IOTCON_ERROR_NONE != ret) - ERR("icd_ioty_notify_list_of_observers() Fail(%d)", ret); + ERR("icd_ioty_notify() Fail(%d)", ret); - ic_dbus_complete_notify_list_of_observers(object, invocation, ret); - - return TRUE; -} - - -static gboolean _dbus_handle_notify_all(icDbus *object, GDBusMethodInvocation *invocation, - gint64 resource) -{ - int ret; - - ret = icd_ioty_notify_all(ICD_INT64_TO_POINTER(resource)); - if (IOTCON_ERROR_NONE != ret) - ERR("icd_ioty_notify_all() Fail(%d)", ret); - - ic_dbus_complete_notify_all(object, invocation, ret); + ic_dbus_complete_notify(object, invocation, ret); return TRUE; } @@ -775,10 +759,8 @@ static void _dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name, G_CALLBACK(_dbus_handle_observer_start), NULL); g_signal_connect(icd_dbus_object, "handle-observer-stop", G_CALLBACK(_dbus_handle_observer_stop), NULL); - g_signal_connect(icd_dbus_object, "handle-notify-list-of-observers", - G_CALLBACK(_dbus_handle_notify_list_of_observers), NULL); - g_signal_connect(icd_dbus_object, "handle-notify-all", - G_CALLBACK(_dbus_handle_notify_all), NULL); + g_signal_connect(icd_dbus_object, "handle-notify", + G_CALLBACK(_dbus_handle_notify), NULL); g_signal_connect(icd_dbus_object, "handle-send-response", G_CALLBACK(_dbus_handle_send_response), NULL); g_signal_connect(icd_dbus_object, "handle-register-device-info", diff --git a/daemon/icd-ioty.c b/daemon/icd-ioty.c index aaad317..f0bbcc0 100644 --- a/daemon/icd-ioty.c +++ b/daemon/icd-ioty.c @@ -234,10 +234,9 @@ int icd_ioty_unbind_resource(OCResourceHandle parent, OCResourceHandle child) } -int icd_ioty_notify_list_of_observers(OCResourceHandle handle, GVariant *msg, - GVariant *observers) +int icd_ioty_notify(OCResourceHandle handle, GVariant *msg, GVariant *observers) { - int i, error_code, obs_length; + int i, error_code, obs_length, msg_length; GVariant *repr_gvar; GVariantIter obs_iter, msg_iter; OCStackResult ret; @@ -253,42 +252,27 @@ int icd_ioty_notify_list_of_observers(OCResourceHandle handle, GVariant *msg, g_variant_iter_loop(&obs_iter, "i", &obs_ids[i]); g_variant_iter_init(&msg_iter, msg); - g_variant_iter_loop(&msg_iter, "(iv)", &error_code, &repr_gvar); - /* TODO : How to use error_code. */ - - payload = icd_payload_representation_from_gvariant(repr_gvar); - - icd_ioty_csdk_lock(); - /* TODO : QoS is come from lib. */ - ret = OCNotifyListOfObservers(handle, obs_ids, obs_length, payload, OC_LOW_QOS); - icd_ioty_csdk_unlock(); - - if (OC_STACK_NO_OBSERVERS == ret) { - WARN("No Observers. Stop Notifying"); - return IOTCON_ERROR_NONE; - } else if (OC_STACK_OK != ret) { - ERR("OCNotifyListOfObservers() Fail(%d)", ret); - return icd_ioty_convert_error(ret); + msg_length = g_variant_iter_n_children(&msg_iter); + if (msg_length) { + g_variant_iter_loop(&msg_iter, "(iv)", &error_code, &repr_gvar); + /* TODO : How to use error_code. */ + payload = icd_payload_representation_from_gvariant(repr_gvar); } - return IOTCON_ERROR_NONE; -} - - -int icd_ioty_notify_all(OCResourceHandle handle) -{ - OCStackResult ret; - icd_ioty_csdk_lock(); /* TODO : QoS is come from lib. */ - ret = OCNotifyAllObservers(handle, OC_LOW_QOS); + if (msg_length) { + ret = OCNotifyListOfObservers(handle, obs_ids, obs_length, payload, OC_LOW_QOS); + } else { + ret = OCNotifyAllObservers(handle, OC_LOW_QOS); + } icd_ioty_csdk_unlock(); if (OC_STACK_NO_OBSERVERS == ret) { WARN("No Observers. Stop Notifying"); return IOTCON_ERROR_NONE; } else if (OC_STACK_OK != ret) { - ERR("OCNotifyAllObservers() Fail(%d)", ret); + ERR("OCNotifyListOfObservers() Fail(%d)", ret); return icd_ioty_convert_error(ret); } diff --git a/daemon/icd-ioty.h b/daemon/icd-ioty.h index cb28e91..30049c8 100644 --- a/daemon/icd-ioty.h +++ b/daemon/icd-ioty.h @@ -62,10 +62,7 @@ int icd_ioty_bind_resource(OCResourceHandle parent, OCResourceHandle child); int icd_ioty_unbind_resource(OCResourceHandle parent, OCResourceHandle child); -int icd_ioty_notify_list_of_observers(OCResourceHandle handle, GVariant *msg, - GVariant *observers); - -int icd_ioty_notify_all(OCResourceHandle handle); +int icd_ioty_notify(OCResourceHandle handle, GVariant *msg, GVariant *observers); int icd_ioty_send_response(GVariant *resp); diff --git a/doc/iotcon_doc.h b/doc/iotcon_doc.h index 379109c..2ea9069 100644 --- a/doc/iotcon_doc.h +++ b/doc/iotcon_doc.h @@ -317,7 +317,7 @@ static void _request_handler(iotcon_request_h request, void *user_data) return; } - ret = iotcon_notify_list_of_observers(door_handle, msg, observers); + ret = iotcon_resource_notify(door_handle, msg, observers); if (IOTCON_ERROR_NONE != ret) { iotcon_notimsg_destroy(msg); iotcon_representation_destroy(resp_repr); @@ -403,11 +403,7 @@ static void _on_observe(iotcon_options_h header_options, iotcon_representation_h * * * - * iotcon_notify_list_of_observers - * - * - * - * iotcon_resource_notify_all + * iotcon_resource_notify * * * diff --git a/lib/icl-resource.c b/lib/icl-resource.c index 27e72ff..718cc3e 100644 --- a/lib/icl-resource.c +++ b/lib/icl-resource.c @@ -119,6 +119,18 @@ static void _icl_request_handler(GDBusConnection *connection, /* TODO remove request.uri */ request.uri_path = "temp_uri_path"; + /* for iotcon_resource_notify */ + if (IOTCON_REQUEST_OBSERVE & request.types) { + int observer_id = request.observation_info.observer_id; + if (IOTCON_OBSERVE_REGISTER == request.observation_info.action) { + if (NULL == resource->observers) + iotcon_observers_create(&resource->observers); + iotcon_observers_insert(resource->observers, observer_id); + } else if (IOTCON_OBSERVE_DEREGISTER == request.observation_info.action) { + iotcon_observers_delete(resource->observers, observer_id); + } + } + if (cb) cb(resource, &request, resource->user_data); @@ -142,6 +154,7 @@ static void _icl_resource_conn_cleanup(iotcon_resource_h resource) } iotcon_resource_types_destroy(resource->types); + iotcon_observers_destroy(resource->observers); free(resource->uri_path); free(resource); } @@ -244,6 +257,7 @@ API int iotcon_resource_destroy(iotcon_resource_h resource) if (0 == resource->sub_id) { WARN("Invalid Resource handle"); iotcon_resource_types_destroy(resource->types); + iotcon_observers_destroy(resource->observers); free(resource->uri_path); free(resource); return IOTCON_ERROR_NONE; @@ -556,8 +570,7 @@ API void iotcon_notimsg_destroy(iotcon_notimsg_h msg) free(msg); } - -API int iotcon_notify_list_of_observers(iotcon_resource_h resource, iotcon_notimsg_h msg, +API int iotcon_resource_notify(iotcon_resource_h resource, iotcon_notimsg_h msg, iotcon_observers_h observers) { int ret; @@ -567,24 +580,28 @@ API int iotcon_notify_list_of_observers(iotcon_resource_h resource, iotcon_notim RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS); RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER); - RETV_IF(NULL == observers, IOTCON_ERROR_INVALID_PARAMETER); if (0 == resource->sub_id) { ERR("Invalid Resource handle"); return IOTCON_ERROR_INVALID_PARAMETER; } + /* TODO: Get default message if msg parameter is NULL */ noti_msg = icl_dbus_notimsg_to_gvariant(msg); if (NULL == noti_msg) { ERR("icl_dbus_notimsg_to_gvariant() Fail"); return IOTCON_ERROR_REPRESENTATION; } - obs = icl_dbus_observers_to_gvariant(observers); - ic_dbus_call_notify_list_of_observers_sync(icl_dbus_get_object(), resource->handle, - noti_msg, obs, &ret, NULL, &error); + if (observers) + obs = icl_dbus_observers_to_gvariant(observers); + else + obs = icl_dbus_observers_to_gvariant(resource->observers); + + ic_dbus_call_notify_sync(icl_dbus_get_object(), resource->handle, noti_msg, obs, &ret, + NULL, &error); if (error) { - ERR("ic_dbus_call_notify_list_of_observers_sync() Fail(%s)", error->message); + ERR("ic_dbus_call_notify_sync() Fail(%s)", error->message); ret = icl_dbus_convert_dbus_error(error->code); g_error_free(error); g_variant_unref(obs); @@ -600,32 +617,3 @@ API int iotcon_notify_list_of_observers(iotcon_resource_h resource, iotcon_notim return IOTCON_ERROR_NONE; } - -API int iotcon_resource_notify_all(iotcon_resource_h resource) -{ - int ret; - GError *error = NULL; - - RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS); - RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER); - if (0 == resource->sub_id) { - ERR("Invalid Resource handle"); - return IOTCON_ERROR_INVALID_PARAMETER; - } - - ic_dbus_call_notify_all_sync(icl_dbus_get_object(), resource->handle, &ret, NULL, - &error); - if (error) { - ERR("ic_dbus_call_notify_all_sync() Fail(%s)", error->message); - ret = icl_dbus_convert_dbus_error(error->code); - g_error_free(error); - return ret; - } - - if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon-daemon Fail(%d)", ret); - return icl_dbus_convert_daemon_error(ret); - } - - return IOTCON_ERROR_NONE; -} diff --git a/lib/icl-resource.h b/lib/icl-resource.h index 8c055ff..1852622 100644 --- a/lib/icl-resource.h +++ b/lib/icl-resource.h @@ -44,6 +44,7 @@ struct icl_resource { unsigned int sub_id; int64_t handle; iotcon_resource_h children[ICL_CONTAINED_RESOURCES_MAX]; + iotcon_observers_h observers; }; #endif /*__IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_H__*/ diff --git a/lib/include/iotcon.h b/lib/include/iotcon.h index e305fc2..32ed45d 100644 --- a/lib/include/iotcon.h +++ b/lib/include/iotcon.h @@ -854,8 +854,7 @@ typedef void (*iotcon_remote_resource_observe_cb)(iotcon_remote_resource_h resou * @see iotcon_remote_resource_observe_cb() * @see iotcon_remote_resource_observer_stop() * @see iotcon_notimsg_create() - * @see iotcon_notify_list_of_observers() - * @see iotcon_resource_notify_all() + * @see iotcon_resource_notify() */ int iotcon_remote_resource_observer_start(iotcon_remote_resource_h resource, int observe_type, @@ -882,8 +881,7 @@ int iotcon_remote_resource_observer_start(iotcon_remote_resource_h resource, * @see iotcon_remote_resource_observe_cb() * @see iotcon_remote_resource_observer_start() * @see iotcon_notimsg_create() - * @see iotcon_notify_list_of_observers() - * @see iotcon_resource_notify_all() + * @see iotcon_resource_notify() */ int iotcon_remote_resource_observer_stop(iotcon_remote_resource_h resource); @@ -923,8 +921,7 @@ int iotcon_response_send(iotcon_response_h resp); * @see iotcon_remote_resource_observe_cb() * @see iotcon_remote_resource_observer_start() * @see iotcon_remote_resource_observer_stop() - * @see iotcon_notify_list_of_observers() - * @see iotcon_resource_notify_all() + * @see iotcon_resource_notify() */ int iotcon_notimsg_create(iotcon_representation_h repr, int iface, iotcon_notimsg_h *notimsg_handle); @@ -943,7 +940,8 @@ int iotcon_notimsg_create(iotcon_representation_h repr, int iface, void iotcon_notimsg_destroy(iotcon_notimsg_h msg); /** - * @brief Notifies only specific clients that resource's attributes have changed. + * @brief Notifies specific clients that resource's attributes have changed. + * @details If @a observers is @c NULL, the @a msg will notify to all observers. * * @since_tizen 3.0 * @privlevel public @@ -951,7 +949,7 @@ void iotcon_notimsg_destroy(iotcon_notimsg_h msg); * * @param[in] resource The handle of the resource * @param[in] msg The handle of the notifications message - * @param[in] observers The handle of the observers + * @param[in] observers The handle of the observers. * * @return 0 on success, otherwise a negative error value. * @retval #IOTCON_ERROR_NONE Successful @@ -965,36 +963,16 @@ void iotcon_notimsg_destroy(iotcon_notimsg_h msg); * @see iotcon_remote_resource_observer_start() * @see iotcon_remote_resource_observer_stop() * @see iotcon_notimsg_create() - * @see iotcon_resource_notify_all() + * @see iotcon_notimsg_destroy() + * @see iotcon_observers_create() + * @see iotcon_observers_destroy() + * @see iotcon_observers_insert() + * @see iotcon_observers_delete() */ -int iotcon_notify_list_of_observers(iotcon_resource_h resource, iotcon_notimsg_h msg, +int iotcon_resource_notify(iotcon_resource_h resource, iotcon_notimsg_h msg, iotcon_observers_h observers); /** - * @brief Notifies all that attributes of the resource have changed. - * - * @since_tizen 3.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/internet - * - * @param[in] resource The handle of the resource - * - * @return 0 on success, otherwise a negative error value. - * @retval #IOTCON_ERROR_NONE Successful - * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #IOTCON_ERROR_DBUS Dbus error - * @retval #IOTCON_ERROR_SYSTEM System error - * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied - * - * @see iotcon_remote_resource_observe_cb() - * @see iotcon_remote_resource_observer_start() - * @see iotcon_remote_resource_observer_stop() - * @see iotcon_notimsg_create() - * @see iotcon_notify_list_of_observers() - */ -int iotcon_resource_notify_all(iotcon_resource_h resource); - -/** * @brief Specifies the type of function passed to iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post() * @details The @a response_result could be one of #iotcon_response_result_e. * diff --git a/packaging/iotcon.conf.in b/packaging/iotcon.conf.in index 113f5b5..a6fbe6f 100644 --- a/packaging/iotcon.conf.in +++ b/packaging/iotcon.conf.in @@ -27,9 +27,6 @@ send_interface="@DBUS_INTERFACE@" send_member="unbindResource" privilege="http://tizen.org/privilege/internet"/> - handle, msg, door->observers); + ret = iotcon_resource_notify(door->handle, msg, door->observers); if (IOTCON_ERROR_NONE != ret) { - ERR("iotcon_notify_list_of_observers() Fail(%d)", ret); + ERR("iotcon_resource_notify() Fail(%d)", ret); iotcon_notimsg_destroy(msg); iotcon_representation_destroy(repr); return FALSE; -- 2.7.4