All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
To: ofono@ofono.org
Subject: [PATCH 06/10] hfpmodem: Add dynamic hfp_slc_info allocation
Date: Tue, 22 Jan 2013 18:43:21 -0300	[thread overview]
Message-ID: <1358891005-24688-7-git-send-email-vinicius.gomes@openbossa.org> (raw)
In-Reply-To: <1358891005-24688-1-git-send-email-vinicius.gomes@openbossa.org>

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

It less error prone to have hfp_slc_info allocated dynamically than
having it allocated statically, as it makes the verification that it
was already de-allocated more direct.
---
 drivers/hfpmodem/slc.c  |  9 ++++++++-
 drivers/hfpmodem/slc.h  |  3 ++-
 plugins/hfp_hf_bluez4.c | 35 ++++++++++++++++++-----------------
 plugins/phonesim.c      |  4 ++--
 4 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/drivers/hfpmodem/slc.c b/drivers/hfpmodem/slc.c
index 646befa..825b8a9 100644
--- a/drivers/hfpmodem/slc.c
+++ b/drivers/hfpmodem/slc.c
@@ -52,8 +52,13 @@ struct slc_establish_data {
 	gpointer userdata;
 };
 
-void hfp_slc_info_init(struct hfp_slc_info *info, guint16 version)
+struct hfp_slc_info *hfp_slc_info_init(GAtChat *chat, guint16 version)
 {
+	struct hfp_slc_info *info;
+
+	info = g_new0(struct hfp_slc_info, 1);
+	info->chat = g_at_chat_ref(chat);
+
 	info->ag_features = 0;
 	info->ag_mpty_features = 0;
 
@@ -75,6 +80,8 @@ void hfp_slc_info_init(struct hfp_slc_info *info, guint16 version)
 done:
 	memset(info->cind_val, 0, sizeof(info->cind_val));
 	memset(info->cind_pos, 0, sizeof(info->cind_pos));
+
+	return info;
 }
 
 static void slc_establish_data_unref(gpointer userdata)
diff --git a/drivers/hfpmodem/slc.h b/drivers/hfpmodem/slc.h
index b71ffe9..8ae8d2f 100644
--- a/drivers/hfpmodem/slc.h
+++ b/drivers/hfpmodem/slc.h
@@ -55,7 +55,8 @@ struct hfp_slc_info {
 	unsigned int cind_val[HFP_INDICATOR_LAST];
 };
 
-void hfp_slc_info_init(struct hfp_slc_info *info, guint16 version);
+struct hfp_slc_info *hfp_slc_info_init(GAtChat *chat, guint16 version);
+
 void hfp_slc_info_free(struct hfp_slc_info *info);
 
 void hfp_slc_establish(struct hfp_slc_info *info, hfp_slc_cb_t connect_cb,
diff --git a/plugins/hfp_hf_bluez4.c b/plugins/hfp_hf_bluez4.c
index 450c183..b0aa1aa 100644
--- a/plugins/hfp_hf_bluez4.c
+++ b/plugins/hfp_hf_bluez4.c
@@ -62,7 +62,7 @@ static DBusConnection *connection;
 static GHashTable *modem_hash = NULL;
 
 struct hfp_data {
-	struct hfp_slc_info info;
+	struct hfp_slc_info *info;
 	char *handsfree_path;
 	char *handsfree_address;
 	DBusMessage *slc_msg;
@@ -109,8 +109,8 @@ static void slc_failed(gpointer userdata)
 	ofono_error("Service level connection failed");
 	ofono_modem_set_powered(modem, FALSE);
 
-	g_at_chat_unref(data->info.chat);
-	data->info.chat = NULL;
+	g_at_chat_unref(data->info->chat);
+	data->info->chat = NULL;
 }
 
 static void hfp_disconnected_cb(gpointer user_data)
@@ -120,12 +120,13 @@ static void hfp_disconnected_cb(gpointer user_data)
 
 	ofono_modem_set_powered(modem, FALSE);
 
-	g_at_chat_unref(data->info.chat);
-	data->info.chat = NULL;
+	g_at_chat_unref(data->info->chat);
+	data->info->chat = NULL;
 }
 
 /* either oFono or Phone could request SLC connection */
