summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-04-20 15:45:34 +0100
committerMarcel Holtmann <marcel@holtmann.org>2009-04-20 15:45:34 +0100
commita264caec4b9b163ab93d66f412d5f6bebd6fa865 (patch)
tree5a183440fed57bac7d8643133d44ce6a4b1476fb /plugins
parente06445ba1d6d6744f22bcd9e175fad0ededc91a1 (diff)
downloadconnman-a264caec4b9b163ab93d66f412d5f6bebd6fa865.tar.gz
connman-a264caec4b9b163ab93d66f412d5f6bebd6fa865.tar.bz2
connman-a264caec4b9b163ab93d66f412d5f6bebd6fa865.zip
Add detection for Modem Manager running state
Diffstat (limited to 'plugins')
-rw-r--r--plugins/modemmgr.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/plugins/modemmgr.c b/plugins/modemmgr.c
index 9a226845..cbb5ebd5 100644
--- a/plugins/modemmgr.c
+++ b/plugins/modemmgr.c
@@ -23,17 +23,87 @@
#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 MODEMMGR_SERVICE "org.freedesktop.ModemManager"
+#define MODEMMGR_INTERFACE MODEMMGR_SERVICE
+
+#define ENUMERATE_DEVICES "EnumerateDevices"
+
+#define TIMEOUT 5000
+
+static void enumerate_devices_reply(DBusPendingCall *call, void *user_data)
+{
+ DBusMessage *reply;
+
+ DBG("");
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_message_unref(reply);
+}
+
+static void modemmgr_connect(DBusConnection *connection, void *user_data)
+{
+ DBusMessage *message;
+ DBusPendingCall *call;
+
+ DBG("connection %p", connection);
+
+ message = dbus_message_new_method_call(MODEMMGR_SERVICE, "/",
+ MODEMMGR_INTERFACE, ENUMERATE_DEVICES);
+ if (message == NULL)
+ return;
+
+ if (dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT) == FALSE) {
+ connman_error("Failed to get modem devices");
+ dbus_message_unref(message);
+ return;
+ }
+
+ dbus_pending_call_set_notify(call, enumerate_devices_reply,
+ NULL, NULL);
+
+ dbus_message_unref(message);
+}
+
+static void modemmgr_disconnect(DBusConnection *connection, void *user_data)
+{
+ DBG("connection %p", connection);
+}
+
+static DBusConnection *connection;
+static guint watch;
+
static int modemmgr_init(void)
{
+ connection = connman_dbus_get_connection();
+ if (connection == NULL)
+ return -EIO;
+
+ watch = g_dbus_add_service_watch(connection, MODEMMGR_SERVICE,
+ modemmgr_connect, modemmgr_disconnect, NULL, NULL);
+ if (watch == 0) {
+ dbus_connection_unref(connection);
+ return -EIO;
+ }
+
return 0;
}
static void modemmgr_exit(void)
{
+ g_dbus_remove_watch(connection, watch);
+
+ dbus_connection_unref(connection);
}
CONNMAN_PLUGIN_DEFINE(modemmgr, "Modem Manager plugin", VERSION,