diff options
Diffstat (limited to 'telephony')
-rw-r--r-- | telephony/CMakeLists.txt | 4 | ||||
-rw-r--r-- | telephony/telephony.cpp | 85 | ||||
-rw-r--r-- | telephony/telephony.h | 5 |
3 files changed, 54 insertions, 40 deletions
diff --git a/telephony/CMakeLists.txt b/telephony/CMakeLists.txt index 1dfcd63..196ad53 100644 --- a/telephony/CMakeLists.txt +++ b/telephony/CMakeLists.txt @@ -1,2 +1,2 @@ -add_headers(telephony.h telephonymessage.h) -add_sources(telephony.cpp telephonymessage.cpp) +add_headers(telephony.h) +add_sources(telephony.cpp) 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(); } diff --git a/telephony/telephony.h b/telephony/telephony.h index 097310f..ca1e52a 100644 --- a/telephony/telephony.h +++ b/telephony/telephony.h @@ -17,13 +17,12 @@ #ifndef TELEPHONY_H #define TELEPHONY_H +#include <memory> #include <QObject> class MessageEngine; class Message; -enum class MessageType; - class Telephony : public QObject { Q_OBJECT @@ -78,7 +77,7 @@ class Telephony : public QObject QString m_colp; void onConnected(); void onDisconnected(); - void onMessageReceived(MessageType, Message*); + void onMessageReceived(std::shared_ptr<Message>); }; #endif // TELEPHONY_H |