a197955dc81a9faa65cfc9174c17432ca338814c
[vicar] / src / vicar-telepathy / cpp / connection.cpp
1 /*
2 @version: 0.6
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5
6 Based on Telepathy-SNOM with copyright notice below.
7 */
8
9 /*
10  * Telepathy SNOM VoIP phone connection manager
11  * Copyright (C) 2006 by basyskom GmbH
12  *  @author Tobias Hunger <info@basyskom.de>
13  *
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.
17  *
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.
22  *
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 Street, Fifth Floor, Boston, MA  02110-1301  USA
27  */
28
29 #include "connection.h"
30 #include "connectionadaptor.h"
31 #include "connectioninterfacerequestsadaptor.h"
32 #include "connectioninterfacerequeststypes.h"
33 #include "connectioninterfacecapabilitiesadaptor.h"
34 #include "connectioninterfacecapabilitiestypes.h"
35 #include "names.h"
36 #include "vicarcallrouterproxy.h"
37 #include <logutility.h>
38
39 #include <QtCore/QDebug>
40 #include <QtCore/QCoreApplication>
41 #include <QtCore/QVariantMap>
42 #include <QDBusMessage>
43 #include <QDBusReply>
44
45 #define SELF_HANDLE 1  //Any non-zero
46
47
48 namespace
49 {
50 static const QString protocol_vicar("tel");
51
52 static const QString connection_service_name_prefix("org.freedesktop.Telepathy.Connection.vicar." + protocol_vicar + '.');
53 static const QString connection_object_path_prefix("/org/freedesktop/Telepathy/Connection/vicar/" + protocol_vicar + '/');
54 static const QString requests_interface("org.freedesktop.Telepathy.Connection.Interface.Requests");
55 }
56
57 using namespace org::maemo;
58
59
60 class ConnectionPrivate
61 {
62 public:
63     ConnectionPrivate(Connection * p,
64                       const QString & acc) :
65         account(acc),
66         connection_status(Connection::Disconnected),
67         adaptor(new ConnectionAdaptor(p)),
68         connIfaceReqsAdaptor(new ConnectionInterfaceRequestsAdaptor(p)),
69 <<<<<<< HEAD
70         logUtility(new LogUtility(p)),
71 =======
72         logUtility(new LogUtility("/var/log/vicar/vicar.log",p)),
73 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
74         parent(p)
75     {
76         Q_ASSERT(0 != adaptor);
77     }
78
79     ~ConnectionPrivate()
80     {
81         qDebug() << "VICaR Connection: Connection Destructing";
82     }
83
84     const QString account;
85
86     Connection::Status connection_status;
87     ConnectionAdaptor * adaptor;
88     ConnectionInterfaceRequestsAdaptor * connIfaceReqsAdaptor;
89     LogUtility * const logUtility;
90     Connection * const parent;
91 };
92
93 // ---------------------------------------------------------------------------
94
95 Connection::Connection(const QString & account,
96                         QObject * parent) :
97     QObject(parent),
98     d(new ConnectionPrivate(this, account))
99 {
100
101     QString strMessage;
102     strMessage = "DEBUG: In Connection Constructor";
103 <<<<<<< HEAD
104 =======
105     qDebug() << strMessage;
106 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
107     d->logUtility->logMessage(strMessage);
108
109     Q_ASSERT(0 != d);
110     Q_ASSERT(!account.isEmpty());
111
112     /*  -- Set the Dynamic property "Interfaces" ---
113
114         Apparently it is not sufficient to implement an additional interface like Conn.I.Requests.
115         We have to assign the list of additional interfaces to the DBus Property Interfaces.
116
117         The actual DBus property "Interfaces" is declared in ConnectionAdaptor class,
118          which is our Connection Interface implementation.
119      */
120
121     QStringList interfaces = QStringList(requests_interface);
122     this->setProperty("Interfaces",interfaces);
123
124     // Set the Dynamic property "HasImmortalHandles" to true as per telepathy Connection spec 0.21.6
125     //The handles for vicar connection are expected to last throughout the lifetime of the connection
126     this->setProperty("HasImmortalHandles",true);
127
128     this->setProperty("Status",org::freedesktop::Telepathy::CONNECTION_STATUS_CONNECTED);
129 <<<<<<< HEAD
130
131
132     //this->setProperty("SelfHandle",org::freedesktop::Telepathy::HANDLE_TYPE_CONTACT);
133     uint selfHandle(SELF_HANDLE);
134     this->setProperty("SelfHandle",selfHandle);
135
136     strMessage = "VICaR Connection: Emitting SelfHandleChanged.";
137     d->logUtility->logMessage(strMessage);
138     emit SelfHandleChanged(selfHandle);
139 =======
140     this->setProperty("SelfHandle",org::freedesktop::Telepathy::HANDLE_TYPE_CONTACT);
141 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
142
143     //Set the property RequestableChannelClasses
144     org::freedesktop::Telepathy::RequestableChannelClassList requestableChannelClasses;
145
146     uint targetHandleType(1);
147
148     org::freedesktop::Telepathy::RequestableChannelClass requestableChannelClass1;
149     requestableChannelClass1.fixedProperties.insert("org.freedesktop.Telepathy.Channel.TargetHandleType",targetHandleType);
150     requestableChannelClass1.fixedProperties.insert("org.freedesktop.Telepathy.Channel.ChannelType","org.freedesktop.Telepathy.Channel.Type.StreamedMedia");
151
152     requestableChannelClass1.allowedProperties.append("org.freedesktop.Telepathy.Channel.TargetHandle");
153     requestableChannelClass1.allowedProperties.append("org.freedesktop.Telepathy.Channel.Type.StreamedMedia.InitialAudio");
154
155     requestableChannelClasses.append(requestableChannelClass1);
156
157     org::freedesktop::Telepathy::RequestableChannelClass requestableChannelClass2;
158     requestableChannelClass2.fixedProperties.insert("org.freedesktop.Telepathy.Channel.TargetHandleType",targetHandleType);
159     requestableChannelClass2.fixedProperties.insert("org.freedesktop.Telepathy.Channel.ChannelType","org.freedesktop.Telepathy.Channel.Type.StreamedMedia");
160
161     requestableChannelClass2.allowedProperties.append("com.nokia.Telepathy.Channel.Interface.Conference.InitialMembers");
162     requestableChannelClass2.allowedProperties.append("org.freedesktop.Telepathy.Channel.TargetHandleType");
163     requestableChannelClass2.allowedProperties.append("org.freedesktop.Telepathy.Channel.Type.StreamedMedia.InitialAudio");
164
165     requestableChannelClasses.append(requestableChannelClass2);
166
167
168     this->setProperty("RequestableChannelClasses",QVariant::fromValue(requestableChannelClasses));
169
170     //Set the property Channels
171     org::freedesktop::Telepathy::ChannelDetailsList channelDetails;
172     this->setProperty("Channels",QVariant::fromValue(channelDetails));
173 <<<<<<< HEAD
174 =======
175
176     //Set the connection status to Connected (default for Vicar)
177     d->connection_status = Connection::Connected;
178 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
179
180     //Set the connection status to Connected (default for Vicar)
181     d->connection_status = Connection::Connected;
182
183
184     strMessage = "VICaR Connection: Connection set up.";
185
186 <<<<<<< HEAD
187 =======
188     strMessage = "VICaR Connection: Connection set up.";
189
190     qDebug() << strMessage;
191 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
192     d->logUtility->logMessage(strMessage);
193 }
194
195 Connection::~Connection()
196 {
197     qDebug() << "VICaR Connection: Connection closed.";
198     delete(d);
199 }
200
201 bool Connection::registerObject()
202 {
203     QString strMessage;
204
205     if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName())){
206         if (!QDBusConnection::sessionBus().registerService(serviceName()))
207         {
208             strMessage = "VICaR Connection: Problem registering connection service:" + serviceName();
209 <<<<<<< HEAD
210 =======
211             qDebug() << strMessage;
212 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
213             d->logUtility->logMessage(strMessage);
214             return false;
215         }
216
217         if (!QDBusConnection::sessionBus().registerObject(objectPath().path(),
218                                                           this))
219         {
220             strMessage = "VICaR Connection: Problem registering object path:" + objectPath().path();
221 <<<<<<< HEAD
222 =======
223             qDebug() << strMessage;
224 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
225             d->logUtility->logMessage(strMessage);
226             return false;
227         }
228     }
229     else{
230         strMessage = "VICaR Connection: " + serviceName()+" is already registered on DBus";
231 <<<<<<< HEAD
232 =======
233         qDebug() << strMessage;
234 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
235         d->logUtility->logMessage(strMessage);
236     }
237     return true;
238 }
239
240 void Connection::unregisterObject()
241 {
242     QString strMessage = "VICaR Connection: Unregistering Connection object from DBus";
243 <<<<<<< HEAD
244 =======
245     qDebug() << strMessage;
246 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
247     d->logUtility->logMessage(strMessage);
248     QDBusConnection::sessionBus().unregisterObject(objectPath().path());
249     QDBusConnection::sessionBus().unregisterService(serviceName());
250 }
251
252 QString Connection::name() const
253 {    
254     return QString("vicar");
255 }
256
257
258 QString Connection::serviceName() const
259 { return connection_service_name_prefix + name(); }
260
261 QDBusObjectPath Connection::objectPath() const
262 { return QDBusObjectPath(connection_object_path_prefix + name()); }
263
264
265 //org.freedesktop.Telepathy.Connection
266 void Connection::Connect()
267 {
268     /*
269        Since this is not a "real" Telepathy Connection to a SIP, Chat server,
270        I am not connecting to anything.
271      */
272     QString strMessage = "VICaR Connection: Changing status to Connected...";
273 <<<<<<< HEAD
274 =======
275     qDebug() << strMessage;
276 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
277     d->logUtility->logMessage(strMessage);
278     d->connection_status = Connection::Connected;
279
280     //Let all the Telepathy clients know that connection status has changed
281     strMessage = "VICaR Connection: Emitting StatusChanged.";
282 <<<<<<< HEAD
283 =======
284     qDebug() << strMessage;
285 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
286     d->logUtility->logMessage(strMessage);
287     emit StatusChanged(d->connection_status, ReasonRequested);
288 }
289
290 void Connection::Disconnect()
291 {
292     QString strMessage = "VICaR Connection: Changing status to Disconnected...";
293 <<<<<<< HEAD
294 =======
295     qDebug() << strMessage;
296 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
297     d->logUtility->logMessage(strMessage);
298     //We don't have any Handles to release here. So just change the status to Disconnected
299     d->connection_status = Connection::Disconnected;
300
301     strMessage = "VICaR Connection: Emitting StatusChanged";
302 <<<<<<< HEAD
303 =======
304     qDebug() << strMessage;
305 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
306     d->logUtility->logMessage(strMessage);
307     emit StatusChanged(d->connection_status, ReasonRequested);
308
309     //As per Telepathy specfication, on disconnect we need to unregister from Dbus and destroy the object.
310     unregisterObject();
311     deleteLater();
312 }
313
314 QStringList Connection::GetInterfaces()
315 {
316     QStringList result;
317
318     QString strMessage = "VICaR Connection: GetInterfaces.";
319     d->logUtility->logMessage(strMessage);
320
321     if (d->connection_status != Connected)
322     {
323         sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
324                        "VICaR - Unable to get Interfaces List. The connection is no longer available.");
325         return result;
326     }    
327     result <<requests_interface;
328     return result;
329 }
330
331 QString Connection::GetProtocol()
332 {
333     QString strMessage = "VICaR Connection: GetProtocol.";
334     d->logUtility->logMessage(strMessage);
335     return protocol_vicar;
336 }
337
338 uint Connection::GetStatus()
339 {
340     QString strMessage = "VICaR Connection: GetStatus.";
341     d->logUtility->logMessage(strMessage);
342     return static_cast<uint>(d->connection_status);
343 }
344
345 uint Connection::GetSelfHandle()
346 {
347     QString strMessage = "VICaR Connection: GetSelfHandle";
348 <<<<<<< HEAD
349 =======
350     qDebug() << strMessage;
351 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
352     d->logUtility->logMessage(strMessage);
353     if (d->connection_status != Connected)
354     {
355         sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
356                        "VICaR - Unable to get Self Handle. The connection is no longer available.");
357         strMessage = "VICaR Connection: NOT CONNECTED when requesting selfhandle!";
358 <<<<<<< HEAD
359 =======
360         qDebug() << strMessage;
361 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
362         d->logUtility->logMessage(strMessage);
363         return 0;
364     }
365
366     //WARNING: Incomplete implemenation
367 <<<<<<< HEAD
368     uint handle(SELF_HANDLE);
369     strMessage = "VICaR Connection: Returning Handle " + QString::number(handle) + "as self handle.";
370 =======
371     uint handle = 0;
372     strMessage = "VICaR Connection: Returning Handle " + QString(handle) + "as self handle.";
373     qDebug() << strMessage;
374 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
375     d->logUtility->logMessage(strMessage);
376     return handle;
377 }
378
379 QList<uint> Connection::RequestHandles(uint handle_type,
380                                        const QStringList & names)
381 {
382     QString strMessage = "VICaR Connection: RequestHandles.";
383     d->logUtility->logMessage(strMessage);
384
385     Q_UNUSED(names);
386     QList<uint> result;
387
388     // check input:
389     if (d->connection_status != Connected)
390     {
391         sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
392                        "VICaR - Unable to process handle request. The connection is no longer available.");
393         return result;
394     }
395     if (handle_type != HandleContact)
396     {
397         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
398                        "VICaR - Supports handles of type Contact only.");
399         return result;
400     }
401
402     //WARNING: Incomplete implementation. Create a handle and return the value here.
403     result.append(this->GetSelfHandle());
404     return result;
405 }
406
407 void Connection::HoldHandles(const uint handle_type, const QList<uint> &handles)
408 {
409     Q_UNUSED(handles);
410     QString strMessage = "VICaR Connection: HoldHandles.";
411 <<<<<<< HEAD
412 =======
413     qDebug() << strMessage;
414 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
415     d->logUtility->logMessage(strMessage);
416     if (d->connection_status != Connected)
417     {
418
419         strMessage = "VICaR Connection: HoldHandles - Not Connected.";
420 <<<<<<< HEAD
421 =======
422         qDebug() << strMessage;
423 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
424         d->logUtility->logMessage(strMessage);
425
426         sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
427                        "VICaR - Unable to process handle request. The connection is no longer available.");
428         return;
429     }
430     if (handle_type != HandleContact)
431     {
432
433         strMessage = "VICaR Connection: HoldHandles - Invalid Handle Type.";
434 <<<<<<< HEAD
435 =======
436         qDebug() << strMessage;
437 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
438         d->logUtility->logMessage(strMessage);
439
440         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
441                        "VICaR - Supports handles of type Contact only.");
442         return;
443     }
444
445     //WARNING: Incomplete implementation
446 }
447
448 QStringList Connection::InspectHandles(const uint handle_type,
449                                        const QList<uint> &handles)
450 {
451     Q_UNUSED(handles);
452     QStringList handlesList;
453 <<<<<<< HEAD
454 =======
455
456     QString strMessage = "VICaR Connection: InspectHandles.";
457     qDebug() << strMessage;
458     d->logUtility->logMessage(strMessage);
459 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
460
461     QString strMessage = "VICaR Connection: InspectHandles.";
462     //d->logUtility->logMessage(strMessage);
463
464      // check input:
465     if (d->connection_status != Connected)
466     {
467         sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
468                        "VICaR - Unable to process handle request. The connection is no longer available.");
469         return handlesList;
470     }
471     if (handle_type != HandleContact)
472     {
473         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
474                        "VICaR - Supports handles of type Contact only.");
475         return handlesList;
476 <<<<<<< HEAD
477 =======
478     }
479
480     uint handle = 0;
481     for (int i = 0 ; i < handles.length(); i++) {
482         handle = handles.at(i);
483         strMessage = "VICaR Connection: Inspecting handle "+QString(handle);
484         qDebug() << strMessage;
485         d->logUtility->logMessage(strMessage);
486         handlesList.append(QString(handle));
487 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
488     }
489
490     uint handle;
491
492     qDebug() << "VICaR Connction: " << handles.length()<< " handles passed to us";
493     for (int i = 0 ; i < handles.length(); i++) {
494         handle = handles.at(i);
495         strMessage = "VICaR Connection: Inspecting handle "+QString::number(handle);
496         d->logUtility->logMessage(strMessage);
497         handlesList.append(QString::number(handle));
498     }
499
500     strMessage = "VICaR Connection: Handle inspection completed";
501     d->logUtility->logMessage(strMessage);
502
503     //WARNING: Incomplete implementation
504     return handlesList;
505 }
506
507 void Connection::ReleaseHandles(const uint handle_type, const QList<uint> &handles)
508 {
509     Q_UNUSED(handles);
510 <<<<<<< HEAD
511     QString strMessage = "VICaR Connection: ReleaseHandles.";
512     d->logUtility->logMessage(strMessage);
513
514 =======
515     QString strMessage;
516 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
517     if (d->connection_status != Connected)
518     {
519         sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
520                        "VICaR - Unable to release handle. The connection is no longer available.");
521         strMessage = "VICaR Connection: Releasing Handle while connection is no longer connected.";
522 <<<<<<< HEAD
523 =======
524         qDebug() << strMessage;
525 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
526         d->logUtility->logMessage(strMessage);
527         return;
528     }
529     if (handle_type != HandleContact)
530     {
531         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
532                        "VICaR - Supports handles of type Contact only.");
533         strMessage =  "VICaR Connection: Trying to release a Handle that is not a contact.";
534 <<<<<<< HEAD
535 =======
536         qDebug() << strMessage;
537 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
538         d->logUtility->logMessage(strMessage);
539         return;
540     }
541
542     //WARNING: Incomplete implementation
543 }
544
545 org::freedesktop::Telepathy::ChannelInfoList Connection::ListChannels()
546 {
547
548     QString strMessage = "VICaR Connection: ListChannels.";
549     d->logUtility->logMessage(strMessage);
550
551     org::freedesktop::Telepathy::ChannelInfoList result;
552     if (d->connection_status != Connected)
553     {
554         sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
555                        "VICaR - Unable to list channels. The connection is no longer available.");
556         return result;
557     }
558
559     //WARNING: Incomplete implementation
560     //Btw - We never have any channels :)
561
562     return result;
563 }
564
565 QDBusObjectPath Connection::RequestChannel(const QString &type,
566                                            uint handle_type, uint handle,
567                                            bool suppress_handler)
568 {
569     Q_UNUSED(handle);
570     Q_UNUSED(suppress_handler);
571     //This method is deprecated and no longer used as per latest Telepathy spec
572
573
574     QString strMessage = "VICaR Connection: RequestChannel.";
575     d->logUtility->logMessage(strMessage);
576
577
578     if (type != QString("org.freedesktop.Telepathy.Channel.Type.StreamedMedia"))
579     {
580         sendErrorReply("org.freedesktop.Telepathy.Error.NotImplemented",
581                        "VICaR Connection: Failed to create channel: Channel type not implemented.");
582         return QDBusObjectPath();
583     }
584
585     if (handle_type != HandleContact )
586     {
587         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidHandle",
588                        "VICaR Connection: Failed to create channel: Handle type not supported.");
589         return QDBusObjectPath();
590     }
591
592     if (d->connection_status != Connected)
593     {
594         sendErrorReply("org.freedesktop.Telepathy.Error.Disconnected",
595                        "VICaR Connection: Failed to create channel: Connection is Disconnected.");
596         return QDBusObjectPath();
597     }
598
599     //WARNING: Incomplete implementation, we are not creating any channels here at all.
600     QDBusObjectPath channel_path;
601     qDebug() << "VICaR Connection: Returning null channel object path";
602     return channel_path;
603 }
604
605 //org.freedesktop.Telepathy.Connection.Interface.Requests
606 QDBusObjectPath Connection::CreateChannel(const QVariantMap &request,
607                                                            QVariantMap &channel_properties)
608 {
609     Q_UNUSED(channel_properties);
610     Q_ASSERT(!request.isEmpty());
611     QString strMessage;
612     strMessage = "VICaR Connection: CreateChannel";
613 <<<<<<< HEAD
614 =======
615     qDebug() << strMessage;
616 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
617     d->logUtility->logMessage(strMessage);
618     qDebug() << " Request details are: "<< request;
619
620      //Ideally we need to emit NewChannels signal here, but since we are not creating any channels we ignore it
621
622     //WARNING: VICaR - Specific implementation
623     return processChannel(request);
624
625 }
626
627 bool Connection::EnsureChannel(const QVariantMap &request,
628                                                 QDBusObjectPath &channel_object,
629                                                 QVariantMap &channel_properties)
630 {
631     Q_UNUSED(channel_object);
632     Q_UNUSED(channel_properties);
633     Q_ASSERT(!request.isEmpty());
634     QString strMessage = "VICaR Connection: EnsureChannel";
635 <<<<<<< HEAD
636 =======
637     qDebug() << strMessage;
638 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
639     d->logUtility->logMessage(strMessage);
640     qDebug() << " Request details are: "<< request;
641
642     //WARNING: Incomplete implementation
643     processChannel(request);
644
645     return true;
646 }
647
648 QDBusObjectPath Connection::processChannel(const QVariantMap &request){
649
650     QString strMessage = "VICaR Connection: ProcessChannel";
651 <<<<<<< HEAD
652 =======
653     qDebug() << strMessage;
654 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
655     d->logUtility->logMessage(strMessage);
656
657     QDBusObjectPath channel_path;
658
659     if (!request.contains("org.freedesktop.Telepathy.Channel.TargetID")){
660         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
661                        "VICaR - Invalid request. TargetID (Phone Number) not included.");
662         return channel_path;
663     }
664
665     QVariant vNumber = request.value("org.freedesktop.Telepathy.Channel.TargetID");
666     if (!vNumber.isValid()){
667         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
668                        "VICaR - Invalid request. Phone Number is not valid.");
669         return channel_path;
670     }
671     QString strNumber = vNumber.toString();
672     if (strNumber.isEmpty()){
673         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
674                        "VICaR - Invalid request. Phone Number is empty.");
675         return channel_path;
676     }
677     else if (strNumber == "publish" || strNumber == "subscribe"){
678     //Deny the persistent Mission control requests to publish and subscribe
679         QString strError = "VICaR - Invalid request. " + strNumber + " is not supported.";
680         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
681                        strError);
682         return channel_path;
683
684     }
685
686     //Only allow requests with handle type as contact
687     QVariant vTargetHandleType = request.value("org.freedesktop.Telepathy.Channel.TargetHandleType");
688     uint intTargetHandleType = vTargetHandleType.toUInt();
689     if (intTargetHandleType != HandleContact)
690     {
691         strMessage = "VICaR - Supports handles of type Contact only. Recieved handle type ";
692         strMessage.append(vTargetHandleType.toString());
693
694         sendErrorReply("org.freedesktop.Telepathy.Error.InvalidArgument",
695                        strMessage);
696         return channel_path;
697     }
698
699
700     /*
701         Send an error reply to Tp Client (Mission Control) to force it to close the active channel.
702         Once it recieves the reply, the client does not bother what we return.
703
704      */
705
706     sendErrorReply("org.freedesktop.Telepathy.Error.NotAvailable",
707                    "VICaR - Creating a new channel to "+strNumber+" via Ring.");
708
709
710     //Initiate a new call to CC/Google Out/Skype-out number by requesting a new channel with Ring CM.
711
712     VicarCallRouterProxy *callRouter = new VicarCallRouterProxy(APPLICATION_DBUS_SERVICE,APPLICATION_DBUS_PATH,QDBusConnection::sessionBus(),this);
713
714     callRouter->callInternationalNumber(strNumber);
715
716     strMessage = "VICaR Connection: Call is processed.";
717
718 <<<<<<< HEAD
719 =======
720     qDebug() << strMessage;
721 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
722     d->logUtility->logMessage(strMessage);
723
724     return channel_path;
725 }
726
727
728 void Connection::AddClientInterest(const QStringList &tokens){
729     //WARNING: Incomplete implementation
730     Q_UNUSED(tokens);    
731     QString strMessage;
732
733     strMessage = "VICaR Connection: AddClientInterest";
734 <<<<<<< HEAD
735 =======
736     qDebug() << strMessage;
737 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
738     d->logUtility->logMessage(strMessage);
739 }
740
741 void Connection::RemoveClientInterest(const QStringList &tokens){
742     //WARNING: Incomplete implementation
743     Q_UNUSED(tokens);    
744     QString strMessage;
745
746     strMessage = "VICaR Connection: RemoveClientInterest";
747 <<<<<<< HEAD
748 =======
749     qDebug() << strMessage;
750 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
751     d->logUtility->logMessage(strMessage);
752 }
753
754 //org.freedesktop.Telepathy.Connection.Interface.Capabilities
755 org::freedesktop::Telepathy::ContactCapabilitiesList Connection::GetCapabilities(const QList<uint> &Handles){
756     Q_UNUSED(Handles);
757     org::freedesktop::Telepathy::ContactCapabilitiesList capabilities;
758     return capabilities;
759
760 }
761
762
763 org::freedesktop::Telepathy::CapabilityPairList Connection::AdvertiseCapabilities(org::freedesktop::Telepathy::CapabilityPairList Add, const QStringList &Remove){
764     Q_UNUSED(Add);
765     Q_UNUSED(Remove);
766     org::freedesktop::Telepathy::CapabilityPairList capabilities;
767     return capabilities;
768 }