summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt27
-rw-r--r--bluetooth/CMakeLists.txt6
-rw-r--r--bluetooth/bluetooth.cpp369
-rw-r--r--bluetooth/bluetooth.h42
-rw-r--r--bluetooth/bluetootheventhandler.cpp121
-rw-r--r--bluetooth/bluetootheventhandler.h71
-rw-r--r--bluetooth/bluetoothmodel.cpp207
-rw-r--r--bluetooth/bluetoothmodel.h20
-rw-r--r--core/CMakeLists.txt28
-rw-r--r--core/callmessage.cpp55
-rw-r--r--core/callmessage.h52
-rw-r--r--core/eventmessage.cpp67
-rw-r--r--core/eventmessage.h61
-rw-r--r--core/message.cpp79
-rw-r--r--core/message.h71
-rw-r--r--core/messageengine.cpp90
-rw-r--r--core/messageengine.h55
-rw-r--r--core/messageenginefactory.cpp39
-rw-r--r--core/messageenginefactory.h41
-rw-r--r--core/messagefactory.cpp39
-rw-r--r--core/messagefactory.h42
-rw-r--r--core/qtappfw-core.pc.in12
-rw-r--r--core/responsemessage.cpp101
-rw-r--r--core/responsemessage.h88
-rw-r--r--hvac/CMakeLists.txt2
-rw-r--r--hvac/hvac.cpp46
-rw-r--r--hvac/hvac.h12
-rw-r--r--navigation/CMakeLists.txt2
-rw-r--r--navigation/navigation.cpp113
-rw-r--r--navigation/navigation.h11
-rw-r--r--network/CMakeLists.txt2
-rw-r--r--network/network.cpp57
-rw-r--r--network/network.h12
-rw-r--r--signal-composer/CMakeLists.txt19
-rw-r--r--signal-composer/qtappfw-signal-composer.pc.in12
-rw-r--r--signal-composer/signalcomposer.cpp102
-rw-r--r--signal-composer/signalcomposer.h60
-rw-r--r--voice-capabilities/CMakeLists.txt19
-rw-r--r--voice-capabilities/guimetadata.cpp349
-rw-r--r--voice-capabilities/guimetadata.h176
-rw-r--r--voice-capabilities/qtappfw-voice-metadata.pc.in12
-rw-r--r--voice/CMakeLists.txt22
-rw-r--r--voice/qtappfw-voice.pc.in12
-rw-r--r--voice/voice.cpp210
-rw-r--r--voice/voice.h71
-rw-r--r--voice/voiceagentmodel.cpp223
-rw-r--r--voice/voiceagentmodel.h66
-rw-r--r--voice/voiceagentprofile.cpp142
-rw-r--r--voice/voiceagentprofile.h78
-rw-r--r--voice/voiceagentregistry.cpp148
-rw-r--r--voice/voiceagentregistry.h78
-rw-r--r--weather/CMakeLists.txt2
-rw-r--r--weather/weather.cpp50
-rw-r--r--weather/weather.h9
54 files changed, 587 insertions, 3313 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 28b724c..f69e364 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,42 +7,27 @@ set(CMAKE_AUTOMOC ON)
set(OE_QMAKE_PATH_EXTERNAL_HOST_BINS $ENV{OE_QMAKE_PATH_HOST_BINS})
find_package(Qt5Qml REQUIRED)
-find_package(Qt5WebSockets REQUIRED)
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(glib REQUIRED IMPORTED_TARGET glib-2.0)
+pkg_check_modules(bluez_glib REQUIRED IMPORTED_TARGET bluez-glib)
+pkg_check_modules(connman_glib REQUIRED IMPORTED_TARGET connman-glib)
include(GNUInstallDirs)
set(DEST_DIR "${CMAKE_INSTALL_PREFIX}")
-set(PRIVATE_LIBS "${PRIVATE_LIBS} -lqtappfw-core
- -lqtappfw-bt
+set(PRIVATE_LIBS "${PRIVATE_LIBS} -lqtappfw-bt
-lqtappfw-hvac
- -lqtappfw-bt-map
- -lqtappfw-mediaplayer
-lqtappfw-navigation
-lqtappfw-network
- -lqtappfw-bt-pbap
- -lqtappfw-radio
- -lqtappfw-signal-composer
- -lqtappfw-phone
- -lqtappfw-voice
- -lqtappfw-voice-metadata
-lqtappfw-weather")
-
set (SUBDIRS
- core
docs
bluetooth
hvac
- map
- mediaplayer
navigation
network
- pbap
- radio
- signal-composer
- telephony
- voice
- voice-capabilities
weather)
foreach(subdir ${SUBDIRS})
diff --git a/bluetooth/CMakeLists.txt b/bluetooth/CMakeLists.txt
index e514aab..3137e3c 100644
--- a/bluetooth/CMakeLists.txt
+++ b/bluetooth/CMakeLists.txt
@@ -3,16 +3,16 @@ CONFIGURE_FILE("qtappfw-bt.pc.in" "qtappfw-bt.pc" @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-bt.pc
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
-add_library(qtappfw-bt SHARED bluetooth.cpp bluetoothmodel.cpp)
+add_library(qtappfw-bt SHARED bluetooth.cpp bluetoothmodel.cpp bluetootheventhandler.cpp)
target_include_directories(qtappfw-bt PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(qtappfw-bt PRIVATE "${CMAKE_INSTALL_INCLUDEDIR}")
-target_link_libraries(qtappfw-bt qtappfw-core)
+target_link_libraries(qtappfw-bt Qt5::Qml PkgConfig::glib PkgConfig::bluez_glib)
set_target_properties(qtappfw-bt PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
- PUBLIC_HEADER "bluetooth.h;bluetoothmodel.h")
+ PUBLIC_HEADER "bluetooth.h")
install(TARGETS qtappfw-bt
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
diff --git a/bluetooth/bluetooth.cpp b/bluetooth/bluetooth.cpp
index 82ef2f1..c58b64b 100644
--- a/bluetooth/bluetooth.cpp
+++ b/bluetooth/bluetooth.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018-2020 Konsulko Group
+ * Copyright (C) 2018-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,301 +16,248 @@
#include <QDebug>
-#include "callmessage.h"
-#include "eventmessage.h"
-#include "responsemessage.h"
-#include "messagefactory.h"
-#include "messageengine.h"
-#include "messageenginefactory.h"
+#include <bluez-glib.h>
+
#include "bluetooth.h"
#include "bluetoothmodel.h"
+#include "bluetootheventhandler.h"
-Bluetooth::Bluetooth (QUrl &url, QQmlContext *context, QObject * parent) :
- QObject(parent),
- m_context(context)
+Bluetooth::Bluetooth (bool register_agent, QQmlContext *context, QObject * parent) :
+ QObject(parent),
+ m_context(context),
+ m_agent(register_agent)
{
- m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
- m_bluetooth = new BluetoothModel();
- QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &Bluetooth::onConnected);
- QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &Bluetooth::onDisconnected);
- QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &Bluetooth::onMessageReceived);
-
- BluetoothModelFilter *m_model = new BluetoothModelFilter();
- m_model->setSourceModel(m_bluetooth);
- m_model->setFilterFixedString("true");
- context->setContextProperty("BluetoothPairedModel", m_model);
-
- m_model = new BluetoothModelFilter();
- m_model->setSourceModel(m_bluetooth);
- m_model->setFilterFixedString("false");
- context->setContextProperty("BluetoothDiscoveryModel", m_model);
-
- uuids.insert("a2dp", "0000110a-0000-1000-8000-00805f9b34fb");
- uuids.insert("avrcp", "0000110e-0000-1000-8000-00805f9b34fb");
- uuids.insert("hfp", "0000111f-0000-1000-8000-00805f9b34fb");
+ m_bluetooth = new BluetoothModel();
+ BluetoothModelFilter *m_model = new BluetoothModelFilter();
+ m_model->setSourceModel(m_bluetooth);
+ m_model->setFilterFixedString("true");
+ context->setContextProperty("BluetoothPairedModel", m_model);
+
+ m_model = new BluetoothModelFilter();
+ m_model->setSourceModel(m_bluetooth);
+ m_model->setFilterFixedString("false");
+ context->setContextProperty("BluetoothDiscoveryModel", m_model);
+
+ m_event_handler = new BluetoothEventHandler(this, register_agent);
+
+ 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()
{
}
-void Bluetooth::send_command(QString verb, QJsonObject parameter)
-{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* btmsg = static_cast<CallMessage*>(msg.get());
- btmsg->createRequest("Bluetooth-Manager", verb, parameter);
- m_mloop->sendMessage(std::move(msg));
-}
-
void Bluetooth::setPower(bool state)
{
- QJsonObject parameter;
- parameter.insert("powered", state ? "true" : "false");
- send_command("adapter_state", parameter);
+ bluez_adapter_set_powered(NULL, state ? TRUE : FALSE);
}
void Bluetooth::setDiscoverable(bool state)
{
- QJsonObject parameter;
- parameter.insert("discoverable", state ? "true" : "false");
- send_command("adapter_state", parameter);
+ bluez_adapter_set_discoverable(NULL, state);
- m_discoverable = state;
+ m_discoverable = state;
- emit discoverableChanged();
+ emit discoverableChanged();
}
-void Bluetooth::discovery_command(bool state)
+void Bluetooth::start()
{
- QJsonObject parameter;
- parameter.insert("discovery", state ? "true" : "false");
+ bluez_init(m_agent, m_agent, m_event_handler->init_cb, m_event_handler);
+}
- set_discovery_filter();
+void Bluetooth::discovery_command(bool state)
+{
+ set_discovery_filter();
- send_command("adapter_state", parameter);
+ bluez_adapter_set_discovery(NULL, state ? TRUE : FALSE);
}
void Bluetooth::start_discovery()
{
- discovery_command(true);
-
- // temp workaround to list already discovered devices
- send_command("managed_objects", QJsonObject());
+ discovery_command(true);
}
void Bluetooth::stop_discovery()
{
- discovery_command(false);
+ discovery_command(false);
}
void Bluetooth::remove_device(QString device)
{
- QJsonObject parameter;
- parameter.insert("device", device);
+ QByteArray device_ba = device.toLocal8Bit();
+ const char *device_cstr = device_ba.data();
- send_command("remove_device", parameter);
+ bluez_device_remove(device_cstr);
}
void Bluetooth::pair(QString device)
{
- QJsonObject parameter;
- parameter.insert("device", device);
+ QByteArray device_ba = device.toLocal8Bit();
+ const char *device_cstr = device_ba.data();
- send_command("pair", parameter);
+ bluez_device_pair(device_cstr, m_event_handler->device_pair_cb, m_event_handler);
}
-void Bluetooth::cancel_pair(QString device)
+void Bluetooth::cancel_pair(void)
{
- send_command("cancel_pairing", QJsonObject());
+ bluez_cancel_pairing();
}
void Bluetooth::connect(QString device, QString uuid)
{
- QJsonObject parameter;
- uuid = process_uuid(uuid);
- parameter.insert("device", device);
- parameter.insert("uuid", uuid);
- send_command("connect", parameter);
+ QByteArray device_ba = device.toLocal8Bit();
+ const char *device_cstr = device_ba.data();
+
+ uuid = process_uuid(uuid);
+ QByteArray uuid_ba = uuid.toLocal8Bit();
+ const char *uuid_cstr = uuid_ba.data();
+
+ bluez_device_connect(device_cstr,
+ uuid_cstr,
+ m_event_handler->device_connect_cb,
+ m_event_handler);
}
void Bluetooth::connect(QString device)
{
- QJsonObject parameter;
- parameter.insert("device", device);
- send_command("connect", parameter);
+ QByteArray device_ba = device.toLocal8Bit();
+ const char *device_cstr = device_ba.data();
+
+ bluez_device_connect(device_cstr,
+ NULL,
+ m_event_handler->device_connect_cb,
+ m_event_handler);
}
void Bluetooth::disconnect(QString device, QString uuid)
{
- QJsonObject parameter;
- uuid = process_uuid(uuid);
- parameter.insert("device", device);
- parameter.insert("uuid", uuid);
- send_command("disconnect", parameter);
-}
+ QByteArray device_ba = device.toLocal8Bit();
+ const char *device_cstr = device_ba.data();
-void Bluetooth::disconnect(QString device)
-{
- QJsonObject parameter;
- parameter.insert("device", device);
- send_command("disconnect", parameter);
-}
+ uuid = process_uuid(uuid);
+ QByteArray uuid_ba = uuid.toLocal8Bit();
+ const char *uuid_cstr = uuid_ba.data();
-void Bluetooth::send_confirmation(int pincode)
-{
- QJsonObject parameter;
- parameter.insert("pincode", pincode);
- send_command("confirm_pairing", parameter);
+ bluez_device_disconnect(device_cstr, uuid_cstr);
}
-
-void Bluetooth::set_discovery_filter()
+void Bluetooth::disconnect(QString device)
{
- QStringListIterator eventIterator(uuids.values());
- QJsonObject parameter;
- QJsonArray array;
-
- while (eventIterator.hasNext())
- array.push_back(eventIterator.next());
+ QByteArray device_ba = device.toLocal8Bit();
+ const char *device_cstr = device_ba.data();
- // send inital adapter state + discovery filter
- parameter.insert("filter", array);
- parameter.insert("transport", "bredr");
- send_command("adapter_state", parameter);
+ bluez_device_disconnect(device_cstr, NULL);
}
-void Bluetooth::onConnected()
+void Bluetooth::send_confirmation(int pincode)
{
- QStringListIterator eventIterator(events);
-
- while (eventIterator.hasNext()) {
- QJsonObject parameter;
- parameter.insert("value", eventIterator.next());
- send_command("subscribe", parameter);
- }
+ QString pincode_str;
+ pincode_str.setNum(pincode);
+ QByteArray pincode_ba = pincode_str.toLocal8Bit();
+ const char *pincode_cstr = pincode_ba.data();
- // send initial list
- send_command("managed_objects", QJsonObject());
-
- // get initial power state
- send_command("adapter_state", QJsonObject());
+ bluez_confirm_pairing(pincode_cstr);
}
-void Bluetooth::onDisconnected()
+void Bluetooth::init_adapter_state(QString adapter)
{
- QStringListIterator eventIterator(events);
+ // Get initial power state
+ GVariant *reply = NULL;
+ gboolean rc = bluez_adapter_get_state(NULL, &reply);
+ if (rc && reply) {
+ GVariantDict *props_dict = g_variant_dict_new(reply);
+ gboolean powered = FALSE;
+ if (g_variant_dict_lookup(props_dict, "Powered", "b", &powered)) {
+ if (m_power != powered) {
+ m_power = powered;
+ emit powerChanged(m_power);
+ }
+ }
+ g_variant_dict_unref(props_dict);
+ g_variant_unref(reply);
+ }
- while (eventIterator.hasNext()) {
- QJsonObject parameter;
- parameter.insert("value", eventIterator.next());
- send_command("unsubscribe", parameter);
- }
+ // Get initial device list
+ refresh_device_list();
}
-void Bluetooth::populateDeviceList(QJsonObject data)
+void Bluetooth::refresh_device_list(void)
{
- QJsonArray devices = data.value("devices").toArray();
-
- m_bluetooth->removeAllDevices();
-
- for (auto value : devices) {
- BluetoothDevice *device = m_bluetooth->updateDeviceProperties(nullptr, value.toObject());
- m_bluetooth->addDevice(device);
- }
+ gboolean rc;
+ GVariant *reply = NULL;
+
+ rc = bluez_adapter_get_devices(NULL, &reply);
+ if(!rc)
+ return;
+
+ m_bluetooth->removeAllDevices();
+
+ GVariantIter *array = NULL;
+ g_variant_get(reply, "a{sv}", &array);
+ const gchar *key = NULL;
+ GVariant *var = NULL;
+ while (g_variant_iter_next(array, "{&sv}", &key, &var)) {
+ BluetoothDevice *device = m_bluetooth->updateDeviceProperties(nullptr, key, var);
+ if (device)
+ m_bluetooth->addDevice(device);
+
+ g_variant_unref(var);
+ }
+ g_variant_iter_free(array);
+ g_variant_unref(reply);
}
-void Bluetooth::processDeviceChangesEvent(QJsonObject data)
+void Bluetooth::set_discovery_filter(void)
{
- QString action = data.value("action").toString();
- QString id = data.value("device").toString();
-
- if (id.isEmpty())
- return;
-
- BluetoothDevice *device = m_bluetooth->getDevice(id);
- if (action == "removed") {
- if (device != nullptr)
- m_bluetooth->removeDevice(device);
- return;
- }
-
- BluetoothDevice *ndevice = m_bluetooth->updateDeviceProperties(device, data);
- if (ndevice == nullptr) {
- qDebug() << "bt - failed to create device object with id: " << id;
- return;
- }
- if (device == nullptr) //device not previously in model
- m_bluetooth->addDevice(ndevice);
+ QList<QString> values = uuids.values();
+ QStringListIterator eventIterator(values);
+
+ gchar **uuids_array = (gchar**) g_malloc0((values.count() + 1) * sizeof(gchar*));
+ int i = 0;
+ while (eventIterator.hasNext()) {
+ QByteArray uuid_ba = eventIterator.next().toLocal8Bit();
+ gchar *uuid_cstr = g_strdup(uuid_ba.data());
+ uuids_array[i++] = uuid_cstr;
+ }
+
+ gchar *transport = g_strdup("bredr");
+ bluez_adapter_set_discovery_filter(NULL, uuids_array, transport);
+
+ for (i = 0; i < values.count(); i++)
+ g_free(uuids_array[i]);
+ g_free(uuids_array);
+ g_free(transport);
}
-void Bluetooth::processAdapterChangesEvent(QJsonObject data)
+void Bluetooth::update_adapter_power(bool powered)
{
- QString action = data.value("action").toString();
- if (action != "changed")
- return;
+ if (!powered)
+ m_bluetooth->removeAllDevices();
- QJsonObject properties = data.value("properties").toObject();
- if (!properties.contains("powered"))
- return;
+ if (m_power != powered) {
+ m_power = powered;
+ emit powerChanged(powered);
- bool powered = properties.find("powered").value().toBool();
- if (!powered)
- m_bluetooth->removeAllDevices();
+ if (powered)
+ refresh_device_list();
+ }
- if (m_power != powered) {
- m_power = powered;
- emit powerChanged(powered);
- }
- if (!m_power)
- m_discoverable = false;
+ if (!m_power) {
+ bool discoverable = m_discoverable;
+ m_discoverable = false;
+ if (discoverable != m_discoverable)
+ emit discoverableChanged();
+ }
}
-void Bluetooth::onMessageReceived(std::shared_ptr<Message> msg)
+void Bluetooth::request_confirmation(int pincode)
{
- if (!msg)
- return;
-
- if (msg->isEvent()) {
- std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
- QString ename = emsg->eventName();
- QString eapi = emsg->eventApi();
- QJsonObject data = emsg->eventData();
- if (eapi != "Bluetooth-Manager")
- return;
- if (ename == "device_changes") {
- processDeviceChangesEvent(data);
- } else if (ename == "adapter_changes") {
- processAdapterChangesEvent(data);
- } else if (ename == "agent") {
- emit requestConfirmationEvent(data);
- }
- } else if (msg->isReply()) {
- std::shared_ptr<ResponseMessage> rmsg = std::static_pointer_cast<ResponseMessage>(msg);
- QString verb = rmsg->requestVerb();
- QJsonObject data = rmsg->replyData();
- if (rmsg->requestApi() != "Bluetooth-Manager")
- return;
-
- if (rmsg->replyStatus() == "failed") {
- qDebug() << "failed bt verb:" << verb;
- if (rmsg->replyInfo().contains("No adapter")) {
- m_power = false;
- emit powerChanged(m_power);
- }
- }
- else if (verb == "managed_objects") {
- populateDeviceList(data);
- } else if (verb == "adapter_state") {
- bool powered = data.value("powered").toBool();
- if (m_power != powered) {
- m_power = powered;
- emit powerChanged(m_power);
- }
- }
- }
+ QString pincode_str;
+ pincode_str.setNum(pincode);
+ emit requestConfirmationEvent(pincode_str);
}
diff --git a/bluetooth/bluetooth.h b/bluetooth/bluetooth.h
index b79e8f9..c7ef55c 100644
--- a/bluetooth/bluetooth.h
+++ b/bluetooth/bluetooth.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018-2020 Konsulko Group
+ * Copyright (C) 2018-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,13 +19,10 @@
#include <memory>
#include <QObject>
-#include <QJsonObject>
-#include <QJsonArray>
#include <QtQml/QQmlContext>
class BluetoothModel;
-class MessageEngine;
-class Message;
+class BluetoothEventHandler;
class Bluetooth : public QObject
{
@@ -34,18 +31,20 @@ class Bluetooth : public QObject
Q_PROPERTY(bool discoverable READ discoverable WRITE setDiscoverable NOTIFY discoverableChanged)
public:
- explicit Bluetooth(QUrl &url, QQmlContext *context, QObject * parent = Q_NULLPTR);
+ explicit Bluetooth(bool register_agent, QQmlContext *context, QObject * parent = Q_NULLPTR);
virtual ~Bluetooth();
void setPower(bool);
void setDiscoverable(bool);
+ Q_INVOKABLE void start(void);
+
Q_INVOKABLE void start_discovery(void);
Q_INVOKABLE void stop_discovery(void);
Q_INVOKABLE void remove_device(QString device);
Q_INVOKABLE void pair(QString device);
- Q_INVOKABLE void cancel_pair(QString device);
+ Q_INVOKABLE void cancel_pair(void);
Q_INVOKABLE void connect(QString device, QString uuid);
Q_INVOKABLE void connect(QString device);
@@ -62,24 +61,21 @@ class Bluetooth : public QObject
void powerChanged(bool state);
void discoverableChanged();
- void connectionEvent(QJsonObject data);
- void requestConfirmationEvent(QJsonObject data);
+ //void connectionEvent(QJsonObject data);
+ void requestConfirmationEvent(QString pincode);
private:
- std::shared_ptr<MessageEngine> m_mloop;
QQmlContext *m_context;
BluetoothModel *m_bluetooth;
- void send_command(QString, QJsonObject);
- void set_discovery_filter();
- void discovery_command(bool);
- void populateDeviceList(QJsonObject data);
- void processDeviceChangesEvent(QJsonObject data);
- void processAdapterChangesEvent(QJsonObject data);
+ BluetoothEventHandler *m_event_handler;
+ bool m_agent;
- // slots
- void onConnected();
- void onDisconnected();
- void onMessageReceived(std::shared_ptr<Message>);
+ void init_adapter_state(QString);
+ void refresh_device_list(void);
+ void set_discovery_filter(void);
+ void discovery_command(bool);
+ void update_adapter_power(bool);
+ void request_confirmation(int);
QString process_uuid(QString uuid) { if (uuid.length() == 36) return uuid; return uuids.value(uuid); };
@@ -89,11 +85,7 @@ class Bluetooth : public QObject
QMap<QString, QString> uuids;
- const QStringList events {
- "adapter_changes",
- "device_changes",
- "agent",
- };
+ friend class BluetoothEventHandler;
};
#endif // BLUETOOTH_H
diff --git a/bluetooth/bluetootheventhandler.cpp b/bluetooth/bluetootheventhandler.cpp
new file mode 100644
index 0000000..0acd5f5
--- /dev/null
+++ b/bluetooth/bluetootheventhandler.cpp
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2021 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <QDebug>
+#include <bluez-glib.h>
+
+#include "bluetootheventhandler.h"
+#include "bluetooth.h"
+#include "bluetoothmodel.h"
+
+
+BluetoothEventHandler::BluetoothEventHandler (Bluetooth *parent, bool register_agent) :
+ m_parent(parent),
+ m_agent(register_agent)
+{
+ bluez_add_adapter_event_callback(adapter_event_cb, this);
+ bluez_add_device_event_callback(device_event_cb, this);
+ if (register_agent)
+ bluez_add_agent_event_callback(agent_event_cb, this);
+}
+
+BluetoothEventHandler::~BluetoothEventHandler()
+{
+}
+
+void BluetoothEventHandler::handle_init_event(gchar *adapter, gboolean status)
+{
+ if (status)
+ m_parent->init_adapter_state(QString(adapter));
+ else
+ qCritical() << "BlueZ initialization failed";
+}
+
+void BluetoothEventHandler::handle_adapter_event(gchar *adapter,
+ bluez_event_t event,
+ GVariant *properties)
+{
+ if (!adapter || event != BLUEZ_EVENT_CHANGE)
+ return;
+
+ GVariantDict *props_dict = g_variant_dict_new(properties);
+ if (!props_dict)
+ return;
+
+ gboolean powered = FALSE;
+ if (!g_variant_dict_lookup(props_dict, "Powered", "b", &powered)) {
+ g_variant_dict_unref(props_dict);
+ return;
+ }
+
+ g_variant_dict_unref(props_dict);
+
+ m_parent->update_adapter_power(powered);
+}
+
+void BluetoothEventHandler::handle_device_event(gchar *adapter,
+ gchar *device,
+ bluez_event_t event,
+ GVariant *properties)
+{
+ if (!device)
+ return;
+
+ BluetoothDevice *model_device = m_parent->m_bluetooth->getDevice(QString(device));
+ if (event == BLUEZ_EVENT_REMOVE) {
+ if(model_device != nullptr)
+ m_parent->m_bluetooth->removeDevice(model_device);
+
+ return;
+ }
+
+ BluetoothDevice *new_device = m_parent->m_bluetooth->updateDeviceProperties(model_device, device, properties);
+ if (new_device == nullptr) {
+ qCritical() << "Failed to create device object with id: " << QString(device);
+ return;
+ }
+ if (model_device == nullptr && event == BLUEZ_EVENT_ADD) {
+ // device not previously in model
+ m_parent->m_bluetooth->addDevice(new_device);
+ }
+}
+
+void BluetoothEventHandler::handle_agent_event(gchar *device,
+ bluez_agent_event_t event,
+ GVariant *properties)
+{
+ const gchar *path = NULL;
+ int pincode;
+
+ if (event == BLUEZ_AGENT_EVENT_REQUEST_CONFIRMATION) {
+ g_variant_get(properties, "(ou)", &path, &pincode);
+ if (path)
+ m_parent->request_confirmation(pincode);
+ }
+}
+
+void BluetoothEventHandler::handle_connect_event(gchar *device, gboolean status)
+{
+ if (!status)
+ qDebug() << "connect failed";
+}
+
+void BluetoothEventHandler::handle_pair_event(gchar *device, gboolean status)
+{
+ if (!status)
+ qDebug() << "pairing failed";
+}
+
diff --git a/bluetooth/bluetootheventhandler.h b/bluetooth/bluetootheventhandler.h
new file mode 100644
index 0000000..ff970f5
--- /dev/null
+++ b/bluetooth/bluetootheventhandler.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2021 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BLUETOOTH_EVENT_HANDLER_H
+#define BLUETOOTH_EVENT_HANDLER_H
+
+class Bluetooth;
+
+class BluetoothEventHandler
+{
+ public:
+ explicit BluetoothEventHandler(Bluetooth *parent, bool register_agent);
+ virtual ~BluetoothEventHandler();
+
+ static void init_cb(gchar *adapter, gboolean status, gpointer user_data) {
+ if (user_data)
+ ((BluetoothEventHandler*) user_data)->handle_init_event(adapter, status);
+ }
+
+ static void device_connect_cb(gchar *device, gboolean status, gpointer user_data) {
+ if (user_data)
+ ((BluetoothEventHandler*) user_data)->handle_connect_event(device, status);
+ }
+
+ static void device_pair_cb(gchar *device, gboolean status, gpointer user_data) {
+ if (user_data)
+ ((BluetoothEventHandler*) user_data)->handle_pair_event(device, status);
+ }
+
+ private:
+ Bluetooth *m_parent;
+ bool m_agent;
+
+ // Callback functions for bluez-glib hooks
+ static void adapter_event_cb(gchar *adapter, bluez_event_t event, GVariant *properties, gpointer user_data) {
+ if (user_data)
+ ((BluetoothEventHandler*) user_data)->handle_adapter_event(adapter, event, properties);
+ }
+
+ static void device_event_cb(gchar *adapter, gchar *device, bluez_event_t event, GVariant *properties, gpointer user_data) {
+ if (user_data)
+ ((BluetoothEventHandler*) user_data)->handle_device_event(adapter, device, event, properties);
+ }
+
+ static void agent_event_cb(gchar *device, bluez_agent_event_t event, GVariant *properties, gpointer user_data) {
+ if (user_data)
+ ((BluetoothEventHandler*) user_data)->handle_agent_event(device, event, properties);
+ }
+
+ void handle_init_event(gchar *adapter, gboolean status);
+ void handle_adapter_event(gchar *adapter, bluez_event_t event, GVariant *properties);
+ void handle_device_event(gchar *adapter, gchar *device, bluez_event_t event, GVariant *properties);
+ void handle_agent_event(gchar *device, bluez_agent_event_t event, GVariant *properties);
+ void handle_connect_event(gchar *device, gboolean status);
+ void handle_pair_event(gchar *device, gboolean status);
+};
+
+#endif // BLUETOOTH_EVENT_HANDLER_H
diff --git a/bluetooth/bluetoothmodel.cpp b/bluetooth/bluetoothmodel.cpp
index 294b50b..605f950 100644
--- a/bluetooth/bluetoothmodel.cpp
+++ b/bluetooth/bluetoothmodel.cpp
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2019-2021 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include "bluetoothmodel.h"
#include <QDebug>
@@ -13,52 +29,52 @@ BluetoothDevice::BluetoothDevice(const QString &id,
QString BluetoothDevice::id() const
{
- return m_id;
+ return m_id;
}
QString BluetoothDevice::address() const
{
- return m_address;
+ return m_address;
}
QString BluetoothDevice::name() const
{
- return m_name;
+ return m_name;
}
bool BluetoothDevice::paired() const
{
- return m_paired;
+ return m_paired;
}
bool BluetoothDevice::connected() const
{
- return m_connected;
+ return m_connected;
}
void BluetoothDevice::setId(const QString id)
{
- m_id = id;
+ m_id = id;
}
void BluetoothDevice::setAddress(const QString address)
{
- m_address = address;
+ m_address = address;
}
void BluetoothDevice::setName(const QString name)
{
- m_name = name;
+ m_name = name;
}
void BluetoothDevice::setPaired(const bool paired)
{
- m_paired = paired;
+ m_paired = paired;
}
void BluetoothDevice::setConnected(const bool connected)
{
- m_connected = connected;
+ m_connected = connected;
}
BluetoothModel::BluetoothModel(QObject *parent)
@@ -68,117 +84,158 @@ BluetoothModel::BluetoothModel(QObject *parent)
void BluetoothModel::addDevice(BluetoothDevice *device)
{
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- m_devices << device;
- endInsertRows();
+ if (!device)
+ return;
+
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ m_devices << device;
+ endInsertRows();
}
void BluetoothModel::removeDevice(BluetoothDevice *device)
{
- int row = m_devices.indexOf(device);
- beginRemoveRows(QModelIndex(), row, row);
- m_devices.removeAt(row);
- endRemoveRows();
- delete device;
+ if (!device)
+ return;
+
+ int row = m_devices.indexOf(device);
+ if (row < 0)
+ return;
+ beginRemoveRows(QModelIndex(), row, row);
+ m_devices.removeAt(row);
+ endRemoveRows();
+ delete device;
}
void BluetoothModel::removeAllDevices()
{
- beginRemoveRows(QModelIndex(), 0, m_devices.count() - 1);
- qDeleteAll(m_devices.begin(), m_devices.end());
- m_devices.clear();
- endRemoveRows();
+ if (!m_devices.count())
+ return;
+
+ beginRemoveRows(QModelIndex(), 0, m_devices.count() - 1);
+ qDeleteAll(m_devices.begin(), m_devices.end());
+ m_devices.clear();
+ endRemoveRows();
}
int BluetoothModel::rowCount(const QModelIndex &parent) const
{
- Q_UNUSED(parent);
- return m_devices.count();
+ Q_UNUSED(parent);
+ return m_devices.count();
}
QVariant BluetoothModel::data(const QModelIndex &index, int role) const
{
- if (index.row() < 0 || index.row() >= m_devices.count())
- return QVariant();
+ if (index.row() < 0 || index.row() >= m_devices.count())
+ return QVariant();
- const BluetoothDevice *device = m_devices[index.row()];
+ const BluetoothDevice *device = m_devices[index.row()];
- switch (role) {
+ switch (role) {
case IdRole:
- return device->id();
+ return device->id();
case AddressRole:
- return device->address();
+ return device->address();
case NameRole:
- return device->name();
+ return device->name();
case PairedRole:
- return device->paired();
+ return device->paired();
case ConnectedRole:
- return device->connected();
- }
+ return device->connected();
+ }
- return QVariant();
+ return QVariant();
}
QHash<int, QByteArray> BluetoothModel::roleNames() const {
- QHash<int, QByteArray> roles;
- roles[IdRole] = "id";
- roles[AddressRole] = "address";
- roles[NameRole] = "name";
- roles[PairedRole] = "paired";
- roles[ConnectedRole] = "connected";
+ QHash<int, QByteArray> roles;
+ roles[IdRole] = "id";
+ roles[AddressRole] = "address";
+ roles[NameRole] = "name";
+ roles[PairedRole] = "paired";
+ roles[ConnectedRole] = "connected";
- return roles;
+ return roles;
}
QModelIndex BluetoothModel::indexOf(BluetoothDevice *device)
{
- int row = m_devices.indexOf(device);
+ int row = m_devices.indexOf(device);
- return index(row);
+ return index(row);
}
BluetoothDevice *BluetoothModel::getDevice(QString id)
{
- for (auto device : m_devices) {
- if (device->id() == id)
- return device;
- }
+ for (auto device : m_devices) {
+ if (device->id() == id)
+ return device;
+ }
- return nullptr;
+ return nullptr;
}
-BluetoothDevice *BluetoothModel::updateDeviceProperties(BluetoothDevice *device, QJsonObject data)
+BluetoothDevice *BluetoothModel::updateDeviceProperties(BluetoothDevice *device, const gchar *dev_str, GVariant *properties)
{
- QJsonObject properties = data.value("properties").toObject();
- QString id = data.value("device").toString();
- QString address = properties.value("address").toString();
- QString name = properties.value("name").toString();
- bool paired = properties.value("paired").toBool();
- bool connected = properties.value("connected").toBool();
+ GVariantDict *props_dict = g_variant_dict_new(properties);
+ if (!props_dict)
+ return nullptr;
+
+ QString id(dev_str);
+ if (id.isEmpty()) {
+ g_variant_dict_unref(props_dict);
+ return nullptr;
+ }
+
+ gchar *p = NULL;
+ QString address;
+ if (g_variant_dict_lookup(props_dict, "Address", "s", &p)) {
+ address = QString(p);
+ g_free(p);
+ }
+
+ p = NULL;
+ QString name;
+ if (g_variant_dict_lookup(props_dict, "Name", "s", &p)) {
+ name = QString(p);
+ g_free(p);
+ }
+
+ gboolean paired = FALSE;
+ bool have_paired = false;
+ if (g_variant_dict_lookup(props_dict, "Paired", "b", &paired)) {
+ have_paired = true;
+ }
+
+ gboolean connected = FALSE;
+ bool have_connected = false;
+ if (g_variant_dict_lookup(props_dict, "Connected", "b", &connected)) {
+ have_connected = true;
+ }
- if (id.isEmpty())
- return nullptr;
+ g_variant_dict_unref(props_dict);
- if (device == nullptr)
- return new BluetoothDevice(id, address, name, paired, connected);
+ if (device == nullptr) {
+ // Create new device object
+ return new BluetoothDevice(id, address, name, paired, connected);
+ }
- device->setId(id);
+ device->setId(id);
- if (!address.isEmpty())
- device->setAddress(address);
+ if (!address.isEmpty())
+ device->setAddress(address);
- if (!name.isEmpty())
- device->setName(name);
+ if (!name.isEmpty())
+ device->setName(name);
- if (properties.contains("paired"))
- device->setPaired(paired);
+ if (have_paired)
+ device->setPaired(paired);
- if (properties.contains("connected"))
- device->setConnected(connected);
+ if (have_connected)
+ device->setConnected(connected);
- emit dataChanged(indexOf(device), indexOf(device));
+ emit dataChanged(indexOf(device), indexOf(device));
- return device;
+ return device;
}
BluetoothModelFilter::BluetoothModelFilter(QObject *parent) : QSortFilterProxyModel(parent)
@@ -187,9 +244,9 @@ BluetoothModelFilter::BluetoothModelFilter(QObject *parent) : QSortFilterProxyMo
bool BluetoothModelFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
- BluetoothModel *model = qobject_cast<BluetoothModel *>(sourceModel());
- QModelIndex index = model->index(sourceRow);
- bool paired = model->data(index, BluetoothModel::BluetoothRoles::PairedRole).toBool();
+ BluetoothModel *model = qobject_cast<BluetoothModel *>(sourceModel());
+ QModelIndex index = model->index(sourceRow);
+ bool paired = model->data(index, BluetoothModel::BluetoothRoles::PairedRole).toBool();
- return ((paired ? "true" : "false") == filterRegExp().pattern());
+ return ((paired ? "true" : "false") == filterRegExp().pattern());
}
diff --git a/bluetooth/bluetoothmodel.h b/bluetooth/bluetoothmodel.h
index 0fc07aa..a060ad8 100644
--- a/bluetooth/bluetoothmodel.h
+++ b/bluetooth/bluetoothmodel.h
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2019,2021 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#ifndef BLUETOOTH_MODEL_H
#define BLUETOOTH_MODEL_H
@@ -5,7 +21,7 @@
#include <QSortFilterProxyModel>
#include <QStringList>
#include <QtQml/QQmlContext>
-#include <QJsonObject>
+#include <glib.h>
class BluetoothDevice
{
@@ -53,7 +69,7 @@ class BluetoothModel : public QAbstractListModel
void removeDevice(BluetoothDevice *device);
void removeAllDevices();
BluetoothDevice *getDevice(QString address);
- BluetoothDevice *updateDeviceProperties(BluetoothDevice *device, QJsonObject data);
+ BluetoothDevice *updateDeviceProperties(BluetoothDevice *device, const gchar *dev_str, GVariant *properties);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
deleted file mode 100644
index 3102f3b..0000000
--- a/core/CMakeLists.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-
-CONFIGURE_FILE("qtappfw-core.pc.in" "qtappfw-core.pc" @ONLY)
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-core.pc
- DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
-
-add_library(qtappfw-core SHARED message.cpp
- messagefactory.cpp
- messageengine.cpp
- messageenginefactory.cpp
- responsemessage.cpp
- callmessage.cpp
- eventmessage.cpp)
-
-target_include_directories(qtappfw-core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
-target_include_directories(qtappfw-core PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}")
-
-target_link_libraries(qtappfw-core Qt5::WebSockets)
-
-set_target_properties(qtappfw-core PROPERTIES
- VERSION ${PROJECT_VERSION}
- SOVERSION 1
- PUBLIC_HEADER "message.h;messagefactory.h;messageengine.h;messageenginefactory.h;responsemessage.h;callmessage.h;eventmessage.h")
-
-
-install(TARGETS qtappfw-core
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-core)
-
diff --git a/core/callmessage.cpp b/core/callmessage.cpp
deleted file mode 100644
index 1dfa72e..0000000
--- a/core/callmessage.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <QDebug>
-#include <QJsonArray>
-#include <QJsonDocument>
-#include <QJsonValue>
-
-#include "callmessage.h"
-#include "message.h"
-
-
-bool CallMessage::createRequest(QString api, QString verb, QJsonValue parameter)
-{
- if (!m_request.isEmpty()){
- qWarning("Message instance has already been used. Cannot send another request.");
- return false;
- }
-
- m_request["msgid"] = static_cast<unsigned int>(MessageId::Call);
- m_request["callid"] = 0;
- m_request["api"] = api;
- m_request["verb"] = verb;
- m_request["parameter"] = parameter;
-
- m_init = true;
-
- return m_init;
-}
-
-QByteArray CallMessage::serialize(QJsonDocument::JsonFormat format)
-{
- QJsonArray array;
- array.append(m_request["msgid"].toInt());
- array.append(m_request["callid"].toInt());
- array.append(m_request["api"].toString() + "/" + m_request["verb"].toString());
- array.append(m_request["parameter"].toJsonValue());
-
- m_jdoc.setArray(array);
-
- return m_jdoc.toJson(format).data();
-}
diff --git a/core/callmessage.h b/core/callmessage.h
deleted file mode 100644
index d08024e..0000000
--- a/core/callmessage.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CALLMESSAGE_H
-#define CALLMESSAGE_H
-
-#include "message.h"
-
-
-class CallMessage : public Message
-{
- public:
- bool createRequest(QString api, QString verb, QJsonValue parameter = "None");
-
- bool isEvent() override
- {
- return false;
- }
-
- bool isReply() override
- {
- return false;
- }
-
- void updateCallId(unsigned int id) override
- {
- m_request["callid"] = qint32(id);
- }
-
- QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact) override;
-
- private:
- QMap<QString, QVariant> m_request;
-
- CallMessage() = default;
- friend class MessageFactory;
-};
-
-#endif // CALLMESSAGE_H
diff --git a/core/eventmessage.cpp b/core/eventmessage.cpp
deleted file mode 100644
index 818830f..0000000
--- a/core/eventmessage.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <QDebug>
-#include <QJsonArray>
-#include <QJsonDocument>
-#include <QJsonObject>
-#include <QJsonValue>
-
-#include "eventmessage.h"
-
-EventMessage::EventMessage(QJsonDocument content): Message()
-{
- QJsonArray msg = content.array();
- if (!msg[2].isObject()) {
- qWarning("Invalid appfw payload: no JSON object");
- return;
- }
-
- //deserialize:
- QJsonObject payload = msg[2].toObject();
-
- auto data_iter = payload.find("data");
- m_event_data = data_iter.value().toObject();
-
- auto event_iter = payload.find("event");
- auto event_string = event_iter.value().toString();
- if (event_string.isEmpty()) {
- qWarning("Invalid appfw event message: empty event name");
- return;
- }
- QStringList event_strings = event_string.split(QRegExp("/"));
- if (event_strings.size() != 2) {
- qWarning("Invalid appfw event message: malformed event name");
- return;
- }
- m_event_api = event_strings[0];
- m_event_name = event_strings[1];
- m_init = true;
-}
-
-QByteArray EventMessage::serialize(QJsonDocument::JsonFormat format)
-{
- QJsonArray array;
- array.append(static_cast<int>(MessageId::Event));
- array.append(0); //unused field
- array.append(m_event_api + "/" + m_event_name);
- array.append(m_event_data);
-
- QJsonDocument jdoc;
- jdoc.setArray(array);
-
- return jdoc.toJson(format).data();
-}
diff --git a/core/eventmessage.h b/core/eventmessage.h
deleted file mode 100644
index 133574c..0000000
--- a/core/eventmessage.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef EVENTMESSAGE_H
-#define EVENTMESSAGE_H
-
-#include "message.h"
-
-
-class EventMessage : public Message
-{
- public:
- inline QString eventApi() const
- {
- return m_event_api;
- }
-
- inline QString eventName() const
- {
- return m_event_name;
- }
-
- inline QJsonObject eventData() const
- {
- return m_event_data;
- }
-
- bool isEvent() override
- {
- return true;
- }
-
- bool isReply() override
- {
- return false;
- }
-
- QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact) override;
-
- private:
- QString m_event_api, m_event_name;
- QJsonObject m_event_data;
-
- explicit EventMessage(QJsonDocument data);
- friend class MessageFactory;
-};
-
-#endif // EVENTMESSAGE_H
diff --git a/core/message.cpp b/core/message.cpp
deleted file mode 100644
index 1865f14..0000000
--- a/core/message.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2017-2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <QDebug>
-#include <QJsonArray>
-#include <QJsonDocument>
-#include <QWebSocket>
-
-#include "message.h"
-
-MessageId Message::isValid(QJsonDocument candidate)
-{
- MessageId id = MessageId::Invalid;
-
- // Validate message is array
- if (!candidate.isArray()) {
- qWarning("Invalid appfw message: not an array");
- return id;
- }
- QJsonArray msg = candidate.array();
-
- // Validate array is proper length
- if ((msg.size() < 3) || (msg.size() > 4)) {
- qWarning("Invalid appfw message: invalid array size");
- return id;
- }
-
- // Validate msgid type
- double msgid;
- if (msg[0].isDouble()) {
- msgid = msg[0].toDouble();
- } else {
- qWarning("Invalid appfw message: invalid msgid type");
- return id;
- }
-
- // Validate msgid element
- if ((msgid >= static_cast<double>(MessageId::Call)) && (msgid <= static_cast<double>(MessageId::Event)))
- id = static_cast<MessageId>(msgid);
-
- return id;
-}
-
-Message::Message()
- : m_init(false)
-{
-}
-
-QByteArray Message::serialize(QJsonDocument::JsonFormat format)
-{
- QByteArray dummy;
- return dummy;
- }
-
-QByteArray Message::send(QWebSocket& transport, unsigned int id)
-{
- QByteArray blob;
- qint64 size = 0;
- updateCallId(id);
- if (m_init)
- blob = serialize().data();
- if (!blob.isEmpty())
- size = transport.sendTextMessage(blob);
-
- return blob;
-}
diff --git a/core/message.h b/core/message.h
deleted file mode 100644
index acbbefd..0000000
--- a/core/message.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2017-2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef MESSAGE_H
-#define MESSAGE_H
-
-#include <memory>
-#include <QObject>
-#include <QMap>
-#include <QVariant>
-#include <QJsonDocument>
-#include <QJsonObject>
-
-enum class MessageId {
- Invalid = 0,
- Call = 2,
- RetOk = 3,
- RetErr = 4,
- Event = 5,
-};
-
-class QWebSocket;
-
-class Message
-{
- public:
- Message();
- virtual bool setAdditionalData(QByteArray data)
- {
- return false;
- }
- QByteArray send(QWebSocket& transport, unsigned int callid);
-
- inline bool isComplete() const
- {
- return m_init;
- }
-
- virtual bool getCallId(unsigned int *id) const
- {
- return false;
- }
-
- static MessageId isValid(QJsonDocument );
-
- virtual bool isEvent() = 0;
- virtual bool isReply() = 0;
-
- protected:
- virtual void updateCallId(unsigned int id) {};
- virtual QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact);
-
- bool m_init;
- QJsonDocument m_jdoc;
-};
-Q_DECLARE_METATYPE(std::shared_ptr<Message>)
-
-#endif // MESSAGE_H
diff --git a/core/messageengine.cpp b/core/messageengine.cpp
deleted file mode 100644
index 42fe95b..0000000
--- a/core/messageengine.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2017-2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <QJsonArray>
-#include <QDebug>
-
-#include "message.h"
-#include "messagefactory.h"
-#include "messageengine.h"
-
-
-MessageEngine::MessageEngine(const QUrl &url) :
- QObject(Q_NULLPTR),
- m_callid(0),
- m_url(url)
-{
- connect(&m_websocket, &QWebSocket::connected, this, &MessageEngine::onConnected);
- connect(&m_websocket, &QWebSocket::disconnected, this, &MessageEngine::onDisconnected);
-
- m_websocket.open(url);
-}
-
-bool MessageEngine::sendMessage(std::unique_ptr<Message> msg)
-{
- if (!msg)
- return false;
-
- unsigned int callid = m_callid++;
- QByteArray forkeeps = msg->send(m_websocket, callid);
- if (forkeeps.isEmpty())
- return false;
-
- std::lock_guard<std::mutex> localguard(m_mutex);
- m_calls.insert(callid, forkeeps);
-
- return true;
-}
-
-void MessageEngine::onConnected()
-{
- connect(&m_websocket, &QWebSocket::textMessageReceived, this, &MessageEngine::onTextMessageReceived);
- emit connected();
-}
-
-void MessageEngine::onDisconnected()
-{
- disconnect(&m_websocket, &QWebSocket::textMessageReceived, this, &MessageEngine::onTextMessageReceived);
- emit disconnected();
-}
-
-void MessageEngine::onTextMessageReceived(QString jsonStr)
-{
- jsonStr = jsonStr.simplified();
- QJsonDocument jdoc(QJsonDocument::fromJson(jsonStr.toUtf8()));
- if (jdoc.isEmpty()) {
- qWarning() << "Received invalid JSON: empty appfw message";
- return;
- }
-
- MessageId id = Message::isValid(jdoc);
- if (id == MessageId::Invalid) {
- qWarning() << "Received unknown message, discarding";
- return;
- }
-
- std::shared_ptr<Message> message = MessageFactory::getInstance().createInboundMessage(id, jdoc);
-
- unsigned int callid;
- if (message->isReply() && message->getCallId(&callid)) {
- message->setAdditionalData(m_calls[callid]);
- std::lock_guard<std::mutex> localguard(m_mutex);
- m_calls.remove(callid);
- }
-
- if (message->isComplete())
- emit messageReceived(message);
-}
diff --git a/core/messageengine.h b/core/messageengine.h
deleted file mode 100644
index 12aa5e9..0000000
--- a/core/messageengine.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2017-2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef MESSAGEENGINE_H
-#define MESSAGEENGINE_H
-
-#include <memory>
-#include <atomic>
-#include <mutex>
-#include <QUrl>
-#include <QWebSocket>
-
-#include "message.h"
-
-class MessageEngine : public QObject
-{
- Q_OBJECT
- public:
- bool sendMessage(std::unique_ptr<Message> message);
-
- Q_SIGNALS:
- void disconnected();
- void connected();
- void messageReceived(std::shared_ptr<Message> message);
-
- private Q_SLOTS:
- void onConnected();
- void onDisconnected();
- void onTextMessageReceived(QString message);
-
- private:
- QWebSocket m_websocket;
- std::mutex m_mutex;
- QMap<qint32, QByteArray> m_calls;
- QUrl m_url;
- std::atomic<unsigned int> m_callid;
-
- explicit MessageEngine(const QUrl &url);
- friend class MessageEngineFactory;
-};
-
-#endif // MESSAGEENGINE_H
diff --git a/core/messageenginefactory.cpp b/core/messageenginefactory.cpp
deleted file mode 100644
index 04fb741..0000000
--- a/core/messageenginefactory.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <unordered_map>
-#include <mutex>
-#include <QDebug>
-#include <QUrl>
-#include "messageenginefactory.h"
-#include "messageengine.h"
-
-std::shared_ptr<MessageEngine> MessageEngineFactory::getMessageEngine(const QUrl& url)
-{
- static std::unordered_map<QString, std::shared_ptr<MessageEngine>> lut;
- static std::mutex m;
-
- std::lock_guard<std::mutex> localguard(m);
- auto urlstr = url.toString();
- auto pme = lut[urlstr];
- if (!pme){
- pme = std::shared_ptr<MessageEngine>{new MessageEngine(url)};
- lut[urlstr] = pme;
- }
-
- return pme;
-}
diff --git a/core/messageenginefactory.h b/core/messageenginefactory.h
deleted file mode 100644
index 1ce107b..0000000
--- a/core/messageenginefactory.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef MESSAGEENGINEFACTORY_H
-#define MESSAGEENGINEFACTORY_H
-
-#include <memory>
-
-class MessageEngine;
-class QUrl;
-
-
-class MessageEngineFactory {
- public:
- static MessageEngineFactory& getInstance() {
- static MessageEngineFactory instance;
- return instance;
- }
- std::shared_ptr<MessageEngine> getMessageEngine(const QUrl &ur);
- MessageEngineFactory(MessageEngineFactory const&) = delete;
- void operator=(MessageEngineFactory const&) = delete;
-
- private:
- MessageEngineFactory() = default;
- ~MessageEngineFactory() = default;
-};
-
-#endif // MESSAGENGINEEFACTORY_H
diff --git a/core/messagefactory.cpp b/core/messagefactory.cpp
deleted file mode 100644
index 6740e25..0000000
--- a/core/messagefactory.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "messagefactory.h"
-#include "message.h"
-#include "responsemessage.h"
-#include "eventmessage.h"
-#include "callmessage.h"
-
-std::unique_ptr<Message> MessageFactory::createInboundMessage(MessageId id, QJsonDocument data)
-{
- std::unique_ptr<Message> msg(nullptr);
- if ((id == MessageId::RetOk) || (id == MessageId::RetErr))
- msg.reset(new ResponseMessage(data));
- else if (id == MessageId::Event)
- msg.reset(new EventMessage(data));
- return msg;
-}
-
-std::unique_ptr<Message> MessageFactory::createOutboundMessage(MessageId id)
-{
- std::unique_ptr<Message> msg(nullptr);
- if (id == MessageId::Call)
- msg.reset(new CallMessage());
- return msg;
-}
diff --git a/core/messagefactory.h b/core/messagefactory.h
deleted file mode 100644
index f826483..0000000
--- a/core/messagefactory.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef MESSAGEFACTORY_H
-#define MESSAGEFACTORY_H
-
-#include <memory>
-#include <QJsonDocument>
-
-class Message;
-enum class MessageId;
-
-class MessageFactory {
- public:
- static MessageFactory& getInstance() {
- static MessageFactory instance;
- return instance;
- }
- std::unique_ptr<Message> createInboundMessage(MessageId id, QJsonDocument content);
- std::unique_ptr<Message> createOutboundMessage(MessageId);
- MessageFactory(MessageFactory const&) = delete;
- void operator=(MessageFactory const&) = delete;
-
- private:
- MessageFactory() = default;
- ~MessageFactory() = default;
-};
-
-#endif // MESSAGEFACTORY_H
diff --git a/core/qtappfw-core.pc.in b/core/qtappfw-core.pc.in
deleted file mode 100644
index bfef2e0..0000000
--- a/core/qtappfw-core.pc.in
+++ /dev/null
@@ -1,12 +0,0 @@
-prefix=@DEST_DIR@
-exec_prefix=${prefix}
-libdir=${prefix}/lib
-includedir=${prefix}/include
-
-Name: qtappfw-core
-Description: Library wrapping AGL AppFW messages and bindings in Qt objects
-Version: 1.0.0
-
-Requires: Qt5WebSockets
-Libs: -L${libdir} -lqtappfw-core
-Cflags: -I${includedir}/qtappfw-core
diff --git a/core/responsemessage.cpp b/core/responsemessage.cpp
deleted file mode 100644
index 9f8e6f2..0000000
--- a/core/responsemessage.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2018-2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <QDebug>
-#include <QJsonArray>
-#include <QJsonDocument>
-#include <QJsonObject>
-#include <QJsonValue>
-
-#include "responsemessage.h"
-
-
-ResponseMessage::ResponseMessage(QJsonDocument content)
-{
- m_jdoc = content;
- QJsonArray msg = content.array();
- if (!msg[2].isObject()) {
- qWarning("Invalid appfw payload: no JSON object");
- return;
- }
-
- //deserialize:
- auto callid = msg[1].toString().toInt();
- QJsonObject payload = msg[2].toObject();
-
- auto request_iter = payload.find("request");
- auto request = request_iter.value().toObject();
- if (request.empty()) {
- qWarning("Invalid appfw reply message: empty request data");
- return;
- }
-
- auto status_iter = request.find("status");
- auto info_iter = request.find("info");
- auto response_iter = payload.find("response");
- auto response = response_iter.value().toObject();
- m_reply_status = status_iter.value().toString();
- m_reply_info = info_iter.value().toString();
- m_reply_data = response;
- m_reply_callid = callid;
- m_init = false; //not complete yet, missing matching request data
-}
-
-bool ResponseMessage::setAdditionalData(QByteArray data)
-{
- QJsonDocument jdoc(QJsonDocument::fromJson(data));
- if (!jdoc.isArray()) {
- qWarning("Invalid data: not an array");
- return false;
- }
-
- QJsonArray content = jdoc.array();
- if (content.size() != 4) {
- qWarning("Invalid data: invalid array size");
- return false;
- }
-
- QStringList api_str_list = content[2].toString().split(QRegExp("/"));
- m_request["msgid"] = content.at(0);
- m_request["callid"] = content.at(1);
- m_request["api"] = api_str_list[0];
- m_request["verb"] = api_str_list[1];
- m_request["parameter"] = content.at(3);
- m_init = true;
- return true;
-}
-
-bool ResponseMessage::copyCallId(unsigned int *id)
-{
- *id = m_reply_callid;
- return true;
-}
-
-QByteArray ResponseMessage::serialize(QJsonDocument::JsonFormat format)
-{
- QJsonArray array;
- (m_reply_status == "failed")?
- array.append(static_cast<int>(MessageId::RetErr)) :
- array.append(static_cast<int>(MessageId::RetOk));
- array.append(static_cast<int>(m_reply_callid));
- array.append(m_request["api"].toString() + "/" + m_request["verb"].toString());
- array.append(m_reply_data);
-
- QJsonDocument jdoc;
- jdoc.setArray(array);
-
- return jdoc.toJson(format).data();
-}
diff --git a/core/responsemessage.h b/core/responsemessage.h
deleted file mode 100644
index af6bda5..0000000
--- a/core/responsemessage.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2018-2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef RESPONSEMESSAGE_H
-#define RESPONSEMESSAGE_H
-
-
-#include "message.h"
-
-class ResponseMessage : public Message
-{
-
-
- public:
- inline QString requestApi() const
- {
- return m_request["api"].toString();
- }
-
- inline QString requestVerb() const
- {
- return m_request["verb"].toString();
- }
-
- inline QVariantMap requestParameters() const
- {
- return m_request["parameter"].toMap();
- }
-
- inline QString replyStatus() const
- {
- return m_reply_status;
- }
-
- inline QString replyInfo() const
- {
- return m_reply_info;
- }
-
- inline QJsonObject replyData() const
- {
- return m_reply_data;
- }
-
- bool getCallId(unsigned int *id) const override
- {
- *id = m_reply_callid;
- return true;
- }
- bool isEvent() override
- {
- return false;
- }
-
- bool isReply() override
- {
- return true;
- }
-
- bool setAdditionalData(QByteArray data) override;
- bool copyCallId(unsigned int *id);
-
- QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact) override;
-
- private:
- QString m_reply_info, m_reply_status, m_reply_uuid;
- unsigned int m_reply_callid;
- QJsonObject m_reply_data;
- QMap<QString, QVariant> m_request;
-
- explicit ResponseMessage(QJsonDocument data);
- friend class MessageFactory;
-};
-
-#endif // RESPONSEMESSAGE_H
diff --git a/hvac/CMakeLists.txt b/hvac/CMakeLists.txt
index c0ebf49..dd0ceea 100644
--- a/hvac/CMakeLists.txt
+++ b/hvac/CMakeLists.txt
@@ -8,7 +8,7 @@ add_library(qtappfw-hvac SHARED hvac.cpp)
target_include_directories(qtappfw-hvac PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(qtappfw-hvac PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}")
-target_link_libraries(qtappfw-hvac qtappfw-core)
+target_link_libraries(qtappfw-hvac Qt5::Core)
set_target_properties(qtappfw-hvac PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
diff --git a/hvac/hvac.cpp b/hvac/hvac.cpp
index edb7e35..bb5fc10 100644
--- a/hvac/hvac.cpp
+++ b/hvac/hvac.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Konsulko Group
+ * Copyright (C) 2020-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,24 +18,16 @@
#include <QMetaEnum>
#include <QMimeDatabase>
#include <QtQml/QQmlEngine>
-
-#include "callmessage.h"
-#include "eventmessage.h"
-#include "messagefactory.h"
-#include "messageengine.h"
-#include "messageenginefactory.h"
#include "hvac.h"
// TODO: don't duplicate defaults from HVAC service here
-HVAC::HVAC (QUrl &url, QObject * parent) :
+HVAC::HVAC (QObject * parent) :
QObject(parent),
m_fanspeed(0),
m_temp_left_zone(21),
m_temp_right_zone(21)
{
- m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
- QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &HVAC::onMessageReceived);
}
HVAC::~HVAC()
@@ -44,53 +36,19 @@ HVAC::~HVAC()
void HVAC::control(QString verb, QString field, int value)
{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* hmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter;
-
- parameter.insert(field, value);
- hmsg->createRequest("hvac", verb, parameter);
- m_mloop->sendMessage(std::move(msg));
}
void HVAC::set_fanspeed(int speed)
{
- control("set", "FanSpeed", speed);
emit fanSpeedChanged(speed);
}
void HVAC::set_temp_left_zone(int temp)
{
- control("set", "LeftTemperature", temp);
- control("set", "LeftLed", temp);
emit leftTemperatureChanged(temp);
}
void HVAC::set_temp_right_zone(int temp)
{
-
- control("set", "RightTemperature", temp);
- control("set", "RightLed", temp);
emit rightTemperatureChanged(temp);
}
-
-void HVAC::onMessageReceived(std::shared_ptr<Message> msg)
-{
- if (!msg)
- return;
-
- if (msg->isEvent()) {
- std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
- if (emsg->eventApi() != "hvac")
- return;
-
- if (emsg->eventName() == "language") {
- // TODO: cannot be currently tested with identity service
- QVariantMap data = emsg->eventData().toVariantMap();
- emit languageChanged(data.value("language").toString());
- }
- }
-}
diff --git a/hvac/hvac.h b/hvac/hvac.h
index 858fddf..1a8b233 100644
--- a/hvac/hvac.h
+++ b/hvac/hvac.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Konsulko Group
+ * Copyright (C) 2020-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,9 +23,6 @@
#include <QtQml/QQmlContext>
#include <QtQml/QQmlListProperty>
-class MessageEngine;
-class Message;
-
class HVAC : public QObject
{
Q_OBJECT
@@ -35,7 +32,7 @@ class HVAC : public QObject
Q_PROPERTY(int rightTemperature READ get_temp_right_zone WRITE set_temp_right_zone NOTIFY rightTemperatureChanged)
public:
- explicit HVAC(QUrl &url, QObject * parent = Q_NULLPTR);
+ explicit HVAC(QObject * parent = Q_NULLPTR);
virtual ~HVAC();
signals:
@@ -45,8 +42,6 @@ class HVAC : public QObject
void languageChanged(QString language);
private:
- std::shared_ptr<MessageEngine> m_mloop;
-
int m_fanspeed;
int m_temp_left_zone;
int m_temp_right_zone;
@@ -59,9 +54,6 @@ class HVAC : public QObject
void set_fanspeed(int speed);
void set_temp_left_zone(int temp);
void set_temp_right_zone(int temp);
-
- // slots
- void onMessageReceived(std::shared_ptr<Message>);
};
#endif // HVAC_H
diff --git a/navigation/CMakeLists.txt b/navigation/CMakeLists.txt
index bb972e0..6264623 100644
--- a/navigation/CMakeLists.txt
+++ b/navigation/CMakeLists.txt
@@ -8,7 +8,7 @@ add_library(qtappfw-navigation SHARED navigation.cpp)
target_include_directories(qtappfw-navigation PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(qtappfw-navigation PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}")
-target_link_libraries(qtappfw-navigation qtappfw-core)
+target_link_libraries(qtappfw-navigation Qt5::Qml)
set_target_properties(qtappfw-navigation PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
diff --git a/navigation/navigation.cpp b/navigation/navigation.cpp
index e24df1a..6116637 100644
--- a/navigation/navigation.cpp
+++ b/navigation/navigation.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019, 2020 Konsulko Group
+ * Copyright (C) 2019-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,21 +16,12 @@
#include <QDebug>
-#include "callmessage.h"
-#include "eventmessage.h"
-#include "messagefactory.h"
-#include "messageengine.h"
-#include "messageenginefactory.h"
#include "navigation.h"
-Navigation::Navigation (QUrl &url, QObject * parent) :
+Navigation::Navigation (QObject * parent) :
QObject(parent)
{
- m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
- QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &Navigation::onConnected);
- QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &Navigation::onDisconnected);
- QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &Navigation::onMessageReceived);
}
Navigation::~Navigation()
@@ -39,124 +30,24 @@ Navigation::~Navigation()
void Navigation::sendWaypoint(double lat, double lon)
{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* nmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter, point;
- QJsonArray points;
- point.insert("latitude", lat);
- point.insert("longitude", lon);
- points.append(point);
- parameter.insert("points", points);
- nmsg->createRequest("navigation", "broadcast_waypoints", parameter);
- m_mloop->sendMessage(std::move(msg));
}
void Navigation::broadcastPosition(double lat, double lon, double drc, double dst)
{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* nmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter;
-
- parameter.insert("position", "car");
- parameter.insert("latitude", lat);
- parameter.insert("longitude", lon);
- parameter.insert("direction", drc);
- parameter.insert("distance", dst);
-
- nmsg->createRequest("navigation", "broadcast_position", parameter);
- m_mloop->sendMessage(std::move(msg));
}
void Navigation::broadcastRouteInfo(double lat, double lon, double route_lat, double route_lon)
{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* nmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter;
-
- parameter.insert("position", "route");
- parameter.insert("latitude", lat);
- parameter.insert("longitude", lon);
- parameter.insert("route_latitude", route_lat);
- parameter.insert("route_longitude", route_lon);
-
- nmsg->createRequest("navigation", "broadcast_position", parameter);
- m_mloop->sendMessage(std::move(msg));
}
void Navigation::broadcastStatus(QString state)
{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* nmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter;
- parameter.insert("state", state);
- nmsg->createRequest("navigation", "broadcast_status", parameter);
- m_mloop->sendMessage(std::move(msg));
}
void Navigation::onConnected()
{
- QStringListIterator eventIterator(events);
-
- while (eventIterator.hasNext()) {
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* nmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter;
- parameter.insert("value", eventIterator.next());
- nmsg->createRequest("navigation", "subscribe", parameter);
- m_mloop->sendMessage(std::move(msg));
- }
}
void Navigation::onDisconnected()
{
- QStringListIterator eventIterator(events);
-
- while (eventIterator.hasNext()) {
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* nmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter;
- parameter.insert("value", eventIterator.next());
- nmsg->createRequest("navigation", "unsubscribe", parameter);
- m_mloop->sendMessage(std::move(msg));
- }
-}
-
-void Navigation::onMessageReceived(std::shared_ptr<Message> msg)
-{
- if (!msg)
- return;
-
- if (msg->isEvent()) {
- std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
- if (emsg->eventApi() != "navigation")
- return;
-
- if (emsg->eventName() == "position") {
- emit positionEvent(emsg->eventData().toVariantMap());
- }
- else if (emsg->eventName() == "status") {
- emit statusEvent(emsg->eventData().toVariantMap());
- }
- else if (emsg->eventName() == "waypoints") {
- emit waypointsEvent(emsg->eventData().toVariantMap());
- }
- }
}
diff --git a/navigation/navigation.h b/navigation/navigation.h
index b1c0412..0606d1e 100644
--- a/navigation/navigation.h
+++ b/navigation/navigation.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019, 2020 Konsulko Group
+ * Copyright (C) 2019-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,18 +19,14 @@
#include <memory>
#include <QObject>
-#include <QJsonArray>
#include <QtQml/QQmlListProperty>
-class MessageEngine;
-class Message;
-
class Navigation : public QObject
{
Q_OBJECT
public:
- explicit Navigation(QUrl &url, QObject * parent = Q_NULLPTR);
+ explicit Navigation(QObject * parent = Q_NULLPTR);
virtual ~Navigation();
Q_INVOKABLE void broadcastPosition(double lat, double lon, double drc, double dst);
@@ -46,10 +42,7 @@ class Navigation : public QObject
void waypointsEvent(QVariantMap data);
private:
- std::shared_ptr<MessageEngine> m_mloop;
-
// slots
- void onMessageReceived(std::shared_ptr<Message> msg);
void onConnected();
void onDisconnected();
diff --git a/network/CMakeLists.txt b/network/CMakeLists.txt
index 162325c..b7ae7a1 100644
--- a/network/CMakeLists.txt
+++ b/network/CMakeLists.txt
@@ -14,7 +14,7 @@ add_library(qtappfw-network SHARED network.cpp
target_include_directories(qtappfw-network PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(qtappfw-network PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}")
-target_link_libraries(qtappfw-network qtappfw-core)
+target_link_libraries(qtappfw-network Qt5::Qml)
set_target_properties(qtappfw-network PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
diff --git a/network/network.cpp b/network/network.cpp
index 46045dc..937266f 100644
--- a/network/network.cpp
+++ b/network/network.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018-2020 Konsulko Group
+ * Copyright (C) 2018-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,26 +17,14 @@
#include <QDebug>
#include <QtQml/QQmlEngine>
-#include "callmessage.h"
-#include "eventmessage.h"
-#include "responsemessage.h"
-#include "messagefactory.h"
-#include "messageengine.h"
-#include "messageenginefactory.h"
#include "networkadapter.h"
#include "network.h"
-Network::Network (QUrl &url, QQmlContext *context, QObject * parent) :
+Network::Network (bool register_agent, QQmlContext *context, QObject * parent) :
QObject(parent)
{
- m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
m_adapters.append(new WifiAdapter(this, context, parent));
-
- QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &Network::onConnected);
- QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &Network::onDisconnected);
- QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &Network::onMessageReceived);
-
m_adapters.append(new WiredAdapter(this, context, parent));
}
@@ -48,6 +36,7 @@ Network::~Network()
void Network::connect(QString service)
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -59,10 +48,12 @@ void Network::connect(QString service)
nmsg->createRequest("network-manager", "connect_service", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
void Network::disconnect(QString service)
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -74,10 +65,12 @@ void Network::disconnect(QString service)
nmsg->createRequest("network-manager", "disconnect_service", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
void Network::remove(QString service)
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -89,6 +82,7 @@ void Network::remove(QString service)
nmsg->createRequest("network-manager", "remove_service", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
void Network::power(bool on, QString type)
@@ -101,6 +95,7 @@ void Network::power(bool on, QString type)
void Network::input(int id, QString passphrase)
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -114,10 +109,12 @@ void Network::input(int id, QString passphrase)
nmsg->createRequest("network-manager", "agent_response", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
void Network::configureAddress(QString service, QVariantList paramlist)
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -141,10 +138,12 @@ void Network::configureAddress(QString service, QVariantList paramlist)
nmsg->createRequest("network-manager", "set_property", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
void Network::configureNameServer(QString service, QVariantList paramlist)
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -167,10 +166,12 @@ void Network::configureNameServer(QString service, QVariantList paramlist)
nmsg->createRequest("network-manager", "set_property", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
void Network::getServices()
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -180,6 +181,7 @@ void Network::getServices()
nmsg->createRequest("network-manager", "services", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
AdapterIf* Network::findAdapter(QString type)
@@ -193,32 +195,36 @@ AdapterIf* Network::findAdapter(QString type)
void Network::updateServiceProperties(QJsonObject data)
{
+#if 0
QString service = data.value("service").toString();
QJsonObject properties = data.value("properties").toObject();
QList<AdapterIf*>::iterator iter;
for (iter = m_adapters.begin(); iter != m_adapters.end(); ++iter)
(*iter)->updateProperties(service, properties);
-
+#endif
}
bool Network::addService(QJsonObject service)
{
+#if 0
QString id = service.value("service").toString();
QJsonObject properties = service.value("properties").toObject();
QList<AdapterIf*>::iterator iter;
for (iter = m_adapters.begin(); iter != m_adapters.end(); ++iter)
if ((*iter)->addService(id, properties))
return true;
-
+#endif
return false;
}
void Network::removeService(QJsonObject service)
{
+#if 0
QString id = service.value("service").toString();
QList<AdapterIf*>::iterator iter;
for (iter = m_adapters.begin(); iter != m_adapters.end(); ++iter)
(*iter)->removeService(id);
+#endif
}
void Network::addServices(QJsonArray services)
@@ -229,6 +235,7 @@ void Network::addServices(QJsonArray services)
void Network::scanServices(QString type)
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -239,10 +246,12 @@ void Network::scanServices(QString type)
parameter.insert("technology", type);
nmsg->createRequest("network-manager", "scan_services", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
void Network::disableTechnology(QString type)
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -253,10 +262,12 @@ void Network::disableTechnology(QString type)
parameter.insert("technology", type);
nmsg->createRequest("network-manager", "disable_technology", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
void Network::enableTechnology(QString type)
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -267,10 +278,12 @@ void Network::enableTechnology(QString type)
parameter.insert("technology", type);
nmsg->createRequest("network-manager", "enable_technology", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
void Network::parseTechnologies(QJsonArray technologies)
{
+#if 0
for (auto value : technologies) {
QJsonObject technology = value.toObject();
QJsonObject properties = technology.value("properties").toObject();
@@ -280,10 +293,12 @@ void Network::parseTechnologies(QJsonArray technologies)
if (adapter)
adapter->updateStatus(properties);
}
+#endif
}
void Network::getTechnologies()
{
+#if 0
std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
if (!msg)
return;
@@ -293,10 +308,13 @@ void Network::getTechnologies()
nmsg->createRequest("network-manager", "technologies", parameter);
m_mloop->sendMessage(std::move(msg));
+#endif
}
+#if 0
void Network::processEvent(std::shared_ptr<Message> msg)
{
+
std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
QString ename = emsg->eventName();
QString eapi = emsg->eventApi();
@@ -363,9 +381,11 @@ void Network::onMessageReceived(std::shared_ptr<Message> msg)
else if (msg->isReply())
processReply(msg);
}
+#endif
void Network::onConnected()
{
+#if 0
QStringListIterator eventIterator(events);
while (eventIterator.hasNext()) {
@@ -379,12 +399,13 @@ void Network::onConnected()
nmsg->createRequest("network-manager", "subscribe", parameter);
m_mloop->sendMessage(std::move(msg));
}
-
+#endif
getTechnologies();
}
void Network::onDisconnected()
{
+#if 0
QStringListIterator eventIterator(events);
while (eventIterator.hasNext()) {
@@ -397,6 +418,6 @@ void Network::onDisconnected()
nmsg->createRequest("network-manager", "unsubscribe", parameter);
m_mloop->sendMessage(std::move(msg));
}
-
+#endif
getTechnologies();
}
diff --git a/network/network.h b/network/network.h
index 07ff54d..3321a81 100644
--- a/network/network.h
+++ b/network/network.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018-2020 Konsulko Group
+ * Copyright (C) 2018-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,21 +20,19 @@
#include <memory>
#include <QObject>
#include <QJsonArray>
+#include <QJsonObject>
#include <QtQml/QQmlContext>
#include <QtQml/QQmlListProperty>
#include "wifiadapter.h"
#include "wiredadapter.h"
-class MessageEngine;
-class Message;
-
class Network : public QObject
{
Q_OBJECT
public:
- explicit Network(QUrl &url, QQmlContext *context, QObject * parent = Q_NULLPTR);
+ explicit Network(bool register_agent, QQmlContext *context, QObject * parent = Q_NULLPTR);
virtual ~Network();
Q_INVOKABLE void connect(QString service);
@@ -54,7 +52,6 @@ class Network : public QObject
void searchResults(QString name);
private:
- std::shared_ptr<MessageEngine> m_mloop;
QQmlContext *m_context;
QList<AdapterIf*> m_adapters;
@@ -69,11 +66,8 @@ class Network : public QObject
void enableTechnology(QString type);
void parseTechnologies(QJsonArray technologies);
void getTechnologies();
- void processEvent(std::shared_ptr<Message> msg);
- void processReply(std::shared_ptr<Message> msg);
// slots
- void onMessageReceived(std::shared_ptr<Message>);
void onConnected();
void onDisconnected();
diff --git a/signal-composer/CMakeLists.txt b/signal-composer/CMakeLists.txt
deleted file mode 100644
index e8c51e3..0000000
--- a/signal-composer/CMakeLists.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-
-CONFIGURE_FILE("qtappfw-signal-composer.pc.in" "qtappfw-signal-composer.pc" @ONLY)
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-signal-composer.pc
- DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
-
-add_library(qtappfw-signal-composer SHARED signalcomposer.cpp)
-
-target_include_directories(qtappfw-signal-composer PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
-target_include_directories(qtappfw-signal-composer PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}")
-
-target_link_libraries(qtappfw-signal-composer qtappfw-core)
-set_target_properties(qtappfw-signal-composer PROPERTIES
- VERSION ${PROJECT_VERSION}
- SOVERSION 1
- PUBLIC_HEADER signalcomposer.h)
-
-install(TARGETS qtappfw-signal-composer
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-signal-composer)
diff --git a/signal-composer/qtappfw-signal-composer.pc.in b/signal-composer/qtappfw-signal-composer.pc.in
deleted file mode 100644
index f00ba19..0000000
--- a/signal-composer/qtappfw-signal-composer.pc.in
+++ /dev/null
@@ -1,12 +0,0 @@
-prefix=@DEST_DIR@
-exec_prefix=${prefix}
-libdir=${prefix}/lib
-includedir=${prefix}/include
-
-Name: qtappfw-signal-composer
-Description: Library wrapping AGL AppFW signal composer data in Qt objects
-Version: 1.0.0
-
-Requires: Qt5Qml
-Libs: -L${libdir} -lqtappfw-signal-composer
-Cflags: -I${includedir}/qtappfw-signal-composer
diff --git a/signal-composer/signalcomposer.cpp b/signal-composer/signalcomposer.cpp
deleted file mode 100644
index d10bcc1..0000000
--- a/signal-composer/signalcomposer.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2018-2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <QDebug>
-
-#include "callmessage.h"
-#include "eventmessage.h"
-#include "messagefactory.h"
-#include "messageengine.h"
-#include "messageenginefactory.h"
-#include "signalcomposer.h"
-
-
-SignalComposer::SignalComposer (QUrl &url, QObject * parent) :
- QObject(parent)
-{
- m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
- QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &SignalComposer::onConnected);
- QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &SignalComposer::onDisconnected);
- QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &SignalComposer::onMessageReceived);
-}
-
-SignalComposer::~SignalComposer()
-{
-}
-
-void SignalComposer::onConnected()
-{
- QStringListIterator eventIterator(events);
-
- while (eventIterator.hasNext()) {
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* tmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter;
- parameter.insert("signal", eventIterator.next());
- tmsg->createRequest("signal-composer", "subscribe", parameter);
- m_mloop->sendMessage(std::move(msg));
- }
-}
-
-void SignalComposer::onDisconnected()
-{
- QStringListIterator eventIterator(events);
-
- while (eventIterator.hasNext()) {
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage* tmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter;
- parameter.insert("signal", eventIterator.next());
- tmsg->createRequest("signal-composer", "unsubscribe", parameter);
- m_mloop->sendMessage(std::move(msg));
- }
-}
-
-void SignalComposer::onMessageReceived(std::shared_ptr<Message> msg)
-{
- if (!msg)
- return;
-
- if (msg->isEvent()) {
- std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
- if (emsg->eventApi() != "signal-composer")
- return;
-
- QJsonObject data = emsg->eventData();
- QString uid = data.value("uid").toString();
- QVariant v = data.value("value").toVariant();
- QString value;
- if(v.canConvert(QMetaType::QString))
- value = v.toString();
- else
- qWarning() << "Unconvertible value type for uid " << uid;
- QString units = data.value("unit").toString();
- v = data.value("timestamp").toVariant();
- quint64 timestamp = 0;
- if(v.canConvert(QMetaType::ULongLong))
- timestamp = v.toULongLong();
- else
- qWarning() << "Unconvertible timestamp type for uid " << uid;
-
- emit signalEvent(uid, value, units, timestamp);
- }
-}
diff --git a/signal-composer/signalcomposer.h b/signal-composer/signalcomposer.h
deleted file mode 100644
index a18f5a8..0000000
--- a/signal-composer/signalcomposer.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2019, 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef SIGNALCOMPOSER_H
-#define SIGNALCOMPOSER_H
-
-#include <memory>
-#include <QObject>
-#include <QJsonArray>
-
-class MessageEngine;
-class Message;
-
-class SignalComposer : public QObject
-{
- Q_OBJECT
-
- public:
- explicit SignalComposer(QUrl &url, QObject * parent = Q_NULLPTR);
- virtual ~SignalComposer();
-
- signals:
- void signalEvent(QString uid, QString value, QString units, quint64 timestamp);
-
- private:
- std::shared_ptr<MessageEngine> m_mloop;
-
- void onConnected();
- void onDisconnected();
- void onMessageReceived(std::shared_ptr<Message>);
-
- const QStringList events {
- "event.vehicle.speed",
- "event.engine.speed",
- "event.cruise.enable",
- "event.cruise.resume",
- "event.cruise.set",
- "event.cruise.cancel",
- "event.cruise.limit",
- "event.cruise.distance",
- "event.lane_departure_warning.enable",
- "event.info",
- "event.horn"
- };
-};
-
-#endif // SIGNALCOMPOSER_H
diff --git a/voice-capabilities/CMakeLists.txt b/voice-capabilities/CMakeLists.txt
deleted file mode 100644
index 1751e71..0000000
--- a/voice-capabilities/CMakeLists.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-
-CONFIGURE_FILE("qtappfw-voice-metadata.pc.in" "qtappfw-voice-metadata.pc" @ONLY)
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-voice-metadata.pc
- DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
-
-add_library(qtappfw-voice-metadata SHARED guimetadata.cpp)
-
-target_include_directories(qtappfw-voice-metadata PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
-target_include_directories(qtappfw-voice-metadata PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}")
-
-target_link_libraries(qtappfw-voice-metadata qtappfw-core)
-set_target_properties(qtappfw-voice-metadata PROPERTIES
- VERSION ${PROJECT_VERSION}
- SOVERSION 1
- PUBLIC_HEADER guimetadata.h)
-
-install(TARGETS qtappfw-voice-metadata
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-voice-metadata)
diff --git a/voice-capabilities/guimetadata.cpp b/voice-capabilities/guimetadata.cpp
deleted file mode 100644
index cc65ba0..0000000
--- a/voice-capabilities/guimetadata.cpp
+++ /dev/null
@@ -1,349 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <QDebug>
-#include <QJsonArray>
-
-#include "callmessage.h"
-#include "eventmessage.h"
-#include "messagefactory.h"
-#include "messageengine.h"
-#include "messageenginefactory.h"
-#include "guimetadata.h"
-
-GuiMetadata::GuiMetadata(QUrl &url, QQmlContext *context, QObject * parent) :
- QObject(parent)
-{
- m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
- m_context = context;
- QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &GuiMetadata::onConnected);
- QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &GuiMetadata::onDisconnected);
- QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &GuiMetadata::onMessageReceived);
-}
-
-GuiMetadata::~GuiMetadata()
-{
-}
-
-// Qt UI Context
-
-void GuiMetadata::clearMetadata()
-{
- m_type = "";
- m_title = "";
- m_subtitle = "";
-
- m_bodyText = "";
- m_bodyImageSmallUrl = "";
- m_bodyImageMediumUrl = "";
- m_bodyImageLargeUrl = "";
-
- m_weatherCurrentTemperature = "";
- m_weatherCurrentWeatherIconSmallUrl = "";
- m_weatherCurrentWeatherIconSmallDarkBgUrl = "";
- m_weatherCurrentWeatherIconMediumUrl = "";
- m_weatherCurrentWeatherIconMediumDarkBgUrl = "";
- m_weatherCurrentWeatherIconLargeUrl = "";
- m_weatherCurrentWeatherIconLargeDarkBgUrl = "";
-
- m_weatherLowTemperature = "";
- m_weatherLowTemperatureArrowSmallUrl = "";
- m_weatherLowTemperatureArrowSmallDarkBgUrl = "";
- m_weatherLowTemperatureArrowMediumUrl = "";
- m_weatherLowTemperatureArrowMediumDarkBgUrl = "";
- m_weatherLowTemperatureArrowLargeUrl = "";
- m_weatherLowTemperatureArrowLargeDarkBgUrl = "";
-
- m_weatherHighTemperature = "";
- m_weatherHighTemperatureArrowSmallUrl = "";
- m_weatherHighTemperatureArrowSmallDarkBgUrl = "";
- m_weatherHighTemperatureArrowMediumUrl = "";
- m_weatherHighTemperatureArrowMediumDarkBgUrl = "";
- m_weatherHighTemperatureArrowLargeUrl = "";
- m_weatherHighTemperatureArrowLargeDarkBgUrl = "";
-}
-
-bool GuiMetadata::parseImageMetadata(QJsonObject &imageObj,
- QUrl &smallUrl, QUrl &mediumUrl, QUrl &largeUrl,
- QUrl *pSmallDarkBgUrl, QUrl *pMediumDarkBgUrl, QUrl *pLargeDarkBgUrl)
-{
- if(!(imageObj.contains("sources") && imageObj["sources"].isArray())) {
- // error
- qWarning() << "Could not find image.sources parameter!";
- return false;
- }
- QJsonArray sourcesObj = imageObj["sources"].toArray();
- bool found = false;
- for(QJsonArray::iterator it = sourcesObj.begin(); it != sourcesObj.end(); it++) {
- if(!it->isObject()) {
- // unexpected, skip
- continue;
- }
- QJsonObject sourceObj = it->toObject();
- if(!(sourceObj.contains("url") && sourceObj["url"].isString())) {
- // error
- qWarning() << "Missing image.sources.url parameter!";
- continue;
- }
- QString url = sourceObj["url"].toString();
- QString darkBackgroundUrl = "";
- if(sourceObj.contains("darkBackgroundUrl") && sourceObj["darkBackgroundUrl"].isString()) {
- darkBackgroundUrl = sourceObj["darkBackgroundUrl"].toString();
- }
- if(sourceObj.contains("size") && sourceObj["size"].isString()) {
- QString size = sourceObj["size"].toString();
- if(size == "SMALL") {
- smallUrl = url;
- if(pSmallDarkBgUrl)
- pSmallDarkBgUrl->setUrl(darkBackgroundUrl);
- found = true;
- } else if(size == "MEDIUM") {
- mediumUrl = url;
- if(pMediumDarkBgUrl)
- pMediumDarkBgUrl->setUrl(darkBackgroundUrl);
- found = true;
- } else if(size == "LARGE") {
- largeUrl = url;
- if(pLargeDarkBgUrl)
- pLargeDarkBgUrl->setUrl(darkBackgroundUrl);
- found = true;
- }
- // else ignore (X-SMALL, X-LARGE)
- }
- // FIXME: Should handle image sources w/o size fields,
- // parse width/height if present
- }
- return found;
-}
-
-bool GuiMetadata::updateMetadata(QJsonObject data)
-{
- if(!data.contains("type"))
- return false;
-
- clearMetadata();
-
- QString type = data["type"].toString();
- if(!(type == "BodyTemplate1" ||
- type == "BodyTemplate2" ||
- type == "WeatherTemplate")) {
- // Show unsupported type message
- m_type = "Unsupported";
- return true;
- }
- m_type = type;
-
- // All template types have title
- if(data.contains("title") && data["title"].isObject()) {
- QJsonObject titleObj = data["title"].toObject();
- if(titleObj.contains("mainTitle")) {
- m_title = titleObj["mainTitle"].toString();
- } else {
- qWarning() << "Could not find title.mainTitle parameter!";
- return false;
- }
- // subTitle is apparently optional
- if(titleObj.contains("subTitle"))
- m_subtitle = titleObj["subTitle"].toString();
- } else {
- // error
- qWarning() << "Could not find title parameter!";
- return false;
- }
-
- if(type == "BodyTemplate1" || type == "BodyTemplate2")
- return updateBodyMetadata(data);
- else
- return updateWeatherMetadata(data);
-}
-
-bool GuiMetadata::updateBodyMetadata(QJsonObject &data)
-{
- if(!data.contains("type"))
- return false;
-
- QString type = data["type"].toString();
- if(!(type == "BodyTemplate1" || type == "BodyTemplate2"))
- return false;
-
- // BodyTemplate1/2 have text field
- if(data.contains("textField")) {
- m_bodyText = data["textField"].toString();
- } else {
- // error
- qWarning() << "Could not find textField parameter!";
- return false;
- }
-
- // BodyTemplate2 has image
- if(type == "BodyTemplate2") {
- if(!(data.contains("image") && data["image"].isObject())) {
- // error
- qWarning() << "Could not find image parameter!";
- return false;
- }
- QJsonObject imageObj = data["image"].toObject();
- if(!parseImageMetadata(imageObj,
- m_bodyImageSmallUrl,
- m_bodyImageMediumUrl,
- m_bodyImageLargeUrl)) {
- qWarning() << "Could not parse image parameter!";
- return false;
- }
- }
-
- return true;
-}
-
-bool GuiMetadata::updateWeatherMetadata(QJsonObject &data)
-{
- if(!data.contains("type"))
- return false;
-
- QString type = data["type"].toString();
- if(type != "WeatherTemplate")
- return false;
-
- if(data.contains("currentWeather")) {
- m_weatherCurrentTemperature = data["currentWeather"].toString();
- } else {
- // error
- qWarning() << "Could not find currentWeather parameter!";
- return false;
- }
-
- if(!(data.contains("currentWeatherIcon") && data["currentWeatherIcon"].isObject())) {
- // error
- qWarning() << "Could not find currentWeatherIcon parameter!";
- return false;
- }
- QJsonObject imageObj = data["currentWeatherIcon"].toObject();
- if(!parseImageMetadata(imageObj,
- m_weatherCurrentWeatherIconSmallUrl,
- m_weatherCurrentWeatherIconMediumUrl,
- m_weatherCurrentWeatherIconLargeUrl,
- &m_weatherCurrentWeatherIconSmallDarkBgUrl,
- &m_weatherCurrentWeatherIconMediumDarkBgUrl,
- &m_weatherCurrentWeatherIconLargeDarkBgUrl)) {
- qWarning() << "Could not parse currentWeatherIcon.image parameter!";
- return false;
- }
-
- if(!(data.contains("lowTemperature") && data["lowTemperature"].isObject())) {
- // error
- qWarning() << "Could not find lowTemperature parameter!";
- return false;
- }
- QJsonObject tempObj = data["lowTemperature"].toObject();
- if(!(tempObj.contains("value") && tempObj["value"].isString())) {
- // error
- qWarning() << "Could not find lowTemperature.value parameter!";
- return false;
- }
- m_weatherLowTemperature = tempObj["value"].toString();
-
- if(!(tempObj.contains("arrow") && tempObj["arrow"].isObject())) {
- // error
- qWarning() << "Could not find lowTemperature.arrow parameter!";
- return false;
- }
- imageObj = tempObj["arrow"].toObject();
- if(!parseImageMetadata(imageObj,
- m_weatherLowTemperatureArrowSmallUrl,
- m_weatherLowTemperatureArrowMediumUrl,
- m_weatherLowTemperatureArrowLargeUrl,
- &m_weatherLowTemperatureArrowSmallDarkBgUrl,
- &m_weatherLowTemperatureArrowMediumDarkBgUrl,
- &m_weatherLowTemperatureArrowLargeDarkBgUrl)) {
- qWarning() << "Could not parse lowTemperature.arrow parameter!";
- return false;
- }
-
- if(!(data.contains("highTemperature") && data["highTemperature"].isObject())) {
- // error
- qWarning() << "Could not find highTemperature parameter!";
- return false;
- }
- tempObj = data["highTemperature"].toObject();
- if(!(tempObj.contains("value") && tempObj["value"].isString())) {
- // error
- qWarning() << "Could not find highTemperature.value parameter!";
- return false;
- }
- m_weatherHighTemperature = tempObj["value"].toString();
-
- if(!(tempObj.contains("arrow") && tempObj["arrow"].isObject())) {
- // error
- qWarning() << "Could not find highTemperature.arrow parameter!";
- return false;
- }
- imageObj = tempObj["arrow"].toObject();
- if(!parseImageMetadata(imageObj,
- m_weatherHighTemperatureArrowSmallUrl,
- m_weatherHighTemperatureArrowMediumUrl,
- m_weatherHighTemperatureArrowLargeUrl,
- &m_weatherHighTemperatureArrowSmallDarkBgUrl,
- &m_weatherHighTemperatureArrowMediumDarkBgUrl,
- &m_weatherHighTemperatureArrowLargeDarkBgUrl)) {
- qWarning() << "Could not parse highTemperature.arrow parameter!";
- return false;
- }
-
- return true;
-
-}
-
-void GuiMetadata::onConnected()
-{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage *tmsg = static_cast<CallMessage*>(msg.get());
- QStringListIterator eventIterator(events);
- QJsonObject parameter;
- QJsonArray actions;
- while (eventIterator.hasNext()) {
- actions.append(QJsonValue(eventIterator.next()));
- }
- parameter.insert("actions", actions);
- tmsg->createRequest("vshl-capabilities", "guimetadata/subscribe", parameter);
- m_mloop->sendMessage(std::move(msg));
-}
-
-void GuiMetadata::onDisconnected()
-{
- // vshl-capabilities currently has no unsubscribe verb...
-}
-
-void GuiMetadata::onMessageReceived(std::shared_ptr<Message> msg)
-{
- if (!msg)
- return;
-
- if (msg->isEvent()) {
- std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
- if (emsg->eventApi() != "vshl-capabilities")
- return;
- QString ename = emsg->eventName();
- QJsonObject data = emsg->eventData();
- if ((ename == "render_template") && updateMetadata(data)) {
- emit renderTemplate();
- } else if (ename == "clear_template") {
- emit clearTemplate();
- }
- }
-}
diff --git a/voice-capabilities/guimetadata.h b/voice-capabilities/guimetadata.h
deleted file mode 100644
index ba6b1a1..0000000
--- a/voice-capabilities/guimetadata.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (C) 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef GUIMETADATA_H
-#define GUIMETADATA_H
-
-#include <memory>
-#include <QObject>
-#include <QtQml/QQmlContext>
-
-class MessageEngine;
-class Message;
-
-
-class GuiMetadata : public QObject
-{
- Q_OBJECT
-
- // Common to all template types
- Q_PROPERTY(QString type READ type)
- Q_PROPERTY(QString title READ title)
- Q_PROPERTY(QString subtitle READ subtitle)
-
- // BodyTemplate1/2
- Q_PROPERTY(QString bodyText READ bodyText)
-
- // BodyTemplate2
- Q_PROPERTY(QUrl bodyImageSmallUrl READ bodyImageSmallUrl)
- Q_PROPERTY(QUrl bodyImageMediumUrl READ bodyImageMediumUrl)
- Q_PROPERTY(QUrl bodyImageLargeUrl READ bodyImageLargeUrl)
-
- // WeatherTemplate
- Q_PROPERTY(QString weatherCurrentTemperature READ weatherCurrentTemperature)
- Q_PROPERTY(QUrl weatherCurrentWeatherIconSmallUrl READ weatherCurrentWeatherIconSmallUrl)
- Q_PROPERTY(QUrl weatherCurrentWeatherIconSmallDarkBgUrl READ weatherCurrentWeatherIconSmallDarkBgUrl)
- Q_PROPERTY(QUrl weatherCurrentWeatherIconMediumUrl READ weatherCurrentWeatherIconMediumUrl)
- Q_PROPERTY(QUrl weatherCurrentWeatherIconMediumDarkBgUrl READ weatherCurrentWeatherIconMediumDarkBgUrl)
- Q_PROPERTY(QUrl weatherCurrentWeatherIconLargeUrl READ weatherCurrentWeatherIconLargeUrl)
- Q_PROPERTY(QUrl weatherCurrentWeatherIconLargeDarkBgUrl READ weatherCurrentWeatherIconLargeDarkBgUrl)
-
- Q_PROPERTY(QString weatherLowTemperature READ weatherLowTemperature)
- Q_PROPERTY(QUrl weatherLowTemperatureArrowSmallUrl READ weatherLowTemperatureArrowSmallUrl)
- Q_PROPERTY(QUrl weatherLowTemperatureArrowSmallDarkBgUrl READ weatherLowTemperatureArrowSmallDarkBgUrl)
- Q_PROPERTY(QUrl weatherLowTemperatureArrowMediumUrl READ weatherLowTemperatureArrowMediumUrl)
- Q_PROPERTY(QUrl weatherLowTemperatureArrowMediumDarkBgUrl READ weatherLowTemperatureArrowMediumDarkBgUrl)
- Q_PROPERTY(QUrl weatherLowTemperatureArrowLargeUrl READ weatherLowTemperatureArrowLargeUrl)
- Q_PROPERTY(QUrl weatherLowTemperatureArrowLargeDarkBgUrl READ weatherLowTemperatureArrowLargeDarkBgUrl)
-
- Q_PROPERTY(QString weatherHighTemperature READ weatherHighTemperature)
- Q_PROPERTY(QUrl weatherHighTemperatureArrowSmallUrl READ weatherHighTemperatureArrowSmallUrl)
- Q_PROPERTY(QUrl weatherHighTemperatureArrowSmallDarkBgUrl READ weatherHighTemperatureArrowSmallDarkBgUrl)
- Q_PROPERTY(QUrl weatherHighTemperatureArrowMediumUrl READ weatherHighTemperatureArrowMediumUrl)
- Q_PROPERTY(QUrl weatherHighTemperatureArrowMediumDarkBgUrl READ weatherHighTemperatureArrowMediumDarkBgUrl)
- Q_PROPERTY(QUrl weatherHighTemperatureArrowLargeUrl READ weatherHighTemperatureArrowLargeUrl)
- Q_PROPERTY(QUrl weatherHighTemperatureArrowLargeDarkBgUrl READ weatherHighTemperatureArrowLargeDarkBgUrl)
- // weatherForecast array ignored for now
-
-public:
- explicit GuiMetadata(QUrl &url, QQmlContext *context, QObject * parent = Q_NULLPTR);
- virtual ~GuiMetadata();
-
- QString type() { return m_type; }
- QString title() { return m_title; }
- QString subtitle() { return m_subtitle; }
-
- // BodyTemplate1/2
- QString bodyText() { return m_bodyText; }
-
- // BodyTemplate2
- QUrl bodyImageSmallUrl() { return m_bodyImageSmallUrl; }
- QUrl bodyImageMediumUrl() { return m_bodyImageMediumUrl; }
- QUrl bodyImageLargeUrl() { return m_bodyImageLargeUrl; }
-
- // WeatherTemplate
- QString weatherCurrentTemperature() { return m_weatherCurrentTemperature; }
- QUrl weatherCurrentWeatherIconSmallUrl() { return m_weatherCurrentWeatherIconSmallUrl; }
- QUrl weatherCurrentWeatherIconSmallDarkBgUrl() { return m_weatherCurrentWeatherIconSmallDarkBgUrl; }
- QUrl weatherCurrentWeatherIconMediumUrl() { return m_weatherCurrentWeatherIconMediumUrl; }
- QUrl weatherCurrentWeatherIconMediumDarkBgUrl() { return m_weatherCurrentWeatherIconMediumDarkBgUrl; }
- QUrl weatherCurrentWeatherIconLargeUrl() { return m_weatherCurrentWeatherIconLargeUrl; }
- QUrl weatherCurrentWeatherIconLargeDarkBgUrl() { return m_weatherCurrentWeatherIconLargeDarkBgUrl; }
-
- QString weatherLowTemperature() { return m_weatherLowTemperature; }
- QUrl weatherLowTemperatureArrowSmallUrl() { return m_weatherLowTemperatureArrowSmallUrl; }
- QUrl weatherLowTemperatureArrowSmallDarkBgUrl() { return m_weatherLowTemperatureArrowSmallDarkBgUrl; }
- QUrl weatherLowTemperatureArrowMediumUrl() { return m_weatherLowTemperatureArrowMediumUrl; }
- QUrl weatherLowTemperatureArrowMediumDarkBgUrl() { return m_weatherLowTemperatureArrowMediumDarkBgUrl; }
- QUrl weatherLowTemperatureArrowLargeUrl() { return m_weatherLowTemperatureArrowLargeUrl; }
- QUrl weatherLowTemperatureArrowLargeDarkBgUrl() { return m_weatherLowTemperatureArrowLargeDarkBgUrl; }
-
- QString weatherHighTemperature() { return m_weatherHighTemperature; }
- QUrl weatherHighTemperatureArrowSmallUrl() { return m_weatherHighTemperatureArrowSmallUrl; }
- QUrl weatherHighTemperatureArrowSmallDarkBgUrl() { return m_weatherHighTemperatureArrowSmallDarkBgUrl; }
- QUrl weatherHighTemperatureArrowMediumUrl() { return m_weatherHighTemperatureArrowMediumUrl; }
- QUrl weatherHighTemperatureArrowMediumDarkBgUrl() { return m_weatherHighTemperatureArrowMediumDarkBgUrl; }
- QUrl weatherHighTemperatureArrowLargeUrl() { return m_weatherHighTemperatureArrowLargeUrl; }
- QUrl weatherHighTemperatureArrowLargeDarkBgUrl() { return m_weatherHighTemperatureArrowLargeDarkBgUrl; }
-
-signals:
- void renderTemplate();
- void clearTemplate();
-
-private:
- std::shared_ptr<MessageEngine> m_mloop;
- QQmlContext *m_context;
-
- void clearMetadata();
- bool parseImageMetadata(QJsonObject &imageObj,
- QUrl &smallUrl, QUrl &mediumUrl, QUrl &largeUrl,
- QUrl *pSmallDarkBgUrl = NULL, QUrl *pMediumDarkBgUrl = NULL, QUrl *pLargeDarkBgUrl = NULL);
-
- bool updateMetadata(QJsonObject data);
- bool updateBodyMetadata(QJsonObject &data);
- bool updateWeatherMetadata(QJsonObject &data);
-
- void onConnected();
- void onDisconnected();
- void onMessageReceived(std::shared_ptr<Message>);
-
- const QStringList events {
- "render_template",
- "clear_template",
- };
-
- QString m_type = "";
- QString m_title = "";
- QString m_subtitle = "";
-
- // BodyTemplate1/2
- QString m_bodyText = "";
-
- // BodyTemplate2
- QUrl m_bodyImageSmallUrl = QString("");
- QUrl m_bodyImageMediumUrl = QString("");
- QUrl m_bodyImageLargeUrl = QString("");
-
- // WeatherTemplate
- QString m_weatherCurrentTemperature = "";
- QUrl m_weatherCurrentWeatherIconSmallUrl = QString("");
- QUrl m_weatherCurrentWeatherIconSmallDarkBgUrl = QString("");
- QUrl m_weatherCurrentWeatherIconMediumUrl = QString("");
- QUrl m_weatherCurrentWeatherIconMediumDarkBgUrl = QString("");
- QUrl m_weatherCurrentWeatherIconLargeUrl = QString("");
- QUrl m_weatherCurrentWeatherIconLargeDarkBgUrl = QString("");
-
- QString m_weatherLowTemperature = "";
- QUrl m_weatherLowTemperatureArrowSmallUrl = QString("");
- QUrl m_weatherLowTemperatureArrowSmallDarkBgUrl = QString("");
- QUrl m_weatherLowTemperatureArrowMediumUrl = QString("");
- QUrl m_weatherLowTemperatureArrowMediumDarkBgUrl = QString("");
- QUrl m_weatherLowTemperatureArrowLargeUrl = QString("");
- QUrl m_weatherLowTemperatureArrowLargeDarkBgUrl = QString("");
-
- QString m_weatherHighTemperature = "";
- QUrl m_weatherHighTemperatureArrowSmallUrl = QString("");
- QUrl m_weatherHighTemperatureArrowSmallDarkBgUrl = QString("");
- QUrl m_weatherHighTemperatureArrowMediumUrl = QString("");
- QUrl m_weatherHighTemperatureArrowMediumDarkBgUrl = QString("");
- QUrl m_weatherHighTemperatureArrowLargeUrl = QString("");
- QUrl m_weatherHighTemperatureArrowLargeDarkBgUrl = QString("");
-};
-
-#endif // GUIMETADATA_H
diff --git a/voice-capabilities/qtappfw-voice-metadata.pc.in b/voice-capabilities/qtappfw-voice-metadata.pc.in
deleted file mode 100644
index 7f69783..0000000
--- a/voice-capabilities/qtappfw-voice-metadata.pc.in
+++ /dev/null
@@ -1,12 +0,0 @@
-prefix=@DEST_DIR@
-exec_prefix=${prefix}
-libdir=${prefix}/lib
-includedir=${prefix}/include
-
-Name: qtappfw-voice-metadata
-Description: Library wrapping AGL AppFW voice metadata in Qt objects
-Version: 1.0.0
-
-Requires: Qt5Qml
-Libs: -L${libdir} -lqtappfw-voice-metadata
-Cflags: -I${includedir}/qtappfw-voice-metadata
diff --git a/voice/CMakeLists.txt b/voice/CMakeLists.txt
deleted file mode 100644
index 3de0586..0000000
--- a/voice/CMakeLists.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-
-CONFIGURE_FILE("qtappfw-voice.pc.in" "qtappfw-voice.pc" @ONLY)
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qtappfw-voice.pc
- DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
-
-add_library(qtappfw-voice SHARED voice.cpp
- voiceagentregistry.cpp
- voiceagentprofile.cpp
- voiceagentmodel.cpp)
-
-target_include_directories(qtappfw-voice PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
-target_include_directories(qtappfw-voice PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}")
-
-target_link_libraries(qtappfw-voice qtappfw-core)
-set_target_properties(qtappfw-voice PROPERTIES
- VERSION ${PROJECT_VERSION}
- SOVERSION 1
- PUBLIC_HEADER "voice.h;voiceagentregistry.h;voiceagentprofile.h;voiceagentmodel.h")
-
-install(TARGETS qtappfw-voice
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qtappfw-voice)
diff --git a/voice/qtappfw-voice.pc.in b/voice/qtappfw-voice.pc.in
deleted file mode 100644
index ebc5276..0000000
--- a/voice/qtappfw-voice.pc.in
+++ /dev/null
@@ -1,12 +0,0 @@
-prefix=@DEST_DIR@
-exec_prefix=${prefix}
-libdir=${prefix}/lib
-includedir=${prefix}/include
-
-Name: qtappfw-voice
-Description: Library wrapping AGL AppFW voice data in Qt objects
-Version: 1.0.0
-
-Requires: Qt5Qml
-Libs: -L${libdir} -lqtappfw-voice
-Cflags: -I${includedir}/qtappfw-voice
diff --git a/voice/voice.cpp b/voice/voice.cpp
deleted file mode 100644
index 396984a..0000000
--- a/voice/voice.cpp
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Copyright (C) 2019, 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <QDebug>
-#include <QStringList>
-
-#include "callmessage.h"
-#include "responsemessage.h"
-#include "eventmessage.h"
-#include "messagefactory.h"
-#include "messageengine.h"
-#include "messageenginefactory.h"
-#include "voiceagentregistry.h"
-#include "voice.h"
-
-Voice::Voice (QUrl &url, QQmlContext *context, QObject *parent) :
- QObject(parent)
-{
- m_loop = MessageEngineFactory::getInstance().getMessageEngine(url);
- m_var = new VoiceAgentRegistry(this, context, parent);
-
- QObject::connect(m_loop.get(), &MessageEngine::connected,
- this, &Voice::onConnected);
- QObject::connect(m_loop.get(), &MessageEngine::disconnected,
- this, &Voice::onDisconnected);
- QObject::connect(m_loop.get(), &MessageEngine::messageReceived,
- this, &Voice::onMessageReceived);
-}
-
-Voice::~Voice()
-{
- delete m_var;
-}
-
-void Voice::scan()
-{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage *vmsg = static_cast<CallMessage*>(msg.get());
- QJsonObject parameter;
-
- vmsg->createRequest("vshl-core", "enumerateVoiceAgents", parameter);
- m_loop->sendMessage(std::move(msg));
-}
-
-void Voice::getCBLpair(QString id)
-{
- triggerCBLProcess(id);
-}
-
-void Voice::subscribeAgentToVshlEvents(QString id)
-{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage *vmsg = static_cast<CallMessage*>(msg.get());
- QJsonArray events = QJsonArray::fromStringList(vshl_events);
- QJsonObject parameter;
-
- parameter.insert("va_id", id);
- parameter.insert("events", events);
- vmsg->createRequest("vshl-core", "subscribe", parameter);
- m_loop->sendMessage(std::move(msg));
-}
-
-void Voice::unsubscribeAgentFromVshlEvents(QString id)
-{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage *vmsg = static_cast<CallMessage*>(msg.get());
- QJsonArray events = QJsonArray::fromStringList(vshl_events);
- QJsonObject parameter;
-
- parameter.insert("va_id", id);
- parameter.insert("events", events);
- vmsg->createRequest("vshl-core", "unsubscribe", parameter);
- m_loop->sendMessage(std::move(msg));
-}
-
-void Voice::triggerCBLProcess(QString id)
-{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage *vmsg = static_cast<CallMessage*>(msg.get());
- QJsonArray events;
- QJsonObject parameter;
-
- parameter.insert("va_id", id);
- parameter.insert("events", events);
- vmsg->createRequest("vshl-core", "subscribeToLoginEvents", parameter);
- m_loop->sendMessage(std::move(msg));
-}
-
-void Voice::parseAgentsList(QJsonArray agents)
-{
- for (auto value : agents) {
- QJsonObject a = value.toObject();
- QString id = m_var->addAgent(a);
- subscribeAgentToVshlEvents(id);
- }
-}
-
-
-
-void Voice::processEvent(std::shared_ptr<Message> msg)
-{
- std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
- QString eapi = emsg->eventApi();
-
- if (eapi != "vshl-core")
- return;
-
- QString ename = emsg->eventName();
- QJsonObject data = emsg->eventData();
- QString agentId = data.value("va_id").toString();
- QString state = data.value("state").toString();
-
- if (ename.contains("voice_authstate_event")) {
- m_var->setAuthState(
- agentId,
- static_cast<VoiceAgentRegistry::ServiceAuthState>(
- m_var->stringToEnum(state, "ServiceAuthState")));
-
- return;
- }
- else if (ename.contains("voice_connectionstate_event")) {
- m_var->setConnectionState(
- agentId,
- static_cast<VoiceAgentRegistry::AgentConnectionState>(
- m_var->stringToEnum(state, "AgentConnectionState")));
- return;
- }
- else if (ename.contains("voice_dialogstate_event")) {
- m_var->setDialogState(
- agentId,
- static_cast<VoiceAgentRegistry::VoiceDialogState>(
- m_var->stringToEnum(state, "VoiceDialogState")));
- return;
- }
- else if (ename.contains("cbl")) {
- QJsonObject payload = data.value("payload").toObject();
- QString url = payload.value("url").toString();
- QString code = payload.value("code").toString();
- if (ename.contains("expired"))
- m_var->updateLoginData(agentId, code, url, true);
- else if (ename.contains("received")) {
- m_var->updateLoginData(agentId, code, url, false);
- } else
- qWarning() << "Unknown cbl event";
- return;
- }
-
- qWarning() << "Unknown vshl event:" << ename;
-}
-
-void Voice::processReply(std::shared_ptr<Message> msg)
-{
- std::shared_ptr<ResponseMessage> rmsg = std::static_pointer_cast<ResponseMessage>(msg);
- QString verb = rmsg->requestVerb();
- QJsonObject data = rmsg->replyData();
- if (rmsg->replyStatus() == "failed") {
- qWarning() << "Reply Failed received for verb:" << verb;
- } else if (verb == "enumerateVoiceAgents") {
- parseAgentsList(data.value("agents").toArray());
- m_var->setDefaultId(data.value("default").toString());
- } else
- qDebug() << "discarding reply received for verb:" << verb;
-}
-
-void Voice::onConnected()
-{
- scan();
-}
-
-void Voice::onDisconnected()
-{
- QStringList mvarlist = m_var->getAgentsListById();
- QStringList::iterator it;
- for (it = mvarlist.begin(); it != mvarlist.end(); ++it)
- unsubscribeAgentFromVshlEvents(*it);
-}
-
-void Voice::onMessageReceived(std::shared_ptr<Message> msg)
-{
- if (msg->isEvent()) {
- processEvent(msg);
- } else if (msg->isReply()) {
- processReply(msg);
- } else
- qWarning() << "Received invalid inbound message";
-}
diff --git a/voice/voice.h b/voice/voice.h
deleted file mode 100644
index 2dc38c3..0000000
--- a/voice/voice.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2019, 2020 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef VOICE_H
-#define VOICE_H
-
-#include <memory>
-#include <QObject>
-#include <QJsonArray>
-#include <QtQml/QQmlContext>
-
-class VoiceAgentRegistry;
-class MessageEngine;
-class Message;
-
-class Voice : public QObject
-{
- Q_OBJECT
-
- public:
- explicit Voice(QUrl &url, QQmlContext *context,
- QObject * parent = Q_NULLPTR);
- virtual ~Voice();
-
- //enumerate agents:
- Q_INVOKABLE void scan();
- //obtain code based login params:
- Q_INVOKABLE void getCBLpair(QString id);
-
- private:
- std::shared_ptr<MessageEngine> m_loop;
- VoiceAgentRegistry *m_var;
-
- void subscribeAgentToVshlEvents(QString id);
- void unsubscribeAgentFromVshlEvents(QString id);
- void triggerCBLProcess(QString id);
- void parseAgentsList(QJsonArray agents);
- void processVshlEvent(std::shared_ptr<Message> msg);
- void processLoginEvent(std::shared_ptr<Message> msg);
-
- void processEvent(std::shared_ptr<Message> emsg);
- void processReply(std::shared_ptr<Message> rmsg);
-
- // slots
- void onConnected();
- void onDisconnected();
- void onMessageReceived(std::shared_ptr<Message> msg);
-
- const QStringList vshl_events {
- "voice_authstate_event",
- "voice_dialogstate_event",
- "voice_connectionstate_event",
- "voice_cbl_codepair_received_event",
- "voice_cbl_codepair_expired_event",
- };
-};
-
-#endif // VOICE_H
diff --git a/voice/voiceagentmodel.cpp b/voice/voiceagentmodel.cpp
deleted file mode 100644
index 90ddf01..0000000
--- a/voice/voiceagentmodel.cpp
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Copyright (C) 2019 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "voiceagentmodel.h"
-#include "voiceagentprofile.h"
-#include <QVector>
-#include <QDebug>
-
-VoiceAgentModel::VoiceAgentModel(QObject *parent)
- : QAbstractListModel(parent)
-{
-}
-
-QVariant VoiceAgentModel::data(const QModelIndex &index, int role) const
-{
- QVariant ret;
-
- if (!index.isValid())
- return ret;
-
- if (index.row() < 0 || index.row() >= m_agents.count())
- return ret;
-
- const VoiceAgentProfile *vap = m_agents[index.row()];
- switch (role) {
- case IdRole:
- return vap->vaid();
- case NameRole:
- return vap->name();
- case WuwRole:
- return vap->activewuw();
- case AuthStateRole:
- return vap->authstate();
- case ConnStateRole:
- return vap->connstate();
- case DialogStateRole:
- return vap->dialogstate();
- case LoginParamsRole:
- return readLoginParams(index);
- case ActiveRole:
- return vap->isactive()? "active" : "inactive";
- case VendorRole:
- return vap->vendor();
- }
- return ret;
-}
-
-int VoiceAgentModel::rowCount(const QModelIndex &parent) const
-{
- Q_UNUSED(parent);
- return m_agents.count();
-}
-
-QVariantList VoiceAgentModel::readLoginParams(const QModelIndex &index) const
-{
- QVariantList ret;
-
- if (!index.isValid())
- return ret;
-
- if (index.row() < 0 || index.row() >= this->m_agents.count())
- return ret;
-
- const VoiceAgentProfile *vap = this->m_agents[index.row()];
- ret.append(vap->logincode());
- ret.append(vap->loginurl());
- ret.append(vap->isloginpairexpired()? "expired" : "valid");
- return ret;
-}
-
-void VoiceAgentModel::addAgent(VoiceAgentProfile *vap)
-{
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- m_agents.insert(rowCount(), vap);
- endInsertRows();
-}
-
-void VoiceAgentModel::removeAgent(VoiceAgentProfile *vap)
-{
- if (m_agents.isEmpty())
- return;
-
- int row = m_agents.indexOf(vap);
- beginRemoveRows(QModelIndex(), row, row);
- m_agents.removeAt(row);
- endRemoveRows();
- delete vap;
-}
-
-void VoiceAgentModel::removeAll()
-{
- if (m_agents.isEmpty())
- return;
-
- beginRemoveRows(QModelIndex(), 0, m_agents.count() -1);
- qDeleteAll(m_agents.begin(), m_agents.end());
- endRemoveRows();
- m_agents.clear();
-}
-
-bool VoiceAgentModel::agentExists(QString name, QString id, QString api) const
-{
- VoiceAgentProfile *vap = getAgentFromName(name);
- if (!vap)
- return false;
- bool sameid = id == vap->vaid();
- bool sameapi = api == vap->vaapi();
- return sameapi && (sameid || id != "UNKNOWN");
-}
-
-VoiceAgentProfile* VoiceAgentModel::getAgentFromName(QString name) const
-{
- if (m_agents.isEmpty())
- return nullptr;
-
- for (auto agent : m_agents) {
- if (agent->name() == name)
- return agent;
- }
- return nullptr;
-}
-
-VoiceAgentProfile* VoiceAgentModel::getAgentFromId(QString id) const
-{
- if (m_agents.isEmpty())
- return nullptr;
-
- for (auto agent : m_agents) {
- if (agent->vaid() == id)
- return agent;
- }
- return nullptr;
-}
-
-void VoiceAgentModel::updateAgentProperties(QString name, QString id, QString api,
- bool active, QString wuw)
-{
- QVector<int> vroles;
- VoiceAgentProfile *vap = getAgentFromName(name);
- if (!vap) {
- qWarning() << "Unknown agent";
- return;
- }
- if ((vap->vaapi() == api) && (vap->vaid() != id) && (id != "UNKNOWN")) {
- vap->setVaid(id);
- vroles.push_back(IdRole);
- }
- vap->setActive(active);
- vroles.push_back(ActiveRole);
- if (!wuw.isEmpty()) {
- vap->setWuw(wuw);
- vroles.push_back(WuwRole);
- }
- if (!vroles.isEmpty())
- emit dataChanged(indexOf(vap), indexOf(vap), vroles);
-}
-
-void VoiceAgentModel::updateAgentState(QString id)
-{
- QVector<int> vroles;
- VoiceAgentProfile *vap = getAgentFromId(id);
-
- if (!vap) {
- qWarning() << "Unknown agent";
- return;
- }
-
- vroles.push_back(AuthStateRole);
- vroles.push_back(ConnStateRole);
- vroles.push_back(DialogStateRole);
-
- if (!vroles.isEmpty())
- emit dataChanged(indexOf(vap), indexOf(vap), vroles);
-}
-
-void VoiceAgentModel::updateAgentLoginData(QString id)
-{
- QVector<int> vroles;
- VoiceAgentProfile *vap = getAgentFromId(id);
-
- if (!vap) {
- qWarning() << "Unknown agent";
- return;
- }
-
- vroles.push_back(LoginParamsRole);
- if (!vroles.isEmpty())
- emit dataChanged(indexOf(vap), indexOf(vap), vroles);
-}
-
-QModelIndex VoiceAgentModel::indexOf(VoiceAgentProfile *vap)
-{
- int row = m_agents.indexOf(vap);
- return index(row);
-}
-
-QHash<int, QByteArray> VoiceAgentModel::roleNames() const
-{
- QHash<int, QByteArray> roles;
- roles[NameRole] = "name";
- roles[IdRole] = "id";
- roles[WuwRole] = "wuw";
- roles[AuthStateRole] = "authstate";
- roles[ConnStateRole] = "connstate";
- roles[DialogStateRole] = "dialogstate";
- roles[LoginParamsRole] = "usrauth";
- roles[ActiveRole] = "active";
- roles[VendorRole] = "vendor";
- return roles;
-}
diff --git a/voice/voiceagentmodel.h b/voice/voiceagentmodel.h
deleted file mode 100644
index 0be9637..0000000
--- a/voice/voiceagentmodel.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2019 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef VOICEAGENTMODEL_H
-#define VOICEAGENTMODEL_H
-
-#include <QAbstractListModel>
-#include <QStringList>
-#include <QtQml/QQmlContext>
-#include <QJsonObject>
-
-#include "voiceagentprofile.h"
-
-class VoiceAgentModel : public QAbstractListModel
-{
- Q_OBJECT
-
- public:
- enum VoiceAgentRoles {
- IdRole = Qt::UserRole + 1,
- NameRole,
- WuwRole,
- AuthStateRole,
- ConnStateRole,
- DialogStateRole,
- LoginParamsRole,
- ActiveRole,
- VendorRole,
- };
-
- VoiceAgentModel(QObject *parent = Q_NULLPTR);
-
- QVariant data(const QModelIndex &index,
- int role = Qt::DisplayRole) const;
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- QVariantList readLoginParams(const QModelIndex &index) const;
- void addAgent(VoiceAgentProfile *vap);
- void removeAgent(VoiceAgentProfile* vap);
- void removeAll();
- bool agentExists(QString name, QString id, QString api) const;
- VoiceAgentProfile *getAgentFromName(QString name) const;
- VoiceAgentProfile *getAgentFromId(QString id) const;
- void updateAgentProperties(QString name, QString id,
- QString api, bool active, QString wuw);
- void updateAgentState(QString id);
- void updateAgentLoginData(QString id);
-
- private:
- QList<VoiceAgentProfile *> m_agents;
- QModelIndex indexOf(VoiceAgentProfile *agent);
- QHash<int, QByteArray> roleNames() const;
-};
-#endif // VOICEAGENTMODEL_H
diff --git a/voice/voiceagentprofile.cpp b/voice/voiceagentprofile.cpp
deleted file mode 100644
index 43d8b34..0000000
--- a/voice/voiceagentprofile.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2019 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "voiceagentprofile.h"
-
-VoiceAgentProfile::VoiceAgentProfile(const QString &name,
- const QString &id,
- const QString &api,
- bool active,
- const QString &wuw,
- const QString &vendor,
- const QString &wuws)
- : m_name(name), m_vaid(id), m_vaapi(api), m_active(active),
- m_activewuw(wuw), m_vendor(vendor), m_wuws(wuws),
- m_authstate("UNINITIALIZED"), m_connstate("DISCONNECTED"),
- m_dialogstate("MICROPHONEOFF"), m_logincode(QString()),
- m_loginurl(QString()), m_expired(true)
-{
-}
-
-QString VoiceAgentProfile::name() const
-{
- return m_name;
-}
-
-QString VoiceAgentProfile::vaid() const
-{
- return m_vaid;
-}
-
-QString VoiceAgentProfile::vaapi() const
-{
- return m_vaapi;
-}
-
-bool VoiceAgentProfile::isactive() const
-{
- return m_active;
-}
-
-QString VoiceAgentProfile::activewuw() const
-{
- return m_activewuw;
-}
-
-QString VoiceAgentProfile::vendor() const
-{
- return m_vendor;
-}
-
-QString VoiceAgentProfile::wuws() const
-{
- return m_wuws;
-}
-
-QString VoiceAgentProfile::authstate() const
-{
- return m_authstate;
-}
-
-QString VoiceAgentProfile::connstate() const
-{
- return m_connstate;
-}
-
-QString VoiceAgentProfile::dialogstate() const
-{
- return m_dialogstate;
-}
-
-QString VoiceAgentProfile::logincode() const
-{
- return m_logincode;
-}
-
-QString VoiceAgentProfile::loginurl() const
-{
- return m_loginurl;
-}
-
-bool VoiceAgentProfile::isloginpairexpired() const
-{
- return m_expired;
-}
-
-void VoiceAgentProfile::setVaid(const QString id)
-{
- m_vaid = id;
-}
-
-void VoiceAgentProfile::setActive(bool active)
-{
- m_active = active;
-}
-
-void VoiceAgentProfile::setAuthState(const QString state)
-{
- m_authstate = state;
-}
-
-void VoiceAgentProfile::setConnState(const QString state)
-{
- m_connstate = state;
-}
-
-void VoiceAgentProfile::setDialogState(const QString state)
-{
- m_dialogstate = state;
-}
-
-void VoiceAgentProfile::setLoginCode(const QString usrcode)
-{
- m_logincode = usrcode;
-}
-
-void VoiceAgentProfile::setLoginUrl(const QString usrurl)
-{
- m_loginurl = usrurl;
-}
-
-void VoiceAgentProfile::setLoginPairExpired(bool expired)
-{
- m_expired = expired;
-}
-
-void VoiceAgentProfile::setWuw(const QString newwuw)
-{
- m_activewuw = newwuw;
-}
diff --git a/voice/voiceagentprofile.h b/voice/voiceagentprofile.h
deleted file mode 100644
index dda96c5..0000000
--- a/voice/voiceagentprofile.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2019 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef VOICEAGENTPROFILE_H
-#define VOICEAGENTPROFILE_H
-
-#include <QString>
-
-class VoiceAgentProfile
-{
- public:
- VoiceAgentProfile(const QString &name,
- const QString &id,
- const QString &api,
- bool active,
- const QString &wuw,
- const QString &vendor,
- const QString &wuws);
-
- QString name() const;
- QString vaid() const;
- QString vaapi() const;
- bool isactive() const;
- QString activewuw() const;
- QString vendor() const;
- QString wuws() const;
- QString authstate() const;
- QString connstate() const;
- QString dialogstate() const;
- QString logincode() const;
- QString loginurl() const;
- bool isloginpairexpired() const;
-
- void setVaid(const QString newid);
- void setActive(bool activemode);
- void setAuthState(const QString newauthstate);
- void setConnState(const QString newconnstate);
- void setDialogState(const QString newdialogstate);
- void setLoginCode(const QString newtoken);
- void setLoginUrl(const QString newurl);
- void setLoginPairExpired(bool expired);
- void setWuw(const QString newwuw);
-
- bool operator==(const VoiceAgentProfile& rhs) {
- return (m_name == rhs.name() &&
- m_vaid == rhs.vaid() &&
- m_vaapi == rhs.vaapi()); };
-
- private:
- QString m_name;
- QString m_vaid;
- QString m_vaapi;
- bool m_active;
- QString m_activewuw;
- QString m_vendor;
- QString m_wuws;
- QString m_authstate;
- QString m_connstate;
- QString m_dialogstate;
- QString m_logincode;
- QString m_loginurl;
- bool m_expired;
-};
-
-#endif // VOICEAGENTPROFILE_H
diff --git a/voice/voiceagentregistry.cpp b/voice/voiceagentregistry.cpp
deleted file mode 100644
index 00eed87..0000000
--- a/voice/voiceagentregistry.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2019 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <QMetaEnum>
-#include <QSortFilterProxyModel>
-#include <QtQml/QQmlEngine>
-
-#include "voice.h"
-#include "voiceagentregistry.h"
-#include "voiceagentmodel.h"
-#include "voiceagentprofile.h"
-
-VoiceAgentRegistry::VoiceAgentRegistry(Voice *voice, QQmlContext *context, QObject *parent) :
- QObject(parent),
- m_model(nullptr),
- vc(voice)
-{
- m_model = new VoiceAgentModel();
- context->setContextProperty("VoiceAgentModel", m_model);
- context->setContextProperty("VoiceAgent", this);
-}
-
-VoiceAgentRegistry::~VoiceAgentRegistry()
-{
- delete m_model;
-}
-
-QString VoiceAgentRegistry::addAgent(QJsonObject va)
-{
- bool active = va.value("active").toBool();
- QString wuw = va.value("activewakeword").toString();
- QString api = va.value("api").toString();
- QString desc = va.value("description").toString();
- QString id = va.value("id").toString();
- QString name = va.value("name").toString();
- QString vendor = va.value("vendor").toString();
- QString wuws = va.value("wakewords").toString();
-
- if (!m_model->agentExists(name, id, api)) {
- VoiceAgentProfile *vap = new VoiceAgentProfile(name, id, api,
- active, wuw,
- vendor, wuws);
- m_model->addAgent(vap);
- m_regids.append(id);
- }
- else
- m_model->updateAgentProperties(name, id, api, active, wuw);
- return id;
-}
-
-bool VoiceAgentRegistry::removeAgent(QString id)
-{
- VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (!vap)
- return false;
- m_model->removeAgent(vap);
- return true;
-}
-
-void VoiceAgentRegistry::clearRegistry()
-{
- m_default_aid.clear();
- m_regids.clear();
- m_model->removeAll();
-}
-
-QStringList VoiceAgentRegistry::getAgentsListById() const
-{
- return m_regids;
-}
-
-QString VoiceAgentRegistry::getDefaultId() const
-{
- return m_default_aid.isEmpty()? "UNKNOWN" : m_default_aid;
-}
-void VoiceAgentRegistry::setDefaultId(QString id)
-{
- m_default_aid = id;
-}
-
-void VoiceAgentRegistry::setAuthState(QString id, ServiceAuthState state)
-{
- QMetaEnum metaEnum = QMetaEnum::fromType<VoiceAgentRegistry::ServiceAuthState>();
- auto stateStr = metaEnum.valueToKey(state);
- VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (vap) {
- vap->setAuthState(stateStr);
- m_model->updateAgentState(id);
- }
-}
-
-void VoiceAgentRegistry::setConnectionState(QString id, AgentConnectionState state)
-{
- QMetaEnum metaEnum = QMetaEnum::fromType<VoiceAgentRegistry::AgentConnectionState>();
- auto stateStr = metaEnum.valueToKey(state);
-
- VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (vap) {
- vap->setConnState(stateStr);
- m_model->updateAgentState(id);
- }
-}
-
-void VoiceAgentRegistry::setDialogState(QString id, VoiceDialogState state)
-{
- QMetaEnum metaEnum = QMetaEnum::fromType<VoiceAgentRegistry::VoiceDialogState>();
- auto stateStr = metaEnum.valueToKey(state);
-
- VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (vap) {
- vap->setDialogState(stateStr);
- m_model->updateAgentState(id);
- }
-}
-
-void VoiceAgentRegistry::updateLoginData(QString id, QString code, QString url,
- bool expired)
-{
- VoiceAgentProfile *vap = m_model->getAgentFromId(id);
- if (vap) {
- vap->setLoginCode(url);
- vap->setLoginUrl(code);
- vap->setLoginPairExpired(expired);
- m_model->updateAgentLoginData(id);
- };
-}
-
-int VoiceAgentRegistry::stringToEnum(const QString key, const QString enumtype)
-{
- const QMetaObject *metaObject = VoiceAgentRegistry::metaObject();
- int enumIndex = metaObject->indexOfEnumerator(enumtype.toUtf8().constData());
- QMetaEnum metaEnum = metaObject->enumerator(enumIndex);
- int value = metaEnum.keyToValue(key.toUtf8().constData());
- return (value < 0)? 0 : value;
-}
diff --git a/voice/voiceagentregistry.h b/voice/voiceagentregistry.h
deleted file mode 100644
index e0a48c5..0000000
--- a/voice/voiceagentregistry.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2019 Konsulko Group
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef VOICEAGENTREGISTRY_H
-#define VOICEAGENTREGISTRY_H
-
-#include <QDebug>
-#include <QObject>
-#include <QJsonArray>
-#include <QtQml/QQmlContext>
-
-class Voice;
-class VoiceAgentModel;
-
-class VoiceAgentRegistry : public QObject
-{
- Q_OBJECT
- public:
- explicit VoiceAgentRegistry(Voice *voice, QQmlContext *context,
- QObject *parent);
- virtual ~VoiceAgentRegistry();
-
- enum AgentConnectionState {
- DISCONNECTED = 0,
- CONNECTED,
- };
- Q_ENUM(AgentConnectionState)
-
- enum VoiceDialogState {
- IDLE = 0,
- LISTENING,
- THINKING,
- SPEAKING,
- MICROPHONEOFF,
- };
- Q_ENUM(VoiceDialogState)
-
- enum ServiceAuthState {
- UNINITIALIZED = 0,
- REFRESHED,
- EXPIRED,
- UNRECOVERABLE_ERROR
- };
- Q_ENUM(ServiceAuthState)
-
- QString addAgent(QJsonObject va);
- bool removeAgent(QString id);
- void clearRegistry();
- QStringList getAgentsListById() const;
- QString getDefaultId() const;
- void setDefaultId(QString id);
- void setAuthState(QString id, ServiceAuthState state);
- void setConnectionState(QString id, AgentConnectionState state);
- void setDialogState(QString id, VoiceDialogState state);
- void updateLoginData(QString id, QString code, QString url,
- bool expired);
- int stringToEnum(QString value, QString enumtype);
- private:
- VoiceAgentModel *m_model;
- Voice *vc;
- QString m_default_aid;
- QStringList m_regids;
-};
-
-#endif // VOICEAGENTREGISTRY_H
diff --git a/weather/CMakeLists.txt b/weather/CMakeLists.txt
index 11d4f91..b622262 100644
--- a/weather/CMakeLists.txt
+++ b/weather/CMakeLists.txt
@@ -8,7 +8,7 @@ add_library(qtappfw-weather SHARED weather.cpp)
target_include_directories(qtappfw-weather PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(qtappfw-weather PUBLIC "${CMAKE_INSTALL_INCLUDEDIR}")
-target_link_libraries(qtappfw-weather qtappfw-core)
+target_link_libraries(qtappfw-weather Qt5::Qml)
set_target_properties(qtappfw-weather PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
diff --git a/weather/weather.cpp b/weather/weather.cpp
index d4a8173..864eeb6 100644
--- a/weather/weather.cpp
+++ b/weather/weather.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018-2020 Konsulko Group
+ * Copyright (C) 2018,2020-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,21 +17,14 @@
#include <QDebug>
#include <QJsonArray>
-#include "callmessage.h"
-#include "eventmessage.h"
-#include "messagefactory.h"
-#include "messageengine.h"
-#include "messageenginefactory.h"
#include "weather.h"
-Weather::Weather (QUrl &url, QObject * parent) :
- QObject(parent)
+Weather::Weather (QObject * parent) :
+ QObject(parent),
+ m_temperature("77"),
+ m_condition("clear sky")
{
- m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
- QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &Weather::onConnected);
- QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &Weather::onDisconnected);
- QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &Weather::onMessageReceived);
}
Weather::~Weather()
@@ -40,41 +33,8 @@ Weather::~Weather()
void Weather::onConnected()
{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage *tmsg = static_cast<CallMessage*>(msg.get());
- tmsg->createRequest("weather", "subscribe", "weather");
- m_mloop->sendMessage(std::move(msg));
}
void Weather::onDisconnected()
{
- std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
- if (!msg)
- return;
-
- CallMessage *tmsg = static_cast<CallMessage*>(msg.get());
- tmsg->createRequest("weater", "unsubscribe", "weather");
- m_mloop->sendMessage(std::move(msg));
-}
-
-void Weather::onMessageReceived(std::shared_ptr<Message> msg)
-{
- if (!msg)
- return;
-
- if (msg->isEvent()) {
- std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
- if (emsg->eventApi() != "weather")
- return;
-
- QJsonObject data = emsg->eventData();
- m_temperature = QString::number(data.value("main").toObject().value("temp").toDouble());
- m_condition = data.value("weather").toArray().at(0).toObject().value("description").toString();
-
- emit temperatureChanged(m_temperature);
- emit conditionChanged(m_condition);
- }
}
diff --git a/weather/weather.h b/weather/weather.h
index 93c5ec4..bb03dca 100644
--- a/weather/weather.h
+++ b/weather/weather.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018-2020 Konsulko Group
+ * Copyright (C) 2018,2020-2021 Konsulko Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,9 +20,6 @@
#include <memory>
#include <QObject>
-class MessageEngine;
-class Message;
-
class Weather : public QObject
{
Q_OBJECT
@@ -30,7 +27,7 @@ class Weather : public QObject
Q_PROPERTY(QString condition READ condition NOTIFY conditionChanged)
public:
- explicit Weather(QUrl &url, QObject * parent = Q_NULLPTR);
+ explicit Weather(QObject * parent = Q_NULLPTR);
virtual ~Weather();
QString temperature() { return m_temperature; }
@@ -41,13 +38,11 @@ class Weather : public QObject
void conditionChanged(QString condition);
private:
- std::shared_ptr<MessageEngine> m_mloop;
QString m_temperature;
QString m_condition;
void onConnected();
void onDisconnected();
- void onMessageReceived(std::shared_ptr<Message>);
};
#endif // WEATHER_H