* [PATCH 1/6] bluetooth: Move functions from hfp.c to bluetooth.c @ 2010-06-20 8:51 Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 2/6] bluetooth: add device_properties_cb() and has_uuid() Gustavo F. Padovan 2010-06-22 3:56 ` [PATCH 1/6] bluetooth: Move functions from hfp.c to bluetooth.c Denis Kenzior 0 siblings, 2 replies; 8+ messages in thread From: Gustavo F. Padovan @ 2010-06-20 8:51 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 3961 bytes --] The part that call device_properties_cb is commented to permit this patch compile. device_properties_cb() will be changed, so it will have separated patch. --- plugins/bluetooth.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 122 insertions(+), 0 deletions(-) diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c index 0b1b560..e27982b 100644 --- a/plugins/bluetooth.c +++ b/plugins/bluetooth.c @@ -199,6 +199,124 @@ done: g_slist_free(prop_handlers); } +static void parse_string(DBusMessageIter *iter, gpointer user_data) +{ + char **str = user_data; + int arg_type = dbus_message_iter_get_arg_type(iter); + + if (arg_type != DBUS_TYPE_OBJECT_PATH && arg_type != DBUS_TYPE_STRING) + return; + + dbus_message_iter_get_basic(iter, str); +} + +static void parse_devices(DBusMessageIter *array, gpointer user_data) +{ + DBusMessageIter value; + GSList **device_list = user_data; + + DBG(""); + + if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(array, &value); + + while (dbus_message_iter_get_arg_type(&value) + == DBUS_TYPE_OBJECT_PATH) { + const char *path; + + dbus_message_iter_get_basic(&value, &path); + + *device_list = g_slist_prepend(*device_list, (gpointer) path); + + dbus_message_iter_next(&value); + } +} + +static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data) +{ + const char *path = user_data; + DBusMessage *reply; + GSList *device_list = NULL; + GSList *l; + const char *addr; + + reply = dbus_pending_call_steal_reply(call); + + if (dbus_message_is_error(reply, DBUS_ERROR_SERVICE_UNKNOWN)) { + DBG("Bluetooth daemon is apparently not available."); + goto done; + } + + bluetooth_parse_properties(reply, "Devices", parse_devices, &device_list, + "Address", parse_string, &addr, NULL); + + DBG("Adapter Address: %s, Path: %s", addr, path); + g_hash_table_insert(adapter_address_hash, + g_strdup(path), g_strdup(addr)); + + for (l = device_list; l; l = l->next) { + /* + const char *device = l->data; + + bluetooth_send_with_reply(device, BLUEZ_DEVICE_INTERFACE, + "GetProperties", device_properties_cb, + g_strdup(device), g_free, -1, DBUS_TYPE_INVALID); + */ + } + +done: + g_slist_free(device_list); + dbus_message_unref(reply); +} + +static void parse_adapters(DBusMessageIter *array, gpointer user_data) +{ + DBusMessageIter value; + + DBG(""); + + if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(array, &value); + + while (dbus_message_iter_get_arg_type(&value) + == DBUS_TYPE_OBJECT_PATH) { + const char *path; + + dbus_message_iter_get_basic(&value, &path); + + DBG("Calling GetProperties on %s", path); + + bluetooth_send_with_reply(path, BLUEZ_ADAPTER_INTERFACE, + "GetProperties", adapter_properties_cb, + g_strdup(path), g_free, -1, DBUS_TYPE_INVALID); + + dbus_message_iter_next(&value); + } +} + +static void manager_properties_cb(DBusPendingCall *call, gpointer user_data) +{ + DBusMessage *reply; + + reply = dbus_pending_call_steal_reply(call); + + if (dbus_message_is_error(reply, DBUS_ERROR_SERVICE_UNKNOWN)) { + DBG("Bluetooth daemon is apparently not available."); + goto done; + } + + DBG(""); + + bluetooth_parse_properties(reply, "Adapters", parse_adapters, NULL, NULL); + +done: + dbus_message_unref(reply); +} + int bluetooth_register_uuid(const char *uuid, struct bluetooth_profile *profile) { if (uuid_hash) @@ -215,6 +333,10 @@ int bluetooth_register_uuid(const char *uuid, struct bluetooth_profile *profile) done: g_hash_table_insert(uuid_hash, g_strdup(uuid), profile); + bluetooth_send_with_reply("/", BLUEZ_MANAGER_INTERFACE, "GetProperties", + manager_properties_cb, NULL, NULL, -1, + DBUS_TYPE_INVALID); + return 0; } -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/6] bluetooth: add device_properties_cb() and has_uuid() 2010-06-20 8:51 [PATCH 1/6] bluetooth: Move functions from hfp.c to bluetooth.c Gustavo F. Padovan @ 2010-06-20 8:51 ` Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 3/6] bluetooth: add watches for the bluetoothd service and adapters Gustavo F. Padovan 2010-06-22 3:56 ` [PATCH 1/6] bluetooth: Move functions from hfp.c to bluetooth.c Denis Kenzior 1 sibling, 1 reply; 8+ messages in thread From: Gustavo F. Padovan @ 2010-06-20 8:51 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 3026 bytes --] --- plugins/bluetooth.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 69 insertions(+), 2 deletions(-) diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c index e27982b..d635989 100644 --- a/plugins/bluetooth.c +++ b/plugins/bluetooth.c @@ -199,6 +199,28 @@ done: g_slist_free(prop_handlers); } +static void has_uuid(DBusMessageIter *array, gpointer user_data) +{ + gboolean *profiles = user_data; + DBusMessageIter value; + + if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(array, &value); + + while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { + const char *uuid; + + dbus_message_iter_get_basic(&value, &uuid); + + if (!strcasecmp(uuid, HFP_AG_UUID)) + *profiles |= HFP_AG; + + dbus_message_iter_next(&value); + } +} + static void parse_string(DBusMessageIter *iter, gpointer user_data) { char **str = user_data; @@ -210,6 +232,53 @@ static void parse_string(DBusMessageIter *iter, gpointer user_data) dbus_message_iter_get_basic(iter, str); } +static void device_properties_cb(DBusPendingCall *call, gpointer user_data) +{ + DBusMessage *reply; + int have_uuid = 0; + const char *path = user_data; + const char *adapter = NULL; + const char *adapter_addr = NULL; + const char *device_addr = NULL; + const char *alias = NULL; + struct bluetooth_profile *profile; + + reply = dbus_pending_call_steal_reply(call); + + if (dbus_message_is_error(reply, DBUS_ERROR_SERVICE_UNKNOWN)) { + DBG("Bluetooth daemon is apparently not available."); + goto done; + } + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { + if (!dbus_message_is_error(reply, DBUS_ERROR_UNKNOWN_METHOD)) + ofono_info("Error from GetProperties reply: %s", + dbus_message_get_error_name(reply)); + + goto done; + } + + bluetooth_parse_properties(reply, "UUIDs", has_uuid, &have_uuid, + "Adapter", parse_string, &adapter, + "Address", parse_string, &device_addr, + "Alias", parse_string, &alias, NULL); + + if (adapter) + adapter_addr = g_hash_table_lookup(adapter_address_hash, + adapter); + + if ((have_uuid & HFP_AG) && device_addr && adapter_addr) { + profile = g_hash_table_lookup(uuid_hash, HFP_AG_UUID); + if (!profile || !profile->create) + goto done; + + profile->create(path, device_addr, adapter_addr, alias); + } + +done: + dbus_message_unref(reply); +} + static void parse_devices(DBusMessageIter *array, gpointer user_data) { DBusMessageIter value; @@ -257,13 +326,11 @@ static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data) g_strdup(path), g_strdup(addr)); for (l = device_list; l; l = l->next) { - /* const char *device = l->data; bluetooth_send_with_reply(device, BLUEZ_DEVICE_INTERFACE, "GetProperties", device_properties_cb, g_strdup(device), g_free, -1, DBUS_TYPE_INVALID); - */ } done: -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/6] bluetooth: add watches for the bluetoothd service and adapters 2010-06-20 8:51 ` [PATCH 2/6] bluetooth: add device_properties_cb() and has_uuid() Gustavo F. Padovan @ 2010-06-20 8:51 ` Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 4/6] bluetooth: add PropertyChanged watch Gustavo F. Padovan 0 siblings, 1 reply; 8+ messages in thread From: Gustavo F. Padovan @ 2010-06-20 8:51 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 3401 bytes --] Exactly the same code from hfp.c --- plugins/bluetooth.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 78 insertions(+), 0 deletions(-) diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c index d635989..a398312 100644 --- a/plugins/bluetooth.c +++ b/plugins/bluetooth.c @@ -338,6 +338,34 @@ done: dbus_message_unref(reply); } +static gboolean adapter_added(DBusConnection *connection, DBusMessage *message, + void *user_data) +{ + const char *path; + int ret; + + dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, + DBUS_TYPE_INVALID); + + ret = bluetooth_send_with_reply(path, BLUEZ_ADAPTER_INTERFACE, + "GetProperties", adapter_properties_cb, g_strdup(path), + g_free, -1, DBUS_TYPE_INVALID); + + return TRUE; +} + +static gboolean adapter_removed(DBusConnection *connection, + DBusMessage *message, void *user_data) +{ + const char *path; + + if (dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, + DBUS_TYPE_INVALID) == TRUE) + g_hash_table_remove(adapter_address_hash, path); + + return TRUE; +} + static void parse_adapters(DBusMessageIter *array, gpointer user_data) { DBusMessageIter value; @@ -384,13 +412,53 @@ done: dbus_message_unref(reply); } +static void bluetooth_remove_all_modem(gpointer key, gpointer value, gpointer user_data) +{ + struct bluetooth_profile *profile = value; + + profile->remove_all(); +} + +static void bluetooth_disconnect(DBusConnection *connection, void *user_data) +{ + if (!uuid_hash) + return; + + g_hash_table_foreach(uuid_hash, bluetooth_remove_all_modem, NULL); +} + +static guint bluetooth_watch; +static guint adapter_added_watch; +static guint adapter_removed_watch; + int bluetooth_register_uuid(const char *uuid, struct bluetooth_profile *profile) { + int err; + if (uuid_hash) goto done; connection = ofono_dbus_get_connection(); + bluetooth_watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE, + NULL, bluetooth_disconnect, NULL, NULL); + + adapter_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL, + BLUEZ_MANAGER_INTERFACE, + "AdapterAdded", + adapter_added, NULL, NULL); + + adapter_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL, + BLUEZ_MANAGER_INTERFACE, + "AdapterRemoved", + adapter_removed, NULL, NULL); + + if (bluetooth_watch == 0 || adapter_added_watch == 0 || + adapter_removed_watch == 0) { + err = -EIO; + goto remove; + } + uuid_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); @@ -405,6 +473,12 @@ done: DBUS_TYPE_INVALID); return 0; + +remove: + g_dbus_remove_watch(connection, bluetooth_watch); + g_dbus_remove_watch(connection, adapter_added_watch); + g_dbus_remove_watch(connection, adapter_removed_watch); + return err; } void bluetooth_unregister_uuid(const char *uuid) @@ -414,6 +488,10 @@ void bluetooth_unregister_uuid(const char *uuid) if (g_hash_table_size(uuid_hash)) return; + g_dbus_remove_watch(connection, bluetooth_watch); + g_dbus_remove_watch(connection, adapter_added_watch); + g_dbus_remove_watch(connection, adapter_removed_watch); + g_hash_table_destroy(uuid_hash); g_hash_table_destroy(adapter_address_hash); uuid_hash = NULL; -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/6] bluetooth: add PropertyChanged watch 2010-06-20 8:51 ` [PATCH 3/6] bluetooth: add watches for the bluetoothd service and adapters Gustavo F. Padovan @ 2010-06-20 8:51 ` Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 5/6] hfp: use bluetooth helpers and remove similar code Gustavo F. Padovan 0 siblings, 1 reply; 8+ messages in thread From: Gustavo F. Padovan @ 2010-06-20 8:51 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 3930 bytes --] This one is a bit diferent from the hfp.c one, so a separated patch for it. --- plugins/bluetooth.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 75 insertions(+), 1 deletions(-) diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c index a398312..cb45b3f 100644 --- a/plugins/bluetooth.c +++ b/plugins/bluetooth.c @@ -303,6 +303,72 @@ static void parse_devices(DBusMessageIter *array, gpointer user_data) } } +static gboolean property_changed(DBusConnection *connection, DBusMessage *msg, + void *user_data) +{ + const char *property; + DBusMessageIter iter; + + dbus_message_iter_init(msg, &iter); + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) + return FALSE; + + dbus_message_iter_get_basic(&iter, &property); + if (g_str_equal(property, "UUIDs") == TRUE) { + int profiles = 0; + const char *path = dbus_message_get_path(msg); + DBusMessageIter variant; + + + if (!dbus_message_iter_next(&iter)) + return FALSE; + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) + return FALSE; + + dbus_message_iter_recurse(&iter, &variant); + + has_uuid(&variant, &profiles); + + /* We need the full set of properties to be able to create + * the modem properly, including Adapter and Alias, so + * refetch everything again + */ + if (profiles) + bluetooth_send_with_reply(path, BLUEZ_DEVICE_INTERFACE, + "GetProperties", device_properties_cb, + g_strdup(path), g_free, -1, + DBUS_TYPE_INVALID); + } else if (g_str_equal(property, "Alias") == TRUE) { + const char *path = dbus_message_get_path(msg); + struct bluetooth_profile *profile; + const char *alias = NULL; + DBusMessageIter variant; + GHashTableIter hash_iter; + gpointer key, value; + + if (!dbus_message_iter_next(&iter)) + return FALSE; + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) + return FALSE; + + dbus_message_iter_recurse(&iter, &variant); + + parse_string(&variant, &alias); + + g_hash_table_iter_init(&hash_iter, uuid_hash); + while (g_hash_table_iter_next(&hash_iter, &key, &value)) { + profile = value; + if (profile->set_alias) + profile->set_alias(path, alias); + } + } + + return TRUE; +} + static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data) { const char *path = user_data; @@ -430,6 +496,7 @@ static void bluetooth_disconnect(DBusConnection *connection, void *user_data) static guint bluetooth_watch; static guint adapter_added_watch; static guint adapter_removed_watch; +static guint property_watch; int bluetooth_register_uuid(const char *uuid, struct bluetooth_profile *profile) { @@ -453,8 +520,13 @@ int bluetooth_register_uuid(const char *uuid, struct bluetooth_profile *profile) "AdapterRemoved", adapter_removed, NULL, NULL); + property_watch = g_dbus_add_signal_watch(connection, NULL, NULL, + BLUEZ_DEVICE_INTERFACE, + "PropertyChanged", + property_changed, NULL, NULL); + if (bluetooth_watch == 0 || adapter_added_watch == 0 || - adapter_removed_watch == 0) { + adapter_removed_watch == 0 || property_watch == 0) { err = -EIO; goto remove; } @@ -478,6 +550,7 @@ remove: g_dbus_remove_watch(connection, bluetooth_watch); g_dbus_remove_watch(connection, adapter_added_watch); g_dbus_remove_watch(connection, adapter_removed_watch); + g_dbus_remove_watch(connection, property_watch); return err; } @@ -491,6 +564,7 @@ void bluetooth_unregister_uuid(const char *uuid) g_dbus_remove_watch(connection, bluetooth_watch); g_dbus_remove_watch(connection, adapter_added_watch); g_dbus_remove_watch(connection, adapter_removed_watch); + g_dbus_remove_watch(connection, property_watch); g_hash_table_destroy(uuid_hash); g_hash_table_destroy(adapter_address_hash); -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/6] hfp: use bluetooth helpers and remove similar code. 2010-06-20 8:51 ` [PATCH 4/6] bluetooth: add PropertyChanged watch Gustavo F. Padovan @ 2010-06-20 8:51 ` Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 6/6] bluetooth: make bluetooth.c not a plugin Gustavo F. Padovan 0 siblings, 1 reply; 8+ messages in thread From: Gustavo F. Padovan @ 2010-06-20 8:51 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 13309 bytes --] --- plugins/hfp.c | 379 ++++++--------------------------------------------------- 1 files changed, 36 insertions(+), 343 deletions(-) diff --git a/plugins/hfp.c b/plugins/hfp.c index 3297358..137e948 100644 --- a/plugins/hfp.c +++ b/plugins/hfp.c @@ -62,8 +62,7 @@ static const char *cmer_prefix[] = { "+CMER:", NULL }; static const char *chld_prefix[] = { "+CHLD:", NULL }; static DBusConnection *connection; -static GHashTable *uuid_hash = NULL; -static GHashTable *adapter_address_hash; +static GHashTable *modem_hash = NULL; static void hfp_debug(const char *str, void *user_data) { @@ -179,17 +178,6 @@ static void cmer_cb(gboolean ok, GAtResult *result, gpointer user_data) sevice_level_conn_established(modem); } -static void parse_string(DBusMessageIter *iter, gpointer user_data) -{ - char **str = user_data; - int arg_type = dbus_message_iter_get_arg_type(iter); - - if (arg_type != DBUS_TYPE_OBJECT_PATH && arg_type != DBUS_TYPE_STRING) - return; - - dbus_message_iter_get_basic(iter, str); -} - static void cind_status_cb(gboolean ok, GAtResult *result, gpointer user_data) { @@ -409,6 +397,10 @@ static int hfp_create_modem(const char *device, const char *dev_addr, struct hfp_data *data; char buf[256]; + /* We already have this device in our hash, ignore */ + if (g_hash_table_lookup(modem_hash, device) != NULL) + return -EALREADY; + ofono_info("Using device: %s, devaddr: %s, adapter: %s", device, dev_addr, adapter_addr); @@ -437,7 +429,7 @@ static int hfp_create_modem(const char *device, const char *dev_addr, ofono_modem_set_name(modem, alias); ofono_modem_register(modem); - g_hash_table_insert(uuid_hash, g_strdup(device), modem); + g_hash_table_insert(modem_hash, g_strdup(device), modem); return 0; @@ -448,292 +440,35 @@ free: return -ENOMEM; } -static void has_hfp_uuid(DBusMessageIter *array, gpointer user_data) -{ - gboolean *hfp = user_data; - DBusMessageIter value; - - if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) - return; - - dbus_message_iter_recurse(array, &value); - - while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { - const char *uuid; - - dbus_message_iter_get_basic(&value, &uuid); - - if (!strcasecmp(uuid, HFP_AG_UUID)) { - *hfp = TRUE; - return; - } - - dbus_message_iter_next(&value); - } -} - -static void device_properties_cb(DBusPendingCall *call, gpointer user_data) -{ - DBusMessage *reply; - char *path = user_data; - gboolean have_hfp = FALSE; - const char *adapter = NULL; - const char *adapter_addr = NULL; - const char *device_addr = NULL; - const char *alias = NULL; - - reply = dbus_pending_call_steal_reply(call); - - if (dbus_message_is_error(reply, DBUS_ERROR_SERVICE_UNKNOWN)) { - DBG("Bluetooth daemon is apparently not available."); - goto done; - } - - if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { - if (!dbus_message_is_error(reply, DBUS_ERROR_UNKNOWN_METHOD)) - ofono_info("Error from GetProperties reply: %s", - dbus_message_get_error_name(reply)); - - goto done; - } - - bluetooth_parse_properties(reply, "UUIDs", has_hfp_uuid, &have_hfp, - "Adapter", parse_string, &adapter, - "Address", parse_string, &device_addr, - "Alias", parse_string, &alias, - NULL); - - if (adapter) - adapter_addr = g_hash_table_lookup(adapter_address_hash, - adapter); - - if (have_hfp && device_addr && adapter_addr) - hfp_create_modem(path, device_addr, adapter_addr, alias); - -done: - dbus_message_unref(reply); -} - -static void parse_devices(DBusMessageIter *array, gpointer user_data) -{ - DBusMessageIter value; - GSList **device_list = user_data; - - DBG(""); - - if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) - return; - - dbus_message_iter_recurse(array, &value); - - while (dbus_message_iter_get_arg_type(&value) - == DBUS_TYPE_OBJECT_PATH) { - const char *path; - - dbus_message_iter_get_basic(&value, &path); - - *device_list = g_slist_prepend(*device_list, (gpointer) path); - - dbus_message_iter_next(&value); - } -} - -static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data) -{ - const char *path = user_data; - DBusMessage *reply; - GSList *device_list = NULL; - GSList *l; - const char *addr; - - reply = dbus_pending_call_steal_reply(call); - - if (dbus_message_is_error(reply, DBUS_ERROR_SERVICE_UNKNOWN)) { - DBG("Bluetooth daemon is apparently not available."); - goto done; - } - - bluetooth_parse_properties(reply, - "Devices", parse_devices, &device_list, - "Address", parse_string, &addr, - NULL); - - DBG("Adapter Address: %s, Path: %s", addr, path); - g_hash_table_insert(adapter_address_hash, - g_strdup(path), g_strdup(addr)); - - for (l = device_list; l; l = l->next) { - const char *device = l->data; - - bluetooth_send_with_reply(device, BLUEZ_DEVICE_INTERFACE, - "GetProperties", device_properties_cb, - g_strdup(device), g_free, - -1, DBUS_TYPE_INVALID); - } - -done: - g_slist_free(device_list); - dbus_message_unref(reply); -} - -static gboolean adapter_added(DBusConnection *connection, DBusMessage *message, - void *user_data) -{ - const char *path; - int ret; - - dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID); - - ret = bluetooth_send_with_reply(path, BLUEZ_ADAPTER_INTERFACE, - "GetProperties", adapter_properties_cb, - g_strdup(path), g_free, - -1, DBUS_TYPE_INVALID); - - return TRUE; -} - -static gboolean adapter_removed(DBusConnection *connection, - DBusMessage *message, void *user_data) -{ - const char *path; - - if (dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID) == TRUE) - g_hash_table_remove(adapter_address_hash, path); - - return TRUE; -} - -static gboolean property_changed(DBusConnection *connection, DBusMessage *msg, - void *user_data) +static gboolean hfp_remove_each_modem(gpointer key, gpointer value, gpointer user_data) { - const char *property; - DBusMessageIter iter; - - dbus_message_iter_init(msg, &iter); - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) - return FALSE; - - dbus_message_iter_get_basic(&iter, &property); - if (g_str_equal(property, "UUIDs") == TRUE) { - gboolean have_hfp = FALSE; - const char *path = dbus_message_get_path(msg); - DBusMessageIter variant; - - /* We already have this device in our hash, ignore */ - if (g_hash_table_lookup(uuid_hash, path) != NULL) - return TRUE; - - if (!dbus_message_iter_next(&iter)) - return FALSE; - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) - return FALSE; - - dbus_message_iter_recurse(&iter, &variant); - - has_hfp_uuid(&variant, &have_hfp); - - /* We need the full set of properties to be able to create - * the modem properly, including Adapter and Alias, so - * refetch everything again - */ - if (have_hfp) - bluetooth_send_with_reply(path, BLUEZ_DEVICE_INTERFACE, - "GetProperties", - device_properties_cb, - g_strdup(path), g_free, - -1, DBUS_TYPE_INVALID); - } else if (g_str_equal(property, "Alias") == TRUE) { - const char *path = dbus_message_get_path(msg); - struct ofono_modem *modem = - g_hash_table_lookup(uuid_hash, path); - const char *alias = NULL; - DBusMessageIter variant; - - if (modem == NULL) - return TRUE; - - if (!dbus_message_iter_next(&iter)) - return FALSE; - - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) - return FALSE; - - dbus_message_iter_recurse(&iter, &variant); - - parse_string(&variant, &alias); + struct ofono_modem *modem = value; - ofono_modem_set_name(modem, alias); - } + ofono_modem_remove(modem); return TRUE; } -static void parse_adapters(DBusMessageIter *array, gpointer user_data) +static void hfp_remove_all_modem() { - DBusMessageIter value; - - DBG(""); - - if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) + if (modem_hash == NULL) return; - dbus_message_iter_recurse(array, &value); - - while (dbus_message_iter_get_arg_type(&value) - == DBUS_TYPE_OBJECT_PATH) { - const char *path; - - dbus_message_iter_get_basic(&value, &path); - - DBG("Calling GetProperties on %s", path); - - bluetooth_send_with_reply(path, BLUEZ_ADAPTER_INTERFACE, - "GetProperties", - adapter_properties_cb, - g_strdup(path), g_free, - -1, DBUS_TYPE_INVALID); - - dbus_message_iter_next(&value); - } -} - -static void manager_properties_cb(DBusPendingCall *call, gpointer user_data) -{ - DBusMessage *reply; - - reply = dbus_pending_call_steal_reply(call); - - if (dbus_message_is_error(reply, DBUS_ERROR_SERVICE_UNKNOWN)) { - DBG("Bluetooth daemon is apparently not available."); - goto done; - } - - bluetooth_parse_properties(reply, "Adapters", parse_adapters, NULL, - NULL); - -done: - dbus_message_unref(reply); + g_hash_table_foreach_remove(modem_hash, hfp_remove_each_modem, NULL); } -static gboolean hfp_remove_each_modem(gpointer key, gpointer value, gpointer user_data) +static void hfp_set_alias(const char *device, const char *alias) { - struct ofono_modem *modem = value; - - ofono_modem_remove(modem); + struct ofono_modem *modem; - return TRUE; -} + if (!device || !alias) + return; -static void bluetooth_disconnect(DBusConnection *connection, void *user_data) -{ - if (uuid_hash == NULL) + modem = g_hash_table_lookup(modem_hash, device); + if (!modem) return; - g_hash_table_foreach_remove(uuid_hash, hfp_remove_each_modem, NULL); + ofono_modem_set_name(modem, alias); } static int hfp_register_ofono_handsfree(struct ofono_modem *modem) @@ -804,7 +539,7 @@ static void hfp_remove(struct ofono_modem *modem) HFP_AGENT_INTERFACE)) hfp_unregister_ofono_handsfree(modem); - g_hash_table_remove(uuid_hash, data->handsfree_path); + g_hash_table_remove(modem_hash, data->handsfree_path); g_free(data->handsfree_path); g_free(data); @@ -936,10 +671,12 @@ static struct ofono_modem_driver hfp_driver = { .post_sim = hfp_post_sim, }; -static guint bluetooth_exit_watch; -static guint adapter_added_watch; -static guint adapter_removed_watch; -static guint uuid_watch; +static struct bluetooth_profile hfp_profile = { + .name = "hfp", + .create = hfp_create_modem, + .remove_all = hfp_remove_all_modem, + .set_alias = hfp_set_alias, +}; static int hfp_init() { @@ -950,72 +687,28 @@ static int hfp_init() connection = ofono_dbus_get_connection(); - bluetooth_exit_watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE, - NULL, bluetooth_disconnect, NULL, NULL); - - adapter_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL, - BLUEZ_MANAGER_INTERFACE, - "AdapterAdded", - adapter_added, NULL, NULL); - - adapter_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL, - BLUEZ_MANAGER_INTERFACE, - "AdapterRemoved", - adapter_removed, NULL, NULL); - - uuid_watch = g_dbus_add_signal_watch(connection, NULL, NULL, - BLUEZ_DEVICE_INTERFACE, - "PropertyChanged", - property_changed, NULL, NULL); + err = ofono_modem_driver_register(&hfp_driver); + if (err < 0) + return err; - if (bluetooth_exit_watch == 0 || adapter_added_watch == 0 || - adapter_removed_watch == 0|| uuid_watch == 0) { - err = -EIO; - goto remove; + err = bluetooth_register_uuid(HFP_AG_UUID, &hfp_profile); + if (err < 0) { + ofono_modem_driver_unregister(&hfp_driver); + return err; } - uuid_hash = g_hash_table_new_full(g_str_hash, g_str_equal, + modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); - adapter_address_hash = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, g_free); - - err = ofono_modem_driver_register(&hfp_driver); - if (err < 0) - goto remove; - - bluetooth_send_with_reply("/", BLUEZ_MANAGER_INTERFACE, "GetProperties", - manager_properties_cb, NULL, NULL, -1, - DBUS_TYPE_INVALID); - return 0; - -remove: - g_dbus_remove_watch(connection, bluetooth_exit_watch); - g_dbus_remove_watch(connection, adapter_added_watch); - g_dbus_remove_watch(connection, adapter_removed_watch); - g_dbus_remove_watch(connection, uuid_watch); - - if (uuid_hash) - g_hash_table_destroy(uuid_hash); - - if (adapter_address_hash) - g_hash_table_destroy(adapter_address_hash); - - return err; } static void hfp_exit() { - g_dbus_remove_watch(connection, bluetooth_exit_watch); - g_dbus_remove_watch(connection, adapter_added_watch); - g_dbus_remove_watch(connection, adapter_removed_watch); - g_dbus_remove_watch(connection, uuid_watch); - + bluetooth_unregister_uuid(HFP_AG_UUID); ofono_modem_driver_unregister(&hfp_driver); - g_hash_table_destroy(uuid_hash); - g_hash_table_destroy(adapter_address_hash); + g_hash_table_destroy(modem_hash); } OFONO_PLUGIN_DEFINE(hfp, "Hands-Free Profile Plugins", VERSION, -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/6] bluetooth: make bluetooth.c not a plugin 2010-06-20 8:51 ` [PATCH 5/6] hfp: use bluetooth helpers and remove similar code Gustavo F. Padovan @ 2010-06-20 8:51 ` Gustavo F. Padovan 2010-06-22 3:59 ` Denis Kenzior 0 siblings, 1 reply; 8+ messages in thread From: Gustavo F. Padovan @ 2010-06-20 8:51 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 1423 bytes --] --- Makefile.am | 7 ++++--- plugins/bluetooth.c | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index 96116a5..d51d6db 100644 --- a/Makefile.am +++ b/Makefile.am @@ -71,6 +71,9 @@ gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \ gatchat/ppp_auth.c gatchat/ppp_net.c \ gatchat/ppp_ipcp.c +bluetooth_sources = plugins/bluetooth.c plugins/bluetooth.h + + udev_files = plugins/ofono.rules if UDEV @@ -133,6 +136,7 @@ endif if ATMODEM builtin_modules += atmodem builtin_sources += $(gatchat_sources) \ + $(bluetooth_sources) \ drivers/atmodem/atmodem.h \ drivers/atmodem/atmodem.c \ drivers/atmodem/call-settings.c \ @@ -238,9 +242,6 @@ builtin_sources += plugins/em770.c builtin_modules += novatel builtin_sources += plugins/novatel.c -builtin_modules += bluetooth -builtin_sources += plugins/bluetooth.c plugins/bluetooth.h - builtin_modules += hfp builtin_sources += plugins/hfp.c plugins/bluetooth.h diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c index cb45b3f..12446f7 100644 --- a/plugins/bluetooth.c +++ b/plugins/bluetooth.c @@ -571,5 +571,3 @@ void bluetooth_unregister_uuid(const char *uuid) uuid_hash = NULL; } -OFONO_PLUGIN_DEFINE(bluetooth, "Bluetooth Utils Plugins", VERSION, - OFONO_PLUGIN_PRIORITY_DEFAULT, NULL, NULL) -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 6/6] bluetooth: make bluetooth.c not a plugin 2010-06-20 8:51 ` [PATCH 6/6] bluetooth: make bluetooth.c not a plugin Gustavo F. Padovan @ 2010-06-22 3:59 ` Denis Kenzior 0 siblings, 0 replies; 8+ messages in thread From: Denis Kenzior @ 2010-06-22 3:59 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 945 bytes --] Hi Gustavo, > --- > Makefile.am | 7 ++++--- > plugins/bluetooth.c | 2 -- > 2 files changed, 4 insertions(+), 5 deletions(-) > > diff --git a/Makefile.am b/Makefile.am > index 96116a5..d51d6db 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -71,6 +71,9 @@ gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \ > gatchat/ppp_auth.c gatchat/ppp_net.c \ > gatchat/ppp_ipcp.c > > +bluetooth_sources = plugins/bluetooth.c plugins/bluetooth.h > + > + > udev_files = plugins/ofono.rules > > if UDEV > @@ -133,6 +136,7 @@ endif > if ATMODEM > builtin_modules += atmodem > builtin_sources += $(gatchat_sources) \ > + $(bluetooth_sources) \ This seems really wrong, ATMODEM has nothing to do with bluetooth. Is it possible to break bluetooth.c library out completely, similar to GAtChat? Do you feel there'll be enough shared between dun/hfp/sap to do so? Regards, -Denis ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/6] bluetooth: Move functions from hfp.c to bluetooth.c 2010-06-20 8:51 [PATCH 1/6] bluetooth: Move functions from hfp.c to bluetooth.c Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 2/6] bluetooth: add device_properties_cb() and has_uuid() Gustavo F. Padovan @ 2010-06-22 3:56 ` Denis Kenzior 1 sibling, 0 replies; 8+ messages in thread From: Denis Kenzior @ 2010-06-22 3:56 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 379 bytes --] Hi Gustavo, > The part that call device_properties_cb is commented to permit this patch > compile. > device_properties_cb() will be changed, so it will have separated patch. I pushed the first 5 patches in this series. Just some minor nagging, but please follow the 80 character per code line limit and the 50 character git commit header limit. Regards, -Denis ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-06-22 3:59 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-06-20 8:51 [PATCH 1/6] bluetooth: Move functions from hfp.c to bluetooth.c Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 2/6] bluetooth: add device_properties_cb() and has_uuid() Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 3/6] bluetooth: add watches for the bluetoothd service and adapters Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 4/6] bluetooth: add PropertyChanged watch Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 5/6] hfp: use bluetooth helpers and remove similar code Gustavo F. Padovan 2010-06-20 8:51 ` [PATCH 6/6] bluetooth: make bluetooth.c not a plugin Gustavo F. Padovan 2010-06-22 3:59 ` Denis Kenzior 2010-06-22 3:56 ` [PATCH 1/6] bluetooth: Move functions from hfp.c to bluetooth.c Denis Kenzior
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.