Initialize Tizen 2.3
[framework/connectivity/bluez.git] / wearable / health / hdp_manager.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2010 GSyC/LibreSoft, Universidad Rey Juan Carlos.
6  *
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.
11  *
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.
16  *
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
20  *
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <bluetooth/sdp.h>
28 #include <bluetooth/sdp_lib.h>
29 #include <bluetooth/uuid.h>
30
31 #include <btio.h>
32 #include <adapter.h>
33 #include <device.h>
34 #include <glib-helper.h>
35 #include <log.h>
36
37 #include "hdp_types.h"
38
39 #include "hdp_manager.h"
40 #include "hdp.h"
41
42 static DBusConnection *connection = NULL;
43
44 static int hdp_adapter_probe(struct btd_adapter *adapter)
45 {
46         return hdp_adapter_register(connection, adapter);
47 }
48
49 static void hdp_adapter_remove(struct btd_adapter *adapter)
50 {
51         hdp_adapter_unregister(adapter);
52 }
53
54 static struct btd_adapter_driver hdp_adapter_driver = {
55         .name   = "hdp-adapter-driver",
56         .probe  = hdp_adapter_probe,
57         .remove = hdp_adapter_remove,
58 };
59
60 static int hdp_driver_probe(struct btd_device *device, GSList *uuids)
61 {
62         return hdp_device_register(connection, device);
63 }
64
65 static void hdp_driver_remove(struct btd_device *device)
66 {
67         hdp_device_unregister(device);
68 }
69
70 static struct btd_device_driver hdp_device_driver = {
71         .name   = "hdp-device-driver",
72         .uuids  = BTD_UUIDS(HDP_UUID, HDP_SOURCE_UUID, HDP_SINK_UUID),
73         .probe  = hdp_driver_probe,
74         .remove = hdp_driver_remove
75 };
76
77 int hdp_manager_init(DBusConnection *conn)
78 {
79         if (hdp_manager_start(conn) < 0)
80                 return -1;
81
82         connection = dbus_connection_ref(conn);
83         btd_register_adapter_driver(&hdp_adapter_driver);
84         btd_register_device_driver(&hdp_device_driver);
85
86         return 0;
87 }
88
89 void hdp_manager_exit(void)
90 {
91         btd_unregister_device_driver(&hdp_device_driver);
92         btd_unregister_adapter_driver(&hdp_adapter_driver);
93         hdp_manager_stop();
94
95         dbus_connection_unref(connection);
96         connection = NULL;
97 }