summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustavo F. Padovan <padovan@profusion.mobi>2010-02-15 18:40:26 -0200
committerDenis Kenzior <denkenz@gmail.com>2010-02-15 15:03:31 -0600
commitf738a84588d3454aa036890040a543ede91ed556 (patch)
tree25d6488d990f9c23f660eb7a256f0aa75b7b8ca0
parent0bac79f1a21f12ca0e3f30ade7b6bf5b85549700 (diff)
downloadofono-f738a84588d3454aa036890040a543ede91ed556.tar.bz2
hfp: remove modems if bluetoothd exits unexpectedly
-rw-r--r--plugins/hfp.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/plugins/hfp.c b/plugins/hfp.c
index 411cfc1c..7b86bc8a 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -894,6 +894,23 @@ done:
dbus_message_unref(reply);
}
+static gboolean hfp_remove_each_modem(gpointer key, gpointer value, gpointer user_data)
+{
+ struct ofono_modem *modem = value;
+
+ ofono_modem_remove(modem);
+
+ return TRUE;
+}
+
+static void bluetooth_disconnect(DBusConnection *connection, void *user_data)
+{
+ if (uuid_hash == NULL)
+ return;
+
+ g_hash_table_foreach_remove(uuid_hash, hfp_remove_each_modem, NULL);
+}
+
static int hfp_register_ofono_handsfree(struct ofono_modem *modem)
{
const char *obj_path = ofono_modem_get_path(modem);
@@ -1081,6 +1098,7 @@ static struct ofono_modem_driver hfp_driver = {
.post_sim = hfp_post_sim,
};
+static guint bluetooth_exit_watch;
static guint adapter_added_watch;
static guint adapter_removed_watch;
static guint uuid_watch;
@@ -1094,6 +1112,9 @@ static int hfp_init()
connection = ofono_dbus_get_connection();
+ bluetooth_exit_watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
+ NULL, bluetooth_disconnect, NULL, NULL);
+
adapter_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
BLUEZ_MANAGER_INTERFACE,
"AdapterAdded",
@@ -1109,8 +1130,8 @@ static int hfp_init()
"PropertyChanged",
property_changed, NULL, NULL);
- if (adapter_added_watch == 0 || adapter_removed_watch == 0||
- uuid_watch == 0) {
+ if (bluetooth_exit_watch == 0 || adapter_added_watch == 0 ||
+ adapter_removed_watch == 0|| uuid_watch == 0) {
err = -EIO;
goto remove;
}
@@ -1133,6 +1154,7 @@ static int hfp_init()
return 0;
remove:
+ g_dbus_remove_watch(connection, bluetooth_exit_watch);
g_dbus_remove_watch(connection, adapter_added_watch);
g_dbus_remove_watch(connection, adapter_removed_watch);
g_dbus_remove_watch(connection, uuid_watch);
@@ -1148,6 +1170,7 @@ remove:
static void hfp_exit()
{
+ g_dbus_remove_watch(connection, bluetooth_exit_watch);
g_dbus_remove_watch(connection, adapter_added_watch);
g_dbus_remove_watch(connection, adapter_removed_watch);
g_dbus_remove_watch(connection, uuid_watch);