summaryrefslogtreecommitdiffstats
path: root/telephony/telephony.cpp
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 /telephony/telephony.cpp
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 'telephony/telephony.cpp')
-rw-r--r--telephony/telephony.cpp85
1 files changed, 50 insertions, 35 deletions
diff --git a/telephony/telephony.cpp b/telephony/telephony.cpp
index e0fe2bd..0660156 100644
--- a/telephony/telephony.cpp
+++ b/telephony/telephony.cpp
@@ -16,8 +16,9 @@
#include <QDebug>
-#include "message.h"
-#include "telephonymessage.h"
+#include "callmessage.h"
+#include "eventmessage.h"
+#include "messagefactory.h"
#include "messageengine.h"
#include "telephony.h"
@@ -41,26 +42,35 @@ Telephony::~Telephony()
void Telephony::dial(QString number)
{
- TelephonyMessage *tmsg = new TelephonyMessage();
- tmsg->createRequest("dial", number);
- m_mloop->sendMessage(tmsg);
- delete tmsg;
+ std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
+ if (!msg)
+ return;
+
+ CallMessage *tmsg = static_cast<CallMessage*>(msg.get());
+ tmsg->createRequest("telephony", "dial", number);
+ m_mloop->sendMessage(std::move(msg));
}
void Telephony::answer()
{
- TelephonyMessage *tmsg = new TelephonyMessage();
- tmsg->createRequest("answer");
- m_mloop->sendMessage(tmsg);
- delete tmsg;
+ std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
+ if (!msg)
+ return;
+
+ CallMessage *tmsg = static_cast<CallMessage*>(msg.get());
+ tmsg->createRequest("telephony", "answer");
+ m_mloop->sendMessage(std::move(msg));
}
void Telephony::hangup()
{
- TelephonyMessage *tmsg = new TelephonyMessage();
- tmsg->createRequest("hangup");
- m_mloop->sendMessage(tmsg);
- delete tmsg;
+ std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
+ if (!msg)
+ return;
+
+ CallMessage *tmsg = static_cast<CallMessage*>(msg.get());
+ tmsg->createRequest("telephony", "hangup");
+ m_mloop->sendMessage(std::move(msg));
}
void Telephony::onConnected()
@@ -72,13 +82,15 @@ void Telephony::onConnected()
"terminatedCall",
"online"};
QStringListIterator eventIterator(events);
- TelephonyMessage *tmsg;
while (eventIterator.hasNext()) {
- tmsg = new TelephonyMessage();
- tmsg->createRequest("subscribe", eventIterator.next());
- m_mloop->sendMessage(tmsg);
- delete tmsg;
+ std::unique_ptr<Message> msg = MessageFactory::getInstance().createOutboundMessage(MessageId::Call);
+ if (!msg)
+ return;
+
+ CallMessage *tmsg = static_cast<CallMessage*>(msg.get());
+ tmsg->createRequest("telephony", "subscribe", eventIterator.next());
+ m_mloop->sendMessage(std::move(msg));
}
setConnected(true);
@@ -89,28 +101,31 @@ void Telephony::onDisconnected()
setConnected(false);
}
-void Telephony::onMessageReceived(MessageType type, Message *message)
+void Telephony::onMessageReceived(std::shared_ptr<Message> msg)
{
- if (type == MessageType::TelephonyEventMessage) {
- TelephonyMessage *tmsg = qobject_cast<TelephonyMessage*>(message);
-
- if (tmsg->isEvent()) {
- if (tmsg->isCallStateChanged()) {
- setCallState(tmsg->state());
- } else if (tmsg->isDialingCall()) {
- m_colp = tmsg->colp();
+ if (!msg)
+ return;
+
+ if (msg->isEvent()) {
+ std::shared_ptr<EventMessage> emsg = std::static_pointer_cast<EventMessage>(msg);
+ if (emsg->eventApi() != "telephony");
+ return;
+ QString ename = emsg->eventName();
+ QJsonObject data = emsg->eventData();
+ if (ename == "callStateChanged") {
+ setCallState(data.find("state").value().toString());
+ } else if (ename == "dialingCall") {
+ m_colp = data.find("colp").value().toString();
setCallState("dialing");
- } else if (tmsg->isIncomingCall()) {
- m_clip = tmsg->clip();
+ } else if (ename == "incomingCall") {
+ m_clip = data.find("clip").value().toString();
setCallState("incoming");
- } else if (tmsg->isTerminatedCall()) {
+ } else if (ename == "terminatedCall") {
setCallState("disconnected");
m_colp = "";
m_clip = "";
- } else if (tmsg->isOnline()) {
- setOnlineState(tmsg->connected());
+ } else if (ename == "online") {
+ setOnlineState(data.find("connected").value().toBool());
}
}
- }
- message->deleteLater();
}