summaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2013-02-22 10:09:45 +0100
committerHarald Welte <laforge@gnumonks.org>2014-08-21 15:34:16 +0200
commit05f655e2b058459c9df5cf9381b5b8ccb9781fe1 (patch)
treef62e0c6d5b3dcaa72cc969f2d8f2b1ec17ef0924 /openbsc
parente6d56159a6ee76b1bd9fd7ade1f64801818861b3 (diff)
ctrl: Make the int range set, get and verify methods available
For the max power reduction we will need to have a different range method. It will need to check if the value is even. Make the set, get and verify methods available through a macro.
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/include/openbsc/control_cmd.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/openbsc/include/openbsc/control_cmd.h b/openbsc/include/openbsc/control_cmd.h
index a0ea055c..9a103515 100644
--- a/openbsc/include/openbsc/control_cmd.h
+++ b/openbsc/include/openbsc/control_cmd.h
@@ -86,7 +86,8 @@ 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_RANGE(cmdname, cmdstr, dtype, element, min, max) \
+
+#define CTRL_HELPER_GET_INT(cmdname, dtype, element) \
static int get_##cmdname(struct ctrl_cmd *cmd, void *_data) \
{ \
dtype *node = cmd->node; \
@@ -96,14 +97,16 @@ static int get_##cmdname(struct ctrl_cmd *cmd, void *_data) \
return CTRL_CMD_ERROR; \
} \
return CTRL_CMD_REPLY; \
-} \
+}
+#define CTRL_HELPER_SET_INT(cmdname, dtype, element) \
static int set_##cmdname(struct ctrl_cmd *cmd, void *_data) \
{ \
dtype *node = cmd->node; \
int tmp = atoi(cmd->value); \
node->element = tmp; \
return get_##cmdname(cmd, _data); \
-} \
+}
+#define CTRL_HELPER_VERIFY_RANGE(cmdname, min, max) \
static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *_data) \
{ \
int tmp = atoi(value); \
@@ -112,7 +115,12 @@ static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *_data
} \
cmd->reply = "Input not within the range"; \
return -1; \
-} \
+}
+
+#define CTRL_CMD_DEFINE_RANGE(cmdname, cmdstr, dtype, element, min, max) \
+ CTRL_HELPER_GET_INT(cmdname, dtype, element) \
+ CTRL_HELPER_SET_INT(cmdname, dtype, element) \
+ CTRL_HELPER_VERIFY_RANGE(cmdname, min, max) \
static struct ctrl_cmd_element cmd_##cmdname = { \
.name = cmdstr, \
.param = NULL, \