summaryrefslogtreecommitdiff
path: root/client/agent.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2012-12-15 00:20:25 +0100
committerMarcel Holtmann <marcel@holtmann.org>2012-12-15 00:20:25 +0100
commitd8d4b4f0c0ed5ddce7df3cf7ddad8322a9787c45 (patch)
tree162a8948c8107c84fccb207a48343b515d704305 /client/agent.c
parent8590e5b610ae12584e13b3495ce3af895233aaff (diff)
downloadbluez-d8d4b4f0c0ed5ddce7df3cf7ddad8322a9787c45.tar.gz
client: Add support for handling agent object registration
Diffstat (limited to 'client/agent.c')
-rw-r--r--client/agent.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/client/agent.c b/client/agent.c
new file mode 100644
index 000000000..0a82e2191
--- /dev/null
+++ b/client/agent.c
@@ -0,0 +1,84 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <readline/readline.h>
+#include <gdbus.h>
+
+#include "display.h"
+#include "agent.h"
+
+static gboolean agent_registered = FALSE;
+
+static DBusMessage *release_agent(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ agent_registered = FALSE;
+
+ g_dbus_unregister_interface(conn, "/org/bluez/agent",
+ "org.bluez.Agent1");
+
+ return dbus_message_new_method_return(msg);
+}
+
+static const GDBusMethodTable methods[] = {
+ { GDBUS_METHOD("Release", NULL, NULL, release_agent) },
+ { }
+};
+
+void agent_register(DBusConnection *conn, GDBusProxy *manager)
+{
+ if (agent_registered == TRUE) {
+ printf("Agent is already registered\n");
+ return;
+ }
+
+ if (g_dbus_register_interface(conn, "/org/bluez/agent",
+ "org.bluez.Agent1", methods,
+ NULL, NULL, NULL, NULL) == FALSE) {
+ printf("Failed to register agent object\n");
+ return;
+ }
+
+ agent_registered = TRUE;
+}
+
+void agent_unregister(DBusConnection *conn, GDBusProxy *manager)
+{
+ if (agent_registered == FALSE) {
+ printf("No agent is registered\n");
+ return;
+ }
+
+ if (g_dbus_unregister_interface(conn, "/org/bluez/agent",
+ "org.bluez.Agent1") == FALSE) {
+ printf("Failed to unregister agent object\n");
+ return;
+ }
+
+ agent_registered = FALSE;
+}