summaryrefslogtreecommitdiffstats
path: root/signal-composer
diff options
context:
space:
mode:
Diffstat (limited to 'signal-composer')
-rw-r--r--signal-composer/CMakeLists.txt4
-rw-r--r--signal-composer/signalcomposer.cpp74
-rw-r--r--signal-composer/signalcomposer.h5
3 files changed, 45 insertions, 38 deletions
diff --git a/signal-composer/CMakeLists.txt b/signal-composer/CMakeLists.txt
index 18f3a0a..f517d27 100644
--- a/signal-composer/CMakeLists.txt
+++ b/signal-composer/CMakeLists.txt
@@ -1,2 +1,2 @@
-add_headers(signalcomposer.h signalcomposermessage.h)
-add_sources(signalcomposer.cpp signalcomposermessage.cpp)
+add_headers(signalcomposer.h)
+add_sources(signalcomposer.cpp)
diff --git a/signal-composer/signalcomposer.cpp b/signal-composer/signalcomposer.cpp
index 59395f5..1296162 100644
--- a/signal-composer/signalcomposer.cpp
+++ b/signal-composer/signalcomposer.cpp
@@ -16,8 +16,9 @@
#include <QDebug>
-#include "message.h"
-#include "signalcomposermessage.h"
+#include "callmessage.h"
+#include "eventmessage.h"
+#include "messagefactory.h"
#include "messageengine.h"
#include "signalcomposer.h"
@@ -40,56 +41,63 @@ SignalComposer::~SignalComposer()
void SignalComposer::onConnected()
{
QStringListIterator eventIterator(events);
- SignalComposerMessage *tmsg;
while (eventIterator.hasNext()) {
- tmsg = new SignalComposerMessage();
+ 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("subscribe", parameter);
- m_mloop->sendMessage(tmsg);
- delete tmsg;
+ tmsg->createRequest("signal-composer", "subscribe", parameter);
+ m_mloop->sendMessage(std::move(msg));
}
}
void SignalComposer::onDisconnected()
{
QStringListIterator eventIterator(events);
- SignalComposerMessage *tmsg;
while (eventIterator.hasNext()) {
- tmsg = new SignalComposerMessage();
+ 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("unsubscribe", parameter);
- m_mloop->sendMessage(tmsg);
- delete tmsg;
+ tmsg->createRequest("signal-composer", "unsubscribe", parameter);
+ m_mloop->sendMessage(std::move(msg));
}
}
-void SignalComposer::onMessageReceived(MessageType type, Message *message)
+void SignalComposer::onMessageReceived(std::shared_ptr<Message> msg)
{
- if (type == MessageType::SignalComposerEventMessage) {
- SignalComposerMessage *tmsg = qobject_cast<SignalComposerMessage*>(message);
+ if (!msg)
+ return;
+
+ if (msg->isEvent()) {
+ std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
+ if (emsg->eventApi() != "signal-composer")
+ return;
- if (tmsg->isEvent()) {
- QString uid = tmsg->eventData().value("uid").toString();
- QVariant v = tmsg->eventData().value("value").toVariant();
- QString value;
- if(v.canConvert(QMetaType::QString))
- value = v.toString();
- else
- qWarning() << "Unconvertible value type for uid " << uid;
- QString units = tmsg->eventData().value("unit").toString();
- v = tmsg->eventData().value("timestamp").toVariant();
- quint64 timestamp = 0;
- if(v.canConvert(QMetaType::ULongLong))
- timestamp = v.toULongLong();
- else
- qWarning() << "Unconvertible timestamp type for uid " << uid;
+ 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);
- }
+ emit signalEvent(uid, value, units, timestamp);
}
- message->deleteLater();
}
diff --git a/signal-composer/signalcomposer.h b/signal-composer/signalcomposer.h
index 13d26c6..382b6e9 100644
--- a/signal-composer/signalcomposer.h
+++ b/signal-composer/signalcomposer.h
@@ -17,14 +17,13 @@
#ifndef SIGNALCOMPOSER_H
#define SIGNALCOMPOSER_H
+#include <memory>
#include <QObject>
#include <QJsonArray>
class MessageEngine;
class Message;
-enum class MessageType;
-
class SignalComposer : public QObject
{
Q_OBJECT
@@ -41,7 +40,7 @@ class SignalComposer : public QObject
void onConnected();
void onDisconnected();
- void onMessageReceived(MessageType, Message*);
+ void onMessageReceived(std::shared_ptr<Message>);
const QStringList events {
"event.vehicle.speed",