Thread (20 messages) flat view 20 messages, 3 authors, 2011-02-24
STALE5687d

[PATCH 3/7] Create helper functions to deal with handles on interactive gatttool

From: Sheldon Demario <hidden>
Date: 2011-02-21 22:50:02
Subsystem: the rest · Maintainer: Linus Torvalds

---
 attrib/interactive.c |   46 ++++++++++++++++++++++++++++++----------------
 1 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 7cc03bc..e9f6019 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -238,36 +238,50 @@ static void cmd_primary(int argcp, char **argvp)
 	gatt_discover_primary(attrib, &uuid, primary_by_uuid_cb, NULL);
 }
 
-static void cmd_char(int argcp, char **argvp)
+static int strtohandle(int *dst, const char *src)
 {
-	int start = 0x0001;
-	int end = 0xffff;
+	char *e;
 
-	if (conn_state != STATE_CONNECTED) {
-		printf("Command failed: disconnected\n");
-		return;
+	*dst = strtoll(src, &e, 16);
+	if (errno != 0 || *e != '\0') {
+		return -1;
 	}
 
-	if (argcp > 1) {
-		char *e;
+	return 0;
+}
 
-		start = strtoll(argvp[1], &e, 16);
-		if (errno != 0 || *e != '\0') {
+static int set_handles(int *start, int *end, int argcp, char **argvp)
+{
+	if (argcp > 1) {
+		if (strtohandle(start, argvp[1])) {
 			printf("Invalid start handle: %s\n", argvp[1]);
-			return;
+			return -1;
 		}
 	}
 
 	if (argcp > 2) {
-		char *e;
-
-		end = strtoll(argvp[2], &e, 16);
-		if (errno != 0 || *e != '\0') {
+		if (strtohandle(end, argvp[2])) {
 			printf("Invalid end handle: %s\n", argvp[2]);
-			return;
+			return -1;
 		}
 	}
 
+	return 0;
+}
+
+static void cmd_char(int argcp, char **argvp)
+{
+	int start = 0x0001;
+	int end = 0xffff;
+
+	if (conn_state != STATE_CONNECTED) {
+		printf("Command failed: disconnected\n");
+		return;
+	}
+
+	if (set_handles(&start, &end, argcp, argvp))
+		return;
+
 	gatt_discover_char(attrib, start, end, char_cb, NULL);
 
 	return;
-- 
1.7.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help