summaryrefslogtreecommitdiffstats
path: root/message.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 /message.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 'message.h')
-rw-r--r--message.h93
1 files changed, 17 insertions, 76 deletions
diff --git a/message.h b/message.h
index 4270651..0b5ad64 100644
--- a/message.h
+++ b/message.h
@@ -23,103 +23,44 @@
#include <QJsonDocument>
#include <QJsonObject>
-enum MessageId {
+enum class MessageId {
+ Invalid = 0,
Call = 2,
RetOk = 3,
RetErr = 4,
Event = 5,
};
-enum class MessageType {
- GenericMessage,
- ResponseRequestMessage,
- TelephonyEventMessage,
- WeatherEventMessage,
- MediaplayerEventMessage,
- NetworkEventMessage,
- BluetoothEventMessage,
- PbapEventMessage,
- RadioEventMessage,
- MapEventMessage,
- NavigationEventMessage,
- VoiceEventMessage,
- SignalComposerEventMessage,
- GuiMetadataCapabilityEventMessage,
- HVACEventMessage,
-};
+class QWebSocket;
-class Message : public QObject
+class Message
{
- Q_OBJECT
- Q_ENUM(MessageId)
-
public:
Message();
+ void setAdditionalData(QByteArray data) {};
+ QByteArray send(QWebSocket& transport, unsigned int callid);
- bool fromJson(QByteArray jsonData);
- virtual bool fromJDoc(QJsonDocument jdocData);
- QByteArray toJson(QJsonDocument::JsonFormat format = QJsonDocument::Compact);
- bool createRequest(QString api, QString verb, QJsonValue parameter = "None");
- inline QString eventApi() const
- {
- return m_event_api;
- }
-
- inline QString eventName() const
- {
- return m_event_name;
- }
-
- inline QJsonObject eventData() const
+ inline bool isComplete() const
{
- return m_event_data;
- }
-
- inline QString replyStatus() const
- {
- return m_reply_status;
- }
-
- inline QString replyInfo() const
- {
- return m_reply_info;
- }
-
- inline QJsonObject replyData() const
- {
- return m_reply_data;
- }
-
- inline bool isEvent() const
- {
- return m_event;
- }
-
- inline bool isReply() const
- {
- return m_reply;
+ return m_init;
}
- inline bool isValid() const
+ virtual bool getCallId(unsigned int *id) const
{
- return m_init;
+ return false;
}
- inline void setCallId(qint32 callId) {
- m_request["callid"] = callId;
- }
+ static MessageId isValid(QJsonDocument );
- inline QMap<QString, QVariant> requestData() const
- {
- return m_request;
- }
+ virtual bool isEvent() = 0;
+ virtual bool isReply() = 0;
protected:
- bool m_event, m_init, m_reply;
- QString m_event_api, m_event_name, m_reply_info, m_reply_status, m_reply_uuid;
- QMap<QString, QVariant> m_request;
+ virtual void updateCallId(unsigned int id) {};
+ virtual QByteArray serialize(QJsonDocument::JsonFormat format = QJsonDocument::Compact);
+
+ bool m_init;
QJsonDocument m_jdoc;
- QJsonObject m_event_data, m_reply_data;
};
#endif // MESSAGE_H