summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-04-15 14:49:59 -0500
committerDenis Kenzior <denkenz@gmail.com>2010-04-15 16:49:42 -0500
commit9a9a05095dff1e7953e66fe934da53c8be2e7db5 (patch)
tree38167381ebfdba7311f2caa3cf3c3c5f62923eac
parent0ac64d66e87e27014b54f21e2d633e4d368ac8cf (diff)
downloadofono-9a9a05095dff1e7953e66fe934da53c8be2e7db5.tar.bz2
Refactor: Keep separate lists for pre/post atoms
-rw-r--r--src/modem.c86
1 files changed, 33 insertions, 53 deletions
diff --git a/src/modem.c b/src/modem.c
index 62ecd3c8..41fc2624 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -258,6 +258,14 @@ gboolean __ofono_modem_remove_atom_watch(struct ofono_modem *modem,
return __ofono_watchlist_remove_item(modem->atom_watches, id);
}
+#define FIND_ATOM_IN_LIST(list) \
+ for (l = list; l; l = l->next) { \
+ atom = l->data; \
+ \
+ if (atom->type == type) \
+ return atom; \
+ } \
+
struct ofono_atom *__ofono_modem_find_atom(struct ofono_modem *modem,
enum ofono_atom_type type)
{
@@ -267,16 +275,22 @@ struct ofono_atom *__ofono_modem_find_atom(struct ofono_modem *modem,
if (modem == NULL)
return NULL;
- for (l = modem->atoms; l; l = l->next) {
- atom = l->data;
-
- if (atom->type == type)
- return atom;
- }
+ FIND_ATOM_IN_LIST(modem->atoms)
+ FIND_ATOM_IN_LIST(modem->pre_sim_atoms);
return NULL;
}
+#define FOREACH_ATOM_IN_LIST(list) \
+ for (l = list; l; l = l->next) { \
+ atom = l->data; \
+ \
+ if (atom->type != type) \
+ continue; \
+ \
+ callback(atom, data); \
+ } \
+
void __ofono_modem_foreach_atom(struct ofono_modem *modem,
enum ofono_atom_type type,
ofono_atom_func callback, void *data)
@@ -287,14 +301,8 @@ void __ofono_modem_foreach_atom(struct ofono_modem *modem,
if (modem == NULL)
return;
- for (l = modem->atoms; l; l = l->next) {
- atom = l->data;
-
- if (atom->type != type)
- continue;
-
- callback(atom, data);
- }
+ FOREACH_ATOM_IN_LIST(modem->atoms)
+ FOREACH_ATOM_IN_LIST(modem->pre_sim_atoms)
}
void __ofono_atom_free(struct ofono_atom *atom)
@@ -312,45 +320,14 @@ void __ofono_atom_free(struct ofono_atom *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);
- g_slist_free(modem->pre_sim_atoms);
- modem->atoms = NULL;
- modem->pre_sim_atoms = NULL;
-}
-
-static void remove_post_sim_atoms(struct ofono_modem *modem)
+static void remove_all_atoms(GSList **atoms)
{
GSList *l;
struct ofono_atom *atom;
- if (modem == NULL)
- return;
-
- for (l = modem->atoms; l; l = l->next) {
+ for (l = *atoms; l; l = l->next) {
atom = l->data;
- if (g_slist_find(modem->pre_sim_atoms, atom))
- continue;
-
__ofono_atom_unregister(atom);
if (atom->destruct)
@@ -359,8 +336,8 @@ static void remove_post_sim_atoms(struct ofono_modem *modem)
g_free(atom);
}
- g_slist_free(modem->atoms);
- modem->atoms = g_slist_copy(modem->pre_sim_atoms);
+ g_slist_free(*atoms);
+ *atoms = NULL;
}
static DBusMessage *modem_get_properties(DBusConnection *conn,
@@ -445,7 +422,8 @@ static int set_powered(struct ofono_modem *modem, ofono_bool_t powered)
/* Remove the atoms even if the driver is no longer available */
if (powered == FALSE) {
- remove_all_atoms(modem);
+ remove_all_atoms(&modem->atoms);
+ remove_all_atoms(&modem->pre_sim_atoms);
modem->call_ids = 0;
}
@@ -623,7 +601,8 @@ void ofono_modem_set_powered(struct ofono_modem *modem, ofono_bool_t powered)
if (modem->driver->pre_sim)
modem->driver->pre_sim(modem);
} else {
- remove_all_atoms(modem);
+ remove_all_atoms(&modem->atoms);
+ remove_all_atoms(&modem->pre_sim_atoms);
modem->call_ids = 0;
}
}
@@ -1154,12 +1133,13 @@ static void modem_sim_ready(void *user, enum ofono_sim_state new_state)
switch (new_state) {
case OFONO_SIM_STATE_NOT_PRESENT:
- remove_post_sim_atoms(modem);
+ remove_all_atoms(&modem->atoms);
break;
case OFONO_SIM_STATE_INSERTED:
break;
case OFONO_SIM_STATE_READY:
- modem->pre_sim_atoms = g_slist_copy(modem->atoms);
+ modem->pre_sim_atoms = modem->atoms;
+ modem->atoms = NULL;
if (modem->driver->post_sim)
modem->driver->post_sim(modem);