All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hfp: create modem for new devices paired on runtime
@ 2010-02-01 17:30 Gustavo F. Padovan
  2010-02-01 17:49 ` Denis Kenzior
  0 siblings, 1 reply; 6+ messages in thread
From: Gustavo F. Padovan @ 2010-02-01 17:30 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2743 bytes --]

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(-)

diff --git a/plugins/hfp.c b/plugins/hfp.c
index 0e2e359..2141078 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -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);
 }
-- 
1.6.4.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] hfp: create modem for new devices paired on runtime
@ 2010-02-01 18:17 Gustavo F. Padovan
  2010-02-01 18:35 ` Gustavo F. Padovan
  0 siblings, 1 reply; 6+ messages in thread
From: Gustavo F. Padovan @ 2010-02-01 18:17 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2953 bytes --]

It listens the Paired property to create a modem to the recently paired
devices.
---
 plugins/hfp.c |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 67 insertions(+), 1 deletions(-)

diff --git a/plugins/hfp.c b/plugins/hfp.c
index 0e2e359..92b6be4 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -594,6 +594,63 @@ 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, *property;
+	DBusMessageIter iter, variant;
+	int ret, value;
+
+	dbus_error_init(&err);
+
+	if (dbus_message_get_args(message, &err, DBUS_TYPE_STRING,
+				 &property, DBUS_TYPE_INVALID) == FALSE) {
+		if (dbus_error_is_set(&err) == TRUE) {
+			ofono_error("%s", err.message);
+			dbus_error_free(&err);
+		}
+
+		return FALSE;
+	}
+
+	dbus_message_iter_init(message, &iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return FALSE;
+
+	if (g_str_equal(property, "Paired") == FALSE)
+		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);
+
+	if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_BOOLEAN)
+		return FALSE;
+
+	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 +859,7 @@ static struct ofono_modem_driver hfp_driver = {
 };
 
 static guint added_watch;
+static guint paired_watch;
 
 static int hfp_init(void)
 {
@@ -817,7 +875,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 +896,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 +906,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);
 }
-- 
1.6.4.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] hfp: create modem for new devices paired on runtime
@ 2010-02-02 21:42 Gustavo F. Padovan
  0 siblings, 0 replies; 6+ messages in thread
From: Gustavo F. Padovan @ 2010-02-02 21:42 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2688 bytes --]

It listens the Paired property to create a modem to the recently paired
devices. It also renames added_watch to adapter_watch, a more proper
name.
---
 plugins/hfp.c |   47 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/plugins/hfp.c b/plugins/hfp.c
index 0e2e359..6f2000a 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -594,6 +594,34 @@ static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,
 	return TRUE;
 }
 
+static gboolean new_device_added(DBusConnection *connection, DBusMessage *message,
+				void *user_data)
+{
+	const char *device, *property;
+	DBusMessageIter iter;
+
+	dbus_message_iter_init(message, &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") == FALSE)
+		return TRUE;
+
+	if (!dbus_message_iter_next(&iter))
+		return FALSE;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return FALSE;
+
+	device = dbus_message_get_path(message);
+
+	parse_uuids(&iter, device);
+
+	return TRUE;
+}
+
 static void list_adapters_cb(DBusPendingCall *call, gpointer user_data)
 {
 	DBusError err;
@@ -801,7 +829,8 @@ static struct ofono_modem_driver hfp_driver = {
 	.post_sim	= hfp_post_sim,
 };
 
-static guint added_watch;
+static guint adapter_watch;
+static guint device_watch;
 
 static int hfp_init(void)
 {
@@ -812,12 +841,18 @@ static int hfp_init(void)
 
 	connection = ofono_dbus_get_connection();
 
-	added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+	adapter_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
 						BLUEZ_MANAGER_INTERFACE,
 						"AdapterAdded",
 						adapter_added, NULL, NULL);
 
-	if (added_watch == 0) {
+	device_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+						BLUEZ_DEVICE_INTERFACE,
+						"PropertyChanged",
+						new_device_added, NULL, NULL);
+
+
+	if (adapter_watch == 0 || device_watch == 0) {
 		err = -EIO;
 		goto remove;
 	}
@@ -831,7 +866,8 @@ static int hfp_init(void)
 	return 0;
 
 remove:
-	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, adapter_watch);
+	g_dbus_remove_watch(connection, device_watch);
 
 	dbus_connection_unref(connection);
 
@@ -840,7 +876,8 @@ remove:
 
 static void hfp_exit(void)
 {
-	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, adapter_watch);
+	g_dbus_remove_watch(connection, device_watch);
 
 	ofono_modem_driver_unregister(&hfp_driver);
 }
-- 
1.6.4.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] hfp: create modem for new devices paired on runtime
@ 2010-02-03 22:18 Gustavo F. Padovan
  0 siblings, 0 replies; 6+ messages in thread
From: Gustavo F. Padovan @ 2010-02-03 22:18 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4582 bytes --]

