Linux bluetooth development
 help / color / mirror / Atom feed
From: Sheldon Demario <sheldon.demario@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Bruna Moreira <bruna.moreira@openbossa.org>
Subject: [PATCH 6/7] Move attr_data_from_string() to utils.c
Date: Mon, 21 Feb 2011 19:50:05 -0300	[thread overview]
Message-ID: <1298328606-7993-6-git-send-email-sheldon.demario@openbossa.org> (raw)
In-Reply-To: <1298328606-7993-1-git-send-email-sheldon.demario@openbossa.org>

From: Bruna Moreira <bruna.moreira@openbossa.org>

The attr_data_from_string() function will be used in interactive and
usual gatttool so this function was moved to common file utils.c.
---
 attrib/gatttool.c |   23 ++---------------------
 attrib/gatttool.h |    1 +
 attrib/utils.c    |   19 +++++++++++++++++++
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 7478043..d7887c6 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -313,25 +313,6 @@ static gboolean characteristics_read(gpointer user_data)
 	return FALSE;
 }
 
-static size_t attr_data_from_string(const char *str, uint8_t **data)
-{
-	char tmp[3];
-	size_t size, i;
-
-	size = strlen(str) / 2;
-	*data = g_try_malloc0(size);
-	if (*data == NULL)
-		return 0;
-
-	tmp[2] = '\0';
-	for (i = 0; i < size; i++) {
-		memcpy(tmp, str + (i * 2), 2);
-		(*data)[i] = (uint8_t) strtol(tmp, NULL, 16);
-	}
-
-	return size;
-}
-
 static void mainloop_quit(gpointer user_data)
 {
 	uint8_t *value = user_data;
@@ -356,7 +337,7 @@ static gboolean characteristics_write(gpointer user_data)
 		goto error;
 	}
 
-	len = attr_data_from_string(opt_value, &value);
+	len = gatt_attr_data_from_string(opt_value, &value);
 	if (len == 0) {
 		g_printerr("Invalid value\n");
 		goto error;
@@ -408,7 +389,7 @@ static gboolean characteristics_write_req(gpointer user_data)
 		goto error;
 	}
 
-	len = attr_data_from_string(opt_value, &value);
+	len = gatt_attr_data_from_string(opt_value, &value);
 	if (len == 0) {
 		g_printerr("Invalid value\n");
 		goto error;
diff --git a/attrib/gatttool.h b/attrib/gatttool.h
index 7eae18d..2fd4a46 100644
--- a/attrib/gatttool.h
+++ b/attrib/gatttool.h
@@ -25,3 +25,4 @@ int interactive(gchar *dst, gboolean le);
 GIOChannel *gatt_connect(const gchar *src, const gchar *dst,
 			const gchar *sec_level, int psm, int mtu,
 			BtIOConnect connect_cb);
+size_t gatt_attr_data_from_string(const char *str, uint8_t **data);
diff --git a/attrib/utils.c b/attrib/utils.c
index 4d0000d..8d1ca74 100644
--- a/attrib/utils.c
+++ b/attrib/utils.c
@@ -104,3 +104,22 @@ GIOChannel *gatt_connect(const gchar *src, const gchar *dst,
 
 	return chan;
 }
+
+size_t gatt_attr_data_from_string(const char *str, uint8_t **data)
+{
+	char tmp[3];
+	size_t size, i;
+
+	size = strlen(str) / 2;
+	*data = g_try_malloc0(size);
+	if (*data == NULL)
+		return 0;
+
+	tmp[2] = '\0';
+	for (i = 0; i < size; i++) {
+		memcpy(tmp, str + (i * 2), 2);
+		(*data)[i] = (uint8_t) strtol(tmp, NULL, 16);
+	}
+
+	return size;
+}
-- 
1.7.1


  parent reply	other threads:[~2011-02-21 22:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-21 22:50 [PATCH 1/7] Improve help messages in interactive gatttool Sheldon Demario
2011-02-21 22:50 ` [PATCH 2/7] Add Characteristics Discovery option to " Sheldon Demario
2011-02-21 22:50 ` [PATCH 3/7] Create helper functions to deal with handles on " Sheldon Demario
2011-02-21 22:50 ` [PATCH 4/7] Add Characteristics Descriptor Discovery option in " Sheldon Demario
2011-02-21 22:50 ` [PATCH 5/7] Add characteristics read options " Sheldon Demario
2011-02-21 22:50 ` Sheldon Demario [this message]
2011-02-21 22:50 ` [PATCH 7/7] Add Write Request " Sheldon Demario
2011-02-22 19:11 ` [PATCH v2 1/7] Improve help messages " Sheldon Demario
2011-02-22 19:11 ` [PATCH v2 2/7] Add Characteristics Discovery option to " Sheldon Demario
2011-02-22 19:12 ` [PATCH v2 3/7] Create helper functions to deal with handles on " Sheldon Demario
2011-02-23  3:09   ` Johan Hedberg
2011-02-23 12:21     ` Anderson Lizardo
2011-02-23 13:23     ` Sheldon Demario
2011-02-23 14:20     ` [PATCH v3 " Sheldon Demario
2011-02-22 19:12 ` [PATCH v2 4/7] Add Characteristics Descriptor Discovery option in " Sheldon Demario
2011-02-22 19:12 ` [PATCH v2 5/7] Add characteristics read options " Sheldon Demario
2011-02-22 19:12 ` [PATCH v2 6/7] Move attr_data_from_string() to utils.c Sheldon Demario
2011-02-22 19:12 ` [PATCH v2 7/7] Add Write Request in interactive gatttool Sheldon Demario
2011-02-24 13:54 ` [PATCH v3 4/7] Add Characteristics Descriptor Discovery option " Sheldon Demario
2011-02-24 13:55 ` [PATCH v3 5/7] Add characteristics read options " Sheldon Demario

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=1298328606-7993-6-git-send-email-sheldon.demario@openbossa.org \
    --to=sheldon.demario@openbossa.org \
    --cc=bruna.moreira@openbossa.org \
    --cc=linux-bluetooth@vger.kernel.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