---
 src/network.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ofono.h   |   10 +++++++++
 2 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/src/network.c b/src/network.c
index c059906..4a0e984 100644
--- a/src/network.c
+++ b/src/network.c
@@ -79,6 +79,7 @@ struct ofono_netreg {
        GKeyFile *settings;
        char *imsi;
        struct ofono_watchlist *status_watches;
+       struct ofono_watchlist *strength_watches;
        const struct ofono_netreg_driver *driver;
        void *driver_data;
        struct ofono_atom *atom;
@@ -1159,6 +1160,51 @@ static void notify_status_watches(struct ofono_netreg 
*netreg)
        }
 }
 
+unsigned int __ofono_netreg_add_strength_watch(struct ofono_netreg *netreg,
+                               ofono_netreg_strength_notify_cb_t notify,
+                               void *data, ofono_destroy_func destroy)
+{
+       struct ofono_watchlist_item *item;
+
+       DBG("%p", netreg);
+
+       if (netreg == NULL)
+               return 0;
+
+       if (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(netreg->strength_watches, item);
+}
+
+gboolean __ofono_netreg_remove_strength_watch(struct ofono_netreg *netreg,
+                                               unsigned int id)
+{
+       DBG("%p", netreg);
+
+       return __ofono_watchlist_remove_item(netreg->strength_watches, id);
+}
+
+static void notify_strength_watches(struct ofono_netreg *netreg)
+{
+       struct ofono_watchlist_item *item;
+       GSList *l;
+       ofono_netreg_strength_notify_cb_t notify;
+
+       for (l = netreg->strength_watches->items; l; l = l->next) {
+               item = l->data;
+               notify = item->notify;
+
+               notify(netreg->signal_strength, item->notify_data);
+       }
+}
+
 static void reset_available(struct network_operator_data *old,
                                const struct ofono_network_operator *new)
 {
@@ -1400,6 +1446,8 @@ void ofono_netreg_strength_notify(struct ofono_netreg 
*netreg, int strength)
                                        OFONO_NETWORK_REGISTRATION_INTERFACE,
                                        "Strength", DBUS_TYPE_BYTE,
                                        &strength);
+
+               notify_strength_watches(netreg);
        }
 }
 
@@ -1599,6 +1647,14 @@ int ofono_netreg_get_status(struct ofono_netreg *netreg)
        return netreg->status;
 }
 
+int ofono_netreg_get_strength(struct ofono_netreg *netreg)
+{
+       if (netreg == NULL)
+               return -1;
+
+       return netreg->signal_strength;
+}
+
 int ofono_netreg_get_technology(struct ofono_netreg *netreg)
 {
        if (netreg == NULL)
@@ -1659,6 +1715,9 @@ static void netreg_unregister(struct ofono_atom *atom)
        __ofono_watchlist_free(netreg->status_watches);
        netreg->status_watches = NULL;
 
+       __ofono_watchlist_free(netreg->strength_watches);
+       netreg->strength_watches = NULL;
+
        for (l = netreg->operator_list; l; l = l->next) {
                struct network_operator_data *opd = l->data;
 
@@ -1857,6 +1916,8 @@ void ofono_netreg_register(struct ofono_netreg *netreg)
 
        netreg->status_watches = __ofono_watchlist_new(g_free);
 
+       netreg->strength_watches = __ofono_watchlist_new(g_free);
+
        ofono_modem_add_interface(modem, OFONO_NETWORK_REGISTRATION_INTERFACE);
 
        if (netreg->driver->registration_status != NULL)
diff --git a/src/ofono.h b/src/ofono.h
index 14dcd18..f82f447 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -404,6 +404,16 @@ unsigned int __ofono_netreg_add_status_watch(struct 
ofono_netreg *netreg,
 gboolean __ofono_netreg_remove_status_watch(struct ofono_netreg *netreg,
                                                unsigned int id);
 
+typedef void (*ofono_netreg_strength_notify_cb_t)(int signal_strength,
+                                                       void *data);
+
+unsigned int __ofono_netreg_add_strength_watch(struct ofono_netreg *netreg,
+                               ofono_netreg_strength_notify_cb_t cb,
+                               void *data, ofono_destroy_func destroy);
+
+gboolean __ofono_netreg_remove_strength_watch(struct ofono_netreg *netreg,
+                                               unsigned int id);
+
 void __ofono_netreg_set_base_station_name(struct ofono_netreg *netreg,
                                                const char *name);
 
-- 
1.7.1

_______________________________________________
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono

Reply via email to