Open Source Telephony
 help / color / mirror / Atom feed
From: Andres Salomon <dilinger@collabora.co.uk>
To: ofono@ofono.org
Subject: Re: driver callback naming
Date: Sun, 30 Aug 2009 16:00:26 -0400	[thread overview]
Message-ID: <20090830160026.75672609@mycelium.queued.net> (raw)
In-Reply-To: <200908301345.45643.denkenz@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3461 bytes --]

On Sun, 30 Aug 2009 13:45:45 -0500
Denis Kenzior <denkenz@gmail.com> wrote:

> Hi Andres,
> 
> > static struct ofono_modem_driver g1_driver = {
> >         .name = "HTC G1",
> >         .probe = g1_probe,
> >         .enable = g1_enable,
> >         .disable = g1_disable,
> >         .remove = g1_remove,
> >         .populate = g1_populate,
> > };
> >
> 
> So the current intention:
> .probe - Detect whether device is really supported by the plugin,
> initialize any data structures specific to the device
> .remove - Destroy data structures
> .enable - Perform power up
> .disable - Perform power down
> .populate - Populate the atoms supported by this device (e.g. netreg, 
> voicecall, etc)  This is called by the core after every power cycle,
> when the device is brought up.
> 

Thanks!  See patch below.


> >
> > Of course, I'm also wondering why there needs to be two separate
> > layers of calls in the first place.  Why not have drivers register
> > everything from within probe, call ofono_set_powered(modem, TRUE)
> > once the device is ready, and be done with it?
> 
> The reason for this is e.g. airplane mode, where you physically want
> to turn off the device.  Another case is for battery / power reasons,
> e.g. a netbook with a USB modem that is not being used.
> 

Fair enough.  In the kernel, we have callbacks named suspend/resume
to handle that. 

> > The only reason why this doesn't blow up in the generic_at plugin is
> > because the driver_data is leaked.  If one were to free it from
> > generic_at_exit in the wrong place (since it's allocated from
> > generic_at_init, it would make sense to free it in generic_at_exit),
> > one would see the same SEGV/SIGBUS/SIGILL errors upon ctrl-c.
> 
> So the leak has now been fixed.
> 
> I think you're being unnecessarily harsh here.  To be fair, the
> generic_at driver does something like this at init:

My criticism is simply w/ the naming.  'enable'/'disable' doesn't imply
anything about power.  powerup/powerdown, poweron/poweroff,
suspend/resume would all imply power state changes (at least the latter
would be familiar to those who do kernel stuff).  Having comments that
describe what the callbacks do would also work, though.




From 80a7b54d52201dfd7d8b590457450ae0a4f72888 Mon Sep 17 00:00:00 2001
From: Andres Salomon <dilinger@collabora.co.uk>
Date: Sun, 30 Aug 2009 15:56:16 -0400
Subject: [PATCH] Add comments to ofono_modem_driver struct

Document what all the callbacks do.
---
 include/modem.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/modem.h b/include/modem.h
index 0a5ef60..4303024 100644
--- a/include/modem.h
+++ b/include/modem.h
@@ -50,10 +50,19 @@ ofono_bool_t ofono_modem_get_powered(struct ofono_modem *modem);
 
 struct ofono_modem_driver {
 	const char *name;
+
+	/* probe - Detect existence of device and initialize any
+	 * device-specific data structures */
 	int (*probe)(struct ofono_modem *modem);
+	/* remove - Destroy data structures allocated during probe */
 	int (*remove)(struct ofono_modem *modem);
+
+	/* enable - Power up device */
 	int (*enable)(struct ofono_modem *modem);
+	/* disable - Power down device */
 	int (*disable)(struct ofono_modem *modem);
+
+	/* populate - Populate the atoms supported by this device */
 	int (*populate)(struct ofono_modem *modem);
 };
 
-- 
1.6.3.3




  reply	other threads:[~2009-08-30 20:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-29 22:01 driver callback naming Andres Salomon
2009-08-30 18:45 ` Denis Kenzior
2009-08-30 20:00   ` Andres Salomon [this message]
2009-08-30 20:10     ` Denis Kenzior
2009-08-30 20:10   ` Aki Niemi
2009-08-30 20:20     ` Denis Kenzior
2009-08-31  8:54       ` Aki Niemi

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=20090830160026.75672609@mycelium.queued.net \
    --to=dilinger@collabora.co.uk \
    --cc=ofono@ofono.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