diff options
author | Denis Kenzior <denkenz@gmail.com> | 2013-02-13 20:30:21 -0600 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2013-02-14 08:47:10 -0600 |
commit | 83b43c8abdafdb9ad4b5dc7fa2d62ff537eab93c (patch) | |
tree | 97ac00bf5d7d9fa26c00716374900976210c2a7f /plugins/hfp_hf_bluez5.c | |
parent | 825feb8cd52345bc950aa7906db17de41bfcd3a9 (diff) | |
download | ofono-83b43c8abdafdb9ad4b5dc7fa2d62ff537eab93c.tar.bz2 |
hfp_hf_bluez5: Remove use of hash table
The number of paired devices is quite small, so the use of the hash
table for lookup seems unnecessary. The typical user will have no more
than 1-2 devices paired, maybe half a dozen in a less common case.
Diffstat (limited to 'plugins/hfp_hf_bluez5.c')
-rw-r--r-- | plugins/hfp_hf_bluez5.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c index ca20bfc0..6de5065e 100644 --- a/plugins/hfp_hf_bluez5.c +++ b/plugins/hfp_hf_bluez5.c @@ -63,7 +63,6 @@ struct hfp { DBusMessage *msg; }; -static GHashTable *modem_hash = NULL; static GDBusClient *bluez = NULL; static guint sco_watch = 0; @@ -181,8 +180,6 @@ static struct ofono_modem *modem_register(const char *device, ofono_modem_set_name(modem, alias); ofono_modem_register(modem); - g_hash_table_insert(modem_hash, g_strdup(device), modem); - return modem; } @@ -300,6 +297,18 @@ static struct ofono_modem_driver hfp_driver = { .post_sim = hfp_post_sim, }; +static ofono_bool_t device_path_compare(struct ofono_modem *modem, + void *userdata) +{ + const char *path = userdata; + const char *value = ofono_modem_get_string(modem, "DevicePath"); + + if (value == NULL) + return FALSE; + + return g_str_equal(path, value); +} + static DBusMessage *profile_new_connection(DBusConnection *conn, DBusMessage *msg, void *user_data) { @@ -327,7 +336,7 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, if (fd < 0) goto invalid; - modem = g_hash_table_lookup(modem_hash, device); + modem = ofono_modem_find(device_path_compare, (void *) device); if (modem == NULL) { close(fd); return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE @@ -392,7 +401,7 @@ static DBusMessage *profile_disconnection(DBusConnection *conn, dbus_message_iter_get_basic(&entry, &device); - modem = g_hash_table_lookup(modem_hash, device); + modem = ofono_modem_find(device_path_compare, (void *) device); if (modem == NULL) goto error; @@ -645,9 +654,6 @@ static int hfp_init(void) return -ENOMEM; } - modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, - NULL); - g_dbus_client_set_connect_watch(bluez, connect_handler, NULL); g_dbus_client_set_proxy_handlers(bluez, proxy_added, NULL, property_changed, NULL); @@ -665,8 +671,6 @@ static void hfp_exit(void) ofono_modem_driver_unregister(&hfp_driver); g_dbus_client_unref(bluez); - g_hash_table_destroy(modem_hash); - if (sco_watch > 0) g_source_remove(sco_watch); } |