Open Source Telephony
 help / color / mirror / Atom feed
From: Andres Salomon <dilinger@collabora.co.uk>
To: ofono@ofono.org
Subject: [PATCH] G1: move chat handling into enable callback
Date: Tue, 29 Sep 2009 23:53:59 -0400	[thread overview]
Message-ID: <20090929235359.2b3dffd7@mycelium.queued.net> (raw)

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


This updates the g1 code to create the GAtChat object in the enable() callback,
and to unref it in the disable() callback.  This is more in line with what
the other plugins do, and as a bonus fixes a segfault when powering down
the G1 modem..

Signed-off-by: Andres Salomon <dilinger@collabora.co.uk>
---
 plugins/g1.c |   48 ++++++++++++++++++++++--------------------------
 1 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/plugins/g1.c b/plugins/g1.c
index 5c53a12..0414f49 100644
--- a/plugins/g1.c
+++ b/plugins/g1.c
@@ -57,39 +57,14 @@ static void g1_debug(const char *str, void *data)
 /* Detect hardware, and initialize if found */
 static int g1_probe(struct ofono_modem *modem)
 {
-	GAtSyntax *syntax;
-	GAtChat *chat;
-	const char *device;
-
 	DBG("");
 
-	device = ofono_modem_get_string(modem, "Device");
-	if (device == NULL)
-		return -EINVAL;
-
-	syntax = g_at_syntax_new_gsm_permissive();
-	chat = g_at_chat_new_from_tty(device, syntax);
-	g_at_syntax_unref(syntax);
-
-	if (chat == NULL)
-		return -EIO;
-
-	if (getenv("OFONO_AT_DEBUG") != NULL)
-		g_at_chat_set_debug(chat, g1_debug, NULL);
-
-	ofono_modem_set_data(modem, chat);
-
 	return 0;
 }
 
 static void g1_remove(struct ofono_modem *modem)
 {
-	GAtChat *chat = ofono_modem_get_data(modem);
-
 	DBG("");
-
-	ofono_modem_set_data(modem, NULL);
-	g_at_chat_unref(chat);
 }
 
 static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -105,10 +80,28 @@ static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data)
 /* power up hardware */
 static int g1_enable(struct ofono_modem *modem)
 {
-	GAtChat *chat = ofono_modem_get_data(modem);
+	GAtSyntax *syntax;
+	GAtChat *chat;
+	const char *device;
 
 	DBG("");
 
+	device = ofono_modem_get_string(modem, "Device");
+	if (device == NULL)
+		return -EINVAL;
+
+	syntax = g_at_syntax_new_gsm_permissive();
+	chat = g_at_chat_new_from_tty(device, syntax);
+	g_at_syntax_unref(syntax);
+
+	if (chat == NULL)
+		return -EIO;
+
+	if (getenv("OFONO_AT_DEBUG") != NULL)
+		g_at_chat_set_debug(chat, g1_debug, NULL);
+
+	ofono_modem_set_data(modem, chat);
+
 	/* ensure modem is in a known state; verbose on, echo/quiet off */
 	g_at_chat_send(chat, "ATE0Q0V1", NULL, NULL, NULL, NULL);
 
@@ -137,6 +130,9 @@ static int g1_disable(struct ofono_modem *modem)
 	/* power down modem */
 	g_at_chat_send(chat, "AT+CFUN=0", NULL, cfun_set_off_cb, modem, NULL);
 
+	g_at_chat_unref(chat);
+	ofono_modem_set_data(modem, NULL);
+
 	return 0;
 }
 
-- 
1.6.4.3




             reply	other threads:[~2009-09-30  3:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-30  3:53 Andres Salomon [this message]
2009-10-02  2:46 ` [PATCH] G1: move chat handling into enable callback Marcel Holtmann

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=20090929235359.2b3dffd7@mycelium.queued.net \
    --to=dilinger@collabora.co.uk \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox