diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-05-15 15:33:46 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-05-15 15:50:55 +0200 |
commit | b66f158b050503a68468aa55ae6e7b7df92e3fb8 (patch) | |
tree | 0bbc477f0c59afcf8c33e336b65d6d210481c614 | |
parent | 6e36255221d588f5de20b124748b589249ea825b (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.h | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/openbsc/include/openbsc/control_cmd.h b/openbsc/include/openbsc/control_cmd.h index 479286983..4d2020366 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; |