* [PATCH v5 1/3] hfp_ag_bluez5: Create a hash to store connections
@ 2013-04-19 22:19 Paulo Borges
2013-04-19 22:19 ` [PATCH v5 2/3] hfp_ag_bluez5: Add watch for G_IO_HUP when connect Paulo Borges
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Paulo Borges @ 2013-04-19 22:19 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]
We need to store active connections so we can disconnect them at
RequestDisconnect().
When we remove a connection from the hash, we also close it.
---
plugins/hfp_ag_bluez5.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index c171c87..bbced26 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -48,6 +48,16 @@
static guint modemwatch_id;
static GList *modems;
static GHashTable *sim_hash = NULL;
+static GHashTable *connection_hash;
+
+static void connection_destroy(gpointer data)
+{
+ int fd = GPOINTER_TO_INT(data);
+
+ DBG("fd %d", fd);
+
+ close(fd);
+}
static DBusMessage *profile_new_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
@@ -251,6 +261,9 @@ static int hfp_ag_init(void)
modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
__ofono_modem_foreach(call_modemwatch, NULL);
+ connection_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, connection_destroy);
+
return 0;
}
@@ -262,6 +275,8 @@ static void hfp_ag_exit(void)
g_dbus_unregister_interface(conn, HFP_AG_EXT_PROFILE_PATH,
BLUEZ_PROFILE_INTERFACE);
+ g_hash_table_destroy(connection_hash);
+
g_list_free(modems);
g_hash_table_foreach_remove(sim_hash, sim_watch_remove, NULL);
g_hash_table_destroy(sim_hash);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 2/3] hfp_ag_bluez5: Add watch for G_IO_HUP when connect
2013-04-19 22:19 [PATCH v5 1/3] hfp_ag_bluez5: Create a hash to store connections Paulo Borges
@ 2013-04-19 22:19 ` Paulo Borges
2013-04-22 8:56 ` Denis Kenzior
2013-04-19 22:19 ` [PATCH v5 3/3] hfp_ag_bluez5: Implement RequestDisconnection() Paulo Borges
2013-04-22 8:55 ` [PATCH v5 1/3] hfp_ag_bluez5: Create a hash to store connections Denis Kenzior
2 siblings, 1 reply; 6+ messages in thread
From: Paulo Borges @ 2013-04-19 22:19 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]
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.
---
plugins/hfp_ag_bluez5.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index bbced26..a0203b1 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:
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 3/3] hfp_ag_bluez5: Implement RequestDisconnection()
2013-04-19 22:19 [PATCH v5 1/3] hfp_ag_bluez5: Create a hash to store connections Paulo Borges
2013-04-19 22:19 ` [PATCH v5 2/3] hfp_ag_bluez5: Add watch for G_IO_HUP when connect Paulo Borges
@ 2013-04-19 22:19 ` Paulo Borges
2013-04-22 8:56 ` Denis Kenzior
2013-04-22 8:55 ` [PATCH v5 1/3] hfp_ag_bluez5: Create a hash to store connections Denis Kenzior
2 siblings, 1 reply; 6+ messages in thread
From: Paulo Borges @ 2013-04-19 22:19 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1505 bytes --]
When a RequestDisconnect() is received, the socket must be closed.
This way, the related emulator will be freed.
---
plugins/hfp_ag_bluez5.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index a0203b1..59e84d2 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -162,11 +162,35 @@ static DBusMessage *profile_cancel(DBusConnection *conn,
static DBusMessage *profile_disconnection(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
+ DBusMessageIter iter;
+ const char *device;
+ gpointer fd;
+
DBG("Profile handler RequestDisconnection");
- return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
- ".NotImplemented",
- "Implementation not provided");
+ if (!dbus_message_iter_init(msg, &iter))
+ goto invalid;
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+ goto invalid;
+
+ dbus_message_iter_get_basic(&iter, &device);
+
+ DBG("%s", device);
+
+ fd = g_hash_table_lookup(connection_hash, device);
+ if (fd == NULL)
+ goto invalid;
+
+ shutdown(GPOINTER_TO_INT(fd), SHUT_RDWR);
+
+ g_hash_table_remove(connection_hash, device);
+
+ return dbus_message_new_method_return(msg);
+
+invalid:
+ return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE ".Rejected",
+ "Invalid arguments in method call");
}
static const GDBusMethodTable profile_methods[] = {
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/3] hfp_ag_bluez5: Create a hash to store connections
2013-04-19 22:19 [PATCH v5 1/3] hfp_ag_bluez5: Create a hash to store connections Paulo Borges
2013-04-19 22:19 ` [PATCH v5 2/3] hfp_ag_bluez5: Add watch for G_IO_HUP when connect Paulo Borges
2013-04-19 22:19 ` [PATCH v5 3/3] hfp_ag_bluez5: Implement RequestDisconnection() Paulo Borges
@ 2013-04-22 8:55 ` Denis Kenzior
2 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2013-04-22 8:55 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 371 bytes --]
Hi Paulo,
On 04/19/2013 05:19 PM, Paulo Borges wrote:
> We need to store active connections so we can disconnect them at
> RequestDisconnect().
>
> When we remove a connection from the hash, we also close it.
> ---
> plugins/hfp_ag_bluez5.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
Patch has been applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 2/3] hfp_ag_bluez5: Add watch for G_IO_HUP when connect
2013-04-19 22:19 ` [PATCH v5 2/3] hfp_ag_bluez5: Add watch for G_IO_HUP when connect Paulo Borges
@ 2013-04-22 8:56 ` Denis Kenzior
0 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2013-04-22 8:56 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 499 bytes --]
Hi Paulo,
On 04/19/2013 05:19 PM, Paulo Borges wrote:
> 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.
> ---
> plugins/hfp_ag_bluez5.c | 23 ++++++++++++++++++++++-
> 1 file changed, 22 insertions(+), 1 deletion(-)
>
Patch has been applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 3/3] hfp_ag_bluez5: Implement RequestDisconnection()
2013-04-19 22:19 ` [PATCH v5 3/3] hfp_ag_bluez5: Implement RequestDisconnection() Paulo Borges
@ 2013-04-22 8:56 ` Denis Kenzior
0 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2013-04-22 8:56 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 365 bytes --]
Hi Paulo,
On 04/19/2013 05:19 PM, Paulo Borges wrote:
> When a RequestDisconnect() is received, the socket must be closed.
> This way, the related emulator will be freed.
> ---
> plugins/hfp_ag_bluez5.c | 30 +++++++++++++++++++++++++++---
> 1 file changed, 27 insertions(+), 3 deletions(-)
>
Patch has been applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-04-22 8:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-19 22:19 [PATCH v5 1/3] hfp_ag_bluez5: Create a hash to store connections Paulo Borges
2013-04-19 22:19 ` [PATCH v5 2/3] hfp_ag_bluez5: Add watch for G_IO_HUP when connect Paulo Borges
2013-04-22 8:56 ` Denis Kenzior
2013-04-19 22:19 ` [PATCH v5 3/3] hfp_ag_bluez5: Implement RequestDisconnection() Paulo Borges
2013-04-22 8:56 ` Denis Kenzior
2013-04-22 8:55 ` [PATCH v5 1/3] hfp_ag_bluez5: Create a hash to store connections Denis Kenzior
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox