All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received
  2010-02-05 18:47 [PATCH 1/3] hfp: create modem for new devices paired on runtime Gustavo F. Padovan
@ 2010-02-05 18:47 ` Gustavo F. Padovan
  2010-02-05 18:47   ` [PATCH 3/3] hfp: wait Disconnect reply to power down the modem Gustavo F. Padovan
  2010-02-05 19:37   ` [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received Denis Kenzior
  2010-02-05 19:36 ` [PATCH 1/3] hfp: create modem for new devices paired on runtime Denis Kenzior
  2010-07-08  7:03 ` =?unknown-8bit?q?R=C3=A9mi?= Denis-Courmont
  2 siblings, 2 replies; 11+ messages in thread
From: Gustavo F. Padovan @ 2010-02-05 18:47 UTC (permalink / raw)
  To: ofono

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

Prevent to call UnregisterAgent on an already unregistered agent.
---
 plugins/hfp.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/plugins/hfp.c b/plugins/hfp.c
index 3e41342..46217c5 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -411,6 +411,9 @@ static DBusMessage *hfp_agent_release(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
 	struct ofono_modem *modem = data;
+	const char *obj_path = ofono_modem_get_path(modem);
+
+	g_dbus_unregister_interface(connection, obj_path, HFP_AGENT_INTERFACE);
 
 	ofono_modem_remove(modem);
 
@@ -757,8 +760,11 @@ static int hfp_probe(struct ofono_modem *modem)
 static void hfp_remove(struct ofono_modem *modem)
 {
 	struct hfp_data *data = ofono_modem_get_data(modem);
+	const char *obj_path = ofono_modem_get_path(modem);
 
-	hfp_unregister_ofono_handsfree(modem);
+	if (g_dbus_unregister_interface(connection, obj_path,
+					HFP_AGENT_INTERFACE))
+		hfp_unregister_ofono_handsfree(modem);
 
 	g_hash_table_remove(uuid_hash, data->handsfree_path);
 
-- 
1.6.4.4


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

* [PATCH 1/3] hfp: create modem for new devices paired on runtime
@ 2010-02-05 18:47 Gustavo F. Padovan
  2010-02-05 18:47 ` [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received Gustavo F. Padovan
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Gustavo F. Padovan @ 2010-02-05 18:47 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4186 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 |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/plugins/hfp.c b/plugins/hfp.c
index 981b05b..3e41342 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -66,6 +66,7 @@ static const char *cmer_prefix[] = { "+CMER:", NULL };
 static const char *chld_prefix[] = { "+CHLD:", NULL };
 
 static DBusConnection *connection;
+static GHashTable *uuid_hash = NULL;
 
 static void hfp_debug(const char *str, void *user_data)
 {
@@ -427,6 +428,7 @@ static int hfp_create_modem(const char *device)
 {
 	struct ofono_modem *modem;
 	struct hfp_data *data;
+	const char *path;
 
 	ofono_info("Using device: %s", device);
 
@@ -451,6 +453,9 @@ static int hfp_create_modem(const char *device)
 	ofono_modem_set_data(modem, data);
 	ofono_modem_register(modem);
 
+	path = ofono_modem_get_path(modem);
+	g_hash_table_insert(uuid_hash, g_strdup(device), g_strdup(path));
+
 	return 0;
 
 free:
@@ -465,6 +470,9 @@ static void parse_uuids(DBusMessageIter *i, const char *device)
 	DBusMessageIter variant, ai;
 	const char *value;
 
+	if (g_hash_table_lookup(uuid_hash, device))
+		return;
+
 	dbus_message_iter_recurse(i, &variant);
 	dbus_message_iter_recurse(&variant, &ai);
 
@@ -624,6 +632,33 @@ static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,
 	return TRUE;
 }
 
+static gboolean uuid_emitted(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;
@@ -725,6 +760,8 @@ static void hfp_remove(struct ofono_modem *modem)
 
 	hfp_unregister_ofono_handsfree(modem);
 
+	g_hash_table_remove(uuid_hash, data->handsfree_path);
+
 	g_free(data->handsfree_path);
 	g_free(data);
 
@@ -798,7 +835,8 @@ static struct ofono_modem_driver hfp_driver = {
 	.post_sim	= hfp_post_sim,
 };
 
-static guint added_watch;
+static guint adapter_watch;
+static guint uuid_watch;
 
 static int hfp_init(void)
 {
@@ -809,12 +847,21 @@ 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) {
+	uuid_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+						BLUEZ_DEVICE_INTERFACE,
+						"PropertyChanged",
+						uuid_emitted, NULL, NULL);
+
+
+	uuid_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+			g_free, g_free);
+
+	if (adapter_watch == 0 || uuid_watch == 0) {
 		err = -EIO;
 		goto remove;
 	}
@@ -828,7 +875,9 @@ 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, uuid_watch);
+	g_hash_table_destroy(uuid_hash);
 
 	dbus_connection_unref(connection);
 
@@ -837,9 +886,12 @@ 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, uuid_watch);
 
 	ofono_modem_driver_unregister(&hfp_driver);
