summaryrefslogtreecommitdiff
path: root/src/dbus-common.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2010-10-26 15:48:59 -0400
committerJohan Hedberg <johan.hedberg@nokia.com>2010-10-26 15:48:59 -0400
commita67e1d8cea5cd07e519b38a345975970e62b38d7 (patch)
tree6c8a64ece25b8c57923ff4cfb6eaee6d3f2b8b56 /src/dbus-common.c
parent91e068319e23b8a7a5f25c195eb81c4ef03b8eff (diff)
downloadbluez-a67e1d8cea5cd07e519b38a345975970e62b38d7.tar.gz
Simplify D-Bus connection handling and move it to main.c
The reconnection logic for the system bus doesn't make much sense. If the system bus daemon dies so does most useful system functionality. Since the code for handling D-Bus setup and cleanup is very simple after this removal it makes sense to move it to main.c and make the functions static.
Diffstat (limited to 'src/dbus-common.c')
-rw-r--r--src/dbus-common.c109
1 files changed, 0 insertions, 109 deletions
diff --git a/src/dbus-common.c b/src/dbus-common.c
index 6fe0940c4..7b4653547 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -49,117 +49,8 @@
#include "event.h"
#include "dbus-common.h"
-#define BLUEZ_NAME "org.bluez"
-
-#define RECONNECT_RETRY_TIMEOUT 5000
-
static DBusConnection *connection = NULL;
-static gboolean system_bus_reconnect(void *data)
-{
- DBusConnection *conn = get_dbus_connection();
- struct hci_dev_list_req *dl = NULL;
- struct hci_dev_req *dr;
- int sk, i;
- gboolean ret_val = TRUE;
-
- if (conn) {
- if (dbus_connection_get_is_connected(conn))
- return FALSE;
- }
-
- if (hcid_dbus_init() < 0)
- return TRUE;
-
- /* Create and bind HCI socket */
- sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
- if (sk < 0) {
- error("Can't open HCI socket: %s (%d)",
- strerror(errno), errno);
- return TRUE;
- }
-
- dl = g_malloc0(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
-
- dl->dev_num = HCI_MAX_DEV;
- dr = dl->dev_req;
-
- if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) {
- info("Can't get device list: %s (%d)",
- strerror(errno), errno);
- goto failed;
- }
-
- /* reset the default device */
- manager_set_default_adapter(-1);
-
- /* FIXME: it shouldn't be needed to register adapters again */
- for (i = 0; i < dl->dev_num; i++, dr++)
- manager_register_adapter(dr->dev_id, TRUE);
-
- ret_val = FALSE;
-
-failed:
- if (sk >= 0)
- close(sk);
-
- g_free(dl);
-
- return ret_val;
-}
-
-static void disconnect_callback(DBusConnection *conn, void *user_data)
-{
- set_dbus_connection(NULL);
-
- g_timeout_add(RECONNECT_RETRY_TIMEOUT,
- system_bus_reconnect, NULL);
-}
-
-void hcid_dbus_exit(void)
-{
- DBusConnection *conn = get_dbus_connection();
-
- if (!conn || !dbus_connection_get_is_connected(conn))
- return;
-
- manager_cleanup(conn, "/");
-
- set_dbus_connection(NULL);
-
- dbus_connection_unref(conn);
-}
-
-int hcid_dbus_init(void)
-{
- DBusConnection *conn;
- DBusError err;
-
- dbus_error_init(&err);
-
- conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, BLUEZ_NAME, &err);
- if (!conn) {
- if (dbus_error_is_set(&err)) {
- dbus_error_free(&err);
- return -EIO;
- }
- return -EALREADY;
- }
-
- if (g_dbus_set_disconnect_function(conn, disconnect_callback,
- NULL, NULL) == FALSE) {
- dbus_connection_unref(conn);
- return -EIO;
- }
-
- if (!manager_init(conn, "/"))
- return -EIO;
-
- set_dbus_connection(conn);
-
- return 0;
-}
-
static void append_variant(DBusMessageIter *iter, int type, void *val)
{
DBusMessageIter value;