#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)
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;
}
NOT_USED(user_data);
- zigbee_manager_complete_disable(zigbee_mgr, invocation, TRUE);
+ zigbee_manager_complete_disable(zigbee_mgr, invocation, 0);
if (service)
zblib_service_exit(service);
}
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);
/* 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,
const gchar *name, gpointer user_data)
{
+ gboolean ret;
+ GError *error = NULL;
ZigbeeObjectSkeleton *zigbee_object;
ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
ZigBeeService *service = NULL;
/*
* Export 'manager' interface on ZigBee D-BUS
*/
- g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(custom_data->zigbee_mgr),
- connection, ZIGBEE_DBUS_PATH, NULL);
-
+ ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(custom_data->zigbee_mgr),
+ connection, ZIGBEE_DBUS_PATH, &error);
+ if (FALSE == ret) {
+ /* LCOV_EXCL_START */
+ Z_LOGW("g_dbus_interface_skeleton_export() Fail(%s)", error->message);
+ g_error_free(error);
+ /* LCOV_EXCL_STOP */
+ }
/*
* Exports all objects managed by 'manager' on Connection (connection)
*/
/* Service interface initialization completed */
custom_data->sevice_interface_init_complete = TRUE;
- if (TRUE == custom_data->name_acquired) {
- /* TODO - Emit zigbee_state signal */
- }
-
OUT:
g_free(path);
}
+static void zigbee_get_activation_sbus(ZigbeeCustomData_t *interface_data)
+{
+ /* Get D-Bus owner to activate zigbee-daemon */
+ interface_data->activation_dbus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+ ZIGBEE_DBUS_SERVICE".manager",
+ G_BUS_NAME_OWNER_FLAGS_REPLACE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ Z_LOGI("ZigBee D-BUS activation ID: [%d]", interface_data->activation_dbus_id);
+}
+
/**< Zigbee service dbus interface initialization */
gboolean zigbee_service_dbus_interface_init(ZigBeeService *service)
{
g_free, NULL);
/*
+ * Acquire "org.tizen.zigbee.manager" named bus on D-BUS SYSTEM bus.
+ */
+ zigbee_get_activation_sbus(interface_data);
+
+ /*
* Acquire "org.tizen.zigbee" named bus on D-BUS SYSTEM bus.
*/
interface_data->bus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
*/
ret = zblib_service_remove_service_interface(service,
service_interface);
- if (FALSE == ret) {
+ if (FALSE == ret)
Z_LOGE("Remove service interface failed!");
- }
/*
* Free Service interface object
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
+ */
+ if (interface_data->activation_dbus_id > 0) {
+ Z_LOGI("Unowning ZigBee Service interface activation D-BUS ID: [%d]",
+ interface_data->activation_dbus_id);
+ g_bus_unown_name(interface_data->activation_dbus_id);
+ }
+
/*
* Unown "org.tizen.zigbee" named bus on D-BUS SYSTEM bus
*/
*/
ret = zblib_service_remove_service_interface(service,
service_interface);
- if (FALSE == ret) {
+ if (FALSE == ret)
Z_LOGE("Remove service interface failed!");
- }
/*
* Free Service interface object