-static int service_level_connection(struct ofono_modem *modem, int fd)
+static int service_level_connection(struct ofono_modem *modem, int fd,
+							guint16 version)
 {
 	struct hfp_data *data = ofono_modem_get_data(modem);
 	GIOChannel *io;
@@ -152,8 +153,10 @@ static int service_level_connection(struct ofono_modem *modem, int fd)
 	if (getenv("OFONO_AT_DEBUG"))
 		g_at_chat_set_debug(chat, hfp_debug, "");
 
-	data->info.chat = chat;
-	hfp_slc_establish(&data->info, slc_established, slc_failed, modem);
+	data->info = hfp_slc_info_init(chat, version);
+	g_at_chat_unref(chat);
+
+	hfp_slc_establish(data->info, slc_established, slc_failed, modem);
 
 	return -EINPROGRESS;
 }
@@ -170,9 +173,7 @@ static DBusMessage *hfp_agent_new_connection(DBusConnection *conn,
 				DBUS_TYPE_UINT16, &version, DBUS_TYPE_INVALID))
 		return __ofono_error_invalid_args(msg);
 
-	hfp_slc_info_init(&hfp_data->info, version);
-
-	err = service_level_connection(modem, fd);
+	err = service_level_connection(modem, fd, version);
 	if (err < 0 && err != -EINPROGRESS)
 		return __ofono_error_failed(msg);
 
@@ -462,8 +463,8 @@ static int hfp_disable(struct ofono_modem *modem)
 
 	DBG("%p", modem);
 
