diff options
author | Denis Kenzior <denkenz@gmail.com> | 2009-09-10 23:01:59 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-09-11 12:39:53 -0500 |
commit | 32fc30fa02a6d46b78f45e446b2347754ba2136a (patch) | |
tree | 306266d6994715256b41e8d2f8389acc15ace038 /src/modem.c | |
parent | 27cfc00eba7cc9a72a33d9d9674e1c31aef84acb (diff) | |
download | ofono-32fc30fa02a6d46b78f45e446b2347754ba2136a.tar.bz2 |
Refactor various watch functions
Use a common core kernel for all the watcher registrations /
notifications. This is now done in watch.c
Diffstat (limited to 'src/modem.c')
-rw-r--r-- | src/modem.c | 113 |
1 files changed, 33 insertions, 80 deletions
diff --git a/src/modem.c b/src/modem.c index 5e6e582a..1a654afa 100644 --- a/src/modem.c +++ b/src/modem.c @@ -48,22 +48,21 @@ enum ofono_property_type { }; struct ofono_modem { - char *path; - GSList *atoms; - GSList *atom_watches; - int next_atom_watch_id; - GSList *interface_list; - unsigned int call_ids; - DBusMessage *pending; - guint interface_update; - ofono_bool_t powered; - ofono_bool_t powered_pending; - ofono_bool_t powered_persistent; - guint timeout; - GHashTable *properties; + char *path; + GSList *atoms; + struct ofono_watchlist *atom_watches; + GSList *interface_list; + unsigned int call_ids; + DBusMessage *pending; + guint interface_update; + ofono_bool_t powered; + ofono_bool_t powered_pending; + ofono_bool_t powered_persistent; + guint timeout; + GHashTable *properties; const struct ofono_modem_driver *driver; - void *driver_data; - char *driver_type; + void *driver_data; + char *driver_type; }; struct ofono_devinfo { @@ -85,11 +84,8 @@ struct ofono_atom { }; struct ofono_atom_watch { + struct ofono_watchlist_item item; enum ofono_atom_type type; - int id; - ofono_atom_watch_func notify; - ofono_destroy_func destroy; - void *notify_data; }; struct ofono_property { @@ -182,16 +178,19 @@ static void call_watches(struct ofono_atom *atom, enum ofono_atom_watch_condition cond) { struct ofono_modem *modem = atom->modem; + GSList *atom_watches = modem->atom_watches->items; GSList *l; struct ofono_atom_watch *watch; + ofono_atom_watch_func notify; - for (l = modem->atom_watches; l; l = l->next) { + for (l = atom_watches; l; l = l->next) { watch = l->data; if (watch->type != atom->type) continue; - watch->notify(atom, cond, watch->notify_data); + notify = watch->item.notify; + notify(atom, cond, watch->item.notify_data); } } @@ -221,7 +220,7 @@ gboolean __ofono_atom_get_registered(struct ofono_atom *atom) return atom->unregister ? TRUE : FALSE; } -int __ofono_modem_add_atom_watch(struct ofono_modem *modem, +unsigned int __ofono_modem_add_atom_watch(struct ofono_modem *modem, enum ofono_atom_type type, ofono_atom_watch_func notify, void *data, ofono_destroy_func destroy) @@ -234,67 +233,18 @@ int __ofono_modem_add_atom_watch(struct ofono_modem *modem, watch = g_new0(struct ofono_atom_watch, 1); watch->type = type; - watch->id = ++modem->next_atom_watch_id; - watch->notify = notify; - watch->destroy = destroy; - watch->notify_data = data; - - modem->atom_watches = g_slist_prepend(modem->atom_watches, watch); - - return watch->id; -} - -gboolean __ofono_modem_remove_atom_watch(struct ofono_modem *modem, int id) -{ - struct ofono_atom_watch *watch; - GSList *p; - GSList *c; - - p = NULL; - c = modem->atom_watches; - - while (c) { - watch = c->data; - - if (watch->id != id) { - p = c; - c = c->next; - continue; - } - - if (p) - p->next = c->next; - else - modem->atom_watches = c->next; - - if (watch->destroy) - watch->destroy(watch->notify_data); + watch->item.notify = notify; + watch->item.destroy = destroy; + watch->item.notify_data = data; - g_free(watch); - g_slist_free_1(c); - - return TRUE; - } - - return FALSE; + return __ofono_watchlist_add_item(modem->atom_watches, + (struct ofono_watchlist_item *)watch); } -static void remove_all_watches(struct ofono_modem *modem) +gboolean __ofono_modem_remove_atom_watch(struct ofono_modem *modem, + unsigned int id) { - struct ofono_atom_watch *watch; - GSList *l; - - for (l = modem->atom_watches; l; l = l->next) { - watch = l->data; - - if (watch->destroy) - watch->destroy(watch->notify_data); - - g_free(watch); - } - - g_slist_free(modem->atom_watches); - modem->atom_watches = NULL; + return __ofono_watchlist_remove_item(modem->atom_watches, id); } struct ofono_atom *__ofono_modem_find_atom(struct ofono_modem *modem, @@ -1076,6 +1026,7 @@ struct ofono_modem *ofono_modem_create(const char *type) modem->driver_type = g_strdup(type); modem->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, unregister_property); + modem->atom_watches = __ofono_watchlist_new(g_free); g_modem_list = g_slist_prepend(g_modem_list, modem); @@ -1165,7 +1116,9 @@ static void modem_unregister(struct ofono_modem *modem) return; remove_all_atoms(modem); - remove_all_watches(modem); + + __ofono_watchlist_free(modem->atom_watches); + modem->atom_watches = NULL; g_slist_foreach(modem->interface_list, (GFunc)g_free, NULL); g_slist_free(modem->interface_list); |