From aff1619ca4bdab4d5a64847866b73854afff7757 Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Thu, 25 Apr 2013 16:15:45 +0300 Subject: client: Implement Agent Release and Cancel method calls Unref the saved Agent D-Bus message on Release and Cancel. In response to the Release method call unnregister Agent interface and quit if in non-interactive mode. --- client/agent.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'client/agent.c') diff --git a/client/agent.c b/client/agent.c index 239c1028..b12cdcaa 100644 --- a/client/agent.c +++ b/client/agent.c @@ -32,10 +32,12 @@ #include +#include "input.h" #include "dbus_helpers.h" #include "agent.h" static bool agent_registered = false; +static DBusMessage *agent_message = NULL; #define AGENT_INTERFACE "net.connman.Agent" @@ -49,7 +51,55 @@ static char *agent_path(void) return path; } +static void pending_message_remove() +{ + if (agent_message != NULL) { + dbus_message_unref(agent_message); + agent_message = NULL; + } +} + +static void pending_command_complete(char *message) +{ + __connmanctl_save_rl(); + + fprintf(stdout, message); + + __connmanctl_redraw_rl(); + + if (__connmanctl_is_interactive() == true) + __connmanctl_command_mode(); + else + __connmanctl_agent_mode("", NULL); +} + +static DBusMessage *agent_release(DBusConnection *connection, + DBusMessage *message, void *user_data) +{ + g_dbus_unregister_interface(connection, agent_path(), AGENT_INTERFACE); + agent_registered = false; + + pending_message_remove(); + pending_command_complete("Agent unregistered by ConnMan\n"); + + if (__connmanctl_is_interactive() == false) + __connmanctl_quit(); + + return dbus_message_new_method_return(message); +} + +static DBusMessage *agent_cancel(DBusConnection *connection, + DBusMessage *message, void *user_data) +{ + pending_message_remove(); + pending_command_complete("Agent request cancelled by ConnMan\n"); + + return dbus_message_new_method_return(message); +} + static const GDBusMethodTable agent_methods[] = { + { GDBUS_METHOD("Release", NULL, NULL, agent_release) }, + { GDBUS_METHOD("Cancel", NULL, NULL, agent_cancel) }, { }, }; -- cgit v1.2.3