summaryrefslogtreecommitdiffstats
path: root/bluetooth/bluetooth.cpp
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2019-04-02 18:12:14 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2019-04-04 11:43:43 -0700
commitfd1810addb8bfc69c4ca3dc218f3d14e5ad3343e (patch)
tree2b6e6c104f329e7d8107d9f3e33e5ca034bb0428 /bluetooth/bluetooth.cpp
parent5ba2e7752c478a386de6c6cf06adb6f9cf7ee79e (diff)
libqtappfw: bluetooth: add adapter_changes event processing
Process events from adapter_changes to emit the respective signal. This has the advantage of avoiding race conditions of waiting for powering up of an adapter, and to allow Settings UI to detect events. Bug-AGL: SPEC-2295 SPEC-2290 Change-Id: I9cd391ed01cab709dad6801331eade7494155af5 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'bluetooth/bluetooth.cpp')
-rw-r--r--bluetooth/bluetooth.cpp45
1 files changed, 32 insertions, 13 deletions
diff --git a/bluetooth/bluetooth.cpp b/bluetooth/bluetooth.cpp
index eb00df4..79cc5f1 100644
--- a/bluetooth/bluetooth.cpp
+++ b/bluetooth/bluetooth.cpp
@@ -225,23 +225,37 @@ void Bluetooth::processDeviceChangesEvent(QJsonObject data)
BluetoothDevice *device = m_bluetooth->updateDeviceProperties(nullptr, data);
m_bluetooth->addDevice(device);
} else if (action == "changed") {
- auto powered = data.find("powered").value();
-
- if (powered.isBool()) {
- m_power = powered.toBool();
- if (!m_power)
- m_bluetooth->removeAllDevices();
- emit powerChanged(m_power);
- } else {
- BluetoothDevice *device = m_bluetooth->getDevice(id);
- m_bluetooth->updateDeviceProperties(device, data);
- }
+ BluetoothDevice *device = m_bluetooth->getDevice(id);
+ m_bluetooth->updateDeviceProperties(device, data);
} else if (action == "removed") {
BluetoothDevice *device = m_bluetooth->getDevice(id);
m_bluetooth->removeDevice(device);
}
}
+void Bluetooth::processAdapterChangesEvent(QJsonObject data)
+{
+ QString action = data.value("action").toString();
+ if (action != "changed")
+ return;
+
+ QJsonObject properties = data.value("properties").toObject();
+ if (!properties.contains("powered"))
+ return;
+
+ bool powered = properties.find("powered").value().toBool();
+ if (!powered)
+ m_bluetooth->removeAllDevices();
+
+ if (m_power != powered) {
+ m_power = powered;
+ emit powerChanged(powered);
+ }
+
+ if (!m_power)
+ m_discoverable = false;
+}
+
void Bluetooth::onMessageReceived(MessageType type, Message *msg)
{
if (msg->isEvent() && type == BluetoothEventMessage) {
@@ -249,6 +263,8 @@ void Bluetooth::onMessageReceived(MessageType type, Message *msg)
if (tmsg->isDeviceChangesEvent()) {
processDeviceChangesEvent(tmsg->eventData());
+ } else if (tmsg->isAdapterChangesEvent()) {
+ processAdapterChangesEvent(tmsg->eventData());
} else if (tmsg->isAgentEvent()) {
emit requestConfirmationEvent(tmsg->eventData());
}
@@ -259,8 +275,11 @@ void Bluetooth::onMessageReceived(MessageType type, Message *msg)
if (tmsg->requestVerb() == "managed_objects") {
populateDeviceList(tmsg->replyData());
} else if (tmsg->requestVerb() == "adapter_state") {
- m_power = tmsg->replyData().value("powered").toBool();
- emit powerChanged(m_power);
+ bool powered = tmsg->replyData().value("powered").toBool();
+ if (m_power != powered) {
+ m_power = powered;
+ emit powerChanged(m_power);
+ }
}
}