ofono/include/modem.h

108 lines
3.4 KiB
C
Raw Normal View History

/*
*
* oFono - Open Source Telephony
*
2010-01-02 01:00:10 +00:00
* Copyright (C) 2008-2010 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __OFONO_MODEM_H
#define __OFONO_MODEM_H
#ifdef __cplusplus
extern "C" {
#endif
2009-08-22 00:11:32 +00:00
#include <ofono/types.h>
2009-07-29 19:33:58 +00:00
struct ofono_modem;
void ofono_modem_add_interface(struct ofono_modem *modem,
const char *interface);
void ofono_modem_remove_interface(struct ofono_modem *modem,
const char *interface);
2009-07-29 19:26:45 +00:00
const char *ofono_modem_get_path(struct ofono_modem *modem);
void ofono_modem_set_data(struct ofono_modem *modem, void *data);
void *ofono_modem_get_data(struct ofono_modem *modem);
2009-07-29 19:33:58 +00:00
2010-01-06 21:50:25 +00:00
struct ofono_modem *ofono_modem_create(const char *name, const char *type);
2009-08-22 00:11:32 +00:00
int ofono_modem_register(struct ofono_modem *modem);
void ofono_modem_remove(struct ofono_modem *modem);
void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered);
ofono_bool_t ofono_modem_get_powered(struct ofono_modem *modem);
ofono_bool_t ofono_modem_get_online(struct ofono_modem *modem);
2010-02-13 00:29:41 +00:00
void ofono_modem_set_name(struct ofono_modem *modem, const char *name);
int ofono_modem_set_string(struct ofono_modem *modem,
const char *key, const char *value);
const char *ofono_modem_get_string(struct ofono_modem *modem, const char *key);
int ofono_modem_set_integer(struct ofono_modem *modem,
const char *key, int value);
int ofono_modem_get_integer(struct ofono_modem *modem, const char *key);
2009-09-08 07:12:19 +00:00
int ofono_modem_set_boolean(struct ofono_modem *modem,
const char *key, ofono_bool_t value);
ofono_bool_t ofono_modem_get_boolean(struct ofono_modem *modem,
const char *key);
2009-09-08 07:12:19 +00:00
typedef void (*ofono_modem_online_cb_t)(const struct ofono_error *error,
2010-05-26 19:25:38 +00:00
void *data);
2009-08-22 00:11:32 +00:00
struct ofono_modem_driver {
const char *name;
driver callback naming 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.
2009-08-30 20:00:26 +00:00
2009-08-30 20:32:08 +00:00
/* Detect existence of device and initialize any device-specific data
* structures */
2009-08-22 00:11:32 +00:00
int (*probe)(struct ofono_modem *modem);
2009-08-30 20:32:08 +00:00
/* Destroy data structures allocated during probe and cleanup */
void (*remove)(struct ofono_modem *modem);
driver callback naming 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.
2009-08-30 20:00:26 +00:00
2009-08-30 20:32:08 +00:00
/* Power up device */
2009-08-22 00:11:32 +00:00
int (*enable)(struct ofono_modem *modem);
2009-08-30 20:32:08 +00:00
/* Power down device */
2009-08-22 00:11:32 +00:00
int (*disable)(struct ofono_modem *modem);
driver callback naming 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.
2009-08-30 20:00:26 +00:00
/* Enable or disable cellular radio */
void (*set_online)(struct ofono_modem *modem, ofono_bool_t online,
ofono_modem_online_cb_t callback, void *data);
/* Populate the atoms available without SIM / Locked SIM */
void (*pre_sim)(struct ofono_modem *modem);
/* Populate the atoms that are available with SIM / Unlocked SIM*/
void (*post_sim)(struct ofono_modem *modem);
/* Populate the atoms available online */
void (*post_online)(struct ofono_modem *modem);
2009-08-22 00:11:32 +00:00
};
int ofono_modem_driver_register(const struct ofono_modem_driver *);
void ofono_modem_driver_unregister(const struct ofono_modem_driver *);
#ifdef __cplusplus
}
#endif
#endif /* __OFONO_MODEM_H */