summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--bluetooth/bluetooth.cpp13
-rw-r--r--bluetooth/bluetooth.h2
-rw-r--r--hvac/hvac.cpp7
-rw-r--r--hvac/hvac.h2
-rw-r--r--map/map.cpp13
-rw-r--r--map/map.h2
-rw-r--r--mediaplayer/mediaplayer.cpp13
-rw-r--r--mediaplayer/mediaplayer.h2
-rw-r--r--messageengine.cpp6
-rw-r--r--messageengine.h5
-rw-r--r--messageenginefactory.cpp40
-rw-r--r--messageenginefactory.h41
-rw-r--r--navigation/navigation.cpp13
-rw-r--r--navigation/navigation.h2
-rw-r--r--network/network.cpp13
-rw-r--r--network/network.h2
-rw-r--r--pbap/pbap.cpp13
-rw-r--r--pbap/pbap.h2
-rw-r--r--radio/radio.cpp11
-rw-r--r--radio/radio.h2
-rw-r--r--signal-composer/signalcomposer.cpp13
-rw-r--r--signal-composer/signalcomposer.h2
-rw-r--r--telephony/telephony.cpp11
-rw-r--r--telephony/telephony.h2
-rw-r--r--utils.h16
-rw-r--r--voice-capabilities/guimetadata.cpp13
-rw-r--r--voice-capabilities/guimetadata.h2
-rw-r--r--voice/voice.cpp13
-rw-r--r--voice/voice.h2
-rw-r--r--voice/voiceagentregistry.cpp6
-rw-r--r--weather/weather.cpp13
-rw-r--r--weather/weather.h2
33 files changed, 193 insertions, 110 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b2f826f..696b8bd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,8 +61,8 @@ set (SUBDIRS
voice-capabilities
weather)
-add_headers(message.h messagefactory.h messageengine.h responsemessage.h callmessage.h eventmessage.h)
-add_sources(message.cpp messagefactory.cpp messageengine.cpp responsemessage.cpp callmessage.cpp eventmessage.cpp)
+add_headers(message.h messagefactory.h messageengine.h messageenginefactory.h responsemessage.h callmessage.h eventmessage.h utils.h)
+add_sources(message.cpp messagefactory.cpp messageengine.cpp messageenginefactory.cpp responsemessage.cpp callmessage.cpp eventmessage.cpp)
foreach(subdir ${SUBDIRS})
add_subdirectory(${subdir})
diff --git a/bluetooth/bluetooth.cpp b/bluetooth/bluetooth.cpp
index e39270a..cea89ad 100644
--- a/bluetooth/bluetooth.cpp
+++ b/bluetooth/bluetooth.cpp
@@ -21,20 +21,20 @@
#include "responsemessage.h"
#include "messagefactory.h"
#include "messageengine.h"
+#include "messageenginefactory.h"
#include "bluetooth.h"
#include "bluetoothmodel.h"
Bluetooth::Bluetooth (QUrl &url, QQmlContext *context, QObject * parent) :
QObject(parent),
- m_context(context),
- m_mloop(nullptr)
+ m_context(context)
{
- m_mloop = new MessageEngine(url);
+ m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
m_bluetooth = new BluetoothModel();
- QObject::connect(m_mloop, &MessageEngine::connected, this, &Bluetooth::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Bluetooth::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Bluetooth::onMessageReceived);
+ 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);
@@ -53,7 +53,6 @@ Bluetooth::Bluetooth (QUrl &url, QQmlContext *context, QObject * parent) :
Bluetooth::~Bluetooth()
{
- delete m_mloop;
}
void Bluetooth::send_command(QString verb, QJsonObject parameter)
diff --git a/bluetooth/bluetooth.h b/bluetooth/bluetooth.h
index 3953fe6..b79e8f9 100644
--- a/bluetooth/bluetooth.h
+++ b/bluetooth/bluetooth.h
@@ -66,7 +66,7 @@ class Bluetooth : public QObject
void requestConfirmationEvent(QJsonObject data);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
QQmlContext *m_context;
BluetoothModel *m_bluetooth;
void send_command(QString, QJsonObject);
diff --git a/hvac/hvac.cpp b/hvac/hvac.cpp
index 23aef30..edb7e35 100644
--- a/hvac/hvac.cpp
+++ b/hvac/hvac.cpp
@@ -23,24 +23,23 @@
#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) :
QObject(parent),
- m_mloop(nullptr),
m_fanspeed(0),
m_temp_left_zone(21),
m_temp_right_zone(21)
{
- m_mloop = new MessageEngine(url);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &HVAC::onMessageReceived);
+ m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
+ QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &HVAC::onMessageReceived);
}
HVAC::~HVAC()
{
- delete m_mloop;
}
void HVAC::control(QString verb, QString field, int value)
diff --git a/hvac/hvac.h b/hvac/hvac.h
index 81378e4..858fddf 100644
--- a/hvac/hvac.h
+++ b/hvac/hvac.h
@@ -45,7 +45,7 @@ class HVAC : public QObject
void languageChanged(QString language);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
int m_fanspeed;
int m_temp_left_zone;
diff --git a/map/map.cpp b/map/map.cpp
index e7a4157..b85a323 100644
--- a/map/map.cpp
+++ b/map/map.cpp
@@ -21,21 +21,20 @@
#include "responsemessage.h"
#include "messagefactory.h"
#include "messageengine.h"
+#include "messageenginefactory.h"
#include "map.h"
Map::Map (QUrl &url, QObject * parent) :
- QObject(parent),
- m_mloop(nullptr)
+ QObject(parent)
{
- m_mloop = new MessageEngine(url);
- QObject::connect(m_mloop, &MessageEngine::connected, this, &Map::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Map::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Map::onMessageReceived);
+ m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
+ QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &Map::onConnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &Map::onDisconnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &Map::onMessageReceived);
}
Map::~Map()
{
- delete m_mloop;
}
void Map::compose(QString recipient, QString message)
diff --git a/map/map.h b/map/map.h
index 91af103..150a95d 100644
--- a/map/map.h
+++ b/map/map.h
@@ -44,7 +44,7 @@ class Map : public QObject
void messageResult(QString handle, QVariantMap message);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
// slots
void onConnected();
diff --git a/mediaplayer/mediaplayer.cpp b/mediaplayer/mediaplayer.cpp
index e723d5d..c578145 100644
--- a/mediaplayer/mediaplayer.cpp
+++ b/mediaplayer/mediaplayer.cpp
@@ -20,6 +20,7 @@
#include "eventmessage.h"
#include "messageengine.h"
#include "messagefactory.h"
+#include "messageenginefactory.h"
#include "mediaplayer.h"
@@ -37,20 +38,18 @@ Playlist::Playlist(QVariantMap &item)
Playlist::~Playlist() {}
Mediaplayer::Mediaplayer (QUrl &url, QQmlContext *context, QObject * parent) :
- QObject(parent),
- m_mloop(nullptr)
+ QObject(parent)
{
- m_mloop = new MessageEngine(url);
+ m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
m_context = context;
m_context->setContextProperty("MediaplayerModel", QVariant::fromValue(m_playlist));
- QObject::connect(m_mloop, &MessageEngine::connected, this, &Mediaplayer::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Mediaplayer::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Mediaplayer::onMessageReceived);
+ QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &Mediaplayer::onConnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &Mediaplayer::onDisconnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &Mediaplayer::onMessageReceived);
}
Mediaplayer::~Mediaplayer()
{
- delete m_mloop;
}
// Qt UI Context
diff --git a/mediaplayer/mediaplayer.h b/mediaplayer/mediaplayer.h
index 374ab06..3d53a24 100644
--- a/mediaplayer/mediaplayer.h
+++ b/mediaplayer/mediaplayer.h
@@ -96,7 +96,7 @@ class Mediaplayer : public QObject
void metadataChanged(QVariantMap metadata);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
QQmlContext *m_context;
QList<QObject *> m_playlist;
diff --git a/messageengine.cpp b/messageengine.cpp
index 2633545..42fe95b 100644
--- a/messageengine.cpp
+++ b/messageengine.cpp
@@ -22,8 +22,8 @@
#include "messageengine.h"
-MessageEngine::MessageEngine(const QUrl &url, QObject *parent) :
- QObject(parent),
+MessageEngine::MessageEngine(const QUrl &url) :
+ QObject(Q_NULLPTR),
m_callid(0),
m_url(url)
{
@@ -43,6 +43,7 @@ bool MessageEngine::sendMessage(std::unique_ptr<Message> msg)
if (forkeeps.isEmpty())
return false;
+ std::lock_guard<std::mutex> localguard(m_mutex);
m_calls.insert(callid, forkeeps);
return true;
@@ -80,6 +81,7 @@ void MessageEngine::onTextMessageReceived(QString jsonStr)
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);
}
diff --git a/messageengine.h b/messageengine.h
index b682ec5..4639c97 100644
--- a/messageengine.h
+++ b/messageengine.h
@@ -19,6 +19,7 @@
#include <memory>
#include <atomic>
+#include <mutex>
#include <QUrl>
#include <QWebSocket>
@@ -28,7 +29,7 @@ class MessageEngine : public QObject
{
Q_OBJECT
public:
- explicit MessageEngine(const QUrl &url, QObject *parent = Q_NULLPTR);
+ explicit MessageEngine(const QUrl &url);
bool sendMessage(std::unique_ptr<Message> message);
Q_SIGNALS:
@@ -43,9 +44,11 @@ class MessageEngine : public QObject
private:
QWebSocket m_websocket;
+ std::mutex m_mutex;
QMap<qint32, QByteArray> m_calls;
QUrl m_url;
std::atomic<unsigned int> m_callid;
+ friend class MessageEngineFactory;
};
#endif // MESSAGEENGINE_H
diff --git a/messageenginefactory.cpp b/messageenginefactory.cpp
new file mode 100644
index 0000000..7a052ce
--- /dev/null
+++ b/messageenginefactory.cpp
@@ -0,0 +1,40 @@
+/*
+ * 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"
+#include "utils.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::make_shared<MessageEngine>(url);
+ lut[urlstr] = pme;
+ }
+
+ return pme;
+}
diff --git a/messageenginefactory.h b/messageenginefactory.h
new file mode 100644
index 0000000..1ce107b
--- /dev/null
+++ b/messageenginefactory.h
@@ -0,0 +1,41 @@
+/*
+ * 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/navigation/navigation.cpp b/navigation/navigation.cpp
index e0078c2..e24df1a 100644
--- a/navigation/navigation.cpp
+++ b/navigation/navigation.cpp
@@ -20,22 +20,21 @@
#include "eventmessage.h"
#include "messagefactory.h"
#include "messageengine.h"
+#include "messageenginefactory.h"
#include "navigation.h"
Navigation::Navigation (QUrl &url, QObject * parent) :
- QObject(parent),
- m_mloop(nullptr)
+ QObject(parent)
{
- m_mloop = new MessageEngine(url);
- QObject::connect(m_mloop, &MessageEngine::connected, this, &Navigation::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Navigation::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Navigation::onMessageReceived);
+ 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()
{
- delete m_mloop;
}
void Navigation::sendWaypoint(double lat, double lon)
diff --git a/navigation/navigation.h b/navigation/navigation.h
index 87e5636..b1c0412 100644
--- a/navigation/navigation.h
+++ b/navigation/navigation.h
@@ -46,7 +46,7 @@ class Navigation : public QObject
void waypointsEvent(QVariantMap data);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
// slots
void onMessageReceived(std::shared_ptr<Message> msg);
diff --git a/network/network.cpp b/network/network.cpp
index 2472279..46045dc 100644
--- a/network/network.cpp
+++ b/network/network.cpp
@@ -22,27 +22,26 @@
#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) :
- QObject(parent),
- m_mloop(nullptr)
+ QObject(parent)
{
- m_mloop = new MessageEngine(url);
+ m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
m_adapters.append(new WifiAdapter(this, context, parent));
- QObject::connect(m_mloop, &MessageEngine::connected, this, &Network::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Network::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Network::onMessageReceived);
+ 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));
}
Network::~Network()
{
- delete m_mloop;
while (!m_adapters.isEmpty())
m_adapters.takeLast();
}
diff --git a/network/network.h b/network/network.h
index b40b432..07ff54d 100644
--- a/network/network.h
+++ b/network/network.h
@@ -54,7 +54,7 @@ class Network : public QObject
void searchResults(QString name);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
QQmlContext *m_context;
QList<AdapterIf*> m_adapters;
diff --git a/pbap/pbap.cpp b/pbap/pbap.cpp
index 53b07bd..f92139b 100644
--- a/pbap/pbap.cpp
+++ b/pbap/pbap.cpp
@@ -24,6 +24,7 @@
#include "responsemessage.h"
#include "messagefactory.h"
#include "messageengine.h"
+#include "messageenginefactory.h"
#include "pbap.h"
@@ -81,24 +82,22 @@ int RecentCall::stringToEnum(QString key)
}
Pbap::Pbap (QUrl &url, QQmlContext *context, QObject * parent) :
- QObject(parent),
- m_mloop(nullptr)
+ QObject(parent)
{
- m_mloop = new MessageEngine(url);
+ m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
m_context = context;
m_context->setContextProperty("ContactsModel", QVariant::fromValue(m_contacts));
qmlRegisterUncreatableType<PhoneNumber>("PhoneNumber", 1, 0, "PhoneNumber", "Enum");
m_context->setContextProperty("RecentCallModel", QVariant::fromValue(m_calls));
qmlRegisterUncreatableType<RecentCall>("RecentCall", 1, 0, "RecentCall", "Enum");
- QObject::connect(m_mloop, &MessageEngine::connected, this, &Pbap::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Pbap::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Pbap::onMessageReceived);
+ QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &Pbap::onConnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &Pbap::onDisconnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &Pbap::onMessageReceived);
}
Pbap::~Pbap()
{
- delete m_mloop;
}
void Pbap::importContacts(int max_entries)
diff --git a/pbap/pbap.h b/pbap/pbap.h
index 4deb9c6..676b49d 100644
--- a/pbap/pbap.h
+++ b/pbap/pbap.h
@@ -157,7 +157,7 @@ class Pbap : public QObject
void statusChanged(bool connected);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
QQmlContext *m_context;
QList<QObject *>m_contacts;
QList<QObject *>m_calls;
diff --git a/radio/radio.cpp b/radio/radio.cpp
index b7c407c..885383d 100644
--- a/radio/radio.cpp
+++ b/radio/radio.cpp
@@ -21,12 +21,12 @@
#include "responsemessage.h"
#include "messagefactory.h"
#include "messageengine.h"
+#include "messageenginefactory.h"
#include "radio.h"
Radio::Radio (QUrl &url, QQmlContext *context, QObject * parent) :
QObject(parent),
- m_mloop(nullptr),
m_band(1),
m_frequency(0),
m_minFrequency(0),
@@ -34,17 +34,16 @@ Radio::Radio (QUrl &url, QQmlContext *context, QObject * parent) :
m_playing(false),
m_scanning(false)
{
- m_mloop = new MessageEngine(url);
+ m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
m_context = context;
- QObject::connect(m_mloop, &MessageEngine::connected, this, &Radio::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Radio::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Radio::onMessageReceived);
+ QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &Radio::onConnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &Radio::onDisconnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &Radio::onMessageReceived);
}
Radio::~Radio()
{
- delete m_mloop;
}
void Radio::setBand(int band)
diff --git a/radio/radio.h b/radio/radio.h
index 77b78d2..b38d9d3 100644
--- a/radio/radio.h
+++ b/radio/radio.h
@@ -76,7 +76,7 @@ class Radio : public QObject
void frequencyStepChanged(int frequencyStep);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
QQmlContext *m_context;
unsigned int m_band;
diff --git a/signal-composer/signalcomposer.cpp b/signal-composer/signalcomposer.cpp
index 1296162..d10bcc1 100644
--- a/signal-composer/signalcomposer.cpp
+++ b/signal-composer/signalcomposer.cpp
@@ -20,22 +20,21 @@
#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(nullptr)
+ QObject(parent)
{
- m_mloop = new MessageEngine(url);
- QObject::connect(m_mloop, &MessageEngine::connected, this, &SignalComposer::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &SignalComposer::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &SignalComposer::onMessageReceived);
+ 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()
{
- delete m_mloop;
}
void SignalComposer::onConnected()
diff --git a/signal-composer/signalcomposer.h b/signal-composer/signalcomposer.h
index 382b6e9..a18f5a8 100644
--- a/signal-composer/signalcomposer.h
+++ b/signal-composer/signalcomposer.h
@@ -36,7 +36,7 @@ class SignalComposer : public QObject
void signalEvent(QString uid, QString value, QString units, quint64 timestamp);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
void onConnected();
void onDisconnected();
diff --git a/telephony/telephony.cpp b/telephony/telephony.cpp
index 3efecc7..b31462c 100644
--- a/telephony/telephony.cpp
+++ b/telephony/telephony.cpp
@@ -20,24 +20,23 @@
#include "eventmessage.h"
#include "messagefactory.h"
#include "messageengine.h"
+#include "messageenginefactory.h"
#include "telephony.h"
Telephony::Telephony (QUrl &url, QObject * parent) :
QObject(parent),
m_connected(false),
- m_mloop(nullptr),
m_call_state("disconnected")
{
- m_mloop = new MessageEngine(url);
- QObject::connect(m_mloop, &MessageEngine::connected, this, &Telephony::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Telephony::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Telephony::onMessageReceived);
+ m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
+ QObject::connect(m_mloop.get(), &MessageEngine::connected, this, &Telephony::onConnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::disconnected, this, &Telephony::onDisconnected);
+ QObject::connect(m_mloop.get(), &MessageEngine::messageReceived, this, &Telephony::onMessageReceived);
}
Telephony::~Telephony()
{
- delete m_mloop;
}
void Telephony::dial(QString number)
diff --git a/telephony/telephony.h b/telephony/telephony.h
index ca1e52a..2aecc86 100644
--- a/telephony/telephony.h
+++ b/telephony/telephony.h
@@ -71,7 +71,7 @@ class Telephony : public QObject
private:
bool m_connected;
bool m_online;
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
QString m_call_state;
QString m_clip;
QString m_colp;
diff --git a/utils.h b/utils.h
new file mode 100644
index 0000000..d0203f9
--- /dev/null
+++ b/utils.h
@@ -0,0 +1,16 @@
+#ifndef UTILS_H
+#define UTILS_H
+
+#include <functional>
+#include <QHash>
+#include <QString>
+
+namespace std {
+ template<> struct hash<QString> {
+ std::size_t operator()(const QString& s) const noexcept {
+ return (size_t) qHash(s);
+ }
+ };
+}
+
+#endif
diff --git a/voice-capabilities/guimetadata.cpp b/voice-capabilities/guimetadata.cpp
index 63d99fc..cc65ba0 100644
--- a/voice-capabilities/guimetadata.cpp
+++ b/voice-capabilities/guimetadata.cpp
@@ -21,22 +21,21 @@
#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(nullptr)
+ QObject(parent)
{
- m_mloop = new MessageEngine(url);
+ m_mloop = MessageEngineFactory::getInstance().getMessageEngine(url);
m_context = context;
- QObject::connect(m_mloop, &MessageEngine::connected, this, &GuiMetadata::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &GuiMetadata::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &GuiMetadata::onMessageReceived);
+ 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()
{
- delete m_mloop;
}
// Qt UI Context
diff --git a/voice-capabilities/guimetadata.h b/voice-capabilities/guimetadata.h
index f082d52..ba6b1a1 100644
--- a/voice-capabilities/guimetadata.h
+++ b/voice-capabilities/guimetadata.h
@@ -114,7 +114,7 @@ signals:
void clearTemplate();
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
QQmlContext *m_context;
void clearMetadata();
diff --git a/voice/voice.cpp b/voice/voice.cpp
index 5961882..396984a 100644
--- a/voice/voice.cpp
+++ b/voice/voice.cpp
@@ -21,27 +21,26 @@
#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(nullptr)
+ QObject(parent)
{
- m_loop = new MessageEngine(url);
+ m_loop = MessageEngineFactory::getInstance().getMessageEngine(url);
m_var = new VoiceAgentRegistry(this, context, parent);
- QObject::connect(m_loop, &MessageEngine::connected,
+ QObject::connect(m_loop.get(), &MessageEngine::connected,
this, &Voice::onConnected);
- QObject::connect(m_loop, &MessageEngine::disconnected,
+ QObject::connect(m_loop.get(), &MessageEngine::disconnected,
this, &Voice::onDisconnected);
- QObject::connect(m_loop, &MessageEngine::messageReceived,
+ QObject::connect(m_loop.get(), &MessageEngine::messageReceived,
this, &Voice::onMessageReceived);
}
Voice::~Voice()
{
- delete m_loop;
delete m_var;
}
diff --git a/voice/voice.h b/voice/voice.h
index ea0649b..2dc38c3 100644
--- a/voice/voice.h
+++ b/voice/voice.h
@@ -41,7 +41,7 @@ class Voice : public QObject
Q_INVOKABLE void getCBLpair(QString id);
private:
- MessageEngine *m_loop;
+ std::shared_ptr<MessageEngine> m_loop;
VoiceAgentRegistry *m_var;
void subscribeAgentToVshlEvents(QString id);
diff --git a/voice/voiceagentregistry.cpp b/voice/voiceagentregistry.cpp
index 62e8cd6..00eed87 100644
--- a/voice/voiceagentregistry.cpp
+++ b/voice/voiceagentregistry.cpp
@@ -29,12 +29,6 @@ VoiceAgentRegistry::VoiceAgentRegistry(Voice *voice, QQmlContext *context, QObje
vc(voice)
{
m_model = new VoiceAgentModel();
- QSortFilterProxyModel *model = new QSortFilterProxyModel();
- model->setSourceModel(m_model);
- model->setSortRole(VoiceAgentModel::VoiceAgentRoles::IdRole);
- model->setSortCaseSensitivity(Qt::CaseInsensitive);
- model->sort(0);
-
context->setContextProperty("VoiceAgentModel", m_model);
context->setContextProperty("VoiceAgent", this);
}
diff --git a/weather/weather.cpp b/weather/weather.cpp
index 298f32c..d4a8173 100644
--- a/weather/weather.cpp
+++ b/weather/weather.cpp
@@ -21,22 +21,21 @@
#include "eventmessage.h"
#include "messagefactory.h"
#include "messageengine.h"
+#include "messageenginefactory.h"
#include "weather.h"
Weather::Weather (QUrl &url, QObject * parent) :
- QObject(parent),
- m_mloop(nullptr)
+ QObject(parent)
{
- m_mloop = new MessageEngine(url);
- QObject::connect(m_mloop, &MessageEngine::connected, this, &Weather::onConnected);
- QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Weather::onDisconnected);
- QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Weather::onMessageReceived);
+ 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()
{
- delete m_mloop;
}
void Weather::onConnected()
diff --git a/weather/weather.h b/weather/weather.h
index 75054d5..93c5ec4 100644
--- a/weather/weather.h
+++ b/weather/weather.h
@@ -41,7 +41,7 @@ class Weather : public QObject
void conditionChanged(QString condition);
private:
- MessageEngine *m_mloop;
+ std::shared_ptr<MessageEngine> m_mloop;
QString m_temperature;
QString m_condition;