From: Alexander Aring <alex.aring@gmail.com>
To: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/7] params: allow to access first sub-device and params via env
Date: Sat, 26 Jan 2013 01:45:49 +0100 [thread overview]
Message-ID: <20130126004548.GA7319@x61s.8.8.8.8> (raw)
In-Reply-To: <1359158132-8023-1-git-send-email-plagnioj@jcrosoft.com>
Hi,
On Sat, Jan 26, 2013 at 12:55:26AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> this will allow to keep retro-compatiblility and adding
> globalvar multiple device support
>
> barebox@Somfy Animeo IP:/
> # echo $platform.soc.
> at91sam9260
> barebox@Somfy Animeo IP:/
> # echo $platform.soc.name
> Unknown
> barebox@Somfy Animeo IP:/
> # echo $global.dhcp.vendor_id
> barebox-animeo-ip
>
> update complete too
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> common/complete.c | 45 ++++++++++++++++++++++++++++++++++++++++-----
> lib/parameter.c | 41 ++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 80 insertions(+), 6 deletions(-)
>
> diff --git a/common/complete.c b/common/complete.c
> index 9206ef0..17ee3c4 100644
> --- a/common/complete.c
> +++ b/common/complete.c
> @@ -169,7 +169,7 @@ int device_complete(struct string_list *sl, char *instr)
> }
> EXPORT_SYMBOL(device_complete);
>
> -static int device_param_complete(char *begin, struct device_d *dev,
> +static int device_param_complete(char *begin, char *dev_fullname, struct device_d *dev,
> struct string_list *sl, char *instr)
> {
> struct param_d *param;
> @@ -185,7 +185,7 @@ static int device_param_complete(char *begin, struct device_d *dev,
> continue;
>
> string_list_add_asprintf(sl, "%s%s.%s%c",
> - begin ? begin : "", dev_name(dev), param->name,
> + begin ? begin : "", dev_fullname, param->name,
> begin ? ' ' : '=');
> }
>
> @@ -253,12 +253,47 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
> }
>
> for_each_device(dev) {
> - if (!strncmp(instr, dev_name(dev), len)) {
> + struct device_d *child;
> + char *devname = asprintf("%s", dev_name(dev));
> +
> + if (!strncmp(instr, devname, len)) {
> if (eval)
> - device_param_complete("$", dev, sl, instr_param);
> + device_param_complete("$", devname, dev, sl, instr_param);
> else
> - device_param_complete(NULL, dev, sl, instr_param);
> + device_param_complete(NULL, devname, dev, sl, instr_param);
> + }
> +
> + if (dev->bus) {
> + free(devname);
> + continue;
> + }
> +
> + device_for_each_child(dev, child) {
> + char *dev_fullname;
> + char *child_instr_param;
> + int child_len;
> +
> + dev_fullname = asprintf("%s.%s", devname, dev_name(child));
> + child_instr_param = strchr(instr_param, '.');
> +
> + if (child_instr_param) {
> + child_len = (child_instr_param - instr);
> + child_instr_param++;
> + } else {
> + child_len = strlen(instr);
> + child_instr_param = "";
> + }
> +
> + if (!strncmp(instr, dev_fullname, child_len)) {
> + if (eval)
> + device_param_complete("$", dev_fullname, child, sl, child_instr_param);
> + else
> + device_param_complete(NULL, dev_fullname, child, sl, child_instr_param);
> + }
> +
> + free(dev_fullname);
> }
> + free(devname);
> }
>
> return 0;
> diff --git a/lib/parameter.c b/lib/parameter.c
> index c00b824..4b7b26a 100644
> --- a/lib/parameter.c
> +++ b/lib/parameter.c
> @@ -28,7 +28,7 @@
> #include <malloc.h>
> #include <driver.h>
>
> -struct param_d *get_param_by_name(struct device_d *dev, const char *name)
> +static struct param_d *__get_param_by_name(struct device_d *dev, const char *name)
> {
> struct param_d *p;
>
> @@ -40,6 +40,45 @@ struct param_d *get_param_by_name(struct device_d *dev, const char *name)
> return NULL;
> }
>
> +static struct param_d *get_child_param_by_name(struct device_d *dev, const char *name)
> +{
> + struct device_d *child;
> + char *devstr;
> + char *par;
> +
> + if (dev->bus)
> + return NULL;
> +
> + if (!strchr(name, '.'))
> + return NULL;
> +
> + devstr = strdup(name);
> + par = strchr(devstr, '.');
> +
> + *par = 0;
> + par++;
> +
> + device_for_each_child(dev, child) {
> + if (!strcmp(devstr, dev_name(child)))
> + return __get_param_by_name(child, par);
Need to call 'free(devstr)' before return?
> + }
> +
> + free(devstr);
> +
> + return NULL;
> +}
> +
> +struct param_d *get_param_by_name(struct device_d *dev, const char *name)
> +{
> + struct param_d *param;
> +
> + param = get_child_param_by_name(dev, name);
> + if (param)
> + return param;
> +
> + return __get_param_by_name(dev, name);
> +}
> +
> /**
> * dev_get_param - get the value of a parameter
> * @param dev The device
> --
> 1.7.10.4
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-01-26 0:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-25 23:53 [PATCH 0/7] globalvar: add multiple device support Jean-Christophe PLAGNIOL-VILLARD
2013-01-25 23:55 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
2013-01-25 23:55 ` [PATCH 2/7] globalvar: add it's own bus Jean-Christophe PLAGNIOL-VILLARD
2013-01-25 23:55 ` [PATCH 3/7] globalvar: allow to register multiple device Jean-Christophe PLAGNIOL-VILLARD
2013-01-25 23:55 ` [PATCH 4/7] net: switch to global device Jean-Christophe PLAGNIOL-VILLARD
2013-01-25 23:55 ` [PATCH 5/7] dhcp: switch globalvar to it's own device Jean-Christophe PLAGNIOL-VILLARD
2013-01-25 23:55 ` [PATCH 6/7] bootm: " Jean-Christophe PLAGNIOL-VILLARD
2013-01-25 23:55 ` [PATCH 7/7] bootargs: " Jean-Christophe PLAGNIOL-VILLARD
2013-01-26 0:45 ` Alexander Aring [this message]
2013-01-27 10:08 ` [PATCH 0/7] globalvar: add multiple device support Sascha Hauer
2013-01-27 10:38 ` Jean-Christophe PLAGNIOL-VILLARD
2013-01-27 10:56 ` Sascha Hauer
2013-03-13 18:01 [PATCH 0/7 v2] " Jean-Christophe PLAGNIOL-VILLARD
2013-03-13 18:05 ` [PATCH 1/7] params: allow to access first sub-device and params via env Jean-Christophe PLAGNIOL-VILLARD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130126004548.GA7319@x61s.8.8.8.8 \
--to=alex.aring@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=plagnioj@jcrosoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox