Add tracking of oFono startup and termination
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 2 Sep 2009 01:29:43 +0000 (18:29 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 2 Sep 2009 01:29:43 +0000 (18:29 -0700)
plugins/ofono.c

index 2055c050ba9659bdf2393711a6f22ea8878991cc..d8af4b9b20c98f67b919e3edcdedfa7341831306 100644 (file)
 #include <config.h>
 #endif
 
+#include <errno.h>
+
+#include <gdbus.h>
+
 #define CONNMAN_API_SUBJECT_TO_CHANGE
 #include <connman/plugin.h>
+#include <connman/dbus.h>
+#include <connman/log.h>
+
+#define OFONO_SERVICE                  "org.ofono"
+
+static DBusConnection *connection;
+
+static GHashTable *ofono_modems = NULL;
+
+static void unregister_modem(gpointer data)
+{
+       DBG("");
+}
+
+static void ofono_connect(DBusConnection *connection, void *user_data)
+{
+       DBG("connection %p", connection);
+
+       ofono_modems = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                               g_free, unregister_modem);
+}
+
+static void ofono_disconnect(DBusConnection *connection, void *user_data)
+{
+       DBG("connection %p", connection);
+
+       if (ofono_modems == NULL)
+               return;
+
+       g_hash_table_destroy(ofono_modems);
+       ofono_modems = NULL;
+}
+
+static guint watch;
 
 static int ofono_init(void)
 {
+       int err;
+
+       connection = connman_dbus_get_connection();
+       if (connection == NULL)
+               return -EIO;
+
+       watch = g_dbus_add_service_watch(connection, OFONO_SERVICE,
+                       ofono_connect, ofono_disconnect, NULL, NULL);
+       if (watch == 0) {
+               err = -EIO;
+               goto unref;
+       }
+
        return 0;
+
+unref:
+       dbus_connection_unref(connection);
+
+       return err;
 }
 
 static void ofono_exit(void)
 {
+       g_dbus_remove_watch(connection, watch);
+
+       ofono_disconnect(connection, NULL);
+
+       dbus_connection_unref(connection);
 }
 
 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,