Blame lib/test-agent.c

Packit 8fb625
/*
Packit 8fb625
 *
Packit 8fb625
 *  BlueZ - Bluetooth protocol stack for Linux
Packit 8fb625
 *
Packit 8fb625
 *  Copyright (C) 2005-2008  Marcel Holtmann <marcel@holtmann.org>
Packit 8fb625
 *
Packit 8fb625
 *
Packit 8fb625
 *  This program is free software; you can redistribute it and/or modify
Packit 8fb625
 *  it under the terms of the GNU General Public License as published by
Packit 8fb625
 *  the Free Software Foundation; either version 2 of the License, or
Packit 8fb625
 *  (at your option) any later version.
Packit 8fb625
 *
Packit 8fb625
 *  This program is distributed in the hope that it will be useful,
Packit 8fb625
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8fb625
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8fb625
 *  GNU General Public License for more details.
Packit 8fb625
 *
Packit 8fb625
 *  You should have received a copy of the GNU General Public License
Packit 8fb625
 *  along with this program; if not, write to the Free Software
Packit 8fb625
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit 8fb625
 *
Packit 8fb625
 */
Packit 8fb625
Packit 8fb625
#ifdef HAVE_CONFIG_H
Packit 8fb625
#include <config.h>
Packit 8fb625
#endif
Packit 8fb625
Packit 8fb625
#include <stdio.h>
Packit 8fb625
#include <stdlib.h>
Packit 8fb625
#include <string.h>
Packit 8fb625
#include <signal.h>
Packit 8fb625
Packit 8fb625
#include "bluetooth-agent.h"
Packit 8fb625
Packit 8fb625
static void
Packit 8fb625
agent_confirm (GDBusMethodInvocation *invocation,
Packit 8fb625
	       GDBusProxy *device,
Packit 8fb625
	       guint passkey,
Packit 8fb625
	       gpointer data)
Packit 8fb625
{
Packit 8fb625
	const char *path;
Packit 8fb625
Packit 8fb625
	path = g_dbus_proxy_get_object_path(device);
Packit 8fb625
Packit 8fb625
	g_print ("Confirming passkey %6.6d from %s\n", passkey, path);
Packit 8fb625
Packit 8fb625
	g_dbus_method_invocation_return_value (invocation, NULL);
Packit 8fb625
}
Packit 8fb625
Packit 8fb625
static GMainLoop *mainloop = NULL;
Packit 8fb625
Packit 8fb625
static void
Packit 8fb625
sig_term (int sig)
Packit 8fb625
{
Packit 8fb625
	g_main_loop_quit(mainloop);
Packit 8fb625
}
Packit 8fb625
Packit 8fb625
int main (int argc, char **argv)
Packit 8fb625
{
Packit 8fb625
	struct sigaction sa;
Packit 8fb625
	BluetoothAgent *agent;
Packit 8fb625
Packit 8fb625
	memset(&sa, 0, sizeof(sa));
Packit 8fb625
	sa.sa_flags = SA_NOCLDSTOP;
Packit 8fb625
	sa.sa_handler = sig_term;
Packit 8fb625
	sigaction(SIGTERM, &sa, NULL);
Packit 8fb625
	sigaction(SIGINT,  &sa, NULL);
Packit 8fb625
Packit 8fb625
	mainloop = g_main_loop_new(NULL, FALSE);
Packit 8fb625
Packit 8fb625
	agent = bluetooth_agent_new(NULL);
Packit 8fb625
Packit 8fb625
	bluetooth_agent_set_confirm_func(agent, agent_confirm, NULL);
Packit 8fb625
Packit 8fb625
	bluetooth_agent_register(agent);
Packit 8fb625
Packit 8fb625
	g_main_loop_run(mainloop);
Packit 8fb625
Packit 8fb625
	bluetooth_agent_unregister(agent);
Packit 8fb625
Packit 8fb625
	g_object_unref(agent);
Packit 8fb625
Packit 8fb625
	g_main_loop_unref(mainloop);
Packit 8fb625
Packit 8fb625
	return 0;
Packit 8fb625
}