summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorPaulo Borges <paulo.borges@openbossa.org>2013-04-19 19:19:04 -0300
committerDenis Kenzior <denkenz@gmail.com>2013-04-22 03:54:24 -0500
commit9332299bb7de7534e8e0d37ae3d1580d45f29b48 (patch)
tree076ca202d6ee3824757c5e2506e8c0badd840b24 /plugins
parentd062d485d6d88af8ef5612a6edb964b2acae7ed2 (diff)
downloadofono-9332299bb7de7534e8e0d37ae3d1580d45f29b48.tar.bz2
hfp_ag_bluez5: Add watch for G_IO_HUP when connect
A watch to G_IO_HUP is added to remove the file descriptor when the emulator is automatically disconnected when its GAtServer closes. We use a dupped file descriptor because the events aren't delivered to the file descriptor who originated them.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/hfp_ag_bluez5.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index bbced263..a0203b13 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -59,12 +59,24 @@ static void connection_destroy(gpointer data)
close(fd);
}
+static gboolean io_hup_cb(GIOChannel *io, GIOCondition cond, gpointer data)
+{
+ char *device = data;
+
+ DBG("Remove %s", device);
+
+ g_hash_table_remove(connection_hash, device);
+
+ return FALSE;
+}
+
static DBusMessage *profile_new_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessageIter entry;
const char *device;
- int fd;
+ GIOChannel *io;
+ int fd, fd_dup;
struct ofono_emulator *em;
struct ofono_modem *modem;
@@ -111,6 +123,15 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
ofono_emulator_register(em, fd);
+ fd_dup = dup(fd);
+ io = g_io_channel_unix_new(fd_dup);
+ g_io_add_watch_full(io, G_PRIORITY_DEFAULT, G_IO_HUP, io_hup_cb,
+ g_strdup(device), g_free);
+ g_io_channel_unref(io);
+
+ g_hash_table_insert(connection_hash, g_strdup(device),
+ GINT_TO_POINTER(fd_dup));
+
return dbus_message_new_method_return(msg);
invalid: