On Mon, 2015-08-10 at 23:12 +0200, Richard Cochran wrote:
> This patch adds method to initialize a configuration and look up 
> values.
> All port options are also global option, with the global option 
> giving the
> default value.  The port look up method first checks for a port 
> specific
> value, falling back to the global default when missing.
> 
> Users are required to call 'config_init', and so this patch add that 
> into
> all three programs, ptp4l, phc2sys and pmc.
> 
> Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
> ---
>  config.c  | 22 ++++++++++++++++++++++
>  config.h  | 28 ++++++++++++++++++++++++++++
>  makefile  | 10 +++++-----
>  phc2sys.c |  3 +++
>  pmc.c     |  3 +++
>  ptp4l.c   |  3 +++
>  6 files changed, 64 insertions(+), 5 deletions(-)
> 
> diff --git a/config.c b/config.c
> index 9ef8be1..f81ac83 100644
> --- a/config.c
> +++ b/config.c
> @@ -823,3 +823,25 @@ void config_destroy(struct config *cfg)
>       }
>       hash_destroy(cfg->htab, free);
>  }
> +
> +struct config_item *config_global_item(struct config *cfg, const 
> char *name)
> +{
> +     struct config_item *ci;
> +     char buf[CONFIG_LABEL_SIZE + 8];
> +     snprintf(buf, sizeof(buf), "global.%s", name);
> +     ci = hash_lookup(cfg->htab, buf);
> +     return ci;
> +}
> +
> +struct config_item *config_port_item(struct config *cfg, const char 
> *port,
> +                                  const char *name)
> +{
> +     struct config_item *ci;
> +     char buf[CONFIG_LABEL_SIZE + MAX_IFNAME_SIZE];
> +     snprintf(buf, sizeof(buf), "%s.%s", port, name);
> +     ci = hash_lookup(cfg->htab, buf);
> +     if (ci) {
> +             return ci;
> +     }
> +     return config_global_item(cfg, name);
> +}
> diff --git a/config.h b/config.h
> index 222883a..78c57df 100644
> --- a/config.h
> +++ b/config.h
> @@ -105,4 +105,32 @@ struct interface *config_create_interface(char 
> *name, struct config *cfg);
>  void config_init_interface(struct interface *iface, struct config 
> *cfg);
>  void config_destroy(struct config *cfg);
>  
> +/* New, hash table based methods: */
> +
> +#define CONFIG_LABEL_SIZE 32
> +
> +enum config_type {
> +     CFG_TYPE_INT,
> +     CFG_TYPE_UINT,
> +     CFG_TYPE_DOUBLE,
> +};
> +
> +typedef union {
> +     int i;
> +     unsigned int u;
> +     double d;
> +} any_t;
> +
> +struct config_item {
> +     char label[CONFIG_LABEL_SIZE];
> +     enum config_type type;
> +     any_t val;
> +     any_t min;
> +     any_t max;
> +};
> +
> +int config_init(struct config *cfg);
> +struct config_item *config_global_item(struct config *cfg, const 
> char *name);
> +struct config_item *config_port_item(struct config *cfg, const char 
> *port,
> +                                  const char *name);
>  #endif
> diff --git a/makefile b/makefile
> index 922769b..bcdbb92 100644
> --- a/makefile
> +++ b/makefile
> @@ -46,13 +46,13 @@ all: $(PRG)
>  
>  ptp4l: $(OBJ)
>  
> -pmc: msg.o pmc.o pmc_common.o print.o raw.o sk.o tlv.o transport.o 
> udp.o \
> - udp6.o uds.o util.o version.o
> -
> -phc2sys: clockadj.o clockcheck.o linreg.o msg.o ntpshm.o nullf.o 
> phc.o \
> - phc2sys.o pi.o pmc_common.o print.o raw.o servo.o sk.o stats.o 
> sysoff.o tlv.o \
> +pmc: config.o hash.o msg.o pmc.o pmc_common.o print.o raw.o sk.o 
> tlv.o \
>   transport.o udp.o udp6.o uds.o util.o version.o
>  
> +phc2sys: clockadj.o clockcheck.o config.o hash.o linreg.o msg.o 
> ntpshm.o \
> + nullf.o phc.o phc2sys.o pi.o pmc_common.o print.o raw.o servo.o 
> sk.o stats.o \
> + sysoff.o tlv.o transport.o udp.o udp6.o uds.o util.o version.o
> +
>  hwstamp_ctl: hwstamp_ctl.o version.o
>  
>  phc_ctl: phc_ctl.o phc.o sk.o util.o clockadj.o sysoff.o print.o 
> version.o
> diff --git a/phc2sys.c b/phc2sys.c
> index 5ba99c3..c737142 100644
> --- a/phc2sys.c
> +++ b/phc2sys.c
> @@ -1369,6 +1369,9 @@ int main(int argc, char *argv[])
>               }
>       }
>  
> +     if (config_init(&phc2sys_config)) {
> +             return -1;
> +     }

Is there a reason to not drop these extra parens? I don't recall if we
keep them for style reason in this codebase or not. (too used to kernel
style to drop unnecessary ones)

Regards,
Jake

>       if (autocfg && (src_name || dst_name || pps_fd >= 0 || 
> wait_sync || node.forced_sync_offset)) {
>               fprintf(stderr,
>                       "autoconfiguration cannot be mixed with 
> manual config options.\n");
> diff --git a/pmc.c b/pmc.c
> index 1fe8183..d26a87e 100644
> --- a/pmc.c
> +++ b/pmc.c
> @@ -800,6 +800,9 @@ int main(int argc, char *argv[])
>               }
>       }
>  
> +     if (config_init(&pmc_config)) {
> +             return -1;
> +     }
>       if (!iface_name) {
>               if (transport_type == TRANS_UDS) {
>                       snprintf(uds_local, sizeof(uds_local),
> diff --git a/ptp4l.c b/ptp4l.c
> index 56cb8bd..6048eb6 100644
> --- a/ptp4l.c
> +++ b/ptp4l.c
> @@ -272,6 +272,9 @@ int main(int argc, char *argv[])
>               }
>       }
>  
> +     if (config_init(&cfg_settings)) {
> +             return -1;
> +     }
>       if (config && (c = config_read(config, &cfg_settings))) {
>               return c;
>       }
------------------------------------------------------------------------------
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to