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-02 20:36:54 -0700
commitaa1f78e57f3131ddbf6ee4154c6bddec00287358 (patch)
tree70cb826a880089db5cc0f2627d0ffe19d6786105 /bluetooth/bluetooth.cpp
parentf4aad7aee0d23560a9b562057b866ea6762ca3cf (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 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);
+ }
}
}