Clients should be disconnected when VoiceCall atom is unregistered
---
 plugins/hfp_ag.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/plugins/hfp_ag.c b/plugins/hfp_ag.c
index cbf3ccd..5fba13d 100644
--- a/plugins/hfp_ag.c
+++ b/plugins/hfp_ag.c
@@ -40,7 +40,7 @@
 static struct server *server;
 static guint modemwatch_id;
 static GList *modems;
-static guint channel_watch;
+static GSList *client_io;
 
 static const gchar *hfp_ag_record =
 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
@@ -89,6 +89,8 @@ static const gchar *hfp_ag_record =
 static gboolean hfp_ag_disconnect_cb(GIOChannel *io, GIOCondition cond,
                                                        gpointer user_data)
 {
+       client_io = g_slist_remove(client_io, io);
+
        return FALSE;
 }
 
@@ -118,8 +120,9 @@ static void hfp_ag_connect_cb(GIOChannel *io, GError *err, 
gpointer user_data)
        fd = g_io_channel_unix_get_fd(io);
        ofono_emulator_register(em, fd);
 
-       channel_watch = g_io_add_watch(io, G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+       g_io_add_watch(io, G_IO_NVAL | G_IO_HUP | G_IO_ERR,
                                        hfp_ag_disconnect_cb, NULL);
+       client_io = g_slist_append(client_io, io);
 
        return;
 
@@ -143,9 +146,18 @@ static void voicecall_watch(struct ofono_atom *atom,
                                                        NULL);
        } else {
                modems = g_list_remove(modems, modem);
-               if (modems == NULL &&  server != NULL) {
-                       bluetooth_unregister_server(server);
-                       server = NULL;
+               if (modems == NULL) {
+                       if (server != NULL) {
+                               bluetooth_unregister_server(server);
+                               server = NULL;
+                       }
+
+                       while (client_io) {
+                               g_io_channel_shutdown(client_io->data, TRUE,
+                                                       NULL);
+                               client_io = g_slist_remove(client_io,
+                                                       client_io->data);
+                       }
                }
        }
 }
-- 
1.7.1

_______________________________________________
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono

Reply via email to