summaryrefslogtreecommitdiffstats
path: root/messageengine.h
diff options
context:
space:
mode:
authorRaquel Medina <raquel.medina@konsulko.com>2020-03-18 23:56:31 +0100
committerRaquel Medina <raquel.medina@konsulko.com>2020-03-23 14:02:28 +0100
commit0ed292d3ccf93c889734960676a321d1166d3f66 (patch)
treeb8d64d1685d2f4bf599ab3867a0d3ff557ff0479 /messageengine.h
parent5c750385d02116a92fa4c120ccc26abb8267bc97 (diff)
rework message hierarchy
Rework message hierarchy with the final objective of splitting libqtappfw into several libraries. This commit carries the following changes: - Simplify message hierarchy, keeping abstract Message class, adding specialization for call and event messages, keeping ResponseMessage, and removing all module specific specializations. - Add MessageFactory class to create message objects. - Change messages life cycle: using smart pointers and removing QObject from message hierarchy (a Message is not a QObject anymore and thus 'deleteLater()' is not available). - Adapt all modules to use new message hierarchy. - Keep ResponseMessage original constructor to avoid breaking TaskManager. - Message constructors have been kept public, but will go private on a follow-up patch (once TaskManager class has been modified to use new MessageFactory). Bug-AGL: SPEC-3112 Signed-off-by: Raquel Medina <raquel.medina@konsulko.com> Change-Id: I3a7a6325209ddeca2293f1ac745371861a947bfb
Diffstat (limited to 'messageengine.h')
-rw-r--r--messageengine.h14
1 files changed, 6 insertions, 8 deletions
diff --git a/messageengine.h b/messageengine.h
index 6b2233f..b682ec5 100644
--- a/messageengine.h
+++ b/messageengine.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 Konsulko Group
+ * 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.
@@ -17,8 +17,8 @@
#ifndef MESSAGEENGINE_H
#define MESSAGEENGINE_H
-#include <QMutex>
-#include <QThread>
+#include <memory>
+#include <atomic>
#include <QUrl>
#include <QWebSocket>
@@ -29,13 +29,12 @@ class MessageEngine : public QObject
Q_OBJECT
public:
explicit MessageEngine(const QUrl &url, QObject *parent = Q_NULLPTR);
- bool sendMessage(Message *message);
- unsigned int requestCallId();
+ bool sendMessage(std::unique_ptr<Message> message);
Q_SIGNALS:
void disconnected();
void connected();
- void messageReceived(MessageType type, Message *message);
+ void messageReceived(std::shared_ptr<Message> message);
private Q_SLOTS:
void onConnected();
@@ -46,8 +45,7 @@ class MessageEngine : public QObject
QWebSocket m_websocket;
QMap<qint32, QByteArray> m_calls;
QUrl m_url;
- QMutex m_mutex;
- unsigned int m_callid;
+ std::atomic<unsigned int> m_callid;
};
#endif // MESSAGEENGINE_H