Change zigbee enabled notification
authorJiwan Kim <ji-wan.kim@samsung.com>
Fri, 31 Mar 2017 08:09:22 +0000 (17:09 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:07:21 +0000 (18:07 +0900)
- previous : sets a callback with zb_enable()
  changed : gets result of zb_enable with event (ZB_ZDP_ENABLE_EVENT)
- Currently it is a platform level API.

Change-Id: Id5b1a188d0f869015674867c28f4d3bf2c0f65fe
Signed-off-by: Jiwan Kim <ji-wan.kim@samsung.com>
include/zigbee_internal.h
lib/zbl.c
lib/zbl_dbus.c
lib/zbl_dbus.h
test/main.c

index 6a937a0..1fd87ec 100644 (file)
@@ -41,21 +41,6 @@ extern "C" {
 
 /**
  * @internal
- * @brief Called after enabling zigbee service
- * @details Response of enabling the zigbee service
- *
- * @since_tizen 4.0
- *
- * @param[in] status #ZB_ZDP_SUCCESS \n
- *                   #ZB_ZDP_NOT_SUPPORTED \n
- * @param[in] user_data user data
- *
- * @see zb_enable()
- */
-typedef void (*zb_enable_cb)(unsigned char status, void *user_data);
-
-/**
- * @internal
  * @brief Enables the zigbee service.
  * @details All this function to start zigbee service
  *
@@ -67,8 +52,6 @@ typedef void (*zb_enable_cb)(unsigned char status, void *user_data);
  * if zigbee service is no longer needed.
  *
  * @param[in] handle The handle of zigbee
- * @param[in] cb zb_enable_cb
- * @param[in] user_data user data
  *
  * @return 0 on success, otherwise a negative error value.
  * @retval #ZIGBEE_ERROR_NONE Successful
@@ -81,7 +64,7 @@ typedef void (*zb_enable_cb)(unsigned char status, void *user_data);
  * @see zb_destroy()
  *
  */
-int zb_enable(zigbee_h handle, zb_enable_cb cb, void *user_data);
+int zb_enable(zigbee_h handle);
 
 /**
  * @internal
index 13f1110..6de28dd 100644 (file)
--- a/lib/zbl.c
+++ b/lib/zbl.c
@@ -56,13 +56,13 @@ API int zb_destroy(zigbee_h handle)
        return ZIGBEE_ERROR_NONE;
 }
 
-API int zb_enable(zigbee_h handle, zb_enable_cb cb, void *user_data)
+API int zb_enable(zigbee_h handle)
 {
        int ret = ZIGBEE_ERROR_NONE;
        CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
        RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
 
-       ret = zbl_enable(handle, cb, user_data);
+       ret = zbl_enable(handle);
        DBG("zbl_enable()=0x%X", ret);
        return ret;
 }
index 0b6febf..412cfbb 100644 (file)
@@ -558,7 +558,7 @@ static void _zbl_signal_handler(GDBusConnection *connection,
        RETM_IF(NULL == container->event_handler, "event_handler is null");
        DBG("%s signal received", signal_name);
 
-       if (g_strcmp0(signal_name, "service_enabled") == 0) {
+       if (g_strcmp0(signal_name, "zigbee_state") == 0) {
                gboolean enabled;
                g_variant_get(parameters, "(b)", &enabled);
 
@@ -935,17 +935,18 @@ static int _zbl_dbus_subscribe_signal(zigbee_h handle)
        unsigned int id;
        struct zbl_zigbee_s* h = handle;
 
-       /* Section 1. Subscribe ZDO signal */
-       id = g_dbus_connection_signal_subscribe(gdbus_conn, NULL, ZIGBEE_SERVICE_INTERFACE,
-                                               "service_enabled", ZIGBEE_CONTROL_OBJECT_PATH, NULL,
+       /* Section 0. Subscribe Manager signal */
+       id = g_dbus_connection_signal_subscribe(gdbus_conn, NULL, ZIGBEE_MANAGER_INTERFACE,
+                                               "zigbee_state", ZIGBEE_DBUS_OBJPATH, NULL,
                                                G_DBUS_CALL_FLAGS_NONE, _zbl_signal_handler, handle, NULL);
        if (0 == id) {
-               ERR("g_dbus_connection_signal_subscribe(service_enabled) Fail(%d)", errno);
+               ERR("g_dbus_connection_signal_subscribe(zigbee_state) Fail(%d)", errno);
                return ZIGBEE_ERROR_IO_ERROR;
        }
        h->dbus_sub_ids = g_list_append(h->dbus_sub_ids, GUINT_TO_POINTER(id));
        DBG("subscribed for service_enabled signal %d", id);
 
+       /* Section 1. Subscribe ZDO signal */
        id = g_dbus_connection_signal_subscribe(gdbus_conn, NULL, ZIGBEE_SERVICE_INTERFACE,
                                                "child_joined", ZIGBEE_CONTROL_OBJECT_PATH, NULL,
                                                G_DBUS_CALL_FLAGS_NONE, _zbl_signal_handler, h, NULL);
@@ -2944,90 +2945,16 @@ int zbl_set_event_cb(zigbee_h handle, zb_event_cb event_handler)
        return ZIGBEE_ERROR_NONE;
 }
 
-static gboolean _zbl_timeout_enable(gpointer p)
-{
-       zbl_req_cb_s *container = NULL;
-       zb_enable_cb cb = NULL;
-
-       DBG("zb_enable_cb()");
-
-       RETVM_IF(NULL == gdbus_conn, G_SOURCE_REMOVE, "gdbus_conn is NULL");
-       container = p;
-       RETVM_IF(NULL == container, G_SOURCE_REMOVE, "cb_container is NULL");
-       cb = container->cb;
-
-       if (false == container->found && container->cb)
-               cb(ZB_ZDP_NOT_SUPPORTED, container->userdata);
-
-       container->tid = 0;
-
-       g_dbus_connection_signal_unsubscribe(gdbus_conn, container->sid);
-       DBG("container->sid=%d unsubscribed");
-       container->sid = 0;
-
-       return G_SOURCE_REMOVE;
-}
-
-static void _zbl_enable_cb(GDBusConnection *connection,
-               const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
-               const gchar *signal_name, GVariant *parameters, gpointer user_data)
-{
-       zbl_req_cb_s *container = user_data;
-       zb_enable_cb cb = container->cb;
-
-       unsigned char ret = ZB_ZDP_SUCCESS;
-       gboolean value = TRUE;
-
-       container->found = true;
-
-       DBG("_zbl_enable_cb");
-
-       g_variant_get(parameters, "(b)", &value);
-       if (!value)
-               ret = ZB_ZDP_UNKNOWN;
-
-       if (cb)
-               cb(ret, container->userdata);
-
-       if (container->sid)
-               g_dbus_connection_signal_unsubscribe(gdbus_conn, container->sid);
-}
-
-
-int zbl_enable(zigbee_h handle, zb_enable_cb cb, void *user_data)
+int zbl_enable(zigbee_h handle)
 {
+       int result = ZIGBEE_ERROR_NONE;
        GVariant *variant = NULL;
        GError *dbus_err = NULL;
 
-       int sub_id, to;
-       zbl_req_cb_s *container;
-       int result = ZIGBEE_ERROR_NONE;
-
        RETV_IF(NULL == gdbus_conn, ZIGBEE_ERROR_IO_ERROR);
-       RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
 
        DBG("zbl_enable()");
 
-       container = calloc(1, sizeof(zbl_req_cb_s));
-       RETVM_IF(NULL == container, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
-
-       to = ZIGBEE_BROADCAST_TIMEOUT;
-       sub_id = g_dbus_connection_signal_subscribe(gdbus_conn, NULL,
-                       ZIGBEE_MANAGER_INTERFACE, "zigbee_state", ZIGBEE_DBUS_OBJPATH,
-                       NULL, G_DBUS_SIGNAL_FLAGS_NONE,
-                       _zbl_enable_cb, container, _zbl_request_cleanup);
-
-       if (0 == sub_id) {
-               ERR("g_dbus_connection_signal_subscribe() Fail");
-               free(container);
-               return ZIGBEE_ERROR_IO_ERROR;
-       }
-
-       container->cb = cb;
-       container->sid = sub_id;
-       container->tid = g_timeout_add_seconds(to, _zbl_timeout_enable, container);
-       container->userdata = user_data;
-
        variant = g_dbus_connection_call_sync(gdbus_conn,
                ZIGBEE_MANAGER_INTERFACE,
                ZIGBEE_DBUS_OBJPATH,
index 66cd259..577d70e 100644 (file)
@@ -28,7 +28,7 @@ GDBusConnection* zbl_dbus_get_object(void);
 int zbl_dbus_get_timeout(GDBusProxy *proxy);
 int zbl_check_privilege();
 
-int zbl_enable(zigbee_h handle, zb_enable_cb cb, void *user_data);
+int zbl_enable(zigbee_h handle);
 int zbl_set_event_cb(zigbee_h handle, zb_event_cb event_handler);
 int zbl_disable(void);
 int zbl_hw_reset(void);
index f2c573b..dca3213 100644 (file)
@@ -262,11 +262,6 @@ static void _init_endpoints()
        huebulb_ep1.out_clusters[0] = ZB_ZCL_OTA_BOOTLOAD_CLUSTER_ID;
 }
 
-static void zigbee_enable_cb(unsigned char status, void *user_data)
-{
-       msgp("\nenable result received = 0x%02X\n", status);
-}
-
 static void zigbee_form_network_done_cb(nwk_addr panid, void *user_data)
 {
        msgp("\nform_network_done received PANID = 0x%04X\n", panid);
@@ -288,7 +283,7 @@ static void zigbee_event_cb(nwk_addr addr16, ieee_addr addr64, zb_event_e e, zb_
        case ZB_ZDP_ENABLE_EVENT:
        {
                status = ev.data.enable->status;
-               msg("  service enabled = %d", status);
+               msg("  zigbee state = %d [%s]", status, (status ? "Enabled" : "Disabled"));
                break;
        }
        case ZB_ZDP_FORM_NETWORK_DONE:
@@ -524,7 +519,7 @@ static int run_enable(MManager *mm, struct menu_data *menu)
        msg(" - zb_set_event_cb() ret: [0x%X]", ret);
 
        /* Enable */
-       ret = zb_enable(handle, zigbee_enable_cb, NULL);
+       ret = zb_enable(handle);
        if (ZIGBEE_ERROR_NONE != ret) {
                msg("zb_enable(0x%X) - FAILED!!! [%s]", ret, zigbee_error_to_string(ret));
                return RET_FAILURE;
@@ -1015,7 +1010,7 @@ static int __select_handle_register_event(MManager *mm, struct menu_data *menu)
        msg(" - zb_set_event_cb() ret: [0x%X] [%s]", ret, zigbee_error_to_string(ret));
 
        /* Enable */
-       ret = zb_enable(handle, zigbee_enable_cb, NULL);
+       ret = zb_enable(handle);
        if (ZIGBEE_ERROR_PERMISSION_DENIED == ret) {
                /* Admin permission is not set, but we can do normal operations */
                msg("zb_enable(0x%X) - FAILED!!!", ret);