diff options
author | Denis Kenzior <denkenz@gmail.com> | 2009-08-12 14:46:59 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-08-13 10:08:32 -0500 |
commit | 03e90fff1630346e6e6f8f81a1240cfdd2e0a20e (patch) | |
tree | f3d9b63b61a3fea6ec19b2864a772741d4e8ddfd | |
parent | 00482e341e946324bf32327e41da6c1cc4293c8f (diff) | |
download | ofono-03e90fff1630346e6e6f8f81a1240cfdd2e0a20e.tar.bz2 |
Add ofono atom routines
-rw-r--r-- | src/modem.c | 106 | ||||
-rw-r--r-- | src/ofono.h | 36 |
2 files changed, 142 insertions, 0 deletions
diff --git a/src/modem.c b/src/modem.c index 0b99e886..285aa332 100644 --- a/src/modem.c +++ b/src/modem.c @@ -54,6 +54,13 @@ struct ofono_modem_data { guint interface_update; }; +struct ofono_atom { + enum ofono_atom_type type; + void (*destruct)(struct ofono_atom *atom); + void (*unregister)(struct ofono_atom *atom); + void *data; +}; + unsigned int __ofono_modem_alloc_callid(struct ofono_modem *modem) { struct ofono_modem_data *d = modem->modem_info; @@ -99,6 +106,102 @@ const char *ofono_modem_get_path(struct ofono_modem *modem) return NULL; } +struct ofono_atom *__ofono_modem_add_atom(struct ofono_modem *modem, + enum ofono_atom_type type, + void (*destruct)(struct ofono_atom *), + void *data) +{ + struct ofono_atom *atom; + + if (modem == NULL) + return NULL; + + atom = g_new0(struct ofono_atom, 1); + + atom->type = type; + atom->destruct = destruct; + atom->data = data; + + modem->atoms = g_slist_prepend(modem->atoms, atom); + + return atom; +} + +void *__ofono_atom_get_data(struct ofono_atom *atom) +{ + return atom->data; +} + +void __ofono_atom_register(struct ofono_atom *atom, + void (*unregister)(struct ofono_atom *)) +{ + atom->unregister = unregister; +} + +void __ofono_atom_unregister(struct ofono_atom *atom) +{ + if (atom->unregister) + atom->unregister(atom); +} + +struct ofono_atom *__ofono_modem_find_atom(struct ofono_modem *modem, + enum ofono_atom_type type) +{ + GSList *l; + struct ofono_atom *atom; + + if (modem == NULL) + return NULL; + + for (l = modem->atoms; l; l = l->next) { + atom = l->data; + + if (atom->type == type) + return atom; + } + + return NULL; +} + +void __ofono_modem_remove_atom(struct ofono_modem *modem, + struct ofono_atom *atom) +{ + if (modem == NULL) + return; + + modem->atoms = g_slist_remove(modem->atoms, atom); + + __ofono_atom_unregister(atom); + + if (atom->destruct) + atom->destruct(atom); + + g_free(atom); +} + +static void remove_all_atoms(struct ofono_modem *modem) +{ + GSList *l; + struct ofono_atom *atom; + + if (modem == NULL) + return; + + for (l = modem->atoms; l; l = l->next) { + atom = l->data; + + __ofono_atom_unregister(atom); + + if (atom->destruct) + atom->destruct(atom); + + g_free(atom); + } + + g_slist_free(modem->atoms); + modem->atoms = NULL; +} + static void modem_free(gpointer data) { struct ofono_modem *modem = data; @@ -124,6 +227,7 @@ static void modem_free(gpointer data) g_source_remove(modem->modem_info->interface_update); g_free(modem->modem_info); + g_free(modem->path); g_free(modem); } @@ -426,6 +530,8 @@ static void modem_remove(struct ofono_modem *modem) ofono_debug("Removing modem: %s", modem->path); + remove_all_atoms(modem); + ofono_cssn_exit(modem); ofono_sim_manager_exit(modem); diff --git a/src/ofono.h b/src/ofono.h index 63f33adb..418a29bc 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -66,6 +66,8 @@ struct ofono_modem { GSList *ss_control_list; GSList *ss_passwd_list; + GSList *atoms; + struct ofono_modem_data *modem_info; struct network_registration_data *network_registration; struct voicecalls_data *voicecalls; @@ -89,6 +91,40 @@ struct ofono_modem { unsigned int __ofono_modem_alloc_callid(struct ofono_modem *modem); void __ofono_modem_release_callid(struct ofono_modem *modem, int id); +struct ofono_atom; + +enum ofono_atom_type { + OFONO_ATOM_TYPE_INFO = 0, + OFONO_ATOM_TYPE_CALL_BARRING = 1, + OFONO_ATOM_TYPE_CALL_FORWARDING = 2, + OFONO_ATOM_TYPE_CALL_METER = 3, + OFONO_ATOM_TYPE_CALL_SETTINGS = 4, + OFONO_ATOM_TYPE_NETWORK_REGISTRATION = 5, + OFONO_ATOM_TYPE_PHONEBOOK = 6, + OFONO_ATOM_TYPE_SMS = 7, + OFONO_ATOM_TYPE_SIM = 8, + OFONO_ATOM_TYPE_USSD = 9, + OFONO_ATOM_TYPE_VOICECALL = 10, + OFONO_ATOM_TYPE_HISTORY = 11 +}; + +struct ofono_atom *__ofono_modem_add_atom(struct ofono_modem *modem, + enum ofono_atom_type type, + void (*destruct)(struct ofono_atom *), + void *data); + +struct ofono_atom *__ofono_modem_find_atom(struct ofono_modem *modem, + enum ofono_atom_type type); + +void *__ofono_atom_get_data(struct ofono_atom *atom); + +void __ofono_atom_register(struct ofono_atom *atom, + void (*unregister)(struct ofono_atom *)); +void __ofono_atom_unregister(struct ofono_atom *atom); + +void __ofono_modem_remove_atom(struct ofono_modem *modem, + struct ofono_atom *atom); + #include <ofono/history.h> void __ofono_history_probe_drivers(struct ofono_modem *modem); |