From 2b50146a21a0382e1fb68374b8f92d02358e1555 Mon Sep 17 00:00:00 2001 From: Guillaume Zajac Date: Mon, 31 Jan 2011 11:01:48 +0100 Subject: [PATCH] modem Add powered watch API --- src/modem.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/ofono.h | 7 +++++++ 2 files changed, 54 insertions(+) diff --git a/src/modem.c b/src/modem.c index 6cb8fab..b195970 100644 --- a/src/modem.c +++ b/src/modem.c @@ -77,6 +77,7 @@ struct ofono_modem { guint timeout; ofono_bool_t online; struct ofono_watchlist *online_watches; + struct ofono_watchlist *powered_watches; GHashTable *properties; struct ofono_sim *sim; unsigned int sim_watch; @@ -383,6 +384,22 @@ static void notify_online_watches(struct ofono_modem *modem) } } +static void notify_powered_watches(struct ofono_modem *modem) +{ + struct ofono_watchlist_item *item; + GSList *l; + ofono_modem_powered_notify_func notify; + + if (modem->powered_watches == NULL) + return; + + for (l = modem->powered_watches->items; l; l = l->next) { + item = l->data; + notify = item->notify; + notify(modem->powered, item->notify_data); + } +} + static void modem_change_state(struct ofono_modem *modem, enum modem_state new_state) { @@ -462,6 +479,30 @@ void __ofono_modem_remove_online_watch(struct ofono_modem *modem, __ofono_watchlist_remove_item(modem->online_watches, id); } +unsigned int __ofono_modem_add_powered_watch(struct ofono_modem *modem, + ofono_modem_powered_notify_func notify, + void *data, ofono_destroy_func destroy) +{ + struct ofono_watchlist_item *item; + + if (modem == NULL || notify == NULL) + return 0; + + item = g_new0(struct ofono_watchlist_item, 1); + + item->notify = notify; + item->destroy = destroy; + item->notify_data = data; + + return __ofono_watchlist_add_item(modem->powered_watches, item); +} + +void __ofono_modem_remove_powered_watch(struct ofono_modem *modem, + unsigned int id) +{ + __ofono_watchlist_remove_item(modem->powered_watches, id); +} + static void common_online_cb(const struct ofono_error *error, void *data) { struct ofono_modem *modem = data; @@ -723,6 +764,8 @@ static int set_powered(struct ofono_modem *modem, ofono_bool_t powered) else if (err != -EINPROGRESS) modem->powered_pending = modem->powered; + notify_powered_watches(modem); + return err; } @@ -1699,6 +1742,7 @@ int ofono_modem_register(struct ofono_modem *modem) modem->atom_watches = __ofono_watchlist_new(g_free); modem->online_watches = __ofono_watchlist_new(g_free); + modem->powered_watches = __ofono_watchlist_new(g_free); emit_modem_added(modem); call_modemwatches(modem, TRUE); @@ -1733,6 +1777,9 @@ static void modem_unregister(struct ofono_modem *modem) __ofono_watchlist_free(modem->online_watches); modem->online_watches = NULL; + __ofono_watchlist_free(modem->powered_watches); + modem->powered_watches = NULL; + modem->sim_watch = 0; modem->sim_ready_watch = 0; diff --git a/src/ofono.h b/src/ofono.h index 229fcb2..328213c 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -188,6 +188,13 @@ unsigned int __ofono_modem_add_online_watch(struct ofono_modem *modem, void __ofono_modem_remove_online_watch(struct ofono_modem *modem, unsigned int id); +typedef void (*ofono_modem_powered_notify_func)(ofono_bool_t powered, void *data); +unsigned int __ofono_modem_add_powered_watch(struct ofono_modem *modem, + ofono_modem_online_notify_func notify, + void *data, ofono_destroy_func destroy); +void __ofono_modem_remove_powered_watch(struct ofono_modem *modem, + unsigned int id); + #include gboolean __ofono_call_barring_is_busy(struct ofono_call_barring *cb); -- 2.7.4