linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anton Vorontsov <cbou@mail.ru>
To: Andres Salomon <dilinger@queued.net>
Cc: cbouatmailru@gmail.com, David Woodhouse <dwmw2@infradead.org>,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Subject: Re: [PATCH 1/5] power: RFC: introduce a new power API
Date: Mon, 17 Dec 2007 14:24:16 +0300	[thread overview]
Message-ID: <20071217112416.GA25948@localhost.localdomain> (raw)
In-Reply-To: <20071217024139.2f81e36d@ephemeral>

On Mon, Dec 17, 2007 at 02:41:39AM -0500, Andres Salomon wrote:
[...]
> > > On Sun, 2007-12-16 at 21:24 -0500, Andres Salomon wrote:
> > > > This API has the power_supply drivers device their own device_attribute
> > > > list; I find this to be a lot more flexible and cleaner.  
> > 
> > I don't see how this is more flexible and cleaner. See below.
> > 
> > > > For example,
> > > > rather than having a function with a huge switch statement (as olpc_battery
> > > > currently has), we have separate callback functions.
> > 
> > Is this an improvement? Look into ds2760_battery.c. I scared to
> > imagine what it will look like after conversion.
> 
> Why?  It would not look bad after conversion.  Basically:
> 
> static ssize_t ds2760_battery_get_status(struct device *dev,
>                 struct device_attribute *attr, char *buf)
> {
> 	struct ds2760_device_info *di = to_ds2760_device_info(psy);
> 	return power_supply_status_str(di->charge_status, buf);
> }
> static ssize_t ds2760_battery_get_voltage_now(struct device *dev,
>                 struct device_attribute *attr, char *buf)
> {
> 	struct ds2760_device_info *di = to_ds2760_device_info(psy);
> 	ds2760_battery_read_status(di);
> 	return sprintf(buf, "%d\n", di->voltage_uV);
> }
> 
> ....an so on.
> 
> If I wanted to get really clever, I could do:
> 
> #define DS2760_CALLBACK(name, fmt, var)                       \
> static ssize_t ds2760_battery_get_##name(struct device *dev,  \
> 		struct device_attribute *attr, char *buf)     \
> {                                                             \
> 	struct ds2760_device_info *di = to_ds2760_device_info(psy); \
>         ds2760_battery_read_status(di);                       \
> 	return sprintf(buf, fmt, var);                        \
> }
> 
> DS2760_CALLBACK(voltage_now, "%d\n", di->voltage_uV)
> DS2760_CALLBACK(current_now, "%d\n", di->current_uA)
> 
> etc.. but, I'm not trying to compress lines of code, I'm trying
> to ensure things are readable.

Hehe, look: http://lkml.org/lkml/2007/4/11/397

These macros are indeed what I've tried to avoid, dozen open-coded
similar functions not a good option either. I also tried to avoid
"function per property" stuff...

[lots of sense snipped]

I see your point now. Basically, now I'm encourage to think just one
more time: is there third (better) option in addition to current and
this? I still hope there is some not obvious, but elegant solution.
If there isn't, I'm ready to surrender and will help with everything
I can.


Thanks!

-- 
Anton Vorontsov
email: cbou@mail.ru
backup email: ya-cbou@yandex.ru
irc://irc.freenode.net/bd2

  reply	other threads:[~2007-12-17 11:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-17  2:24 [PATCH 1/5] power: RFC: introduce a new power API Andres Salomon
2007-12-17  2:36 ` David Woodhouse
2007-12-17  5:51   ` Anton Vorontsov
2007-12-17  7:41     ` Andres Salomon
2007-12-17 11:24       ` Anton Vorontsov [this message]
2007-12-18  7:10         ` Andres Salomon
2007-12-19 12:35           ` Anton Vorontsov
2007-12-19 18:02             ` Andres Salomon
2007-12-19 18:50               ` Anton Vorontsov
2007-12-19 23:13                 ` Andres Salomon
2007-12-20 15:07                   ` Anton Vorontsov
2007-12-20 16:00                     ` Andres Salomon
2007-12-20 17:09                       ` Anton Vorontsov

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=20071217112416.GA25948@localhost.localdomain \
    --to=cbou@mail.ru \
    --cc=akpm@linux-foundation.org \
    --cc=cbouatmailru@gmail.com \
    --cc=dilinger@queued.net \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).