5 * Copyright (C) 2012-2013 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
29 #include <connman/log.h>
30 #include <connman/agent.h>
32 #include "../src/connman.h"
35 #include "connman/vpn-dbus.h"
37 static int vpn_connect_count;
38 static DBusConnection *connection;
40 static DBusMessage *create(DBusConnection *conn, DBusMessage *msg, void *data)
46 err = __vpn_provider_create(msg);
48 if (err == -EINPROGRESS) {
49 connman_error("Invalid return code (%d) "
54 return __connman_error_failed(msg, -err);
60 static DBusMessage *remove(DBusConnection *conn, DBusMessage *msg, void *data)
65 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
68 DBG("conn %p path %s", conn, path);
70 err = __vpn_provider_remove(path);
72 return __connman_error_failed(msg, -err);
74 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
77 static DBusMessage *get_connections(DBusConnection *conn, DBusMessage *msg,
84 reply = __vpn_provider_get_connections(msg);
86 return __connman_error_failed(msg, EINVAL);
91 static DBusMessage *register_agent(DBusConnection *conn,
92 DBusMessage *msg, void *data)
94 const char *sender, *path;
99 sender = dbus_message_get_sender(msg);
101 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
104 err = connman_agent_register(sender, path);
106 return __connman_error_failed(msg, -err);
108 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
111 static DBusMessage *unregister_agent(DBusConnection *conn,
112 DBusMessage *msg, void *data)
114 const char *sender, *path;
117 DBG("conn %p", conn);
119 sender = dbus_message_get_sender(msg);
121 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
124 err = connman_agent_unregister(sender, path);
126 return __connman_error_failed(msg, -err);
128 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
131 static const GDBusMethodTable manager_methods[] = {
132 { GDBUS_ASYNC_METHOD("Create",
133 GDBUS_ARGS({ "properties", "a{sv}" }),
134 GDBUS_ARGS({ "path", "o" }),
136 { GDBUS_ASYNC_METHOD("Remove",
137 GDBUS_ARGS({ "identifier", "o" }), NULL,
139 { GDBUS_METHOD("GetConnections", NULL,
140 GDBUS_ARGS({ "connections", "a(oa{sv})" }),
142 { GDBUS_METHOD("RegisterAgent",
143 GDBUS_ARGS({ "path", "o" }), NULL,
145 { GDBUS_METHOD("UnregisterAgent",
146 GDBUS_ARGS({ "path", "o" }), NULL,
151 static const GDBusSignalTable manager_signals[] = {
152 { GDBUS_SIGNAL("ConnectionAdded",
153 GDBUS_ARGS({ "identifier", "o" },
154 { "properties", "a{sv}" })) },
155 { GDBUS_SIGNAL("ConnectionRemoved",
156 GDBUS_ARGS({ "identifier", "o" })) },
160 int __vpn_manager_init(void)
164 connection = connman_dbus_get_connection();
168 g_dbus_register_interface(connection, VPN_MANAGER_PATH,
169 VPN_MANAGER_INTERFACE,
171 manager_signals, NULL, NULL, NULL);
173 vpn_connect_count = 0;
178 void __vpn_manager_cleanup(void)
185 g_dbus_unregister_interface(connection, VPN_MANAGER_PATH,
186 VPN_MANAGER_INTERFACE);
188 dbus_connection_unref(connection);