#define ZCL_REPORTING_DIRECTION_REPORTED 0x00
#define ZCL_REPORTING_DIRECTION_RECEIVED 0x01
-static GDBusConnection *_zbl_get_connection(void)
-{
- GError *error = NULL;
-
- return g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-}
-
static GDBusProxy *_zbl_get_manager_proxy(void)
{
GDBusProxy *proxy = NULL;
static void _zbl_dbus_unsubscribe_signal(GList *sub_ids)
{
- GDBusConnection *conn = _zbl_get_connection();
- if (NULL == conn || NULL == sub_ids)
- return;
+ RET_IF(NULL == gdbus_conn);
+ RET_IF(NULL == sub_ids);
while (sub_ids) {
- g_dbus_connection_signal_unsubscribe(conn, GPOINTER_TO_UINT(sub_ids));
- sub_ids = g_list_remove(sub_ids, sub_ids);
+ g_dbus_connection_signal_unsubscribe(gdbus_conn, GPOINTER_TO_UINT(sub_ids->data));
+ sub_ids = g_list_remove(sub_ids, sub_ids->data);
}
+ g_list_free(sub_ids);
}
static int _zbl_dbus_subscribe_signal(zigbee_h handle)
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(child_rejoined) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(child_rejoined) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(child_left) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(leave_network_done) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(form_network_done) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(zcl_global_default_response) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(report_attr_handler_rsp) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(alarm_count) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(status_change_rpt) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
if (0 == id) {
ERR("g_dbus_connection_signal_subscribe(enroll_request) Fail(%d)\n", errno);
_zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
return ZIGBEE_ERROR_IO_ERROR;
}
handle->dbus_sub_ids = g_list_append(handle->dbus_sub_ids, GUINT_TO_POINTER(id));
{
GDBusProxy *proxy = G_DBUS_PROXY(object);
gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
+ zigbee_h handle = (zigbee_h)user_data;
+
if (name_owner)
return;
- zbl_dbus_stop();
+
+ zbl_dbus_stop(handle);
}
static void _zbl_request_cleanup(gpointer data)
int zbl_disable(void)
{
+ int result = ZIGBEE_ERROR_NONE;
GVariant *variant = NULL;
GError *dbus_err = NULL;
- int result = ZIGBEE_ERROR_NONE;
+
+ RETV_IF(NULL == gdbus_conn, ZIGBEE_ERROR_IO_ERROR);
+ RETV_IF(NULL == manager_gproxy, ZIGBEE_ERROR_IO_ERROR);
DBG("zbl_disable()");
- if (0 >= zbl_ref_count) {
- WARN("dbus does not initiaized\n");
- return ZIGBEE_ERROR_NO_DATA;
- }
+ variant = g_dbus_proxy_call_sync(manager_gproxy, "disable", NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &dbus_err);
- if (0 > --zbl_ref_count) {
- DBG("all connections closed\n");
- return ZIGBEE_ERROR_NONE;
+ if (!variant) {
+ ERR("Failed to get 'disable' [%s]", dbus_err->message);
+ g_error_free(dbus_err);
+ return ZIGBEE_ERROR_IO_ERROR;
}
- if (gdbus_conn) {
- variant = g_dbus_connection_call_sync(gdbus_conn,
- ZIGBEE_SERVER_NAME,
- ZIGBEE_DBUS_OBJPATH,
- ZIGBEE_DBUS_INTERFACE,
- "disable",
- NULL, NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &dbus_err);
-
- if (!variant) {
- ERR("Failed to get 'disable' [%s]", dbus_err->message);
- g_error_free(dbus_err);
- }
-
- g_variant_get(variant, "(i)", &result);
- DBG("ret = [0x%x]", result);
- g_variant_unref(variant);
-
- g_object_unref(manager_gproxy);
- manager_gproxy = NULL;
- g_object_unref(service_gproxy);
- service_gproxy = NULL;
- g_object_unref(on_off_gproxy);
- on_off_gproxy = NULL;
- g_object_unref(door_lock_gproxy);
- door_lock_gproxy = NULL;
- g_object_unref(level_control_gproxy);
- level_control_gproxy = NULL;
- g_object_unref(thermostat_gproxy);
- thermostat_gproxy = NULL;
- g_object_unref(alarm_gproxy);
- alarm_gproxy = NULL;
- g_object_unref(fan_control_gproxy);
- fan_control_gproxy = NULL;
-
- g_object_unref(mfglib_gproxy);
- mfglib_gproxy = NULL;
- g_object_unref(zcl_global_proxy);
- zcl_global_proxy = NULL;
- g_object_unref(zcl_color_control_proxy);
- zcl_color_control_proxy = NULL;
- g_object_unref(custom_gproxy);
- custom_gproxy = NULL;
-
- g_object_unref(gdbus_conn);
- gdbus_conn = NULL;
- }
+ g_variant_get(variant, "(i)", &result);
+ DBG("ret = [0x%x]", result);
+ g_variant_unref(variant);
- return ZIGBEE_ERROR_NONE;
+ return result;
}
int zbl_hw_reset(void)
{
FN_CALL;
+ GError *error = NULL;
unsigned int id;
if (gdbus_conn) {
return ZIGBEE_ERROR_NONE;
}
- gdbus_conn = _zbl_get_connection();
- if (!gdbus_conn) {
- ERR("Couldn't connect to the System bus");
+ gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (NULL == gdbus_conn) {
+ ERR("Couldn't connect to the System bus [%s]\n", error->message);
+ g_error_free(error);
return ZIGBEE_ERROR_IO_ERROR;
}
id = g_signal_connect(gdbus_conn, "notify::g-name-owner",
- G_CALLBACK(_zbl_dbus_name_owner_notify), NULL);
+ G_CALLBACK(_zbl_dbus_name_owner_notify), handle);
if (0 == id) {
ERR("g_signal_connect() Fail\n");
return ZIGBEE_ERROR_IO_ERROR;
return ZIGBEE_ERROR_NONE;
}
-void zbl_dbus_stop(void)
+void zbl_dbus_stop(zigbee_h handle)
{
- if (0 <= zbl_ref_count) {
+ DBG("zbl_dbus_stop()");
+
+ if (0 >= zbl_ref_count) {
WARN("dbus does not initiaized\n");
return;
}
- if (0 > --zbl_ref_count)
+
+ if (0 > --zbl_ref_count) {
DBG("all connections closed\n");
+ zbl_ref_count = 0;
+ return;
+ }
- g_object_unref(gdbus_conn);
- gdbus_conn = NULL;
- return;
+ if (gdbus_conn) {
+ _zbl_dbus_unsubscribe_signal(handle->dbus_sub_ids);
+ handle->dbus_sub_ids = NULL;
+
+ g_object_unref(manager_gproxy);
+ manager_gproxy = NULL;
+ g_object_unref(service_gproxy);
+ service_gproxy = NULL;
+ g_object_unref(on_off_gproxy);
+ on_off_gproxy = NULL;
+ g_object_unref(door_lock_gproxy);
+ door_lock_gproxy = NULL;
+ g_object_unref(level_control_gproxy);
+ level_control_gproxy = NULL;
+ g_object_unref(thermostat_gproxy);
+ thermostat_gproxy = NULL;
+ g_object_unref(alarm_gproxy);
+ alarm_gproxy = NULL;
+ g_object_unref(fan_control_gproxy);
+ fan_control_gproxy = NULL;
+
+ g_object_unref(mfglib_gproxy);
+ mfglib_gproxy = NULL;
+ g_object_unref(zcl_global_proxy);
+ zcl_global_proxy = NULL;
+ g_object_unref(zcl_color_control_proxy);
+ zcl_color_control_proxy = NULL;
+ g_object_unref(custom_gproxy);
+ custom_gproxy = NULL;
+
+ g_object_unref(gdbus_conn);
+ gdbus_conn = NULL;
+
+ DBG("zbl_dbus_stop() finished");
+ }
}
GDBusConnection* zbl_dbus_get_object(void)