+
+	g_hash_table_destroy(uuid_hash);
 }
 
 OFONO_PLUGIN_DEFINE(hfp, "Hands-Free Profile Plugins", VERSION,
-- 
1.6.4.4


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

* [PATCH 3/3] hfp: wait Disconnect reply to power down the modem
  2010-02-05 18:47 ` [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received Gustavo F. Padovan
@ 2010-02-05 18:47   ` Gustavo F. Padovan
  2010-02-05 19:13     ` [PATCH 4/4] hfp: set timeout service level connection procedure Gustavo F. Padovan
  2010-02-05 19:37     ` [PATCH 3/3] hfp: wait Disconnect reply to power down the modem Denis Kenzior
  2010-02-05 19:37   ` [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received Denis Kenzior
  1 sibling, 2 replies; 11+ messages in thread
From: Gustavo F. Padovan @ 2010-02-05 18:47 UTC (permalink / raw)
  To: ofono

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

---
 plugins/hfp.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/plugins/hfp.c b/plugins/hfp.c
index 46217c5..d0af7e8 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -796,13 +796,34 @@ static int hfp_enable(struct ofono_modem *modem)
 	return -EINPROGRESS;
 }
 
+static void hfp_power_down(DBusPendingCall *call, gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	DBusMessage *reply;
+	DBusError derr;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&derr);
+	if (dbus_set_error_from_message(&derr, reply)) {
+		ofono_debug("Disconnect reply: %s", derr.message);
+		dbus_error_free(&derr);
+		goto done;
+	}
+
+	ofono_modem_set_powered(modem, FALSE);
+
+done:
+	dbus_message_unref(reply);
+}
+
 static int hfp_disconnect_ofono_handsfree(struct ofono_modem *modem)
 {
 	struct hfp_data *data = ofono_modem_get_data(modem);
 
 	return send_method_call(BLUEZ_SERVICE, data->handsfree_path,
 				BLUEZ_GATEWAY_INTERFACE, "Disconnect",
-				NULL, NULL, DBUS_TYPE_INVALID);
+				hfp_power_down, modem, DBUS_TYPE_INVALID);
 }
 
 static int hfp_disable(struct ofono_modem *modem)
@@ -812,7 +833,8 @@ static int hfp_disable(struct ofono_modem *modem)
 	clear_data(modem);
 
 	hfp_disconnect_ofono_handsfree(modem);
-	return 0;
+
+	return -EINPROGRESS;
 }
 
 static void hfp_pre_sim(struct ofono_modem *modem)
-- 
1.6.4.4


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

* [PATCH 4/4] hfp: set timeout service level connection procedure
  2010-02-05 18:47   ` [PATCH 3/3] hfp: wait Disconnect reply to power down the modem Gustavo F. Padovan
@ 2010-02-05 19:13     ` Gustavo F. Padovan
  2010-02-05 19:54       ` Denis Kenzior
  2010-02-05 19:37     ` [PATCH 3/3] hfp: wait Disconnect reply to power down the modem Denis Kenzior
  1 sibling, 1 reply; 11+ messages in thread
From: Gustavo F. Padovan @ 2010-02-05 19:13 UTC (permalink / raw)
  To: ofono

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

If it expires we call org.bluez.HandsfreeGateway.Disconnect()
---
 drivers/hfpmodem/hfpmodem.h |    1 +
 plugins/hfp.c               |   27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/drivers/hfpmodem/hfpmodem.h b/drivers/hfpmodem/hfpmodem.h
index 6ec8a7c..deb6399 100644
--- a/drivers/hfpmodem/hfpmodem.h
+++ b/drivers/hfpmodem/hfpmodem.h
@@ -71,6 +71,7 @@ struct hfp_data {
 	unsigned int hf_features;
 	unsigned char cind_pos[HFP_INDICATOR_LAST];
 	unsigned int cind_val[HFP_INDICATOR_LAST];
+	unsigned int connect_to;
 };
 
 extern void hfp_netreg_init();
diff --git a/plugins/hfp.c b/plugins/hfp.c
index d0af7e8..0c1c508 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -99,6 +99,8 @@ static void sevice_level_conn_established(struct ofono_modem *modem)
 	dbus_message_unref(data->slc_msg);
 	data->slc_msg = NULL;
 
+	g_source_remove(data->connect_to);
+
 	ofono_info("Service level connection established");
 
 	g_at_chat_send(data->chat, "AT+CMEE=1", NULL, NULL, NULL, NULL);
@@ -118,6 +120,8 @@ static void service_level_conn_failed(struct ofono_modem *modem)
 	dbus_message_unref(data->slc_msg);
 	data->slc_msg = NULL;
 
+	g_source_remove(data->connect_to);
+
 	ofono_error("Service level connection failed");
 	ofono_modem_set_powered(modem, FALSE);
 	clear_data(modem);
@@ -785,11 +789,34 @@ static int hfp_connect_ofono_handsfree(struct ofono_modem *modem)
 				NULL, NULL, DBUS_TYPE_INVALID);
 }
 
+static gboolean hfp_enable_timeout(gpointer user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct hfp_data *data = ofono_modem_get_data(modem);
+	int ret;
+
+	if (ofono_modem_get_powered(modem))
+		return FALSE;
+
+	ret = send_method_call(BLUEZ_SERVICE, data->handsfree_path,
+				BLUEZ_GATEWAY_INTERFACE, "Disconnect",
+				NULL, NULL, DBUS_TYPE_INVALID);
+	if (ret < 0)
+		ofono_error("GetProperties failed(%d)", ret);
+
+	return FALSE;
+}
+
 /* power up hardware */
 static int hfp_enable(struct ofono_modem *modem)
 {
+	struct hfp_data *data = ofono_modem_get_data(modem);
+
 	DBG("%p", modem);
 
+	data->connect_to =
+		g_timeout_add_seconds(15, hfp_enable_timeout, modem);
+
 	if (hfp_connect_ofono_handsfree(modem) < 0)
 		return -EINVAL;
 
-- 
1.6.4.4


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

* Re: [PATCH 1/3] hfp: create modem for new devices paired on runtime
  2010-02-05 18:47 [PATCH 1/3] hfp: create modem for new devices paired on runtime Gustavo F. Padovan
  2010-02-05 18:47 ` [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received Gustavo F. Padovan
@ 2010-02-05 19:36 ` Denis Kenzior
  2010-07-08  7:03 ` =?unknown-8bit?q?R=C3=A9mi?= Denis-Courmont
  2 siblings, 0 replies; 11+ messages in thread
From: Denis Kenzior @ 2010-02-05 19:36 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

> 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.
> ---

Patch has been applied, thanks.

Regards,
-Denis

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

* Re: [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received
  2010-02-05 18:47 ` [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received Gustavo F. Padovan
  2010-02-05 18:47   ` [PATCH 3/3] hfp: wait Disconnect reply to power down the modem Gustavo F. Padovan
@ 2010-02-05 19:37   ` Denis Kenzior
  1 sibling, 0 replies; 11+ messages in thread
From: Denis Kenzior @ 2010-02-05 19:37 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

> Prevent to call UnregisterAgent on an already unregistered agent.
> ---
Patch has been applied, thanks.

Regards,
-Denis

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

* Re: [PATCH 3/3] hfp: wait Disconnect reply to power down the modem
  2010-02-05 18:47   ` [PATCH 3/3] hfp: wait Disconnect reply to power down the modem Gustavo F. Padovan
  2010-02-05 19:13     ` [PATCH 4/4] hfp: set timeout service level connection procedure Gustavo F. Padovan
@ 2010-02-05 19:37     ` Denis Kenzior
  1 sibling, 0 replies; 11+ messages in thread
From: Denis Kenzior @ 2010-02-05 19:37 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

Patch has been applied, thanks.

Regards,
-Denis

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

* Re: [PATCH 4/4] hfp: set timeout service level connection procedure
  2010-02-05 19:13     ` [PATCH 4/4] hfp: set timeout service level connection procedure Gustavo F. Padovan
@ 2010-02-05 19:54       ` Denis Kenzior
  0 siblings, 0 replies; 11+ messages in thread
From: Denis Kenzior @ 2010-02-05 19:54 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

> If it expires we call org.bluez.HandsfreeGateway.Disconnect()
> ---
>  drivers/hfpmodem/hfpmodem.h |    1 +
>  plugins/hfp.c               |   27 +++++++++++++++++++++++++++
>  2 files changed, 28 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/hfpmodem/hfpmodem.h b/drivers/hfpmodem/hfpmodem.h
> index 6ec8a7c..deb6399 100644
> --- a/drivers/hfpmodem/hfpmodem.h
> +++ b/drivers/hfpmodem/hfpmodem.h
> @@ -71,6 +71,7 @@ struct hfp_data {
>  	unsigned int hf_features;
>  	unsigned char cind_pos[HFP_INDICATOR_LAST];
>  	unsigned int cind_val[HFP_INDICATOR_LAST];
> +	unsigned int connect_to;

Don't need to use g_source for this, see below.

>  };
> 
>  extern void hfp_netreg_init();
> diff --git a/plugins/hfp.c b/plugins/hfp.c
> index d0af7e8..0c1c508 100644
> --- a/plugins/hfp.c
> +++ b/plugins/hfp.c
> @@ -99,6 +99,8 @@ static void sevice_level_conn_established(struct
>  ofono_modem *modem) dbus_message_unref(data->slc_msg);
>  	data->slc_msg = NULL;
> 
> +	g_source_remove(data->connect_to);
> +

Don't need this

>  	ofono_info("Service level connection established");
> 
>  	g_at_chat_send(data->chat, "AT+CMEE=1", NULL, NULL, NULL, NULL);
> @@ -118,6 +120,8 @@ static void service_level_conn_failed(struct
>  ofono_modem *modem) dbus_message_unref(data->slc_msg);
>  	data->slc_msg = NULL;
> 
> +	g_source_remove(data->connect_to);
> +

Or this

>  	ofono_error("Service level connection failed");
>  	ofono_modem_set_powered(modem, FALSE);
>  	clear_data(modem);
> @@ -785,11 +789,34 @@ static int hfp_connect_ofono_handsfree(struct
>  ofono_modem *modem) NULL, NULL, DBUS_TYPE_INVALID);
>  }
> 
> +static gboolean hfp_enable_timeout(gpointer user_data)
> +{
> +	struct ofono_modem *modem = user_data;
> +	struct hfp_data *data = ofono_modem_get_data(modem);
> +	int ret;
> +
> +	if (ofono_modem_get_powered(modem))
> +		return FALSE;
> +
> +	ret = send_method_call(BLUEZ_SERVICE, data->handsfree_path,
> +				BLUEZ_GATEWAY_INTERFACE, "Disconnect",
> +				NULL, NULL, DBUS_TYPE_INVALID);
> +	if (ret < 0)
> +		ofono_error("GetProperties failed(%d)", ret);

What does GetProperties have to do here?

> +
> +	return FALSE;
> +}
> +
>  /* power up hardware */
>  static int hfp_enable(struct ofono_modem *modem)
>  {
> +	struct hfp_data *data = ofono_modem_get_data(modem);
> +
>  	DBG("%p", modem);
> 
> +	data->connect_to =
> +		g_timeout_add_seconds(15, hfp_enable_timeout, modem);
> +
>  	if (hfp_connect_ofono_handsfree(modem) < 0)

In hfp_connect_ofono_handsfree, simply set a proper timeout and callback 
function.  You don't need to use a g_source here@all.

>  		return -EINVAL;
> 

Regards,
-Denis

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

* Re: [PATCH 1/3] hfp: create modem for new devices paired on runtime
  2010-02-05 18:47 [PATCH 1/3] hfp: create modem for new devices paired on runtime Gustavo F. Padovan
  2010-02-05 18:47 ` [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received Gustavo F. Padovan
  2010-02-05 19:36 ` [PATCH 1/3] hfp: create modem for new devices paired on runtime Denis Kenzior
@ 2010-07-08  7:03 ` =?unknown-8bit?q?R=C3=A9mi?= Denis-Courmont
  2 siblings, 0 replies; 11+ messages in thread
From: =?unknown-8bit?q?R=C3=A9mi?= Denis-Courmont @ 2010-07-08  7:03 UTC (permalink / raw)
  To: ofono

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


On Sat, 14 Jan 2012 18:00:55 -0200, "Gustavo F. Padovan"
<padovan@profusion.mobi> wrote:
> 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.

Care to fix your system time and date? TIA.

-- 
Rémi Denis-Courmont
http://www.remlab.net
http://fi.linkedin.com/in/remidenis


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

* Re: [PATCH 1/3] hfp: create modem for new devices paired on runtime
  2010-02-04 21:30 Gustavo F. Padovan
@ 2010-02-04 21:58 ` Denis Kenzior
  0 siblings, 0 replies; 11+ messages in thread
From: Denis Kenzior @ 2010-02-04 21:58 UTC (permalink / raw)
  To: ofono

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

Hi Gustavo,

> 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 |   64
>  ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files 
changed,
>  59 insertions(+), 5 deletions(-)
> 
> diff --git a/plugins/hfp.c b/plugins/hfp.c
> index 981b05b..cd43af7 100644
> --- a/plugins/hfp.c
> +++ b/plugins/hfp.c
> @@ -66,6 +66,7 @@ static const char *cmer_prefix[] = { "+CMER:", NULL };
>  static const char *chld_prefix[] = { "+CHLD:", NULL };
> 
>  static DBusConnection *connection;
> +static GHashTable *uuid_hash = NULL;
> 
>  static void hfp_debug(const char *str, void *user_data)
>  {
> @@ -410,6 +411,9 @@ static DBusMessage *hfp_agent_release(DBusConnection
>  *conn, DBusMessage *msg, void *data)
>  {
>  	struct ofono_modem *modem = data;
> +	const char * path;
> +
> +	path = dbus_message_get_path(msg);

Whats this part for?

> 
>  	ofono_modem_remove(modem);
> 
> @@ -427,6 +431,10 @@ static int hfp_create_modem(const char *device)
>  {
>  	struct ofono_modem *modem;
>  	struct hfp_data *data;
> +	const char *path;
> +
> +	if (g_hash_table_lookup(uuid_hash, device))
> +		return -EALREADY;

I suggest we move this check to parse_uuids.

> 
>  	ofono_info("Using device: %s", device);
> 
> @@ -451,6 +459,9 @@ static int hfp_create_modem(const char *device)
>  	ofono_modem_set_data(modem, data);
>  	ofono_modem_register(modem);
> 
> +	path = ofono_modem_get_path(modem);
> +	g_hash_table_insert(uuid_hash, g_strdup(device), g_strdup(path));
> +
>  	return 0;
> 
>  free:
> @@ -624,6 +635,33 @@ static gboolean adapter_added(DBusConnection
>  *connection, DBusMessage *message, return TRUE;
>  }
> 
> +static gboolean uuid_emitted(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;
> @@ -725,6 +763,8 @@ static void hfp_remove(struct ofono_modem *modem)
> 
>  	hfp_unregister_ofono_handsfree(modem);
> 
> +	g_hash_table_remove(uuid_hash, data->handsfree_path);
> +
>  	g_free(data->handsfree_path);
>  	g_free(data);
> 
> @@ -798,7 +838,8 @@ static struct ofono_modem_driver hfp_driver = {
>  	.post_sim	= hfp_post_sim,
>  };
> 
> -static guint added_watch;
> +static guint adapter_watch;
> +static guint uuid_watch;
> 
>  static int hfp_init(void)
>  {
> @@ -809,12 +850,21 @@ 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) {
> +	uuid_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
> +						BLUEZ_DEVICE_INTERFACE,
> +						"PropertyChanged",
> +						uuid_emitted, NULL, NULL);
> +
> +
> +	uuid_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
> +			g_free, g_free);
> +
> +	if (adapter_watch == 0 || uuid_watch == 0) {
>  		err = -EIO;
>  		goto remove;
>  	}
> @@ -828,7 +878,9 @@ 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, uuid_watch);
> +	g_hash_table_destroy(uuid_hash);
> 
>  	dbus_connection_unref(connection);
> 
> @@ -837,7 +889,9 @@ 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, uuid_watch);
> +	g_hash_table_destroy(uuid_hash);
> 
>  	ofono_modem_driver_unregister(&hfp_driver);
>  }
> 

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

* [PATCH 1/3] hfp: create modem for new devices paired on runtime
@ 2010-02-04 21:30 Gustavo F. Padovan
  2010-02-04 21:58 ` Denis Kenzior
  0 siblings, 1 reply; 11+ messages in thread
From: Gustavo F. Padovan @ 2010-02-04 21:30 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4149 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 |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/plugins/hfp.c b/plugins/hfp.c
index 981b05b..cd43af7 100644
--- a/plugins/hfp.c
+++ b/plugins/hfp.c
@@ -66,6 +66,7 @@ static const char *cmer_prefix[] = { "+CMER:", NULL };
 static const char *chld_prefix[] = { "+CHLD:", NULL };
 
 static DBusConnection *connection;
+static GHashTable *uuid_hash = NULL;
 
 static void hfp_debug(const char *str, void *user_data)
 {
@@ -410,6 +411,9 @@ static DBusMessage *hfp_agent_release(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
 	struct ofono_modem *modem = data;
+	const char * path;
+
+	path = dbus_message_get_path(msg);
 
 	ofono_modem_remove(modem);
 
@@ -427,6 +431,10 @@ static int hfp_create_modem(const char *device)
 {
 	struct ofono_modem *modem;
 	struct hfp_data *data;
+	const char *path;
+
+	if (g_hash_table_lookup(uuid_hash, device))
+		return -EALREADY;
 
 	ofono_info("Using device: %s", device);
 
@@ -451,6 +459,9 @@ static int hfp_create_modem(const char *device)
 	ofono_modem_set_data(modem, data);
 	ofono_modem_register(modem);
 
+	path = ofono_modem_get_path(modem);
+	g_hash_table_insert(uuid_hash, g_strdup(device), g_strdup(path));
+
 	return 0;
 
 free:
@@ -624,6 +635,33 @@ static gboolean adapter_added(DBusConnection *connection, DBusMessage *message,
 	return TRUE;
 }
 
+static gboolean uuid_emitted(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;
@@ -725,6 +763,8 @@ static void hfp_remove(struct ofono_modem *modem)
 
 	hfp_unregister_ofono_handsfree(modem);
 
+	g_hash_table_remove(uuid_hash, data->handsfree_path);
+
 	g_free(data->handsfree_path);
 	g_free(data);
 
@@ -798,7 +838,8 @@ static struct ofono_modem_driver hfp_driver = {
 	.post_sim	= hfp_post_sim,
 };
 
-static guint added_watch;
+static guint adapter_watch;
+static guint uuid_watch;
 
 static int hfp_init(void)
 {
@@ -809,12 +850,21 @@ 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) {
+	uuid_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+						BLUEZ_DEVICE_INTERFACE,
+						"PropertyChanged",
+						uuid_emitted, NULL, NULL);
+
+
+	uuid_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+			g_free, g_free);
+
+	if (adapter_watch == 0 || uuid_watch == 0) {
 		err = -EIO;
 		goto remove;
 	}
@@ -828,7 +878,9 @@ 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, uuid_watch);
+	g_hash_table_destroy(uuid_hash);
 
 	dbus_connection_unref(connection);
 
@@ -837,7 +889,9 @@ 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, uuid_watch);
+	g_hash_table_destroy(uuid_hash);
 
 	ofono_modem_driver_unregister(&hfp_driver);
 }
-- 
1.6.4.4


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

end of thread, other threads:[~2010-07-08  7:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-05 18:47 [PATCH 1/3] hfp: create modem for new devices paired on runtime Gustavo F. Padovan
2010-02-05 18:47 ` [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received Gustavo F. Padovan
2010-02-05 18:47   ` [PATCH 3/3] hfp: wait Disconnect reply to power down the modem Gustavo F. Padovan
2010-02-05 19:13     ` [PATCH 4/4] hfp: set timeout service level connection procedure Gustavo F. Padovan
2010-02-05 19:54       ` Denis Kenzior
2010-02-05 19:37     ` [PATCH 3/3] hfp: wait Disconnect reply to power down the modem Denis Kenzior
2010-02-05 19:37   ` [PATCH 2/3] hfp: Don't call UnregisterAgent if a Release was received Denis Kenzior
2010-02-05 19:36 ` [PATCH 1/3] hfp: create modem for new devices paired on runtime Denis Kenzior
2010-07-08  7:03 ` =?unknown-8bit?q?R=C3=A9mi?= Denis-Courmont
  -- strict thread matches above, loose matches on Subject: below --
2010-02-04 21:30 Gustavo F. Padovan
2010-02-04 21:58 ` 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.