5 * Copyright (C) 2007-2010 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
28 #define CONNMAN_API_SUBJECT_TO_CHANGE
29 #include <connman/plugin.h>
30 #include <connman/log.h>
31 #include <connman/notifier.h>
32 #include <connman/dbus.h>
42 #define NM_SERVICE "org.freedesktop.NetworkManager"
43 #define NM_PATH "/org/freedesktop/NetworkManager"
44 #define NM_INTERFACE NM_SERVICE
46 static DBusConnection *connection = NULL;
47 static dbus_uint32_t state = NM_STATE_UNKNOWN;
50 static void nm_send_signal(const char *name, dbus_uint32_t state)
54 signal = dbus_message_new_signal(NM_PATH, NM_INTERFACE, name);
58 dbus_message_append_args(signal, DBUS_TYPE_UINT32, &state,
61 g_dbus_send_message(connection, signal);
64 static void default_changed(struct connman_service *service)
67 state = NM_STATE_CONNECTED;
69 state = NM_STATE_DISCONNECTED;
71 DBG("%p %d", service, state);
73 /* older deprecated signal, in case applications still use this */
74 nm_send_signal("StateChange", state);
76 /* the preferred current signal */
77 nm_send_signal("StateChanged", state);
80 static struct connman_notifier notifier = {
82 .priority = CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
83 .default_changed= default_changed,
86 static DBusMessage *nm_sleep(DBusConnection *conn,
87 DBusMessage *msg, void *data)
93 reply = dbus_message_new_method_return(msg);
97 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
102 static DBusMessage *nm_wake(DBusConnection *conn,
103 DBusMessage *msg, void *data)
107 DBG("conn %p", conn);
109 reply = dbus_message_new_method_return(msg);
113 dbus_message_append_args(reply, DBUS_TYPE_INVALID);
118 static DBusMessage *nm_state(DBusConnection *conn,
119 DBusMessage *msg, void *data)
123 DBG("conn %p", conn);
125 reply = dbus_message_new_method_return(msg);
129 dbus_message_append_args(reply, DBUS_TYPE_UINT32, &state,
135 static GDBusMethodTable nm_methods[] = {
136 { "sleep", "", "", nm_sleep },
137 { "wake", "", "", nm_wake },
138 { "state", "", "u", nm_state },
142 static int nmcompat_init(void)
148 connection = connman_dbus_get_connection();
149 if (connection == NULL)
152 if (g_dbus_request_name(connection, NM_SERVICE, NULL) == FALSE) {
153 connman_error("nmcompat: can't register nm service\n");
157 if (connman_notifier_register(¬ifier) < 0) {
158 connman_error("nmcompat: failed to register notifier");
162 ret = g_dbus_register_interface(connection, NM_PATH, NM_INTERFACE,
163 nm_methods, NULL, NULL, NULL, NULL);
165 connman_error("nmcompat: can't register " NM_INTERFACE);
172 static void nmcompat_exit(void)
176 connman_notifier_unregister(¬ifier);
178 if (connection == NULL)
181 g_dbus_unregister_interface(connection, NM_PATH, NM_INTERFACE);
183 dbus_connection_unref(connection);
186 CONNMAN_PLUGIN_DEFINE(nmcompat, "NetworkManager compatibility interfaces",
187 VERSION, CONNMAN_PLUGIN_PRIORITY_DEFAULT,
188 nmcompat_init, nmcompat_exit)