<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"/>
}
-static gboolean _dbus_handle_notify_list_of_observers(icDbus *object,
+static gboolean _dbus_handle_notify(icDbus *object,
GDBusMethodInvocation *invocation,
gint64 resource,
GVariant *notify_msg,
{
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;
}
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",
}
-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;
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);
}
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);
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);
* <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>
/* 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);
}
iotcon_resource_types_destroy(resource->types);
+ iotcon_observers_destroy(resource->observers);
free(resource->uri_path);
free(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;
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;
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);
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;
-}
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__*/
* @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,
* @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);
* @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);
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
*
* @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
* @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.
*
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@"
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;