Fix bug:TIVI-374[2.0] no hidd binary, which blocks bluetooth keyboard connection
[profile/ivi/bluez.git] / thermometer / manager.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2011 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 #include <gdbus.h>
24 #include <errno.h>
25 #include <bluetooth/uuid.h>
26
27 #include "adapter.h"
28 #include "device.h"
29 #include "att.h"
30 #include "gattrib.h"
31 #include "gatt.h"
32 #include "thermometer.h"
33 #include "manager.h"
34
35 static DBusConnection *connection = NULL;
36
37 static gint primary_uuid_cmp(gconstpointer a, gconstpointer b)
38 {
39         const struct gatt_primary *prim = a;
40         const char *uuid = b;
41
42         return g_strcmp0(prim->uuid, uuid);
43 }
44
45 static int thermometer_driver_probe(struct btd_device *device, GSList *uuids)
46 {
47         struct gatt_primary *tattr;
48         GSList *primaries, *l;
49
50         primaries = btd_device_get_primaries(device);
51
52         l = g_slist_find_custom(primaries, HEALTH_THERMOMETER_UUID,
53                                                         primary_uuid_cmp);
54         if (l == NULL)
55                 return -EINVAL;
56
57         tattr = l->data;
58
59         return thermometer_register(connection, device, tattr);
60 }
61
62 static void thermometer_driver_remove(struct btd_device *device)
63 {
64         thermometer_unregister(device);
65 }
66
67 static struct btd_device_driver thermometer_device_driver = {
68         .name   = "thermometer-device-driver",
69         .uuids  = BTD_UUIDS(HEALTH_THERMOMETER_UUID),
70         .probe  = thermometer_driver_probe,
71         .remove = thermometer_driver_remove
72 };
73
74 int thermometer_manager_init(DBusConnection *conn)
75 {
76         int ret;
77
78         ret = btd_register_device_driver(&thermometer_device_driver);
79         if (ret < 0)
80                 return ret;
81
82         connection = dbus_connection_ref(conn);
83         return 0;
84 }
85
86 void thermometer_manager_exit(void)
87 {
88         btd_unregister_device_driver(&thermometer_device_driver);
89
90         dbus_connection_unref(connection);
91         connection = NULL;
92 }