ofono: Listen to oFono's D-Bus signals
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Mon, 21 Nov 2011 17:28:01 +0000 (18:28 +0100)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Mon, 12 Dec 2011 16:33:58 +0000 (17:33 +0100)
The intersting signals are from the Modem, SimManager
ConnectionManager, ConnectionContext and the NetwworkRegistration
interfaces. In this patch we add the empty functions.

plugins/ofono.c

index 7d979c4..7fbdbac 100644 (file)
 #include <connman/dbus.h>
 #include <connman/log.h>
 
+#define OFONO_SERVICE                  "org.ofono"
+
+#define OFONO_MANAGER_INTERFACE                OFONO_SERVICE ".Manager"
+#define OFONO_MODEM_INTERFACE          OFONO_SERVICE ".Modem"
+#define OFONO_SIM_INTERFACE            OFONO_SERVICE ".SimManager"
+#define OFONO_NETREG_INTERFACE         OFONO_SERVICE ".NetworkRegistration"
+#define OFONO_CM_INTERFACE             OFONO_SERVICE ".ConnectionManager"
+#define OFONO_CONTEXT_INTERFACE                OFONO_SERVICE ".ConnectionContext"
+
+#define MODEM_ADDED                    "ModemAdded"
+#define MODEM_REMOVED                  "ModemRemoved"
+#define PROPERTY_CHANGED               "PropertyChanged"
+#define CONTEXT_ADDED                  "ContextAdded"
+#define CONTEXT_REMOVED                        "ContextRemoved"
+
 static DBusConnection *connection;
 
+static gboolean context_changed(DBusConnection *connection,
+                               DBusMessage *message,
+                               void *user_data)
+{
+       return TRUE;
+}
+
+static gboolean cm_context_added(DBusConnection *connection,
+                                       DBusMessage *message,
+                                       void *user_data)
+{
+       return TRUE;
+}
+
+static gboolean cm_context_removed(DBusConnection *connection,
+                                       DBusMessage *message,
+                                       void *user_data)
+{
+       return TRUE;
+}
+
+static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
+                               void *user_data)
+{
+       return TRUE;
+}
+
+static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
+                               void *user_data)
+{
+       return TRUE;
+}
+
+static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
+                               void *user_data)
+{
+       return TRUE;
+}
+
+static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
+                               void *user_data)
+{
+       return TRUE;
+}
+
+static gboolean modem_added(DBusConnection *connection,
+                               DBusMessage *message, void *user_data)
+{
+       return TRUE;
+}
+
+static gboolean modem_removed(DBusConnection *connection,
+                               DBusMessage *message, void *user_data)
+{
+       return TRUE;
+}
+
+static void ofono_connect(DBusConnection *conn, void *user_data)
+{
+}
+
+static void ofono_disconnect(DBusConnection *conn, void *user_data)
+{
+}
+
 static int network_probe(struct connman_network *network)
 {
        DBG("network %p", network);
@@ -109,6 +189,17 @@ static struct connman_device_driver modem_driver = {
        .disable        = modem_disable,
 };
 
+static guint watch;
+static guint modem_added_watch;
+static guint modem_removed_watch;
+static guint modem_watch;
+static guint cm_watch;
+static guint sim_watch;
+static guint context_added_watch;
+static guint context_removed_watch;
+static guint netreg_watch;
+static guint context_watch;
+
 static int ofono_init(void)
 {
        int err;
@@ -119,6 +210,74 @@ static int ofono_init(void)
        if (connection == NULL)
                return -EIO;
 
+       watch = g_dbus_add_service_watch(connection,
+                                       OFONO_SERVICE, ofono_connect,
+                                       ofono_disconnect, NULL, NULL);
+
+       modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               OFONO_MANAGER_INTERFACE,
+                                               MODEM_ADDED,
+                                               modem_added,
+                                               NULL, NULL);
+
+       modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               OFONO_MANAGER_INTERFACE,
+                                               MODEM_REMOVED,
+                                               modem_removed,
+                                               NULL, NULL);
+
+       modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               OFONO_MODEM_INTERFACE,
+                                               PROPERTY_CHANGED,
+                                               modem_changed,
+                                               NULL, NULL);
+
+       cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               OFONO_CM_INTERFACE,
+                                               PROPERTY_CHANGED,
+                                               cm_changed,
+                                               NULL, NULL);
+
+       sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               OFONO_SIM_INTERFACE,
+                                               PROPERTY_CHANGED,
+                                               sim_changed,
+                                               NULL, NULL);
+
+       context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               OFONO_CM_INTERFACE,
+                                               CONTEXT_ADDED,
+                                               cm_context_added,
+                                               NULL, NULL);
+
+       context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               OFONO_CM_INTERFACE,
+                                               CONTEXT_REMOVED,
+                                               cm_context_removed,
+                                               NULL, NULL);
+
+       context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               OFONO_CONTEXT_INTERFACE,
+                                               PROPERTY_CHANGED,
+                                               context_changed,
+                                               NULL, NULL);
+
+       netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+                                               OFONO_NETREG_INTERFACE,
+                                               PROPERTY_CHANGED,
+                                               netreg_changed,
+                                               NULL, NULL);
+
+
+       if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
+                       modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
+                       context_added_watch == 0 ||
+                       context_removed_watch == 0 ||
+                       context_watch == 0 || netreg_watch == 0) {
+               err = -EIO;
+               goto remove;
+       }
+
        err = connman_network_driver_register(&network_driver);
        if (err < 0)
                goto remove;
@@ -132,6 +291,16 @@ static int ofono_init(void)
        return 0;
 
 remove:
+       g_dbus_remove_watch(connection, netreg_watch);
+       g_dbus_remove_watch(connection, context_watch);
+       g_dbus_remove_watch(connection, context_removed_watch);
+       g_dbus_remove_watch(connection, context_added_watch);
+       g_dbus_remove_watch(connection, sim_watch);
+       g_dbus_remove_watch(connection, cm_watch);
+       g_dbus_remove_watch(connection, modem_watch);
+       g_dbus_remove_watch(connection, modem_removed_watch);
+       g_dbus_remove_watch(connection, modem_added_watch);
+       g_dbus_remove_watch(connection, watch);
        dbus_connection_unref(connection);
 
        return err;
@@ -144,6 +313,17 @@ static void ofono_exit(void)
        connman_device_driver_unregister(&modem_driver);
        connman_network_driver_unregister(&network_driver);
 
+       g_dbus_remove_watch(connection, netreg_watch);
+       g_dbus_remove_watch(connection, context_watch);
+       g_dbus_remove_watch(connection, context_removed_watch);
+       g_dbus_remove_watch(connection, context_added_watch);
+       g_dbus_remove_watch(connection, sim_watch);
+       g_dbus_remove_watch(connection, cm_watch);
+       g_dbus_remove_watch(connection, modem_watch);
+       g_dbus_remove_watch(connection, modem_added_watch);
+       g_dbus_remove_watch(connection, modem_removed_watch);
+       g_dbus_remove_watch(connection, watch);
+
        dbus_connection_unref(connection);
 }