(ACR) Integrate notify_list and notify_all
authorsung.goo.kim <sung.goo.kim@samsung.com>
Mon, 19 Oct 2015 05:01:53 +0000 (14:01 +0900)
committeryoungman <yman.jung@samsung.com>
Tue, 3 Nov 2015 11:08:20 +0000 (20:08 +0900)
Change-Id: I3d1f75d4263bc372d0ff15c0d9cf4ac8f2e697cc

common/ic-dbus.xml
daemon/icd-dbus.c
daemon/icd-ioty.c
daemon/icd-ioty.h
doc/iotcon_doc.h
lib/icl-resource.c
lib/icl-resource.h
lib/include/iotcon.h
packaging/iotcon.conf.in
test/crud-test-server.c

index 261dab9..a649bcf 100644 (file)
                        <arg type="x" name="child" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
-               <method name="notifyListOfObservers">
+               <method name="notify">
                        <arg type="x" name="resource" direction="in"/>
                        <arg type="a(iv)" name="notify_msg" direction="in"/>
                        <arg type="ai" name="observers" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
-               <method name="notifyAll">
-                       <arg type="x" name="resource" direction="in"/>
-                       <arg type="i" name="ret" direction="out"/>
-               </method>
                <method name="sendResponse">
                        <arg type="(sia(qs)ivxx)" name="response" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
index 1092e90..030d2da 100644 (file)
@@ -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",
index aaad317..f0bbcc0 100644 (file)
@@ -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);
        }
 
index cb28e91..30049c8 100644 (file)
@@ -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);
 
index 379109c..2ea9069 100644 (file)
@@ -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
  *         <td></td>
  *     </tr>
  *     <tr>
- *         <td>iotcon_notify_list_of_observers</td>
- *         <td></td>
- *     </tr>
- *     <tr>
- *         <td>iotcon_resource_notify_all</td>
+ *         <td>iotcon_resource_notify</td>
  *         <td></td>
  *     </tr>
  *     <tr>
index 27e72ff..718cc3e 100644 (file)
@@ -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;
-}
index 8c055ff..1852622 100644 (file)
@@ -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__*/
index e305fc2..32ed45d 100644 (file)
@@ -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.
  *
index 113f5b5..a6fbe6f 100644 (file)
@@ -27,9 +27,6 @@
                                send_interface="@DBUS_INTERFACE@" send_member="unbindResource"
                                privilege="http://tizen.org/privilege/internet"/>
                <check send_destination="@DBUS_INTERFACE@"
-                               send_interface="@DBUS_INTERFACE@" send_member="notifyListOfObservers"
-                               privilege="http://tizen.org/privilege/internet"/>
-               <check send_destination="@DBUS_INTERFACE@"
                                send_interface="@DBUS_INTERFACE@" send_member="notifyAll"
                                privilege="http://tizen.org/privilege/internet"/>
                <check send_destination="@DBUS_INTERFACE@"
index 0a37ee0..8526a84 100644 (file)
@@ -305,9 +305,9 @@ static gboolean _notifier(gpointer user_data)
                return FALSE;
        }
 
-       ret = iotcon_notify_list_of_observers(door->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;