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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2011 GSyC/LibreSoft, Universidad Rey Juan Carlos.
*
* 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
*
*/
#include <gdbus.h>
#include <errno.h>
#include <bluetooth/uuid.h>
#include "adapter.h"
#include "device.h"
#include "error.h"
#include "log.h"
#include "gattrib.h"
#include "att.h"
#include "thermometer.h"
#define THERMOMETER_INTERFACE "org.bluez.Thermometer"
struct thermometer {
DBusConnection *conn; /* The connection to the bus */
struct btd_device *dev; /* Device reference */
struct att_range *svc_range; /* Thermometer range */
};
static GSList *thermometers = NULL;
static void destroy_thermometer(gpointer user_data)
{
struct thermometer *t = user_data;
dbus_connection_unref(t->conn);
btd_device_unref(t->dev);
g_free(t->svc_range);
g_free(t);
}
static DBusMessage *get_properties(DBusConnection *conn, DBusMessage *msg,
void *data)
{
/* TODO: */
return g_dbus_create_error(msg, ERROR_INTERFACE ".ThermometerError",
"Function not implemented.");
}
static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
void *data)
{
/* TODO: */
return g_dbus_create_error(msg, ERROR_INTERFACE ".ThermometerError",
"Function not implemented.");
}
static DBusMessage *register_watcher(DBusConnection *conn, DBusMessage *msg,
void *data)
{
/* TODO: */
return g_dbus_create_error(msg, ERROR_INTERFACE ".ThermometerError",
"Function not implemented.");
}
static DBusMessage *unregister_watcher(DBusConnection *conn, DBusMessage *msg,
void *data)
{
/* TODO: */
return g_dbus_create_error(msg, ERROR_INTERFACE ".ThermometerError",
"Function not implemented.");
}
static DBusMessage *enable_intermediate(DBusConnection *conn, DBusMessage *msg,
void *data)
{
/* TODO: */
return g_dbus_create_error(msg, ERROR_INTERFACE ".ThermometerError",
"Function not implemented.");
}
static DBusMessage *disable_intermediate(DBusConnection *conn, DBusMessage *msg,
void *data)
{
/* TODO: */
return g_dbus_create_error(msg, ERROR_INTERFACE ".ThermometerError",
"Function not implemented.");
}
static GDBusMethodTable thermometer_methods[] = {
{ "GetProperties", "", "a{sv}", get_properties },
{ "SetProperty", "sv", "", set_property,
G_DBUS_METHOD_FLAG_ASYNC },
{ "RegisterWatcher", "o", "", register_watcher },
{ "UnregisterWatcher", "o", "", unregister_watcher },
{ "EnableIntermediateMeasurement", "o", "", enable_intermediate },
{ "DisableIntermediateMeasurement","o", "", disable_intermediate },
{ }
};
static GDBusSignalTable thermometer_signals[] = {
{ "PropertyChanged", "sv" },
{ }
};
int thermometer_register(DBusConnection *connection, struct btd_device *device,
struct att_primary *tattr)
{
const gchar *path = device_get_path(device);
struct thermometer *t;
t = g_new0(struct thermometer, 1);
t->conn = dbus_connection_ref(connection);
t->dev = btd_device_ref(device);
t->svc_range = g_new0(struct att_range, 1);
t->svc_range->start = tattr->start;
t->svc_range->end = tattr->end;
if (!g_dbus_register_interface(t->conn, path, THERMOMETER_INTERFACE,
thermometer_methods, thermometer_signals,
NULL, t, destroy_thermometer)) {
error("D-Bus failed to register %s interface",
THERMOMETER_INTERFACE);
destroy_thermometer(t);
return -EIO;
}
thermometers = g_slist_prepend(thermometers, t);
return 0;
}
void thermometer_unregister(struct btd_device *device)
{
/* TODO: Unregister Health Thermometer Interface */
}
|