summaryrefslogtreecommitdiff
path: root/profiles/alert
diff options
context:
space:
mode:
authorEder Ruiz Maria <eder.ruiz@openbossa.org>2012-10-02 16:24:35 -0400
committerJohan Hedberg <johan.hedberg@intel.com>2012-10-03 22:25:43 +0300
commit82c8c8164ae3ec925286f7a1eeedbfb321e5431f (patch)
tree4fc21950d1dc7d43b157b81232415380dad1c4d2 /profiles/alert
parente98204d2d9395f9aed59cc33593e864ed954b6d0 (diff)
downloadbluez-82c8c8164ae3ec925286f7a1eeedbfb321e5431f.tar.gz
alert: Automatically unregister alert when agent leaves D-Bus
Diffstat (limited to 'profiles/alert')
-rw-r--r--profiles/alert/server.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/profiles/alert/server.c b/profiles/alert/server.c
index 3b277030a..5cf750c77 100644
--- a/profiles/alert/server.c
+++ b/profiles/alert/server.c
@@ -84,6 +84,7 @@ struct alert_data {
const char *category;
char *srv;
char *path;
+ guint watcher;
};
static GSList *registered_alerts = NULL;
@@ -113,6 +114,9 @@ static void alert_data_destroy(gpointer user_data)
{
struct alert_data *alert = user_data;
+ if (alert->watcher)
+ g_dbus_remove_watch(btd_get_dbus_connection(), alert->watcher);
+
g_free(alert->srv);
g_free(alert->path);
g_free(alert);
@@ -210,6 +214,16 @@ static gboolean valid_count(const char *category, uint16_t count)
return FALSE;
}
+static void watcher_disconnect(DBusConnection *conn, void *user_data)
+{
+ struct alert_data *alert = user_data;
+
+ DBG("Category %s was disconnected", alert->category);
+
+ registered_alerts = g_slist_remove(registered_alerts, alert);
+ alert_data_destroy(alert);
+}
+
static DBusMessage *register_alert(DBusConnection *conn, DBusMessage *msg,
void *data)
{
@@ -238,6 +252,15 @@ static DBusMessage *register_alert(DBusConnection *conn, DBusMessage *msg,
alert->srv = g_strdup(sender);
alert->path = g_strdup(path);
alert->category = category;
+ alert->watcher = g_dbus_add_disconnect_watch(conn, alert->srv,
+ watcher_disconnect, alert, NULL);
+
+ if (alert->watcher == 0) {
+ alert_data_destroy(alert);
+ DBG("Could not register disconnect watcher");
+ return btd_error_failed(msg,
+ "Could not register disconnect watcher");
+ }
registered_alerts = g_slist_append(registered_alerts, alert);