summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c4
-rw-r--r--src/modem.c50
-rw-r--r--src/ofono.h8
3 files changed, 62 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 20bf0d7d..010384ce 100644
--- a/src/main.c
+++ b/src/main.c
@@ -226,6 +226,8 @@ int main(int argc, char **argv)
__ofono_dbus_init(conn);
+ __ofono_modemwatch_init();
+
__ofono_manager_init();
__ofono_plugin_init(option_plugin, option_noplugin);
@@ -239,6 +241,8 @@ int main(int argc, char **argv)
__ofono_manager_cleanup();
+ __ofono_modemwatch_cleanup();
+
__ofono_dbus_cleanup();
dbus_connection_unref(conn);
diff --git a/src/modem.c b/src/modem.c
index b7ca9646..7a29edfe 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -42,6 +42,8 @@ static int next_modem_id = 0;
static gboolean powering_down = FALSE;
static int modems_remaining = 0;
+static struct ofono_watchlist *g_modemwatches = NULL;
+
enum property_type {
PROPERTY_TYPE_INVALID = 0,
PROPERTY_TYPE_STRING,
@@ -1334,6 +1336,52 @@ static void sim_watch(struct ofono_atom *atom,
modem, NULL);
}
+void __ofono_modemwatch_init()
+{
+ g_modemwatches = __ofono_watchlist_new(g_free);
+}
+
+void __ofono_modemwatch_cleanup()
+{
+ __ofono_watchlist_free(g_modemwatches);
+}
+
+unsigned int __ofono_modemwatch_add(ofono_modemwatch_cb_t cb, void *user,
+ ofono_destroy_func destroy)
+{
+ struct ofono_watchlist_item *watch;
+
+ if (cb == NULL)
+ return 0;
+
+ watch = g_new0(struct ofono_watchlist_item, 1);
+
+ watch->notify = cb;
+ watch->destroy = destroy;
+ watch->notify_data = user;
+
+ return __ofono_watchlist_add_item(g_modemwatches, watch);
+}
+
+gboolean __ofono_modemwatch_remove(unsigned int id)
+{
+ return __ofono_watchlist_remove_item(g_modemwatches, id);
+}
+
+static void call_modemwatches(struct ofono_modem *modem, gboolean added)
+{
+ GSList *l;
+ struct ofono_watchlist_item *watch;
+ ofono_modemwatch_cb_t notify;
+
+ for (l = g_modemwatches->items; l; l = l->next) {
+ watch = l->data;
+
+ notify = watch->notify;
+ notify(modem, added, watch->notify_data);
+ }
+}
+
static void emit_modem_added(struct ofono_modem *modem)
{
DBusMessage *signal;
@@ -1411,6 +1459,7 @@ int ofono_modem_register(struct ofono_modem *modem)
modem->atom_watches = __ofono_watchlist_new(g_free);
emit_modem_added(modem);
+ call_modemwatches(modem, TRUE);
modem->sim_watch = __ofono_modem_add_atom_watch(modem,
OFONO_ATOM_TYPE_SIM,
@@ -1476,6 +1525,7 @@ static void modem_unregister(struct ofono_modem *modem)
modem->driver = NULL;
emit_modem_removed(modem);
+ call_modemwatches(modem, FALSE);
}
void ofono_modem_remove(struct ofono_modem *modem)
diff --git a/src/ofono.h b/src/ofono.h
index 899929eb..f63ff1d3 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -168,6 +168,14 @@ gboolean __ofono_modem_remove_atom_watch(struct ofono_modem *modem,
void __ofono_atom_free(struct ofono_atom *atom);
+typedef void (*ofono_modemwatch_cb_t)(struct ofono_modem *modem,
+ gboolean added, void *data);
+void __ofono_modemwatch_init();
+void __ofono_modemwatch_cleanup();
+unsigned int __ofono_modemwatch_add(ofono_modemwatch_cb_t cb, void *user,
+ ofono_destroy_func destroy);
+gboolean __ofono_modemwatch_remove(unsigned int id);
+
#include <ofono/call-barring.h>
gboolean __ofono_call_barring_is_busy(struct ofono_call_barring *cb);