Support asynchronous plugin initializer
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface.c
index 3f729d5..97111d9 100644 (file)
@@ -26,6 +26,7 @@
 #include <zblib.h>
 #include <zblib_service.h>
 #include <zblib_service_interface.h>
+#include <zblib_driver_manager.h>
 
 #include "zigbee_service_interface.h"
 #include "zigbee_service_interface_common.h"
 /**< ZigBee D-BUS service interface name */
 #define ZIGBEE_DBUS_SERVICE_INTERFACE_NAME "zigbee-dbus"
 
+static void _notify_zigbee_state(ZigBeeServiceInterface *service_interface,
+               gboolean result)
+{
+       ZigbeeCustomData_t *custom_data = zblib_service_interface_ref_user_data(service_interface);
+       ZigBeeService *service = zblib_service_interface_ref_service(service_interface);
+
+       if (NULL == custom_data) {
+               Z_LOGE("Unexpected invalid parameter !");
+               return;
+       }
+
+       if (result) {
+               /* Notify zigbee service manually here (Enabled) */
+               zigbee_manager_emit_zigbee_state(custom_data->zigbee_mgr, result);
+       } else {
+               /* ZigBee state will be emitted on bus termination */
+               zblib_service_exit(service);
+       }
+}
+
 static gboolean on_manager_enable(ZigbeeManager *zigbee_mgr,
        GDBusMethodInvocation *invocation,
        gpointer user_data)
@@ -49,11 +70,6 @@ static gboolean on_manager_enable(ZigbeeManager *zigbee_mgr,
 
        zigbee_manager_complete_enable(zigbee_mgr, invocation);
 
-       if (TRUE == custom_data->sevice_interface_init_complete) {
-               /* Emit zigbee_state - enabled */
-               zigbee_manager_emit_zigbee_state(zigbee_mgr, TRUE);
-       }
-
        return TRUE;
 }
 
@@ -291,6 +307,18 @@ static void zigbee_service_dbus_interface_noti_cb(ZigBeeServiceInterface *servic
        }
        break;
 
+       case ZBLIB_DRIVER_TYPE_MANAGER: {
+               /* Handle 'enabled' notification here */
+               if (notification_id == ZBLIB_MANAGER_NOTI_ZIGBEE_ENABLED) {
+                       gboolean *rsp = (gboolean*)noti_data;
+
+                       Z_LOGD("Firmware update result : [%s]", ((*rsp) ? "Succeed" : "Failed"));
+                       _notify_zigbee_state(service_interface, *rsp);
+               } else
+                       Z_LOGE("Unhandled notification id: [%d]", notification_id);
+       }
+       break;
+
        case ZBLIB_DRIVER_TYPE_NONE: /* Fall through */
        default: {
                Z_LOGE("Unhandled driver type: [%d]", driver_type);
@@ -329,11 +357,6 @@ static void zigbee_on_name_acquired(GDBusConnection *connection,
 
        /* Bus name is 'acquired' */
        custom_data->name_acquired = TRUE;
-
-       if (TRUE == custom_data->sevice_interface_init_complete) {
-               /* Emit zigbee_state - enabled */
-               zigbee_manager_emit_zigbee_state(custom_data->zigbee_mgr, TRUE);
-       }
 }
 
 static void zigbee_on_bus_acquired(GDBusConnection *connection,
@@ -591,6 +614,10 @@ void zigbee_service_dbus_interface_deinit(ZigBeeService *service)
                goto EXIT;
        }
 
+       /* Emit zigbee_state - disabled */
+       Z_LOGD("Update zigbee_state ----");
+       zigbee_manager_emit_zigbee_state(interface_data->zigbee_mgr, FALSE);
+
        /*
         * Unown "org.tizen.zigbee.manager" named bus on D-BUS SYSTEM bus
         */