/*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hocheol Seo <hocheol.seo@samsung.com>
- * Girishashok Joshi <girish.joshi@samsung.com>
- * Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "bt-core-common.h"
#include "bt-core-dbus-handler.h"
#include "bt-internal-types.h"
-#include "bt-request-service.h"
#include "bt-core-noti-handler.h"
#include "bt-core-main.h"
#define BT_SERVICE_NAME "org.projectx.bt"
#define BT_SERVICE_PATH "/org/projectx/bt_service"
-DBusGProxy *service_proxy = NULL;
-DBusGConnection *service_conn = NULL;
+#ifdef TIZEN_FEATURE_BT_HPS
+#define BT_HPS_SERVICE_NAME "org.projectx.httpproxy"
+#define BT_HPS_OBJECT_PATH "/org/projectx/httpproxy"
+#define BT_HPS_INTERFACE_NAME "org.projectx.httpproxy_service"
+#endif
static GDBusConnection *service_gconn;
static GDBusProxy *service_gproxy;
+#ifdef TIZEN_FEATURE_BT_HPS
+static GDBusProxy *hps_gproxy;
+#endif
+static gboolean factory_test_mode;
void _bt_core_fill_garray_from_variant(GVariant *var, GArray *param)
{
}
}
-static GDBusProxy *__bt_core_gdbus_init_service_proxy(void)
+GDBusConnection * _bt_core_get_gdbus_connection(void)
{
- GDBusProxy *proxy;
GError *err = NULL;
- g_type_init();
-
if (service_gconn == NULL)
service_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
return NULL;
}
- proxy = g_dbus_proxy_new_sync(service_gconn,
+ return service_gconn;
+}
+
+static GDBusProxy *__bt_core_gdbus_init_service_proxy(void)
+{
+ GDBusProxy *proxy;
+ GError *err = NULL;
+ GDBusConnection *conn;
+
+ conn = _bt_core_get_gdbus_connection();
+ if (!conn)
+ return NULL;
+
+ proxy = g_dbus_proxy_new_sync(conn,
G_DBUS_PROXY_FLAGS_NONE, NULL,
BT_SERVICE_NAME,
BT_SERVICE_PATH,
g_clear_error(&err);
}
- g_object_unref(service_gconn);
- service_gconn = NULL;
return NULL;
}
return (service_gproxy) ? service_gproxy : __bt_core_gdbus_init_service_proxy();
}
+#ifdef TIZEN_FEATURE_BT_HPS
+int _bt_core_start_httpproxy(void)
+{
+ GVariant *variant = NULL;
+ unsigned char enabled;
+ GError *err = NULL;
+ BT_DBG(" ");
+
+ hps_gproxy = _bt_core_gdbus_get_hps_proxy();
+ if (!hps_gproxy) {
+ BT_DBG("Couldn't get service proxy");
+ return -1;
+ }
+
+ variant = g_dbus_proxy_call_sync(hps_gproxy, "enable",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (err) {
+ BT_ERR("Error : %s" , err->message);
+ g_clear_error(&err);
+ }
+ if (variant) {
+ g_variant_get(variant, "(y)", &enabled);
+ BT_ERR("HPS enabled status 0x%x", enabled);
+ }
+ return 0;
+}
+
+int _bt_core_stop_httpproxy(void)
+{
+ GVariant *variant = NULL;
+ unsigned char enabled;
+ GError *err = NULL;
+ BT_DBG(" ");
+
+ hps_gproxy = _bt_core_gdbus_get_hps_proxy();
+ if (!hps_gproxy) {
+ BT_DBG("Couldn't get service proxy");
+ return -1;
+ }
+
+ variant = g_dbus_proxy_call_sync(hps_gproxy, "disable",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+ if (err) {
+ BT_ERR("Error : %s" , err->message);
+ g_clear_error(&err);
+ }
+ if (variant) {
+ g_variant_get(variant, "(y)", &enabled);
+ BT_ERR("HPS disabled status 0x%x", enabled);
+ }
+ return 0;
+}
+
+static GDBusProxy *_bt_core_gdbus_init_hps_proxy(void)
+{
+ GDBusProxy *proxy;
+ GError *err = NULL;
+ GDBusConnection *conn;
+
+ BT_DBG(" ");
+
+ conn = _bt_core_get_gdbus_connection();
+ if (!conn)
+ return NULL;
+
+ proxy = g_dbus_proxy_new_sync(conn,
+ G_DBUS_PROXY_FLAGS_NONE, NULL,
+ BT_HPS_SERVICE_NAME,
+ BT_HPS_OBJECT_PATH,
+ BT_HPS_INTERFACE_NAME,
+ NULL, &err);
+ if (proxy == NULL) {
+ if (err) {
+ BT_ERR("Unable to create proxy: %s", err->message);
+ g_clear_error(&err);
+ }
+ return NULL;
+ }
+
+ hps_gproxy = proxy;
+
+ return proxy;
+}
+
+GDBusProxy *_bt_core_gdbus_get_hps_proxy(void)
+{
+ return (hps_gproxy) ? hps_gproxy : _bt_core_gdbus_init_hps_proxy();
+}
+#endif
+
void _bt_core_gdbus_deinit_proxys(void)
{
+ BT_DBG("");
+
if (service_gproxy) {
- g_object_unref(service_proxy);
- service_proxy = NULL;
+ g_object_unref(service_gproxy);
+ service_gproxy = NULL;
+ }
+
+#ifdef TIZEN_FEATURE_BT_HPS
+ if (hps_gproxy) {
+ g_object_unref(hps_gproxy);
+ hps_gproxy = NULL;
}
+#endif
if (service_gconn) {
g_object_unref(service_gconn);
GArray **out_param1)
{
GDBusProxy *proxy;
- GVariant *ret;
+ GVariant *ret = NULL;
GVariant *param1;
GVariant *param2;
GVariant *param3;
int result = BLUETOOTH_ERROR_NONE;
GError *error = NULL;
GArray *in_param5 = NULL;
- GArray *out_param2 = NULL;
+
+ int retry = 5;
proxy = _bt_core_gdbus_get_service_proxy();
if (!proxy)
return BLUETOOTH_ERROR_INTERNAL;
in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
- param1 = g_variant_new_from_data((const GVariantType *)"ay",
- in_param1->data, in_param1->len,
- TRUE, NULL, NULL);
- param2 = g_variant_new_from_data((const GVariantType *)"ay",
- in_param2->data, in_param2->len,
- TRUE, NULL, NULL);
- param3 = g_variant_new_from_data((const GVariantType *)"ay",
- in_param3->data, in_param3->len,
- TRUE, NULL, NULL);
- param4 = g_variant_new_from_data((const GVariantType *)"ay",
- in_param4->data, in_param4->len,
- TRUE, NULL, NULL);
- param5 = g_variant_new_from_data((const GVariantType *)"ay",
- in_param5->data, in_param5->len,
- TRUE, NULL, NULL);
-
- ret = g_dbus_proxy_call_sync(proxy, "service_request",
- g_variant_new("(iii@ay@ay@ay@ay@ay)",
- service_type, service_function,
- BT_SYNC_REQ, param1,
- param2, param3,
- param4, param5),
- G_DBUS_CALL_FLAGS_NONE, -1,
- NULL, &error);
+ while (--retry >= 0) {
+ param1 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param1->data, in_param1->len,
+ TRUE, NULL, NULL);
+ param2 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param2->data, in_param2->len,
+ TRUE, NULL, NULL);
+ param3 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param3->data, in_param3->len,
+ TRUE, NULL, NULL);
+ param4 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param4->data, in_param4->len,
+ TRUE, NULL, NULL);
+ param5 = g_variant_new_from_data((const GVariantType *)"ay",
+ in_param5->data, in_param5->len,
+ TRUE, NULL, NULL);
+
+ ret = g_dbus_proxy_call_sync(proxy, "service_request",
+ g_variant_new("(iii@ay@ay@ay@ay@ay)",
+ service_type, service_function,
+ BT_SYNC_REQ, param1,
+ param2, param3,
+ param4, param5),
+ G_DBUS_CALL_FLAGS_NONE, 2000,
+ NULL, &error);
+ if (ret == NULL && error != NULL) {
+ if (error->code == G_IO_ERROR_TIMED_OUT) {
+ BT_ERR("D-Bus Timed out.");
+ g_clear_error(&error);
+ continue;
+ }
+ }
+
+ break;
+ }
g_array_free(in_param5, TRUE);
}
param1 = NULL;
- param2 = NULL;
- g_variant_get(ret, "(@ay@ay)", ¶m1, ¶m2);
+ g_variant_get(ret, "(iv)", &result, ¶m1);
if (param1) {
*out_param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
g_variant_unref(param1);
}
- if (param2) {
- out_param2 = g_array_new(TRUE, TRUE, sizeof(gchar));
- _bt_core_fill_garray_from_variant(param2, out_param2);
- result = g_array_index(out_param2, int, 0);
- g_variant_unref(param2);
- g_array_free(out_param2, TRUE);
- } else {
- result = BLUETOOTH_ERROR_INTERNAL;
- }
-
g_variant_unref(ret);
return result;
}
-
-static int __bt_core_get_object_path(DBusMessage *msg, char **path)
+static const gchar bt_core_introspection_xml[] =
+"<node name='/'>"
+" <interface name='org.projectx.btcore'>"
+" <method name='EnableAdapter'>"
+" </method>"
+" <method name='DisableAdapter'>"
+" </method>"
+" <method name='RecoverAdapter'>"
+" </method>"
+" <method name='ResetAdapter'>"
+" </method>"
+" <method name='EnableAdapterLe'>"
+" </method>"
+" <method name='DisableAdapterLe'>"
+" </method>"
+" <method name='EnableCore'>"
+" </method>"
+" <method name='SetTransferValue'>"
+" <arg type='b' name='value' direction='in'/>"
+" </method>"
+" <method name='FactoryTestMode'>"
+" <arg type='s' name='type' direction='in'/>"
+" <arg type='s' name='arg' direction='in'/>"
+" <arg type='i' name='ret' direction='out'/>"
+" </method>"
+" </interface>"
+"</node>";
+
+static guint obj_id, sig_id1, sig_id2, sig_id3;
+
+static void __bt_core_dbus_method(GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- DBusMessageIter item_iter;
-
- dbus_message_iter_init(msg, &item_iter);
-
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_OBJECT_PATH) {
- BT_ERR("This is bad format dbus");
- return BLUETOOTH_ERROR_INTERNAL;
+ gboolean ret;
+
+ BT_DBG("method %s", method_name);
+
+ if (g_strcmp0(method_name, "EnableAdapter") == 0) {
+ ret = _bt_core_enable_adapter();
+ } else if (g_strcmp0(method_name, "DisableAdapter") == 0) {
+ ret = _bt_core_disable_adapter();
+ } else if (g_strcmp0(method_name, "RecoverAdapter") == 0) {
+ ret = _bt_core_recover_adapter();
+ } else if (g_strcmp0(method_name, "ResetAdapter") == 0) {
+ ret = __bt_core_reset_adapter();
+ } else if (g_strcmp0(method_name, "EnableAdapterLe") == 0) {
+ ret = _bt_core_enable_adapter_le();
+ } else if (g_strcmp0(method_name, "DisableAdapterLe") == 0) {
+ ret = _bt_core_disable_adapter_le();
+ } else if (g_strcmp0(method_name, "EnableCore") == 0) {
+ ret = _bt_core_enable_core();
+ } else if (g_strcmp0(method_name, "SetTransferValue") == 0) {
+ gboolean value = FALSE;
+
+ g_variant_get(parameters, "(b)", &value);
+ BT_DBG("Transfer value: %d", value);
+
+ ret = _bt_core_set_transfer_value(value);
+ } else if (g_strcmp0(method_name, "FactoryTestMode") == 0) {
+ const char *type = NULL;
+ const char *arg = NULL;
+
+ g_variant_get(parameters, "(&s&s)", &type, &arg);
+ ret = _bt_core_factory_test_mode(type, arg);
+ factory_test_mode = TRUE;
+
+ if (ret == TRUE)
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(i)", ret));
+ else
+ _bt_core_terminate();
+
+ return;
+ } else {
+ ret = FALSE;
}
- dbus_message_iter_get_basic(&item_iter, path);
-
- if (*path == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
-
- return BLUETOOTH_ERROR_NONE;
-}
-
-static int __bt_core_get_owner_info(DBusMessage *msg, char **name,
- char **previous, char **current)
-{
- DBusMessageIter item_iter;
-
- dbus_message_iter_init(msg, &item_iter);
-
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus");
- return BLUETOOTH_ERROR_INTERNAL;
+ if (!ret) {
+ GQuark quark = g_quark_from_string("bt-core");
+ GError *err = g_error_new(quark, 0, "Failed");
+ g_dbus_method_invocation_return_gerror(invocation, err);
+ g_error_free(err);
+ } else {
+ g_dbus_method_invocation_return_value(invocation, NULL);
}
- dbus_message_iter_get_basic(&item_iter, name);
-
- if (*name == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
-
- dbus_message_iter_next(&item_iter);
+ BT_DBG("-");
+}
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus");
- return BLUETOOTH_ERROR_INTERNAL;
- }
+static const GDBusInterfaceVTable method_table = {
+ __bt_core_dbus_method,
+ NULL,
+ NULL,
+};
- dbus_message_iter_get_basic(&item_iter, previous);
+static GDBusNodeInfo *__bt_core_create_node_info(
+ const gchar *introspection_data)
+{
+ GError *err = NULL;
+ GDBusNodeInfo *node_info = NULL;
- if (*previous == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
+ if (introspection_data == NULL)
+ return NULL;
- dbus_message_iter_next(&item_iter);
+ node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
- if (dbus_message_iter_get_arg_type(&item_iter)
- != DBUS_TYPE_STRING) {
- BT_ERR("This is bad format dbus");
- return BLUETOOTH_ERROR_INTERNAL;
+ if (err) {
+ BT_ERR("Unable to create node: %s", err->message);
+ g_clear_error(&err);
}
-
- dbus_message_iter_get_basic(&item_iter, current);
-
- if (*current == NULL)
- return BLUETOOTH_ERROR_INTERNAL;
-
- return BLUETOOTH_ERROR_NONE;
+ return node_info;
}
-static DBusHandlerResult __bt_core_event_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+gboolean __is_interface_and_signal_valid(const gchar *interface_name,
+ const gchar *signal_name)
{
- char *object_path = NULL;
- const char *member = dbus_message_get_member(msg);
-
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- if (member == NULL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ if (g_strcmp0(interface_name, "org.freedesktop.DBus") &&
+ g_strcmp0(interface_name, "org.freedesktop.DBus.ObjectManager"))
+ return FALSE;
- if (strcasecmp(member, "InterfacesAdded") == 0) {
- if (__bt_core_get_object_path(msg, &object_path)) {
- BT_ERR("Fail to get the path");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ if (g_strcmp0(signal_name, "NameOwnerChanged") &&
+ g_strcmp0(signal_name, "InterfacesAdded") &&
+ g_strcmp0(signal_name, "InterfacesRemoved"))
+ return FALSE;
- if (strcasecmp(object_path, "/org/bluez/hci0") == 0) {
- _bt_core_adapter_added_cb();
- }
- } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
- if (__bt_core_get_object_path(msg, &object_path)) {
- BT_ERR("Fail to get the path");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ return TRUE;
+}
- if (strcasecmp(object_path, "/org/bluez/hci0") == 0) {
- _bt_core_adapter_removed_cb();
- }
- } else if (strcasecmp(member, "NameOwnerChanged") == 0) {
- char *name = NULL;
- char *previous = NULL;
- char *current = NULL;
- gboolean flight_mode_status;
-
- if (__bt_core_get_owner_info(msg, &name, &previous, ¤t)) {
- BT_ERR("Fail to get the owner info");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+static void __handle_name_owner_changed(const char *name)
+{
+ gboolean flight_mode_status;
- if (*current != '\0')
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ flight_mode_status = _bt_core_is_flight_mode_enabled();
- if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode_status) != 0)
- BT_ERR("Fail to get the flight_mode status value");
- if (flight_mode_status == FALSE && _bt_is_flightmode_request() == TRUE) {
- BT_DBG("flightmode requested");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+ if (flight_mode_status == FALSE && _bt_is_flightmode_request() == TRUE) {
+ BT_DBG("flightmode requested");
+ return;
+ }
- if (strcasecmp(name, "org.bluez") == 0) {
- BT_DBG("Bluetoothd is terminated");
- if (_bt_check_terminating_condition() == TRUE) {
- _bt_disable_adapter();
- _bt_disable_adapter_le();
- _bt_core_terminate();
- }
- } else if (strcasecmp(name, "org.projectx.bt") == 0) {
- BT_DBG("bt-service is terminated");
- if (_bt_check_terminating_condition() == TRUE) {
- _bt_disable_adapter();
- _bt_disable_adapter_le();
- _bt_core_terminate();
- }
+ if ((g_strcmp0(name, "org.bluez") == 0) ||
+ (g_strcmp0(name, "org.projectx.bt") == 0)) {
+ BT_DBG("%s is terminated", name);
+ if (_bt_check_terminating_condition() == TRUE && factory_test_mode == FALSE) {
+ _bt_disable_adapter();
+ _bt_disable_adapter_le();
+ _bt_core_terminate();
}
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-DBusGProxy *_bt_core_register_event_filter(DBusGConnection *g_conn,
- BtCore *bt_core)
+static void __bt_core_event_filter(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
- DBusError dbus_error;
- DBusConnection *conn;
- DBusGProxy *proxy;
- GError *err = NULL;
- guint result = 0;
-
- if (g_conn == NULL)
- return NULL;
+ if (!__is_interface_and_signal_valid(interface_name, signal_name))
+ return;
- conn = dbus_g_connection_get_connection(g_conn);
- if (conn == NULL)
- return NULL;
+ if (!g_strcmp0(signal_name, "InterfacesAdded")) {
+ char *obj_path = NULL;
+ GVariant *optional_param;
- proxy = dbus_g_proxy_new_for_name(g_conn, DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
- if (proxy == NULL) {
- BT_ERR("proxy is NULL");
- return NULL;
- }
+ g_variant_get(parameters, "(&o@a{sa{sv}})",
+ &obj_path, &optional_param);
- if (!dbus_g_proxy_call(proxy, "RequestName", &err, G_TYPE_STRING,
- BT_CORE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID,
- G_TYPE_UINT, &result, G_TYPE_INVALID)) {
- if (err != NULL) {
- BT_ERR("RequestName RPC failed[%s]\n", err->message);
- g_error_free(err);
- }
- g_object_unref(proxy);
- return NULL;
- }
-
- if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- BT_ERR("Failed to get the primary well-known name.\n");
- g_object_unref(proxy);
- return NULL;
- }
+ if (g_strcmp0(obj_path, "/org/bluez/hci0") == 0)
+ _bt_core_adapter_added_cb();
- if (!dbus_connection_add_filter(conn, __bt_core_event_filter,
- NULL, NULL)) {
- BT_ERR("Fail to add filter");
- g_object_unref(proxy);
- return NULL;
- }
+ } else if (!g_strcmp0(signal_name, "InterfacesRemoved")) {
+ char *obj_path = NULL;
+ GVariant *optional_param;
- dbus_error_init(&dbus_error);
+ g_variant_get(parameters, "(&o@as)", &obj_path,
+ &optional_param);
- dbus_bus_add_match(conn,
- "type='signal',interface='org.freedesktop.DBus'"
- ",member='NameOwnerChanged'",
- &dbus_error);
+ if (g_strcmp0(obj_path, "/org/bluez/hci0") == 0)
+ _bt_core_adapter_removed_cb();
- if (dbus_error_is_set(&dbus_error)) {
- BT_ERR("Fail to add match: %s\n", dbus_error.message);
- dbus_error_free(&dbus_error);
- g_object_unref(proxy);
- return NULL;
- }
+ } else { /* NameOwnerChanged */
+ const char *name = NULL;
+ const char *old_owner = NULL;
+ const char *new_owner = NULL;
- dbus_bus_add_match(conn,
- "type='signal',interface='org.freedesktop.DBus.ObjectManager'"
- ",member='InterfacesAdded'",
- &dbus_error);
+ g_variant_get(parameters, "(&s&s&s)", &name, &old_owner,
+ &new_owner);
- if (dbus_error_is_set(&dbus_error)) {
- BT_ERR("Fail to add match: %s\n", dbus_error.message);
- dbus_error_free(&dbus_error);
- g_object_unref(proxy);
- return NULL;
+ if (new_owner != NULL && *new_owner == '\0')
+ __handle_name_owner_changed(name);
}
+}
- dbus_bus_add_match(conn,
- "type='signal',interface='org.freedesktop.DBus.ObjectManager'"
- ",member='InterfacesRemoved'",
- &dbus_error);
-
- if (dbus_error_is_set(&dbus_error)) {
- BT_ERR("Fail to add match: %s\n", dbus_error.message);
- dbus_error_free(&dbus_error);
- g_object_unref(proxy);
- return NULL;
+gboolean _bt_core_register_dbus(void)
+{
+ GError *error = NULL;
+ guint owner_id;
+ GDBusNodeInfo *node_info;
+ gchar *path;
+ GDBusConnection *conn;
+
+ conn = _bt_core_get_gdbus_connection();
+ if (!conn)
+ return FALSE;
+
+ owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+ BT_CORE_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL, NULL, NULL,
+ NULL, NULL);
+
+ BT_DBG("owner_id is [%d]", owner_id);
+
+ node_info = __bt_core_create_node_info(bt_core_introspection_xml);
+ if (node_info == NULL)
+ return FALSE;
+
+ path = g_strdup(BT_CORE_PATH);
+ BT_DBG("path is [%s]", path);
+
+ obj_id = g_dbus_connection_register_object(conn, path,
+ node_info->interfaces[0],
+ &method_table,
+ NULL, NULL, &error);
+ g_dbus_node_info_unref(node_info);
+ if (obj_id == 0) {
+ BT_ERR("Failed to register: %s", error->message);
+ g_error_free(error);
+ g_free(path);
+ return FALSE;
}
- dbus_g_connection_register_g_object(g_conn, BT_CORE_PATH,
- G_OBJECT(bt_core));
-
- return proxy;
+ g_free(path);
+
+ sig_id1 = g_dbus_connection_signal_subscribe(conn,
+ NULL, "org.freedesktop.DBus",
+ "NameOwnerChanged", NULL, NULL, 0,
+ __bt_core_event_filter, NULL, NULL);
+ sig_id2 = g_dbus_connection_signal_subscribe(conn,
+ NULL, "org.freedesktop.DBus.ObjectManager",
+ "InterfacesAdded", NULL, NULL,
+ 0, __bt_core_event_filter, NULL, NULL);
+ sig_id2 = g_dbus_connection_signal_subscribe(conn,
+ NULL, "org.freedesktop.DBus.ObjectManager",
+ "InterfacesRemoved", NULL,
+ NULL, 0, __bt_core_event_filter, NULL, NULL);
+
+ return TRUE;
}
-void _bt_unregister_event_filter(DBusGConnection *g_conn,
- BtCore *bt_core,
- DBusGProxy *dbus_proxy)
+void _bt_core_unregister_dbus(void)
{
- DBusConnection *conn;
+ GDBusConnection *conn;
- if (g_conn == NULL ||
- bt_core == NULL ||
- dbus_proxy == NULL) {
- BT_ERR("Invalid parameter");
- return;
- }
-
- conn = dbus_g_connection_get_connection(g_conn);
+ BT_DBG("");
- dbus_connection_remove_filter(conn, __bt_core_event_filter, NULL);
+ conn = _bt_core_get_gdbus_connection();
+ if (!conn)
+ return;
- dbus_g_connection_unregister_g_object(g_conn, G_OBJECT(bt_core));
+ if (obj_id > 0) {
+ g_dbus_connection_unregister_object(conn, obj_id);
+ obj_id = 0;
+ }
- g_object_unref(bt_core);
- g_object_unref(dbus_proxy);
+ if (sig_id1 > 0) {
+ g_dbus_connection_signal_unsubscribe(conn, sig_id1);
+ sig_id1 = 0;
+ }
+ if (sig_id2 > 0) {
+ g_dbus_connection_signal_unsubscribe(conn, sig_id2);
+ sig_id2 = 0;
+ }
+ if (sig_id3 > 0) {
+ g_dbus_connection_signal_unsubscribe(conn, sig_id3);
+ sig_id3 = 0;
+ }
}
-