It listens the Paired property to create a modem to the recently paired
devices. It also renames added_watch to adapter_watch, a more proper
name.
---
 plugins/hfp.c |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 101 insertions(+), 5 deletions(-)

diff --git a/plugins/hfp.c b/plugins/hfp.c
index 0e2e359..c32a18f 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -65,6 +65,7 @@ static const char *cmer_prefix[] = { "+CMER:", NULL };
 static const char *chld_prefix[] = { "+CHLD:", NULL };
 
 static DBusConnection *connection;
+static GHashTable *uuid_watches = NULL;
 
 static int hfp_disable(struct ofono_modem *modem);
 static void hfp_remove(struct ofono_modem *modem);
@@ -594,6 +595,79 @@ static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,
 	return TRUE;
 }
 
+static void uuid_watch_remove(gpointer data)
+{
+	guint id;
+
+	g_dbus_remove_watch(connection, id);
+}
+
+static gboolean uuid_emitted(DBusConnection *connection, DBusMessage *message,
+				void *user_data)
+{
+	const char *device, *property;
+	const char *path = user_data;
+	DBusMessageIter iter;
+
+	device = dbus_message_get_path(message);
+
+	if (!g_str_equal(path, device))
+		return TRUE;
+
+	dbus_message_iter_init(message, &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") == FALSE)
+		return TRUE;
+
+	g_hash_table_remove(uuid_watches, path);
+
+	if (!dbus_message_iter_next(&iter))
+		return FALSE;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return FALSE;
+
+	parse_uuids(&iter, device);
+
+	return TRUE;
+}
+
+static gboolean device_created(DBusConnection *connection, DBusMessage *message,
+				void *user_data)
+{
+	const char *path;
+	guint uuid_watch;
+
+	dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+				DBUS_TYPE_INVALID);
+
+	uuid_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+						BLUEZ_DEVICE_INTERFACE,
+						"PropertyChanged", uuid_emitted,
+						(void *)path, NULL);
+
+	g_hash_table_insert(uuid_watches, g_strdup(path), &uuid_watch);
+
+	return TRUE;
+}
+
+static gboolean device_removed(DBusConnection *connection, DBusMessage *message,
+				void *user_data)
+{
+	const char *path;
+
+	dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+				DBUS_TYPE_INVALID);
+
+	g_hash_table_remove(uuid_watches, path);
+
+	return TRUE;
+}
+
 static void list_adapters_cb(DBusPendingCall *call, gpointer user_data)
 {
 	DBusError err;
@@ -801,7 +875,9 @@ static struct ofono_modem_driver hfp_driver = {
 	.post_sim	= hfp_post_sim,
 };
 
-static guint added_watch;
+static guint adapter_watch;
+static guint device_watch;
+static guint removed_watch;
 
 static int hfp_init(void)
 {
@@ -812,12 +888,26 @@ static int hfp_init(void)
 
 	connection = ofono_dbus_get_connection();
 
-	added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+	adapter_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
 						BLUEZ_MANAGER_INTERFACE,
 						"AdapterAdded",
 						adapter_added, NULL, NULL);
 
-	if (added_watch == 0) {
+	device_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+						BLUEZ_ADAPTER_INTERFACE,
+						"DeviceCreated",
+						device_created, NULL, NULL);
+
+	removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+						BLUEZ_ADAPTER_INTERFACE,
+						"DeviceRemoved",
+						device_removed, NULL, NULL);
+
+
+	uuid_watches = g_hash_table_new_full(g_str_hash, g_str_equal,
+			g_free, uuid_watch_remove);
+
+	if (adapter_watch == 0 || device_watch == 0 || removed_watch == 0) {
 		err = -EIO;
 		goto remove;
 	}
@@ -831,7 +921,10 @@ static int hfp_init(void)
 	return 0;
 
 remove:
-	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, adapter_watch);
+	g_dbus_remove_watch(connection, device_watch);
+	g_dbus_remove_watch(connection, removed_watch);
+	g_hash_table_destroy(uuid_watches);
 
 	dbus_connection_unref(connection);
 
@@ -840,7 +933,10 @@ remove:
 
 static void hfp_exit(void)
 {
-	g_dbus_remove_watch(connection, added_watch);
+	g_dbus_remove_watch(connection, adapter_watch);
+	g_dbus_remove_watch(connection, device_watch);
+	g_dbus_remove_watch(connection, removed_watch);
+	g_hash_table_destroy(uuid_watches);
 
 	ofono_modem_driver_unregister(&hfp_driver);
 }
-- 
1.6.4.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-02-03 22:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-01 17:30 [PATCH] hfp: create modem for new devices paired on runtime Gustavo F. Padovan
2010-02-01 17:49 ` Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2010-02-01 18:17 Gustavo F. Padovan
2010-02-01 18:35 ` Gustavo F. Padovan
2010-02-02 21:42 Gustavo F. Padovan
2010-02-03 22:18 Gustavo F. Padovan

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.