Linux bluetooth development
 help / color / mirror / Atom feed
From: Jerzy Kasenberg <jerzy.kasenberg@tieto.com>
To: <linux-bluetooth@vger.kernel.org>
Cc: Jerzy Kasenberg <jerzy.kasenberg@tieto.com>
Subject: [PATCH 05/10] android/client: Add helper macros to verify args
Date: Thu, 31 Oct 2013 11:45:10 +0100	[thread overview]
Message-ID: <1383216315-30627-6-git-send-email-jerzy.kasenberg@tieto.com> (raw)
In-Reply-To: <1383216315-30627-1-git-send-email-jerzy.kasenberg@tieto.com>

This patch adds bunch of macros that will simplify
common arguments checking for methods.
---
 android/client/if-gatt.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/android/client/if-gatt.c b/android/client/if-gatt.c
index 90cc805..60b1ec5 100644
--- a/android/client/if-gatt.c
+++ b/android/client/if-gatt.c
@@ -30,6 +30,63 @@ const btgatt_interface_t *if_gatt = NULL;
 #define MAX_READ_PARAMS_STR_LEN (MAX_SRVC_ID_STR_LEN + MAX_CHAR_ID_STR_LEN \
 		+ MAX_UUID_STR_LEN + MAX_HEX_VAL_STR_LEN + 80)
 
+#define VERIFY_INT_ARG(n, v, err) \
+	do { \
+		if (n < argc) \
+			v = atoi(argv[n]); \
+		else { \
+			haltest_error(err); \
+			return;\
+		} \
+	} while (0)
+
+#define VERIFY_HEX_ARG(n, v, err) \
+	do { \
+		if (n < argc) \
+			v = strtol(argv[n], NULL, 16); \
+		else { \
+			haltest_error(err); \
+			return;\
+		} \
+	} while (0)
+
+/* Helper macros to verify arguments of methods */
+#define VERIFY_CLIENT_IF(n, v) VERIFY_INT_ARG(n, v, "No client_if specified\n")
+#define VERIFY_SERVER_IF(n, v) VERIFY_INT_ARG(n, v, "No server_if specified\n")
+#define VERIFY_CONN_ID(n, v) VERIFY_INT_ARG(n, v, "No conn_if specified\n")
+#define VERIFY_HANDLE(n, v) VERIFY_HEX_ARG(n, v, "No "#v" specified\n")
+#define VERIFY_SERVICE_HANDLE(n, v) VERIFY_HANDLE(n, v)
+
+#define VERIFY_UUID(n, v) \
+	do { \
+		if (n < argc) \
+			gatt_str2bt_uuid_t(argv[n], -1, v); \
+		else { \
+			haltest_error("No uuid specified\n"); \
+			return;\
+		} \
+	} while (0)
+
+#define VERIFY_SRVC_ID(n, v) \
+	do { \
+		if (n < argc) \
+			str2btgatt_srvc_id_t(argv[n], v); \
+		else { \
+			haltest_error("No srvc_id specified\n"); \
+			return;\
+		} \
+	} while (0)
+
+#define VERIFY_CHAR_ID(n, v) \
+	do { \
+		if (n < argc) \
+			str2btgatt_char_id_t(argv[n], v); \
+		else { \
+			haltest_error("No char_id specified\n"); \
+			return;\
+		} \
+	} while (0)
+
 /* Gatt uses little endian uuid */
 static const char GATT_BASE_UUID[] = {
 	0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
-- 
1.7.9.5


  parent reply	other threads:[~2013-10-31 10:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-31 10:45 [PATCH 00/10] Add GATT support to haltest Jerzy Kasenberg
2013-10-31 10:45 ` [PATCH 01/10] android/client: Add skeleton for GATT interface Jerzy Kasenberg
2013-10-31 10:45 ` [PATCH 02/10] android/client: Add GATT client callbacks code Jerzy Kasenberg
2013-10-31 10:45 ` [PATCH 03/10] android/client: Add complex GATT type formating Jerzy Kasenberg
2013-10-31 10:45 ` [PATCH 04/10] android/client: Add init/cleanup for GATT Jerzy Kasenberg
2013-10-31 10:45 ` Jerzy Kasenberg [this message]
2013-10-31 10:45 ` [PATCH 06/10] android/client: Add GATT client method calls Jerzy Kasenberg
2013-10-31 10:45 ` [PATCH 07/10] android/client: Add GATT complex type parsing Jerzy Kasenberg
2013-10-31 10:45 ` [PATCH 08/10] android/client: Add tab completion to GATT client Jerzy Kasenberg
2013-10-31 10:45 ` [PATCH 09/10] android/client: Add GATT server callbacks code Jerzy Kasenberg
2013-10-31 10:45 ` [PATCH 10/10] android/client: Add GATT server methods Jerzy Kasenberg
2013-10-31 14:03 ` [PATCH 00/10] Add GATT support to haltest Johan Hedberg

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=1383216315-30627-6-git-send-email-jerzy.kasenberg@tieto.com \
    --to=jerzy.kasenberg@tieto.com \
    --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