5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #define CONNMAN_API_SUBJECT_TO_CHANGE
31 #include <connman/plugin.h>
32 #include <connman/dbus.h>
33 #include <connman/log.h>
35 #define MODEMMGR_SERVICE "org.freedesktop.ModemManager"
36 #define MODEMMGR_INTERFACE MODEMMGR_SERVICE
38 #define ENUMERATE_DEVICES "EnumerateDevices"
42 static void enumerate_devices_reply(DBusPendingCall *call, void *user_data)
48 reply = dbus_pending_call_steal_reply(call);
50 dbus_message_unref(reply);
53 static void modemmgr_connect(DBusConnection *connection, void *user_data)
56 DBusPendingCall *call;
58 DBG("connection %p", connection);
60 message = dbus_message_new_method_call(MODEMMGR_SERVICE, "/",
61 MODEMMGR_INTERFACE, ENUMERATE_DEVICES);
65 if (dbus_connection_send_with_reply(connection, message,
66 &call, TIMEOUT) == FALSE) {
67 connman_error("Failed to get modem devices");
72 connman_error("D-Bus connection not available");
76 dbus_pending_call_set_notify(call, enumerate_devices_reply,
80 dbus_message_unref(message);
83 static void modemmgr_disconnect(DBusConnection *connection, void *user_data)
85 DBG("connection %p", connection);
88 static DBusConnection *connection;
91 static int modemmgr_init(void)
93 connection = connman_dbus_get_connection();
94 if (connection == NULL)
97 watch = g_dbus_add_service_watch(connection, MODEMMGR_SERVICE,
98 modemmgr_connect, modemmgr_disconnect, NULL, NULL);
100 dbus_connection_unref(connection);
107 static void modemmgr_exit(void)
109 g_dbus_remove_watch(connection, watch);
111 dbus_connection_unref(connection);
114 CONNMAN_PLUGIN_DEFINE(modemmgr, "Modem Manager plugin", VERSION,
115 CONNMAN_PLUGIN_PRIORITY_DEFAULT, modemmgr_init, modemmgr_exit)