summaryrefslogtreecommitdiffstats
path: root/mediaplayer
diff options
context:
space:
mode:
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",