From f5b66594d5488c8754293410a0902d165b3e2eee Mon Sep 17 00:00:00 2001 From: Alok Anand Date: Sat, 20 Aug 2016 23:51:47 +0530 Subject: [PATCH] Implemented incoming call channel creation --- connection.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++- connection.hpp | 9 +++-- 2 files changed, 109 insertions(+), 4 deletions(-) diff --git a/connection.cpp b/connection.cpp index 8dfa9ad..827e1e9 100644 --- a/connection.cpp +++ b/connection.cpp @@ -3,7 +3,7 @@ #include "connection.hpp" #include "common.hpp" #include "protocol.hpp" - +#include "ringcallchannel.hpp" using namespace Bell; Connection::Connection(const QDBusConnection&dbusConnection, const QString &cmName, const QString &protocolName, const QVariantMap ¶meters) @@ -95,6 +95,7 @@ setSelfContact(_self, mRingID); /* Set Callbacks for client */ setConnectCallback(Tp::memFun(this, &Connection::doConnect)); setInspectHandlesCallback(Tp::memFun(this, &Connection::inspectHandles)); +setCreateChannelCallback(Tp::memFun(this, &Connection::createChannel)); setRequestHandlesCallback(Tp::memFun(this, &Connection::requestHandles)); connect(this, SIGNAL(disconnected()), SLOT(doDisconnect())); } @@ -169,6 +170,7 @@ void Connection::onVolatileAccountDetailsChanged(QString accountID, MapStringStr void Connection::onConnected() { setStatus(Tp::ConnectionStatusConnected, Tp::ConnectionStatusReasonRequested); + isConnected = true; mSelfPresence.type = Tp::ConnectionPresenceTypeAvailable; mSelfPresence.status = QLatin1String("available"); // Tp::SimpleContactPresences presences; @@ -193,6 +195,34 @@ void Connection::onIncomingMessage(QString one, QString two, MapStringString map void Connection::onIncomingCall(QString accountID, QString callID, QString contact) { qDebug() << Q_FUNC_INFO << accountID << callID << contact ; + QString contactAlias; + QString contactID; + QStringList contactDetails = contact.split(" <"); + if(!contactDetails.isEmpty()) + { + contactAlias = contactDetails.first(); + contactID = (contactDetails.last()).remove('>'); + } + uint handle = ensureHandle(contactID); + // TODO setAlias to add the contact here. + uint initiatorHandle = handle; + QVariantMap request; + // request[TP_QT_IFACE_CHANNEL + QLatin1String(".Requested")] = false; + request[TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")] = TP_QT_IFACE_CHANNEL_TYPE_CALL; + request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")] = Tp::HandleTypeContact; + request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")] = handle; + request[TP_QT_IFACE_CHANNEL + QLatin1String(".InitiatorHandle")] = initiatorHandle; + request["Call_ID"] = callID; + + +bool yours; +Tp::DBusError error; +Tp::BaseChannelPtr channel = ensureChannel(request, yours, false, &error); + +if (error.isValid() || channel.isNull()) { + qWarning() << "error creating the channel " << error.name() << error.message(); + return; +} } @@ -288,3 +318,75 @@ Tp::ContactAttributesMap Connection::getContactAttributes(const Tp::UIntList &ha } return attributesMap; } + +Tp::BaseChannelPtr Connection::createChannel(const QVariantMap &request, Tp::DBusError *error) +{ + qDebug() << Q_FUNC_INFO << "Here"; + // for(QVariantMap::const_iterator iter = request.begin(); iter != request.end(); ++iter) { + // qDebug() << iter.key() << iter.value(); + // } + uint targetHandleType = Tp::HandleTypeNone; + uint targetHandle = 0; + QString targetID; + + bool requested = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".Requested")).toBool(); + const QString channelType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType")).toString(); + targetHandleType = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")).toUInt(); + + switch (targetHandleType) + { + case Tp::HandleTypeContact: + if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle"))) + { + targetHandle = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")).toUInt(); + targetID = mHandles[targetHandle]; + } + else if (request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetID"))) + { + targetID = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetID")).toString(); + targetHandle = ensureHandle(targetID); + } + break; + default: + if (error) + { + error->set(TP_QT_ERROR_INVALID_ARGUMENT, QLatin1String("Unknown Handle type for target")); + return Tp::BaseChannelPtr(); + } + break; + } + + if (targetHandleType == Tp::HandleTypeNone) + { + if (error) + { + error->set(TP_QT_ERROR_INVALID_ARGUMENT, QLatin1String("Target handle type is not present in the request details.")); + } + return Tp::BaseChannelPtr(); + } + if(targetID.isEmpty()) + { + if(error) + { + error->set(TP_QT_ERROR_INVALID_HANDLE, QLatin1String("Target handle is unknown.")); + } + return Tp::BaseChannelPtr(); + } + uint initiatorHandle = request.value(TP_QT_IFACE_CHANNEL + QLatin1String(".InitiatorHandle")).toUInt(); + + if (channelType == TP_QT_IFACE_CHANNEL_TYPE_TEXT) { + if (targetHandleType == Tp::HandleTypeContact) { + qDebug() << "Create a text Channel"; + //TextChannelPtr textChannel = Create messaging channel. + //baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(textChannel)); + } + } else if (channelType == TP_QT_IFACE_CHANNEL_TYPE_CALL ) { + qDebug() << "Incoming call Channel"; + QString callID = request.value("Call_ID").toString(); + RingCallChannel *channel = new RingCallChannel(true, this, targetID, targetHandle, callID); + channel->baseChannel()->setInitiatorHandle(initiatorHandle); + return channel->baseChannel(); + // baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast()); + } + +} diff --git a/connection.hpp b/connection.hpp index e2805c2..b67b609 100644 --- a/connection.hpp +++ b/connection.hpp @@ -27,6 +27,7 @@ Tp::UIntList requestHandles(uint handleType, const QStringList &identifiers, Tp: QString getAlias(uint handle, Tp::DBusError *error); Tp::ContactAttributesMap getContactAttributes(const Tp::UIntList &handles, const QStringList &ifaces, Tp::DBusError *error); uint ensureHandle(const QString& identifier); +Tp::BaseChannelPtr createChannel(const QVariantMap &request, Tp::DBusError *error); void sendRegister(bool enable); void setAccountActive(bool enable); @@ -48,14 +49,16 @@ Tp::BaseConnectionContactListInterfacePtr mContactListInterface; Tp::BaseConnectionAliasingInterfacePtr mAliasingInterface; Tp::BaseConnectionAvatarsInterfacePtr mAvatarInterface; Tp::BaseConnectionRequestsInterfacePtr mRequestsInterface; -QDBusInterface mConfigurationManagerInterface; -QDBusInterface mCallManagerInterface; -QDBusInterface mInstanceInterface; Tp::SimplePresence mSelfPresence; QMap mHandles; QMap mIdentifiers; bool isConnected; long nextHandleId; + +public: +QDBusInterface mConfigurationManagerInterface; +QDBusInterface mCallManagerInterface; +QDBusInterface mInstanceInterface; }; }