5 * Copyright (C) 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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <sys/types.h>
35 #include "dbus_helpers.h"
38 static bool agent_registered = false;
40 #define AGENT_INTERFACE "net.connman.Agent"
42 static char *agent_path(void)
44 static char *path = NULL;
47 path = g_strdup_printf("/net/connman/connmanctl%d", getpid());
52 static const GDBusMethodTable agent_methods[] = {
56 static int agent_register_return(DBusMessageIter *iter, const char *error,
59 DBusConnection *connection = user_data;
62 g_dbus_unregister_interface(connection, agent_path(),
64 fprintf(stderr, "Error registering Agent: %s\n", error);
68 agent_registered = true;
69 fprintf(stdout, "Agent registered\n");
74 int __connmanctl_agent_register(DBusConnection *connection)
76 char *path = agent_path();
79 if (agent_registered == true) {
80 fprintf(stderr, "Agent already registered\n");
84 if (g_dbus_register_interface(connection, path,
85 AGENT_INTERFACE, agent_methods,
86 NULL, NULL, NULL, NULL) == FALSE) {
87 fprintf(stderr, "Error: Failed to register Agent callbacks\n");
91 result = __connmanctl_dbus_method_call(connection, "/",
92 "net.connman.Manager", "RegisterAgent",
93 agent_register_return, connection,
94 DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
96 if (result != -EINPROGRESS) {
97 g_dbus_unregister_interface(connection, agent_path(),
100 fprintf(stderr, "Error: Failed to register Agent\n");
106 static int agent_unregister_return(DBusMessageIter *iter, const char *error,
110 fprintf(stderr, "Error unregistering Agent: %s\n", error);
114 agent_registered = false;
115 fprintf(stdout, "Agent unregistered\n");
120 int __connmanctl_agent_unregister(DBusConnection *connection)
122 char *path = agent_path();
125 if (agent_registered == false) {
126 fprintf(stderr, "Agent not registered\n");
130 g_dbus_unregister_interface(connection, agent_path(), AGENT_INTERFACE);
132 result = __connmanctl_dbus_method_call(connection, "/",
133 "net.connman.Manager", "UnregisterAgent",
134 agent_unregister_return, NULL,
135 DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
137 if (result != -EINPROGRESS)
138 fprintf(stderr, "Error: Failed to unregister Agent\n");