summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md40
-rw-r--r--binding/bluetooth-api.c26
-rw-r--r--binding/bluetooth-api.h8
-rw-r--r--binding/bluetooth-common.h1
4 files changed, 71 insertions, 4 deletions
diff --git a/README.md b/README.md
index 86b971f..fa77efc 100644
--- a/README.md
+++ b/README.md
@@ -175,11 +175,49 @@ To do the same for the respective device, verb, and for singular profile
| Name | Description | JSON Event Data |
|-------------------|------------------------------------------|-------------------------------------------|
-| device_changes | report on bluetooth devices | see device_changes event section |
+| adapter_changes | report on Bluetooth adapter states | see adapter_changes event section |
+| device_changes | report on Bluetooth devices | see device_changes event section |
| media | report on MediaPlayer1 events | see media event section |
| agent | PIN from BlueZ agent for confirmation | see agent event section |
+### adapter_changes event
+
+Sample of adding new adapter event:
+
+<pre>
+{
+ "adapter": "hci0",
+ "action": "added",
+ "properties": {
+ "address": "60:30:D4:66:55:A7",
+ "powered": false,
+ "discoverable": false,
+ "discoverabletimeout": 180,
+ "pairable": true,
+ "pairabletimeout": 0,
+ "discovering": false,
+ "uuids": [
+ "00001801-0000-1000-8000-00805f9b34fb",
+ "0000110e-0000-1000-8000-00805f9b34fb",
+ "00001200-0000-1000-8000-00805f9b34fb",
+ "00001800-0000-1000-8000-00805f9b34fb",
+ "0000111e-0000-1000-8000-00805f9b34fb",
+ "0000110c-0000-1000-8000-00805f9b34fb"
+ ]
+ }
+}
+</pre>
+
+Sample of adapter being remove:
+
+<pre>
+{
+ "adapter": "hci0",
+ "action": "removed",
+}
+</pre>
+
### device_changes event
Sample of discovering a new device event:
diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c
index 9ce0541..4c1165c 100644
--- a/binding/bluetooth-api.c
+++ b/binding/bluetooth-api.c
@@ -249,6 +249,9 @@ void call_work_destroy(struct call_work *cw)
static afb_event_t get_event_from_value(struct bluetooth_state *ns,
const char *value)
{
+ if (!g_strcmp0(value, "adapter_changes"))
+ return ns->adapter_changes_event;
+
if (!g_strcmp0(value, "device_changes"))
return ns->device_changes_event;
@@ -305,18 +308,27 @@ static void bluez_devices_signal_callback(
GVariant *val = NULL;
if (g_strcmp0(key, BLUEZ_DEVICE_INTERFACE) &&
- g_strcmp0(key, BLUEZ_MEDIATRANSPORT_INTERFACE))
+ g_strcmp0(key, BLUEZ_MEDIATRANSPORT_INTERFACE) &&
+ g_strcmp0(key, BLUEZ_ADAPTER_INTERFACE))
continue;
array1 = g_variant_iter_new(var);
while (g_variant_iter_next(array1, "{&sv}", &name, &val)) {
- if (!g_strcmp0(key, BLUEZ_DEVICE_INTERFACE))
+ if (!g_strcmp0(key, BLUEZ_DEVICE_INTERFACE)) {
ret = device_property_dbus2json(jobj,
name, val, &is_config, &error);
- else
+ } else if (!g_strcmp0(key, BLUEZ_MEDIATRANSPORT_INTERFACE)) {
ret = mediatransport_property_dbus2json(jobj,
name, val, &is_config, &error);
+ } else if (!g_strcmp0(key, BLUEZ_ADAPTER_INTERFACE)) {
+ ret = adapter_property_dbus2json(jobj,
+ name, val, &is_config, &error);
+ event = ns->adapter_changes_event;
+ } else {
+ ret = TRUE;
+ }
+
g_variant_unref(val);
if (!ret) {
AFB_DEBUG("%s property %s - %s",
@@ -383,6 +395,12 @@ static void bluez_devices_signal_callback(
json_object_object_add(jresp, "type",
json_object_new_string("playback"));
event = ns->media_event;
+ /* adapter removal */
+ } else if (split_length(path) == 4) {
+ json_object_object_add(jresp, "action",
+ json_object_new_string("removed"));
+ event = ns->adapter_changes_event;
+ /* device removal */
} else if (split_length(path) == 5) {
json_object_object_add(jresp, "action",
json_object_new_string("removed"));
@@ -515,6 +533,8 @@ static struct bluetooth_state *bluetooth_init(GMainLoop *loop)
AFB_INFO("connected to dbus");
+ ns->adapter_changes_event =
+ afb_daemon_make_event("adapter_changes");
ns->device_changes_event =
afb_daemon_make_event("device_changes");
ns->media_event =
diff --git a/binding/bluetooth-api.h b/binding/bluetooth-api.h
index 31418ae..6b24d13 100644
--- a/binding/bluetooth-api.h
+++ b/binding/bluetooth-api.h
@@ -194,6 +194,14 @@ static inline gboolean device_property_dbus2json(json_object *jprop,
jprop, key, var, is_config, error);
}
+static inline gboolean adapter_property_dbus2json(json_object *jprop,
+ const gchar *key, GVariant *var, gboolean *is_config,
+ GError **error)
+{
+ return bluez_property_dbus2json(BLUEZ_AT_ADAPTER,
+ jprop, key, var, is_config, error);
+}
+
static inline gboolean agent_property_dbus2json(json_object *jprop,
const gchar *key, GVariant *var, gboolean *is_config,
GError **error)
diff --git a/binding/bluetooth-common.h b/binding/bluetooth-common.h
index 8b21656..5ff1c27 100644
--- a/binding/bluetooth-common.h
+++ b/binding/bluetooth-common.h
@@ -40,6 +40,7 @@ struct bluetooth_state {
guint device_sub;
guint autoconnect_sub;
+ afb_event_t adapter_changes_event;
afb_event_t device_changes_event;
afb_event_t media_event;
afb_event_t agent_event;