3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
6 Based on Telepathy-SNOM with copyright notice below.
10 * Telepathy SNOM VoIP phone connection manager
11 * Copyright (C) 2006 by basyskom GmbH
12 * @author Tobias Hunger <info@basyskom.de>
14 * This library is free software; you can redisQObject::tribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License version 2.1 as published by the Free Software Foundation.
18 * This library is disQObject::tributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the
25 * Free Software Foundation, Inc.,
26 * 51 Franklin SQObject::treet, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "connection.h"
30 #include "connectionadaptor.h"
31 #include "connectioninterfacerequestsadaptor.h"
32 #include "connectioninterfacerequeststypes.h"
33 #include "connectioninterfacecapabilitiesadaptor.h"
34 #include "connectioninterfacecapabilitiestypes.h"
36 #include "vicarcallrouterproxy.h"
38 #include <QtCore/QDebug>
39 #include <QtCore/QCoreApplication>
40 #include <QtCore/QVariantMap>
41 #include <QDBusMessage>
47 static const QString protocol_vicar("tel");
49 static const QString connection_service_name_prefix("org.freedesktop.Telepathy.Connection.vicar." + protocol_vicar + '.');
50 static const QString connection_object_path_prefix("/org/freedesktop/Telepathy/Connection/vicar/" + protocol_vicar + '/');
51 static const QString requests_interface("org.freedesktop.Telepathy.Connection.Interface.Requests");
54 using namespace org::maemo;
57 class ConnectionPrivate
60 ConnectionPrivate(Connection * p,
61 const QString & acc) :
63 connection_status(Connection::Disconnected),
64 adaptor(new ConnectionAdaptor(p)),
65 connIfaceReqsAdaptor(new ConnectionInterfaceRequestsAdaptor(p)),
68 Q_ASSERT(0 != adaptor);
73 qDebug() << "VICaR: Connection Destructing";
76 const QString account;
78 Connection::Status connection_status;
79 ConnectionAdaptor * adaptor;
80 ConnectionInterfaceRequestsAdaptor * connIfaceReqsAdaptor;
81 Connection * const parent;
84 // ---------------------------------------------------------------------------
86 Connection::Connection(const QString & account,
89 d(new ConnectionPrivate(this, account))
92 Q_ASSERT(!account.isEmpty());
94 /* -- Set the Dynamic property "Interfaces" ---
96 Apparently it is not sufficient to implement an additional interface like Conn.I.Requests.
97 We have to assign the list of additional interfaces to the DBus Property Interfaces.
99 The actual DBus property "Interfaces" is declared in ConnectionAdaptor class,
100 which is our Connection Interface implementation.
103 QStringList interfaces = QStringList(requests_interface);
104 this->setProperty("Interfaces",interfaces);
107 //Set the property RequestableChannelClasses
108 org::freedesktop::Telepathy::RequestableChannelClassList requestableChannelClasses;
110 uint targetHandleType(1);
112 org::freedesktop::Telepathy::RequestableChannelClass requestableChannelClass1;
113 requestableChannelClass1.fixedProperties.insert("org.freedesktop.Telepathy.Channel.TargetHandleType",targetHandleType);
114 requestableChannelClass1.fixedProperties.insert("org.freedesktop.Telepathy.Channel.ChannelType","org.freedesktop.Telepathy.Channel.Type.StreamedMedia");
116 requestableChannelClass1.allowedProperties.append("org.freedesktop.Telepathy.Channel.TargetHandle");
117 requestableChannelClass1.allowedProperties.append("org.freedesktop.Telepathy.Channel.Type.StreamedMedia.InitialAudio");
119 requestableChannelClasses.append(requestableChannelClass1);
121 org::freedesktop::Telepathy::RequestableChannelClass requestableChannelClass2;
122 requestableChannelClass2.fixedProperties.insert("org.freedesktop.Telepathy.Channel.TargetHandleType",targetHandleType);
123 requestableChannelClass2.fixedProperties.insert("org.freedesktop.Telepathy.Channel.ChannelType","org.freedesktop.Telepathy.Channel.Type.StreamedMedia");
125 requestableChannelClass2.allowedProperties.append("com.nokia.Telepathy.Channel.Interface.Conference.InitialMembers");
126 requestableChannelClass2.allowedProperties.append("org.freedesktop.Telepathy.Channel.TargetHandleType");
127 requestableChannelClass2.allowedProperties.append("org.freedesktop.Telepathy.Channel.Type.StreamedMedia.InitialAudio");
129 requestableChannelClasses.append(requestableChannelClass2);
132 this->setProperty("RequestableChannelClasses",QVariant::fromValue(requestableChannelClasses));
136 qDebug() << "VICaR: Connection set up.";
139 Connection::~Connection()
141 qDebug() << "VICaR: Connection closed.";
145 bool Connection::registerObject()
147 if (!QDBusConnection::sessionBus().registerService(serviceName()))
149 qDebug() << "VICaR: Problem registering connection service:" << serviceName();
153 if (!QDBusConnection::sessionBus().registerObject(objectPath().path(),
156 qDebug() << "VICaR: Problem registering object path:" << objectPath().path();
162 void Connection::unregisterObject()
164 qDebug() << "VICaR: Unregistering Connection object from DBus";
165 QDBusConnection::sessionBus().unregisterObject(objectPath().path());
166 QDBusConnection::sessionBus().unregisterService(serviceName());
169 QString Connection::name() const
171 return QString("vicar");
175 QString Connection::serviceName() const
176 { return connection_service_name_prefix + name(); }
178 QDBusObjectPath Connection::objectPath() const
179 { return QDBusObjectPath(connection_object_path_prefix + name()); }
182 //org.freedesktop.Telepathy.Connection
183 void Connection::Connect()
186 Since this is not a "real" Telepathy Connection to a SIP, Chat server,
187 I am not connecting to anything.
189 qDebug() << "VICaR: Changing status to Connected...";
190 d->connection_status = Connection::Connected;
192 //Let all the Telepathy clients know that connection status has changed
193 qDebug() << "VICaR: Emitting StatusChanged.";
194 emit StatusChanged(d->connection_status, ReasonRequested);
198 void Connection::Disconnect()
200 qDebug() << "VICaR: Changing status to Disconnected...";
201 //We don't have any Handles to release here. So just change the status to Disconnected
202 d->connection_status = Connection::Disconnected;
204 qDebug() << "VICaR: Emitting StatusChanged";
205 emit StatusChanged(d->connection_status, ReasonRequested);
207 //As per Telepathy specfication, on disconnect we need to unregister from Dbus and destroy the object.
212 QStringList Connection::GetInterfaces()
215 if (d->connection_status != Connected)
217 sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
218 "VICaR - Unable to get Interfaces List. The connection is no longer available.");
221 result <<requests_interface;
225 QString Connection::GetProtocol()
226 { return protocol_vicar; }
228 uint Connection::GetStatus()
229 { return static_cast<uint>(d->connection_status); }
231 uint Connection::GetSelfHandle()
233 qDebug() << "VICaR: GetSelfHandle";
234 if (d->connection_status != Connected)
236 sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
237 "VICaR - Unable to get Self Handle. The connection is no longer available.");
238 qDebug() << "VICaR: NOT CONNECTED when requesting selfhandle!";
242 //WARNING: Incomplete implemenation
244 qDebug() << "VICaR: Returning Handle" << handle << "as self handle.";
248 QList<uint> Connection::RequestHandles(uint handle_type,
249 const QStringList & names)
255 if (d->connection_status != Connected)
257 sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
258 "VICaR - Unable to process handle request. The connection is no longer available.");
261 if (handle_type != HandleContact)
263 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
264 "VICaR - Supports handles of type Contact only.");
268 //WARNING: Incomplete implementation. Create a handle and return the value here.
272 void Connection::HoldHandles(const uint handle_type, const QList<uint> &handles)
275 qDebug() << "VICaR: HoldHandles.";
276 if (d->connection_status != Connected)
278 sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
279 "VICaR - Unable to process handle request. The connection is no longer available.");
282 if (handle_type != HandleContact)
284 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
285 "VICaR - Supports handles of type Contact only.");
289 //WARNING: Incomplete implementation
292 QStringList Connection::InspectHandles(const uint handle_type,
293 const QList<uint> &handles)
299 if (d->connection_status != Connected)
301 sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
302 "VICaR - Unable to process handle request. The connection is no longer available.");
305 if (handle_type != HandleContact)
307 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
308 "VICaR - Supports handles of type Contact only.");
312 //WARNING: Incomplete implementation
316 void Connection::ReleaseHandles(const uint handle_type, const QList<uint> &handles)
319 if (d->connection_status != Connected)
321 sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
322 "VICaR - Unable to release handle. The connection is no longer available.");
323 qDebug() << "VICaR: Releasing Handle while connection is no longer connected.";
326 if (handle_type != HandleContact)
328 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
329 "VICaR - Supports handles of type Contact only.");
330 qDebug() << "VICaR: Trying to release a Handle that is not a contact.";
334 //WARNING: Incomplete implementation
337 org::freedesktop::Telepathy::ChannelInfoList Connection::ListChannels()
339 org::freedesktop::Telepathy::ChannelInfoList result;
340 if (d->connection_status != Connected)
342 sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
343 "VICaR - Unable to list channels. The connection is no longer available.");
347 //WARNING: Incomplete implementation
348 //Btw - We never have any channels :)
353 QDBusObjectPath Connection::RequestChannel(const QString &type,
354 uint handle_type, uint handle,
355 bool suppress_handler)
358 Q_UNUSED(suppress_handler);
359 //This method is deprecated and no longer used as per latest Telepathy spec
361 if (type != QString("org.freedesktop.Telepathy.Channel.Type.StreamedMedia"))
363 sendErrorReply("org.freedesktop.Telepathy.Error.NotImplemented",
364 "VICaR: Failed to create channel: Channel type not implemented.");
365 return QDBusObjectPath();
368 if (handle_type != HandleContact )
370 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidHandle",
371 "VICaR: Failed to create channel: Handle type not supported.");
372 return QDBusObjectPath();
375 if (d->connection_status != Connected)
377 sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
378 "VICaR: Failed to create channel: Connection is Disconnected.");
379 return QDBusObjectPath();
382 //TODO VICaR Specific code here
384 //WARNING: Incomplete implementation, we are not creating any channels here at all.
385 QDBusObjectPath channel_path;
389 //org.freedesktop.Telepathy.Connection.Interface.Requests
390 QDBusObjectPath Connection::CreateChannel(const QVariantMap &request,
391 QVariantMap &channel_properties)
393 Q_UNUSED(channel_properties);
394 Q_ASSERT(!request.isEmpty());
395 qDebug() << "VICaR: CreateChannel";
396 qDebug() << " Request details are: "<< request;
398 //Ideally we need to emit NewChannels signal here, but since we are not creating any channels we ignore it
400 //WARNING: VICaR - Specific implementation
401 return processChannel(request);
405 bool Connection::EnsureChannel(const QVariantMap &request,
406 QDBusObjectPath &channel_object,
407 QVariantMap &channel_properties)
409 Q_UNUSED(channel_object);
410 Q_UNUSED(channel_properties);
411 Q_ASSERT(!request.isEmpty());
412 qDebug() << "VICaR: EnsureChannel";
413 qDebug() << " Request details are: "<< request;
415 //WARNING: Incomplete implementation
416 processChannel(request);
421 QDBusObjectPath Connection::processChannel(const QVariantMap &request){
423 QDBusObjectPath channel_path;
425 if (!request.contains("org.freedesktop.Telepathy.Channel.TargetID")){
426 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
427 "VICaR - Invalid request. TargetID (Phone Number) not included.");
431 QVariant vNumber = request.value("org.freedesktop.Telepathy.Channel.TargetID");
432 if (!vNumber.isValid()){
433 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
434 "VICaR - Invalid request. Phone Number is not valid.");
437 QString strNumber = vNumber.toString();
438 if (strNumber.isEmpty()){
439 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
440 "VICaR - Invalid request. Phone Number is empty.");
443 else if (strNumber == "publish" || strNumber == "subscribe"){
444 //Deny the persistent Mission control requests to publish and subscribe
445 QString strError = "VICaR - Invalid request. " + strNumber + " is not supported.";
446 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
452 //Only allow requests with handle type as contact
453 QVariant vTargetHandleType = request.value("org.freedesktop.Telepathy.Channel.TargetHandleType");
454 uint intTargetHandleType = vTargetHandleType.toUInt();
455 if (intTargetHandleType != HandleContact)
457 QString strMessage = "VICaR - Supports handles of type Contact only. Recieved handle type ";
458 strMessage.append(vTargetHandleType.toString());
460 sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
467 Send an error reply to Tp Client (Mission Control) to force it to close the active channel.
468 Once it recieves the reply, the client does not bother what we return.
472 sendErrorReply("org.freedesktop.Telepathy.Error.NotAvailable",
473 "VICaR - Creating a new channel to "+strNumber+" via Ring.");
476 //Initiate a new call to CC/Google Out/Skype-out number by requesting a new channel with Ring CM.
478 VicarCallRouterProxy *callRouter = new VicarCallRouterProxy(APPLICATION_DBUS_SERVICE,APPLICATION_DBUS_PATH,QDBusConnection::sessionBus(),this);
480 callRouter->callInternationalNumber(strNumber);
482 qDebug() << "VICaR: Call is processed.";
488 //org.freedesktop.Telepathy.Connection.Interface.Capabilities
489 org::freedesktop::Telepathy::ContactCapabilitiesList Connection::GetCapabilities(const QList<uint> &Handles){
491 org::freedesktop::Telepathy::ContactCapabilitiesList capabilities;
497 org::freedesktop::Telepathy::CapabilityPairList Connection::AdvertiseCapabilities(org::freedesktop::Telepathy::CapabilityPairList Add, const QStringList &Remove){
500 org::freedesktop::Telepathy::CapabilityPairList capabilities;