That's much better that adding dummy functions manually.

On 15.05.2014 11:24, Holger Freyther wrote:
> From: Holger Hans Peter Freyther <[email protected]>
> 
> Certain attributes are read-only. Add a macro to make it more
> easy to define those.
> ---
> --- a/openbsc/include/openbsc/control_cmd.h
> +++ b/openbsc/include/openbsc/control_cmd.h
> +#define CTRL_CMD_DEFINE_RO(cmdname, cmdstr) \
> +static int get_##cmdname(struct ctrl_cmd *cmd, void *data);          \
> +static inline int set_##cmdname(struct ctrl_cmd *cmd, void *data)    \

Why inline? We basically need the addresses of these functions.

> +{                                                                    \
> +     cmd->reply = "Read Only attribute";                             \
> +     return CTRL_CMD_ERROR;                                          \
> +}                                                                    \
> +static inline int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, 
> void *data) \
> +{                                                                    \
> +     cmd->reply = "Read Only attribute";                             \
> +     return 1;                                                       \
> +}                                                                    \
> +static struct ctrl_cmd_element cmd_##cmdname = { \
> +     .name = cmdstr, \
> +     .param = NULL, \
> +     .get = &get_##cmdname, \
> +     .set = &set_##cmdname, \
> +     .verify = &verify_##cmdname, \
> +}

It's quite some code duplication. What about something like the
following (even if the resulting 'forward' declarations are somewhat
senseless). This would even work with the ';' in the 'calling' code:

#define CTRL_CMD_DEFINE_RO(cmdname, cmdstr) \
static int set_##cmdname(struct ctrl_cmd *cmd, void *data)      \
{                                                               \
        cmd->reply = "Read Only attribute";                     \
        return CTRL_CMD_ERROR;                                  \
}                                                                       \
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)


Jacob


-- 
- Jacob Erlbeck <[email protected]>       http://www.sysmocom.de/
=======================================================================
* sysmocom - systems for mobile communications GmbH
* Schivelbeiner Str. 5
* 10439 Berlin, Germany
* Sitz / Registered office: Berlin, HRB 134158 B
* Geschaeftsfuehrer / Managing Directors: Holger Freyther, Harald Welte

Reply via email to