From c8304d3ec2f83aed4f6b87a31f79dac72bb432de Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Mon, 29 Oct 2018 09:59:31 -0700 Subject: Revert "libqtappfw: bluetooth: add binding version 2.0 verbs" This reverts commit 4508f46e8b3b42f2d062566ecbc741daf5cf1338. Revert "libqtappfw: bluetooth: add initial API versioning to BluetoothMessage" This reverts commit daadd6ca0e572fe55d307ff034d8cd3342c1c7c1. Bug-AGL: SPEC-1630 Change-Id: Iac48c5a1b3bd2d1147c208cebe6b86bbdfa6d2ac Signed-off-by: Matt Ranostay --- bluetooth/bluetoothmessage.cpp | 13 +++---------- bluetooth/bluetoothmessage.h | 19 +------------------ 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/bluetooth/bluetoothmessage.cpp b/bluetooth/bluetoothmessage.cpp index 9eef02f..52ecbed 100644 --- a/bluetooth/bluetoothmessage.cpp +++ b/bluetooth/bluetoothmessage.cpp @@ -23,15 +23,8 @@ bool BluetoothMessage::createRequest(QString verb, QJsonObject parameter) { - if (m_api_version == "1.0") { - if (!verbs_v1.contains(verb)) - return false; - } + if (!verbs.contains(verb)) + return false; - if (m_api_version == "2.0") { - if (!verbs_v2.contains(verb)) - return false; - } - - return Message::createRequest("Bluetooth-Manager", verb, parameter); + return Message::createRequest("Bluetooth-Manager", verb, parameter); } diff --git a/bluetooth/bluetoothmessage.h b/bluetooth/bluetoothmessage.h index 0a26322..89aef1a 100644 --- a/bluetooth/bluetoothmessage.h +++ b/bluetooth/bluetoothmessage.h @@ -23,23 +23,15 @@ class BluetoothMessage : public Message { Q_OBJECT public: - explicit BluetoothMessage(QString api_version = "1.0", QObject *parent = 0) { m_api_version = api_version; }; - - // Bluetooth API Schema 1.0 bool isConnectionEvent() { return (this->eventName() == "connection"); }; bool isRequestConfirmationEvent() { return (this->eventName() == "request_confirmation"); }; bool isDeviceAddedEvent() { return (this->eventName() == "device_added"); }; bool isDeviceRemovedEvent() { return (this->eventName() == "device_removed"); }; bool isDeviceUpdatedEvent() { return (this->eventName() == "device_updated"); }; - - // Bluetooth API Schema 2.0 - bool isDeviceChangesEvent() { return (this->eventName() == "device_changes"); }; - bool isAgentEvent() { return (this->eventName() == "agent"); }; - bool createRequest(QString verb, QJsonObject parameter); private: - QStringList verbs_v1 { + QStringList verbs { "start_discovery" , "stop_discovery", "power", "remove_device", "pair", "cancel_pair", "connect", "disconnect", "device_priorities", @@ -47,15 +39,6 @@ class BluetoothMessage : public Message "set_avrcp_controls", "send_confirmation", "version", "subscribe", "unsubscribe", }; - - QStringList verbs_v2 { - "connect", "disconnect", "managed_objects", - "adapter_state", "pair", "cancel_pairing", - "confirm_pairing", "remove_device", "version", - "subscribe", "unsubscribe", - }; - - QString m_api_version; }; #endif // BLUETOOTH_MESSAGE_H -- cgit 1.2.3-korg From 6446a124787e95acb7f65916ca0b09254de0b86e Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Tue, 30 Oct 2018 08:39:02 -0700 Subject: libqtappfw: bluetooth: remove avrcp_controls Bluetooth avrcp controls will be moved into their own respective binding in the near future. Bug-AGL: SPEC-1630 Change-Id: I688cc19c2e30957f507cdcda54bf5a2f863317d5 Signed-off-by: Matt Ranostay --- bluetooth/bluetooth.cpp | 12 ------------ bluetooth/bluetooth.h | 1 - 2 files changed, 13 deletions(-) diff --git a/bluetooth/bluetooth.cpp b/bluetooth/bluetooth.cpp index d205e7d..7ae8240 100644 --- a/bluetooth/bluetooth.cpp +++ b/bluetooth/bluetooth.cpp @@ -151,18 +151,6 @@ void Bluetooth::send_confirmation() generic_command("send_confirmation", "yes"); } -void Bluetooth::set_avrcp_controls(QString address, QString cmd) -{ - BluetoothMessage *tmsg = new BluetoothMessage(); - QJsonObject parameter; - - parameter.insert("Address", address); - parameter.insert("value", cmd); - tmsg->createRequest("set_avrcp_controls", parameter); - m_mloop->sendMessage(tmsg); - delete tmsg; -} - void Bluetooth::onConnected() { QStringListIterator eventIterator(events); diff --git a/bluetooth/bluetooth.h b/bluetooth/bluetooth.h index 24605cf..d8bbb80 100644 --- a/bluetooth/bluetooth.h +++ b/bluetooth/bluetooth.h @@ -49,7 +49,6 @@ class Bluetooth : public QObject Q_INVOKABLE void disconnect(QString address); Q_INVOKABLE void send_confirmation(void); - Q_INVOKABLE void set_avrcp_controls(QString address, QString cmd); bool power() const { return m_power; }; bool discoverable() const { return m_discoverable; }; -- cgit 1.2.3-korg From 61ef43a4520faa2c2c3118013b7bf26cac2e76bb Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Tue, 30 Oct 2018 09:49:21 -0700 Subject: libqtappfw: bluetooth: update to rewrite of bluetooth binding Bug-AGL: SPEC-1630 Change-Id: I705df82deefa371afa1f1d6ee57bb5457479408d Signed-off-by: Matt Ranostay --- bluetooth/bluetooth.cpp | 173 +++++++++++++++++++++++-------------------- bluetooth/bluetooth.h | 29 ++++---- bluetooth/bluetoothmessage.h | 15 ++-- 3 files changed, 112 insertions(+), 105 deletions(-) diff --git a/bluetooth/bluetooth.cpp b/bluetooth/bluetooth.cpp index 7ae8240..091cb26 100644 --- a/bluetooth/bluetooth.cpp +++ b/bluetooth/bluetooth.cpp @@ -31,6 +31,7 @@ Bluetooth::Bluetooth (QUrl &url, QObject * parent) : uuids.insert("a2dp", "0000110a-0000-1000-8000-00805f9b34fb"); uuids.insert("avrcp", "0000110e-0000-1000-8000-00805f9b34fb"); + uuids.insert("hfp", "0000111f-0000-1000-8000-00805f9b34fb"); } Bluetooth::~Bluetooth() @@ -38,14 +39,9 @@ Bluetooth::~Bluetooth() delete m_mloop; } -void Bluetooth::generic_command(QString verb, QString value) +void Bluetooth::send_command(QString verb, QJsonObject parameter) { BluetoothMessage *tmsg = new BluetoothMessage(); - QJsonObject parameter; - - if (!value.isEmpty()) - parameter.insert("value", value); - tmsg->createRequest(verb, parameter); m_mloop->sendMessage(tmsg); delete tmsg; @@ -53,163 +49,178 @@ void Bluetooth::generic_command(QString verb, QString value) void Bluetooth::setPower(bool state) { - generic_command("power", state ? "true": "false"); - - m_power = state; - - emit powerChanged(m_power); + QJsonObject parameter; + parameter.insert("powered", state ? "true" : "false"); + send_command("adapter_state", parameter); } void Bluetooth::setDiscoverable(bool state) { - const QStringList properties { "Pairable", "Discoverable" }; - QStringListIterator propertyIterator(properties); + QJsonObject parameter; + parameter.insert("discoverable", state ? "true" : "false"); + send_command("adapter_state", parameter); - while (propertyIterator.hasNext()) { - BluetoothMessage *tmsg = new BluetoothMessage(); - QJsonObject parameter; + m_discoverable = state; - parameter.insert("Property", propertyIterator.next()); - parameter.insert("value", state ? "true" : "false"); + emit discoverableChanged(); +} - tmsg->createRequest("set_property", parameter); - m_mloop->sendMessage(tmsg); - delete tmsg; - } +void Bluetooth::discovery_command(bool state) +{ + QJsonObject parameter; + parameter.insert("discovery", state ? "true" : "false"); - m_discoverable = state; + set_discovery_filter(); - emit discoverableChanged(); + send_command("adapter_state", parameter); } void Bluetooth::start_discovery() { - generic_command("start_discovery", ""); - generic_command("discovery_result", ""); + discovery_command(true); + + // temp workaround to list already discovered devices + send_command("managed_objects", QJsonObject()); } void Bluetooth::stop_discovery() { - generic_command("stop_discovery", ""); + discovery_command(false); } -void Bluetooth::remove_device(QString address) +void Bluetooth::remove_device(QString device) { - generic_command("remove_device", address); + QJsonObject parameter; + parameter.insert("device", device); + + send_command("remove_device", parameter); } -void Bluetooth::pair(QString address) +void Bluetooth::pair(QString device) { - generic_command("pair", address); + QJsonObject parameter; + parameter.insert("device", device); + + send_command("pair", parameter); } -void Bluetooth::cancel_pair(QString address) +void Bluetooth::cancel_pair(QString device) { - generic_command("cancel_pair", address); + send_command("cancel_pairing", QJsonObject()); } -void Bluetooth::connect(QString address, QString uuid) +void Bluetooth::connect(QString device, QString uuid) { - BluetoothMessage *tmsg = new BluetoothMessage(); QJsonObject parameter; - uuid = process_uuid(uuid); - - parameter.insert("value", address); + parameter.insert("device", device); parameter.insert("uuid", uuid); - tmsg->createRequest("connect", parameter); - m_mloop->sendMessage(tmsg); - delete tmsg; + send_command("connect", parameter); } -void Bluetooth::connect(QString address) +void Bluetooth::connect(QString device) { - generic_command("connect", address); + QJsonObject parameter; + parameter.insert("device", device); + send_command("connect", parameter); } -void Bluetooth::disconnect(QString address, QString uuid) +void Bluetooth::disconnect(QString device, QString uuid) { - BluetoothMessage *tmsg = new BluetoothMessage(); QJsonObject parameter; - uuid = process_uuid(uuid); - - parameter.insert("value", address); + parameter.insert("device", device); parameter.insert("uuid", uuid); - tmsg->createRequest("disconnect", parameter); - m_mloop->sendMessage(tmsg); - delete tmsg; + send_command("disconnect", parameter); } -void Bluetooth::disconnect(QString address) +void Bluetooth::disconnect(QString device) { - generic_command("disconnect", address); + QJsonObject parameter; + parameter.insert("device", device); + send_command("disconnect", parameter); } -void Bluetooth::send_confirmation() +void Bluetooth::send_confirmation(int pincode) { - generic_command("send_confirmation", "yes"); + QJsonObject parameter; + parameter.insert("pincode", pincode); + send_command("confirm_pairing", parameter); +} + + +void Bluetooth::set_discovery_filter() +{ + QStringListIterator eventIterator(uuids.values()); + QJsonObject parameter; + QJsonArray array; + + while (eventIterator.hasNext()) + array.push_back(eventIterator.next()); + + // send inital adapter state + discovery filter + parameter.insert("filter", array); + send_command("adapter_state", parameter); } void Bluetooth::onConnected() { QStringListIterator eventIterator(events); - BluetoothMessage *tmsg; while (eventIterator.hasNext()) { - tmsg = new BluetoothMessage(); QJsonObject parameter; parameter.insert("value", eventIterator.next()); - tmsg->createRequest("subscribe", parameter); - m_mloop->sendMessage(tmsg); - delete tmsg; + send_command("subscribe", parameter); } - // get initial power state - generic_command("power", QString()); - // send initial list - generic_command("discovery_result", ""); + send_command("managed_objects", QJsonObject()); + + // get initial power state + send_command("adapter_state", QJsonObject()); } void Bluetooth::onDisconnected() { QStringListIterator eventIterator(events); - BluetoothMessage *tmsg; while (eventIterator.hasNext()) { - tmsg = new BluetoothMessage(); QJsonObject parameter; parameter.insert("value", eventIterator.next()); - tmsg->createRequest("unsubscribe", parameter); - m_mloop->sendMessage(tmsg); - delete tmsg; + send_command("unsubscribe", parameter); } } +void Bluetooth::processDeviceChangesEvent(QJsonObject data) +{ + QString action = data.value("action").toString(); + + if (action == "added") + emit deviceAddedEvent(data); + else if (action == "changed") + emit deviceUpdatedEvent(data); + else if (action == "removed") + emit deviceRemovedEvent(data); +} + void Bluetooth::onMessageReceived(MessageType type, Message *msg) { if (msg->isEvent() && type == BluetoothEventMessage) { BluetoothMessage *tmsg = qobject_cast(msg); - if (tmsg->isConnectionEvent()) { - emit connectionEvent(tmsg->eventData()); - } else if (tmsg->isRequestConfirmationEvent()) { + if (tmsg->isDeviceChangesEvent()) { + processDeviceChangesEvent(tmsg->eventData()); + } else if (tmsg->isAgentEvent()) { emit requestConfirmationEvent(tmsg->eventData()); - } else if (tmsg->isDeviceAddedEvent()) { - emit deviceAddedEvent(tmsg->eventData()); - } else if (tmsg->isDeviceRemovedEvent()) { - emit deviceRemovedEvent(tmsg->eventData()); - } else if (tmsg->isDeviceUpdatedEvent()) { - emit deviceUpdatedEvent(tmsg->eventData()); } + } else if (msg->isReply() && type == ResponseRequestMessage) { ResponseMessage *tmsg = qobject_cast(msg); - if (tmsg->requestVerb() == "discovery_result") { + if (tmsg->requestVerb() == "managed_objects") { emit deviceListEvent(tmsg->replyData()); - } else if (tmsg->requestVerb() == "power") { - m_power = tmsg->replyData().value("power").toString() == "on"; + } else if (tmsg->requestVerb() == "adapter_state") { + m_power = tmsg->replyData().value("powered").toBool(); emit powerChanged(m_power); } } diff --git a/bluetooth/bluetooth.h b/bluetooth/bluetooth.h index d8bbb80..0f38381 100644 --- a/bluetooth/bluetooth.h +++ b/bluetooth/bluetooth.h @@ -19,6 +19,7 @@ #include #include +#include #include "messageengine.h" @@ -38,17 +39,17 @@ class Bluetooth : public QObject Q_INVOKABLE void start_discovery(void); Q_INVOKABLE void stop_discovery(void); - Q_INVOKABLE void remove_device(QString address); - Q_INVOKABLE void pair(QString address); - Q_INVOKABLE void cancel_pair(QString address); + Q_INVOKABLE void remove_device(QString device); + Q_INVOKABLE void pair(QString device); + Q_INVOKABLE void cancel_pair(QString device); - Q_INVOKABLE void connect(QString address, QString uuid); - Q_INVOKABLE void connect(QString address); + Q_INVOKABLE void connect(QString device, QString uuid); + Q_INVOKABLE void connect(QString device); - Q_INVOKABLE void disconnect(QString address, QString uuid); - Q_INVOKABLE void disconnect(QString address); + Q_INVOKABLE void disconnect(QString device, QString uuid); + Q_INVOKABLE void disconnect(QString device); - Q_INVOKABLE void send_confirmation(void); + Q_INVOKABLE void send_confirmation(int pincode); bool power() const { return m_power; }; bool discoverable() const { return m_discoverable; }; @@ -66,7 +67,10 @@ class Bluetooth : public QObject private: MessageEngine *m_mloop; - void generic_command(QString, QString); + void send_command(QString, QJsonObject); + void set_discovery_filter(); + void discovery_command(bool); + void processDeviceChangesEvent(QJsonObject data); // slots void onConnected(); @@ -82,11 +86,8 @@ class Bluetooth : public QObject QMap uuids; const QStringList events { - "connection", - "request_confirmation", - "device_added", - "device_removed", - "device_updated", + "device_changes", + "agent", }; }; diff --git a/bluetooth/bluetoothmessage.h b/bluetooth/bluetoothmessage.h index 89aef1a..4fc9124 100644 --- a/bluetooth/bluetoothmessage.h +++ b/bluetooth/bluetoothmessage.h @@ -23,20 +23,15 @@ class BluetoothMessage : public Message { Q_OBJECT public: - bool isConnectionEvent() { return (this->eventName() == "connection"); }; - bool isRequestConfirmationEvent() { return (this->eventName() == "request_confirmation"); }; - bool isDeviceAddedEvent() { return (this->eventName() == "device_added"); }; - bool isDeviceRemovedEvent() { return (this->eventName() == "device_removed"); }; - bool isDeviceUpdatedEvent() { return (this->eventName() == "device_updated"); }; + bool isDeviceChangesEvent() { return (this->eventName() == "device_changes"); }; + bool isAgentEvent() { return (this->eventName() == "agent"); }; bool createRequest(QString verb, QJsonObject parameter); private: QStringList verbs { - "start_discovery" , "stop_discovery", "power", - "remove_device", "pair", "cancel_pair", - "connect", "disconnect", "device_priorities", - "set_device_property", "set_property", "discovery_result", - "set_avrcp_controls", "send_confirmation", "version", + "connect", "disconnect", "managed_objects", + "adapter_state", "pair", "cancel_pairing", + "confirm_pairing", "remove_device", "version", "subscribe", "unsubscribe", }; }; -- cgit 1.2.3-korg From 0e1dae0af026f6a30e82f7129596da83bc4d8426 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Sun, 4 Nov 2018 15:50:17 -0800 Subject: libqtappfw: bluetooth: send out power event Send power event when device_changes powered parameter is detected Bug-AGL: SPEC-1630 Change-Id: I0170eafa03ce28ab9f907a37bcf7fefa9e205e33 Signed-off-by: Matt Ranostay --- bluetooth/bluetooth.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bluetooth/bluetooth.cpp b/bluetooth/bluetooth.cpp index 091cb26..f7ef970 100644 --- a/bluetooth/bluetooth.cpp +++ b/bluetooth/bluetooth.cpp @@ -197,9 +197,16 @@ void Bluetooth::processDeviceChangesEvent(QJsonObject data) if (action == "added") emit deviceAddedEvent(data); - else if (action == "changed") - emit deviceUpdatedEvent(data); - else if (action == "removed") + else if (action == "changed") { + auto powered = data.find("powered").value(); + + if (powered.isBool()) { + m_power = powered.toBool(); + emit powerChanged(m_power); + } else { + emit deviceUpdatedEvent(data); + } + } else if (action == "removed") emit deviceRemovedEvent(data); } -- cgit 1.2.3-korg