summaryrefslogtreecommitdiffstats
path: root/mediaplayer
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 /mediaplayer
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 'mediaplayer')
-rw-r--r--mediaplayer/CMakeLists.txt4
-rw-r--r--mediaplayer/mediaplayer.cpp67
-rw-r--r--mediaplayer/mediaplayer.h5
3 files changed, 43 insertions, 33 deletions
diff --git a/mediaplayer/CMakeLists.txt b/mediaplayer/CMakeLists.txt
index fd7e3f3..75bbca1 100644
--- a/mediaplayer/CMakeLists.txt
+++ b/mediaplayer/CMakeLists.txt
@@ -1,2 +1,2 @@
-add_headers(mediaplayer.h mediaplayermessage.h)
-add_sources(mediaplayer.cpp mediaplayermessage.cpp)
+add_headers(mediaplayer.h)
+add_sources(mediaplayer.cpp)
diff --git a/mediaplayer/mediaplayer.cpp b/mediaplayer/mediaplayer.cpp
index 69b2dea..e723d5d 100644
--- a/mediaplayer/mediaplayer.cpp
+++ b/mediaplayer/mediaplayer.cpp
@@ -16,9 +16,10 @@
#include <QDebug>
-#include "message.h"
-#include "mediaplayermessage.h"
+#include "callmessage.h"
+#include "eventmessage.h"
#include "messageengine.h"
+#include "messagefactory.h"
#include "mediaplayer.h"
@@ -89,13 +90,15 @@ void Mediaplayer::updatePlaylist(QVariantMap playlist)
void Mediaplayer::control(QString control, QJsonObject parameter)
{
- MediaplayerMessage *tmsg = new MediaplayerMessage();
+ std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
+ if (!msg)
+ return;
+ CallMessage* mpmsg = static_cast<CallMessage*>(msg.get());
parameter.insert("value", control);
- tmsg->createRequest("controls", parameter);
- m_mloop->sendMessage(tmsg);
- delete tmsg;
+ mpmsg->createRequest("mediaplayer", "controls", parameter);
+ m_mloop->sendMessage(std::move(msg));
}
@@ -186,44 +189,54 @@ void Mediaplayer::loop(QString state)
void Mediaplayer::onConnected()
{
QStringListIterator eventIterator(events);
- MediaplayerMessage *tmsg;
while (eventIterator.hasNext()) {
- tmsg = new MediaplayerMessage();
+ std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
+ if (!msg)
+ return;
+
+ CallMessage* mpmsg = static_cast<CallMessage*>(msg.get());
QJsonObject parameter;
parameter.insert("value", eventIterator.next());
- tmsg->createRequest("subscribe", parameter);
- m_mloop->sendMessage(tmsg);
- delete tmsg;
+ mpmsg->createRequest("mediaplayer", "subscribe", parameter);
+ m_mloop->sendMessage(std::move(msg));
}
}
void Mediaplayer::onDisconnected()
{
QStringListIterator eventIterator(events);
- MediaplayerMessage *tmsg;
while (eventIterator.hasNext()) {
- tmsg = new MediaplayerMessage();
+ std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
+ if (!msg)
+ return;
+
+ CallMessage* mpmsg = static_cast<CallMessage*>(msg.get());
QJsonObject parameter;
parameter.insert("value", eventIterator.next());
- tmsg->createRequest("unsubscribe", parameter);
- m_mloop->sendMessage(tmsg);
- delete tmsg;
+ mpmsg->createRequest("mediaplayer", "unsubscribe", parameter);
+ m_mloop->sendMessage(std::move(msg));
}
}
-void Mediaplayer::onMessageReceived(MessageType type, Message *message)
+void Mediaplayer::onMessageReceived(std::shared_ptr<Message> msg)
{
- if (type == MessageType::MediaplayerEventMessage) {
- MediaplayerMessage *tmsg =
- qobject_cast<MediaplayerMessage*>(message);
-
- if (tmsg->isEvent()) {
- if (tmsg->isPlaylistEvent()) {
- updatePlaylist(tmsg->eventData().toVariantMap());
- } else if (tmsg->isMetadataEvent()) {
- QVariantMap map = tmsg->eventData().toVariantMap();
+ 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 != "mediaplayer")
+ return;
+
+ if (ename == "playlist") {
+ updatePlaylist(data.toVariantMap());
+ } else if (ename == "metadata") {
+ QVariantMap map = data.toVariantMap();
if (map.contains("track")) {
QVariantMap track = map.value("track").toMap();
@@ -247,6 +260,4 @@ void Mediaplayer::onMessageReceived(MessageType type, Message *message)
emit metadataChanged(map);
}
}
- }
- message->deleteLater();
}
diff --git a/mediaplayer/mediaplayer.h b/mediaplayer/mediaplayer.h
index f3930f4..374ab06 100644
--- a/mediaplayer/mediaplayer.h
+++ b/mediaplayer/mediaplayer.h
@@ -17,6 +17,7 @@
#ifndef MEDIAPLAYER_H
#define MEDIAPLAYER_H
+#include <memory>
#include <QObject>
#include <QtQml/QQmlContext>
#include <QtQml/QQmlListProperty>
@@ -24,8 +25,6 @@
class MessageEngine;
class Message;
-enum class MessageType;
-
class Playlist : public QObject
{
Q_OBJECT
@@ -106,7 +105,7 @@ class Mediaplayer : public QObject
void onConnected();
void onDisconnected();
- void onMessageReceived(MessageType, Message*);
+ void onMessageReceived(std::shared_ptr<Message>);
const QStringList events {
"playlist",