summaryrefslogtreecommitdiff
path: root/sap/manager.c
blob: a97f43485bd494b718b6bdeed40d6e520c2d2c47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 *  BlueZ - Bluetooth protocol stack for Linux
 *
 *  Copyright (C) 2010 Instituto Nokia de Tecnologia - INdT
 *
 *  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 <errno.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

#include <gdbus.h>

#include "log.h"
#include "adapter.h"
#include "device.h"

#include "manager.h"
#include "server.h"

static DBusConnection *connection = NULL;

static int sap_server_probe(struct btd_adapter *adapter)
{
	const char *path = adapter_get_path(adapter);
	bdaddr_t src;

	DBG("path %s", path);

	adapter_get_address(adapter, &src);

	return sap_server_register(path, &src);
}

static void sap_server_remove(struct btd_adapter *adapter)
{
	const char *path = adapter_get_path(adapter);

	DBG("path %s", path);

	sap_server_unregister(path);
}

static struct btd_adapter_driver sap_server_driver = {
	.name	= "sap-server",
	.probe	= sap_server_probe,
	.remove	= sap_server_remove,
};

int sap_manager_init(DBusConnection *conn)
{
	connection = dbus_connection_ref(conn);

	if (sap_server_init(connection) < 0) {
		error("Can't init SAP server");
		dbus_connection_unref(conn);
		return -1;
	}

	btd_register_adapter_driver(&sap_server_driver);

	return 0;
}

void sap_manager_exit(void)
{
	btd_unregister_adapter_driver(&sap_server_driver);

	dbus_connection_unref(connection);
	connection = NULL;

	sap_server_exit();
}