aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-05-15 15:33:46 +0200
committerHarald Welte <laforge@gnumonks.org>2014-08-21 15:34:16 +0200
commit6217930688a95ab236e80ba49b247cec3786407f (patch)
treeef7abbcac92eccf2bdeb09b05e6b90991e200b64
parent50059bb64f64f3d7842d9edd454433d9e5fd8b36 (diff)
ctrl: Reduce code duplication and add a define to create the struct
This has been pointed out by Jacob and removes two more duplicates of the struct. For the unused CTRL_CMD_DEFINE_STRING macro there will be no verify command.
-rw-r--r--openbsc/include/openbsc/control_cmd.h23
1 files changed, 10 insertions, 13 deletions
diff --git a/openbsc/include/openbsc/control_cmd.h b/openbsc/include/openbsc/control_cmd.h
index 47928698..4d202036 100644
--- a/openbsc/include/openbsc/control_cmd.h
+++ b/openbsc/include/openbsc/control_cmd.h
@@ -87,6 +87,13 @@ struct ctrl_cmd *ctrl_cmd_cpy(void *ctx, struct ctrl_cmd *cmd);
struct ctrl_cmd *ctrl_cmd_create(void *ctx, enum ctrl_type);
struct ctrl_cmd *ctrl_cmd_trap(struct ctrl_cmd *cmd);
+#define CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, verify_name) \
+static struct ctrl_cmd_element cmd_##cmdname = { \
+ .name = cmdstr, \
+ .get = &get_##cmdname, \
+ .set = &set_##cmdname, \
+ .verify = verify_name, \
+}
#define CTRL_HELPER_GET_INT(cmdname, dtype, element) \
static int get_##cmdname(struct ctrl_cmd *cmd, void *_data) \
@@ -150,23 +157,13 @@ static int set_##cmdname(struct ctrl_cmd *cmd, void *_data) \
#define CTRL_CMD_DEFINE_STRING(cmdname, cmdstr, dtype, element) \
CTRL_HELPER_GET_STRING(cmdname, dtype, element) \
CTRL_HELPER_SET_STRING(cmdname, dtype, element) \
-static struct ctrl_cmd_element cmd_##cmdname = { \
- .name = cmdstr, \
- .get = &get_##cmdname, \
- .set = &set_##cmdname, \
- .verify = NULL, \
-}
+CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, NULL)
#define CTRL_CMD_DEFINE(cmdname, cmdstr) \
static int get_##cmdname(struct ctrl_cmd *cmd, void *data); \
static int set_##cmdname(struct ctrl_cmd *cmd, void *data); \
static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *data); \
-static struct ctrl_cmd_element cmd_##cmdname = { \
- .name = cmdstr, \
- .get = &get_##cmdname, \
- .set = &set_##cmdname, \
- .verify = &verify_##cmdname, \
-}
+CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, verify_##cmdname)
#define CTRL_CMD_DEFINE_RO(cmdname, cmdstr) \
static int get_##cmdname(struct ctrl_cmd *cmd, void *data); \
@@ -180,7 +177,7 @@ static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *data)
cmd->reply = "Read Only attribute"; \
return 1; \
} \
-CTRL_CMD_DEFINE(cmdname, cmdstr)
+CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, verify_##cmdname)
struct gsm_network;