hfp: create modem for new devices paired on runtime
PATCH 1/1 hfp: create modem for new devices paired on runtime
It listens the Paired property to create a modem to the recently paired devices.
--- plugins/hfp.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 59 insertions(+), 1 deletions(-)
plugins/hfp.c +59 -1
@@ -594,6 +594,55 @@ static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,return TRUE; } +static gboolean paired_added (DBusConnection *connection,DBusMessage *message, +void *user_data) +{ +DBusError err; +const char *device, *paired; +DBusMessageIter iter, variant; +int ret, value; + +dbus_error_init (&err); + +if (dbus_message_get_args (message, &err,DBUS_TYPE_STRING , + &paired,DBUS_TYPE_INVALID ) == FALSE) { +if (dbus_error_is_set (&err) == TRUE) { +ofono_error ("%s" , err.message); +dbus_error_free (&err); + } + +return FALSE; + } + +if (strcmp (paired,"Paired" )) +return TRUE; + +dbus_message_iter_init (message, &iter); +if (dbus_message_iter_get_arg_type (&iter) ==DBUS_TYPE_STRING ) { + +if (!dbus_message_iter_next (&iter)) +return FALSE; + +dbus_message_iter_recurse (&iter, &variant); +dbus_message_iter_get_basic (&variant, &value); + +if (!value) +return TRUE; + } + + device =dbus_message_get_path (message); + ret =send_method_call (BLUEZ_SERVICE , device, +BLUEZ_DEVICE_INTERFACE ,"GetProperties" , + get_properties_cb, (void *)device, +DBUS_TYPE_INVALID ); +if (ret <0 ) { +ofono_error ("GetProperties failed(%d)" , ret); +return FALSE; + } + +return TRUE; +} +static void list_adapters_cb (DBusPendingCall *call,gpointer user_data) {DBusError err;
@@ -802,6 +851,7 @@ static struct ofono_modem_driver hfp_driver = { };static guint added_watch; +static guint paired_watch;static int hfp_init (void ) {
@@ -817,7 +867,13 @@ static int hfp_init(void)"AdapterAdded" , adapter_added, NULL, NULL); -if (added_watch ==0 ) { + paired_watch =g_dbus_add_signal_watch (connection,NULL ,NULL , +BLUEZ_DEVICE_INTERFACE , +"PropertyChanged" , + paired_added,NULL ,NULL ); + + +if (added_watch ==0 || paired_watch ==0 ) { err = -EIO ; goto remove; }
@@ -832,6 +888,7 @@ static int hfp_init(void) remove:g_dbus_remove_watch (connection, added_watch); +g_dbus_remove_watch (connection, paired_watch);dbus_connection_unref (connection);
@@ -841,6 +898,7 @@ remove:static void hfp_exit (void ) {g_dbus_remove_watch (connection, added_watch); +g_dbus_remove_watch (connection, paired_watch);ofono_modem_driver_unregister (&hfp_driver); }
Signature · 1 line
1.6.4.4
Hi Gustavo,
Quoted 5 lines
It listens the Paired property to create a modem to the recently paired devices.
--- plugins/hfp.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files
changed,
Quoted 24 lines
59 insertions(+), 1 deletions(-)
plugins/hfp.c +13
-0@@ -594,6 +594,55 @@ static gboolean adapter_added(DBusConnection *connection, DBusMessage *message, return TRUE; } +static gboolean paired_added (DBusConnection *connection,DBusMessage *message, + void *user_data) +{ +DBusError err; +const char *device, *paired; +DBusMessageIter iter, variant; +int ret, value; + +dbus_error_init (&err); + +if (dbus_message_get_args (message, &err,DBUS_TYPE_STRING , + &paired,DBUS_TYPE_INVALID ) == FALSE) { +if (dbus_error_is_set (&err) == TRUE) { +ofono_error ("%s" , err.message);
plugins/hfp.c static gboolean adapter_added(DBusConnection · line 620
Quoted 10 lines
plugins/hfp.c +10
-0+dbus_error_free (&err); + } + +return FALSE; + } + +if (strcmp (paired,"Paired" )) +return TRUE; + +dbus_message_iter_init (message, &iter);
Why can't we do something like? dbus_message_iter_init();
if (dbus_message_iter_get_arg_type(&iter) != STRING)
return;
dbus_message_iter_get_basic(&iter, &property);
if (g_str_equal(property, "Paired") == FALSE)
return;
I really don't like mixing the two ways of parsing the message and this way seems cleaner.
plugins/hfp.c static gboolean adapter_added(DBusConnection *connection, DBusMessage *message, · line 631
Quoted 11 lines
plugins/hfp.c +11
-0+if (dbus_message_iter_get_arg_type (&iter) ==DBUS_TYPE_STRING ) { + +if (!dbus_message_iter_next (&iter)) +return FALSE; + +dbus_message_iter_recurse (&iter, &variant); +dbus_message_iter_get_basic (&variant, &value); + +if (!value) +return TRUE; + }
You might want to check the second argument is indeed a DBUS_TYPE_VARIANT and the value of the variant is what you're expecting.
We really need to make a function for this in gdbus.
Regards,
-Denis