-	g_at_chat_unref(data->info.chat);
-	data->info.chat = NULL;
+	g_at_chat_unref(data->info->chat);
+	data->info->chat = NULL;
 
 	if (data->agent_registered) {
 		status = bluetooth_send_with_reply(data->handsfree_path,
@@ -486,10 +487,10 @@ static void hfp_pre_sim(struct ofono_modem *modem)
 	DBG("%p", modem);
 
 	ofono_devinfo_create(modem, 0, "hfpmodem", data->handsfree_address);
-	ofono_voicecall_create(modem, 0, "hfpmodem", &data->info);
-	ofono_netreg_create(modem, 0, "hfpmodem", &data->info);
-	ofono_call_volume_create(modem, 0, "hfpmodem", &data->info);
-	ofono_handsfree_create(modem, 0, "hfpmodem", &data->info);
+	ofono_voicecall_create(modem, 0, "hfpmodem", data->info);
+	ofono_netreg_create(modem, 0, "hfpmodem", data->info);
+	ofono_call_volume_create(modem, 0, "hfpmodem", data->info);
+	ofono_handsfree_create(modem, 0, "hfpmodem", data->info);
 }
 
 static void hfp_post_sim(struct ofono_modem *modem)
diff --git a/plugins/phonesim.c b/plugins/phonesim.c
index 26f96d0..9210e02 100644
--- a/plugins/phonesim.c
+++ b/plugins/phonesim.c
@@ -929,8 +929,8 @@ static int localhfp_enable(struct ofono_modem *modem)
 
 	g_at_chat_set_disconnect_function(chat, slc_failed, modem);
 
-	hfp_slc_info_init(info, HFP_VERSION_LATEST);
-	info->chat = chat;
+	info = hfp_slc_info_init(chat, HFP_VERSION_LATEST);
+	g_at_chat_unref(chat);
 	hfp_slc_establish(info, slc_established, slc_failed, modem);
 
 	return -EINPROGRESS;
-- 
1.8.1.1


  parent reply	other threads:[~2013-01-22 21:43 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-22 21:43 [PATCH 00/10] HFP Service Level Connection establishment Vinicius Costa Gomes
2013-01-22 21:43 ` [PATCH 01/10] hfp_hf_bluez5: Initial GDBusClient for BlueZ Vinicius Costa Gomes
2013-01-23  4:30   ` Denis Kenzior
2013-01-23 14:16     ` Vinicius Costa Gomes
2013-01-22 21:43 ` [PATCH 02/10] hfp_hf_bluez5: Add GDBusProxy for Bluetooth devices Vinicius Costa Gomes
2013-01-22 21:43 ` [PATCH 03/10] hfp_hf_bluez5: Register modem for HFP AG capable devices Vinicius Costa Gomes
2013-01-23  4:59   ` Denis Kenzior
2013-01-23 14:22     ` Vinicius Costa Gomes
2013-01-22 21:43 ` [PATCH 04/10] hfp_hf_bluez5: Keep track of changes of devices Aliases Vinicius Costa Gomes
2013-01-22 21:43 ` [PATCH 05/10] hfp_hf_bluez5: Handle NewConnection from BlueZ Vinicius Costa Gomes
2013-01-23  4:54   ` Denis Kenzior
2013-01-23 12:03   ` AW: " Kling, Andreas
2013-01-23 14:49     ` Denis Kenzior
2013-01-23 16:39       ` Vinicius Costa Gomes
2013-01-22 21:43 ` Vinicius Costa Gomes [this message]
2013-01-22 21:43 ` [PATCH 07/10] hfpmodem: Implement hfp_slc_info_free Vinicius Costa Gomes
2013-01-22 21:43 ` [PATCH 08/10] hfp_hf_bluez4: Use hfp_slc_info_free() Vinicius Costa Gomes
2013-01-22 21:43 ` [PATCH 09/10] phonesim: " Vinicius Costa Gomes
2013-01-22 21:43 ` [PATCH 10/10] hfp_hf_bluez5: Add SLC establishment procedure Vinicius Costa Gomes
2013-01-23  5:26   ` Denis Kenzior
2013-01-23 18:27 ` [PATCH v1 00/10] HFP Service Level Connection establishment Vinicius Costa Gomes
2013-01-23 18:27   ` [PATCH v1 01/10] hfp_hf_bluez5: Initial GDBusClient for BlueZ Vinicius Costa Gomes
2013-01-23 20:31     ` Denis Kenzior
2013-01-23 18:27   ` [PATCH v1 02/10] hfp_hf_bluez5: Add GDBusProxy for Bluetooth devices Vinicius Costa Gomes
2013-01-23 20:31     ` Denis Kenzior
2013-01-23 18:27   ` [PATCH v1 03/10] hfp_hf_bluez5: Register modem for HFP AG capable devices Vinicius Costa Gomes
2013-01-23 20:32     ` Denis Kenzior
2013-01-23 18:27   ` [PATCH v1 04/10] hfp_hf_bluez5: Keep track of changes of devices Aliases Vinicius Costa Gomes
2013-01-23 20:32     ` Denis Kenzior
2013-01-23 18:27   ` [PATCH v1 05/10] hfp_hf_bluez5: Handle NewConnection from BlueZ Vinicius Costa Gomes
2013-01-23 20:32     ` Denis Kenzior
2013-01-23 18:27   ` [PATCH v1 06/10] hfpmodem: Add dynamic hfp_slc_info allocation Vinicius Costa Gomes
2013-01-23 20:34     ` Denis Kenzior
2013-01-23 23:04       ` Vinicius Costa Gomes
2013-01-23 18:27   ` [PATCH v1 07/10] hfpmodem: Implement hfp_slc_info_free() Vinicius Costa Gomes
2013-01-23 18:27   ` [PATCH v1 08/10] hfp_hf_bluez4: Use hfp_slc_info_free() Vinicius Costa Gomes
2013-01-23 18:28   ` [PATCH v1 09/10] phonesim: " Vinicius Costa Gomes
2013-01-23 18:28   ` [PATCH v1 10/10] hfp_hf_bluez5: Add SLC establishment procedure Vinicius Costa Gomes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1358891005-24688-7-git-send-email-vinicius.gomes@openbossa.org \
    --to=vinicius.gomes@openbossa.org \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.