File: channel-dispatch-operation.cpp

package info (click to toggle)
telepathy-qt 0.9.1-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 38,764 kB
  • sloc: cpp: 59,914; xml: 34,543; ansic: 21,194; python: 3,370; sh: 118; makefile: 20
file content (621 lines) | stat: -rw-r--r-- 24,837 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/**
 * This file is part of TelepathyQt
 *
 * @copyright Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
 * @copyright Copyright (C) 2009 Nokia Corporation
 * @license LGPL 2.1
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <TelepathyQt/ChannelDispatchOperation>
#include "TelepathyQt/channel-dispatch-operation-internal.h"

#include "TelepathyQt/_gen/cli-channel-dispatch-operation-body.hpp"
#include "TelepathyQt/_gen/cli-channel-dispatch-operation.moc.hpp"
#include "TelepathyQt/_gen/channel-dispatch-operation.moc.hpp"
#include "TelepathyQt/_gen/channel-dispatch-operation-internal.moc.hpp"

#include "TelepathyQt/debug-internal.h"
#include "TelepathyQt/fake-handler-manager-internal.h"

#include <TelepathyQt/Account>
#include <TelepathyQt/AccountFactory>
#include <TelepathyQt/Channel>
#include <TelepathyQt/ChannelFactory>
#include <TelepathyQt/Connection>
#include <TelepathyQt/ConnectionFactory>
#include <TelepathyQt/ContactFactory>
#include <TelepathyQt/PendingComposite>
#include <TelepathyQt/PendingReady>
#include <TelepathyQt/PendingVoid>

namespace Tp
{

struct TP_QT_NO_EXPORT ChannelDispatchOperation::Private
{
    Private(ChannelDispatchOperation *parent);
    ~Private();

    static void introspectMain(Private *self);

    void extractMainProps(const QVariantMap &props,
            bool immutableProperties);

    // Public object
    ChannelDispatchOperation *parent;

    // Context
    AccountFactoryConstPtr accFactory;
    ConnectionFactoryConstPtr connFactory;
    ChannelFactoryConstPtr chanFactory;
    ContactFactoryConstPtr contactFactory;

    // Instance of generated interface class
    Client::ChannelDispatchOperationInterface *baseInterface;

    // Mandatory properties interface proxy
    Client::DBus::PropertiesInterface *properties;

    ReadinessHelper *readinessHelper;

    // Introspection
    QVariantMap immutableProperties;
    ConnectionPtr connection;
    AccountPtr account;
    QList<ChannelPtr> channels;
    QStringList possibleHandlers;
    bool gotPossibleHandlers;
};

ChannelDispatchOperation::Private::Private(ChannelDispatchOperation *parent)
    : parent(parent),
      baseInterface(new Client::ChannelDispatchOperationInterface(parent)),
      properties(parent->interface<Client::DBus::PropertiesInterface>()),
      readinessHelper(parent->readinessHelper()),
      gotPossibleHandlers(false)
{
    debug() << "Creating new ChannelDispatchOperation:" << parent->objectPath();

    parent->connect(baseInterface,
            SIGNAL(Finished()),
            SLOT(onFinished()));

    parent->connect(baseInterface,
            SIGNAL(ChannelLost(QDBusObjectPath,QString,QString)),
            SLOT(onChannelLost(QDBusObjectPath,QString,QString)));

    ReadinessHelper::Introspectables introspectables;

    // As ChannelDispatchOperation does not have predefined statuses let's simulate one (0)
    ReadinessHelper::Introspectable introspectableCore(
        QSet<uint>() << 0,                                           // makesSenseForStatuses
        Features(),                                                  // dependsOnFeatures
        QStringList(),                                               // dependsOnInterfaces
        (ReadinessHelper::IntrospectFunc) &Private::introspectMain,
        this);
    introspectables[FeatureCore] = introspectableCore;

    readinessHelper->addIntrospectables(introspectables);
}

ChannelDispatchOperation::Private::~Private()
{
}

void ChannelDispatchOperation::Private::introspectMain(ChannelDispatchOperation::Private *self)
{
    QVariantMap mainProps;
    foreach (QString key, self->immutableProperties.keys()) {
        if (key.startsWith(TP_QT_IFACE_CHANNEL_DISPATCH_OPERATION + QLatin1String("."))) {
            QVariant value = self->immutableProperties.value(key);
            mainProps.insert(
                    key.remove(TP_QT_IFACE_CHANNEL_DISPATCH_OPERATION + QLatin1String(".")),
                    value);
        }
    }

    if (!self->channels.isEmpty() && mainProps.contains(QLatin1String("Account"))
            && mainProps.contains(QLatin1String("Connection"))
            && mainProps.contains(QLatin1String("Interfaces"))
            && mainProps.contains(QLatin1String("PossibleHandlers"))) {
        debug() << "Supplied properties were sufficient, not introspecting"
            << self->parent->objectPath();
        self->extractMainProps(mainProps, true);
        return;
    }

    debug() << "Calling Properties::GetAll(ChannelDispatchOperation)";
    QDBusPendingCallWatcher *watcher =
        new QDBusPendingCallWatcher(
                self->properties->GetAll(TP_QT_IFACE_CHANNEL_DISPATCH_OPERATION),
                self->parent);
    self->parent->connect(watcher,
            SIGNAL(finished(QDBusPendingCallWatcher*)),
            SLOT(gotMainProperties(QDBusPendingCallWatcher*)));
}

void ChannelDispatchOperation::Private::extractMainProps(const QVariantMap &props,
        bool immutableProperties)
{
    parent->setInterfaces(qdbus_cast<QStringList>(props.value(QLatin1String("Interfaces"))));

    QList<PendingOperation *> readyOps;

    if (!connection && props.contains(QLatin1String("Connection"))) {
        QDBusObjectPath connectionObjectPath =
            qdbus_cast<QDBusObjectPath>(props.value(QLatin1String("Connection")));
        QString connectionBusName =
            connectionObjectPath.path().mid(1).replace(QLatin1String("/"),
                    QLatin1String("."));

        PendingReady *readyOp =
            connFactory->proxy(connectionBusName, connectionObjectPath.path(),
                    chanFactory, contactFactory);
        connection = ConnectionPtr::qObjectCast(readyOp->proxy());
        readyOps.append(readyOp);
    }

    if (!account && props.contains(QLatin1String("Account"))) {
        QDBusObjectPath accountObjectPath =
            qdbus_cast<QDBusObjectPath>(props.value(QLatin1String("Account")));

        PendingReady *readyOp =
            accFactory->proxy(TP_QT_ACCOUNT_MANAGER_BUS_NAME,
                    accountObjectPath.path(), connFactory, chanFactory, contactFactory);
        account = AccountPtr::qObjectCast(readyOp->proxy());
        readyOps.append(readyOp);
    }

    if (!immutableProperties) {
        // If we're here, it means we had to introspect the object, and now for sure have the
        // correct channels list, so let's overwrite the initial channels - but keep the refs around
        // for a while as an optimization enabling the factory to still return the same ones instead
        // of constructing everything anew. Note that this is not done at all in the case the
        // immutable props and initial channels etc were sufficient.
        QList<ChannelPtr> saveChannels = channels;
        channels.clear();

        ChannelDetailsList channelDetailsList =
            qdbus_cast<ChannelDetailsList>(props.value(QLatin1String("Channels")));
        ChannelPtr channel;
        foreach (const ChannelDetails &channelDetails, channelDetailsList) {
            PendingReady *readyOp =
                chanFactory->proxy(connection,
                        channelDetails.channel.path(), channelDetails.properties);
            channels.append(ChannelPtr::qObjectCast(readyOp->proxy()));
            readyOps.append(readyOp);
        }

        // saveChannels goes out of scope now, so any initial channels which don't exist anymore are
        // freed
    }

    if (props.contains(QLatin1String("PossibleHandlers"))) {
        possibleHandlers = qdbus_cast<QStringList>(props.value(QLatin1String("PossibleHandlers")));
        gotPossibleHandlers = true;
    }

    if (readyOps.isEmpty()) {
        debug() << "No proxies to prepare for CDO" << parent->objectPath();
        readinessHelper->setIntrospectCompleted(FeatureCore, true);
    } else {
        parent->connect(new PendingComposite(readyOps, ChannelDispatchOperationPtr(parent)),
                SIGNAL(finished(Tp::PendingOperation*)),
                SLOT(onProxiesPrepared(Tp::PendingOperation*)));
    }
}

ChannelDispatchOperation::PendingClaim::PendingClaim(const ChannelDispatchOperationPtr &op,
        const AbstractClientHandlerPtr &handler)
    : PendingOperation(op),
      mDispatchOp(op),
      mHandler(handler)
{
    debug() << "Invoking CDO.Claim";
    connect(new PendingVoid(op->baseInterface()->Claim(), op),
            SIGNAL(finished(Tp::PendingOperation*)),
            SLOT(onClaimFinished(Tp::PendingOperation*)));
}

ChannelDispatchOperation::PendingClaim::~PendingClaim()
{
}

void ChannelDispatchOperation::PendingClaim::onClaimFinished(
        PendingOperation *op)
{
    if (!op->isError()) {
        debug() << "CDO.Claim returned successfully, updating HandledChannels";
        if (mHandler) {
            // register the channels in HandledChannels
            FakeHandlerManager::instance()->registerChannels(
                    mDispatchOp->channels());
        }
        setFinished();
    } else {
        warning() << "CDO.Claim failed with" << op->errorName() << "-" << op->errorMessage();
        setFinishedWithError(op->errorName(), op->errorMessage());
    }
}

/**
 * \class ChannelDispatchOperation
 * \ingroup clientchanneldispatchoperation
 * \headerfile TelepathyQt/channel-dispatch-operation.h <TelepathyQt/ChannelDispatchOperation>
 *
 * \brief The ChannelDispatchOperation class represents a Telepathy channel
 * dispatch operation.
 *
 * One of the channel dispatcher's functions is to offer incoming channels to
 * Approver clients for approval. An approver should generally ask the user
 * whether they want to participate in the requested communication channels
 * (join the chat or chatroom, answer the call, accept the file transfer, or
 * whatever is appropriate). A collection of channels offered in this way
 * is represented by a ChannelDispatchOperation object.
 *
 * If the user wishes to accept the communication channels, the approver
 * should call handleWith() to indicate the user's or approver's preferred
 * handler for the channels (the empty string indicates no particular
 * preference, and will cause any suitable handler to be used).
 *
 * If the user wishes to reject the communication channels, or if the user
 * accepts the channels and the approver will handle them itself, the approver
 * should call claim(). If the resulting PendingOperation succeeds, the approver
 * immediately has control over the channels as their primary handler,
 * and may do anything with them (in particular, it may close them in whatever
 * way seems most appropriate).
 *
 * There are various situations in which the channel dispatch operation will
 * be closed, causing the DBusProxy::invalidated() signal to be emitted. If this
 * happens, the approver should stop prompting the user.
 *
 * Because all approvers are launched simultaneously, the user might respond
 * to another approver; if this happens, the invalidated signal will be
 * emitted with the error code #TP_QT_ERROR_OBJECT_REMOVED.
 *
 * If a channel closes, the signal channelLost() is emitted. If all channels
 * close, there is nothing more to dispatch, so the invalidated signal will be
 * emitted with the error code #TP_QT_ERROR_OBJECT_REMOVED.
 *
 * If the channel dispatcher crashes or exits, the invalidated
 * signal will be emitted with the error code
 * #TP_QT_DBUS_ERROR_NAME_HAS_NO_OWNER. In a high-quality implementation,
 * the dispatcher should be restarted, at which point it will create new
 * channel dispatch operations for any undispatched channels, and the approver
 * will be notified again.
 */

/**
 * Feature representing the core that needs to become ready to make the
 * ChannelDispatchOperation object usable.
 *
 * Note that this feature must be enabled in order to use most
 * ChannelDispatchOperation methods.
 *
 * When calling isReady(), becomeReady(), this feature is implicitly added
 * to the requested features.
 */
const Feature ChannelDispatchOperation::FeatureCore = Feature(QLatin1String(ChannelDispatchOperation::staticMetaObject.className()), 0, true);

/**
 * Create a new channel dispatch operation object using the given \a bus, the given factories and
 * the given initial channels.
 *
 * \param bus QDBusConnection to use.
 * \param objectPath The channel dispatch operation object path.
 * \param immutableProperties The channel dispatch operation immutable properties.
 * \param initialChannels The channels this CDO has initially (further tracking is done internally).
 * \param accountFactory The account factory to use.
 * \param connectionFactory The connection factory to use.
 * \param channelFactory The channel factory to use.
 * \param contactFactory The contact factory to use.
 * \return A ChannelDispatchOperationPtr object pointing to the newly created
 *         ChannelDispatchOperation object.
 */
ChannelDispatchOperationPtr ChannelDispatchOperation::create(const QDBusConnection &bus,
        const QString &objectPath, const QVariantMap &immutableProperties,
        const QList<ChannelPtr> &initialChannels,
        const AccountFactoryConstPtr &accountFactory,
        const ConnectionFactoryConstPtr &connectionFactory,
        const ChannelFactoryConstPtr &channelFactory,
        const ContactFactoryConstPtr &contactFactory)
{
    return ChannelDispatchOperationPtr(new ChannelDispatchOperation(
                bus, objectPath, immutableProperties, initialChannels, accountFactory,
                connectionFactory, channelFactory, contactFactory));
}

/**
 * Construct a new channel dispatch operation object using the given \a bus, the given factories and
 * the given initial channels.
 *
 * \param bus QDBusConnection to use
 * \param objectPath The channel dispatch operation object path.
 * \param immutableProperties The channel dispatch operation immutable properties.
 * \param initialChannels The channels this CDO has initially (further tracking is done internally).
 * \param accountFactory The account factory to use.
 * \param connectionFactory The connection factory to use.
 * \param channelFactory The channel factory to use.
 * \param contactFactory The contact factory to use.
 */
ChannelDispatchOperation::ChannelDispatchOperation(const QDBusConnection &bus,
        const QString &objectPath, const QVariantMap &immutableProperties,
        const QList<ChannelPtr> &initialChannels,
        const AccountFactoryConstPtr &accountFactory,
        const ConnectionFactoryConstPtr &connectionFactory,
        const ChannelFactoryConstPtr &channelFactory,
        const ContactFactoryConstPtr &contactFactory)
    : StatefulDBusProxy(bus,
            TP_QT_IFACE_CHANNEL_DISPATCHER,
            objectPath, FeatureCore),
      OptionalInterfaceFactory<ChannelDispatchOperation>(this),
      mPriv(new Private(this))
{
    if (accountFactory->dbusConnection().name() != bus.name()) {
        warning() << "  The D-Bus connection in the account factory is not the proxy connection";
    }

    if (connectionFactory->dbusConnection().name() != bus.name()) {
        warning() << "  The D-Bus connection in the connection factory is not the proxy connection";
    }

    if (channelFactory->dbusConnection().name() != bus.name()) {
        warning() << "  The D-Bus connection in the channel factory is not the proxy connection";
    }

    mPriv->channels = initialChannels;

    mPriv->accFactory = accountFactory;
    mPriv->connFactory = connectionFactory;
    mPriv->chanFactory = channelFactory;
    mPriv->contactFactory = contactFactory;

    mPriv->immutableProperties = immutableProperties;
}

/**
 * Class destructor.
 */
ChannelDispatchOperation::~ChannelDispatchOperation()
{
    delete mPriv;
}

/**
 * Return the connection with which the channels for this dispatch
 * operation are associated.
 *
 * This method requires ChannelDispatchOperation::FeatureCore to be ready.
 *
 * \return A pointer to the Connection object.
 */
ConnectionPtr ChannelDispatchOperation::connection() const
{
    return mPriv->connection;
}

/**
 * Return the account with which the connection and channels for this dispatch
 * operation are associated.
 *
 * This method requires ChannelDispatchOperation::FeatureCore to be ready.
 *
 * \return A pointer to the Account object.
 */
AccountPtr ChannelDispatchOperation::account() const
{
    return mPriv->account;
}

/**
 * Return the channels to be dispatched.
 *
 * This method requires ChannelDispatchOperation::FeatureCore to be ready.
 *
 * \return A list of pointers to Channel objects.
 */
QList<ChannelPtr> ChannelDispatchOperation::channels() const
{
    if (!isReady()) {
        warning() << "ChannelDispatchOperation::channels called with channel "
            "not ready";
    }
    return mPriv->channels;
}

/**
 * Return the well known bus names (starting with
 * org.freedesktop.Telepathy.Client.) of the possible Handlers for this
 * dispatch operation channels with the preferred handlers first.
 *
 * As a result, approvers should use the first handler by default, unless they
 * have a reason to do otherwise.
 *
 * This method requires ChannelDispatchOperation::FeatureCore to be ready.
 *
 * \return List of possible handlers names.
 */
QStringList ChannelDispatchOperation::possibleHandlers() const
{
    return mPriv->possibleHandlers;
}

/**
 * Called by an approver to accept a channel bundle and request that the given
 * handler be used to handle it.
 *
 * If successful, this method will cause the ChannelDispatchOperation object to
 * disappear, emitting invalidated with error
 * #TP_QT_ERROR_OBJECT_REMOVED.
 *
 * However, this method may fail because the dispatch has already been completed
 * and the object has already gone. If this occurs, it indicates that another
 * approver has asked for the bundle to be handled by a particular handler. The
 * approver must not attempt to interact with the channels further in this case,
 * unless it is separately invoked as the handler.
 *
 * Approvers which are also channel handlers should use claim() instead of
 * this method to request that they can handle a channel bundle themselves.
 *
 * \param handler The well-known bus name (starting with
 *                org.freedesktop.Telepathy.Client.) of the channel handler that
 *                should handle the channel, or an empty string if
 *                the client has no preferred channel handler.
 * \return A PendingOperation which will emit PendingOperation::finished
 *         when the call has finished.
 */
PendingOperation *ChannelDispatchOperation::handleWith(const QString &handler)
{
    return new PendingVoid(
            mPriv->baseInterface->HandleWith(handler),
            ChannelDispatchOperationPtr(this));
}

/**
 * Called by an approver to claim channels for closing them.
 *
 * \return A PendingOperation which will emit PendingOperation::finished
 *         when the call has finished.
 */
PendingOperation *ChannelDispatchOperation::claim()
{
    return new PendingClaim(ChannelDispatchOperationPtr(this));
}

/**
 * Called by an approver to claim channels for handling internally. If this
 * method is called successfully, the \a handler becomes the
 * handler for the channel, but does not have the
 * AbstractClientHandler::handleChannels() method called on it.
 *
 * Approvers wishing to reject channels must call this method to claim ownership
 * of them, and must not call requestClose() on the channels unless/until this
 * method returns successfully.
 *
 * The channel dispatcher can't know how best to close arbitrary channel types,
 * so it leaves it up to the approver to do so. For instance, for text channels
 * it is necessary to acknowledge any messages that have already been displayed
 * to the user first - ideally, the approver would display and then acknowledge
 * the messages - or to call Channel::requestClose() if the destructive
 * behaviour of that method is desired.
 *
 * Similarly, an approver for streamed media channels can close the channel with
 * a reason (e.g. "busy") if desired. The channel dispatcher, which is designed
 * to have no specific knowledge of particular channel types, can't do that.
 *
 * If successful, this method will cause the ChannelDispatchOperation object to
 * disappear, emitting Finished, in the same way as for handleWith().
 *
 * This method may fail because the dispatch operation has already been
 * completed. Again, see handleWith() for more details. The approver must not
 * attempt to interact with the channels further in this case.
 *
 * \param handler The channel handler, that should remain registered during the
 *                lifetime of channels(), otherwise dispatching will fail if the
 *                channel dispatcher restarts.
 * \return A PendingOperation which will emit PendingOperation::finished
 *         when the call has finished.
 * \sa claim(), handleWith()
 */
PendingOperation *ChannelDispatchOperation::claim(const AbstractClientHandlerPtr &handler)
{
    if (!handler->isRegistered()) {
        return new PendingFailure(TP_QT_ERROR_INVALID_ARGUMENT,
                QLatin1String("Handler must be registered for using claim(handler)"),
                ChannelDispatchOperationPtr(this));
    }

    return new PendingClaim(ChannelDispatchOperationPtr(this),
           handler);
}

/**
 * \fn void ChannelDispatchOperation::channelLost(const ChannelPtr &channel,
 *             const QString &errorName, const QString &errorMessage);
 *
 * Emitted when a channel has closed before it could be claimed or handled. If this is
 * emitted for the last remaining channel in a channel dispatch operation, it
 * will immediately be followed by invalidated() with error
 * #TP_QT_ERROR_OBJECT_REMOVED.
 *
 * \param channel The channel that was closed.
 * \param error The name of a D-Bus error indicating why the channel closed.
 * \param errorMessage The error message.
 */

/**
 * Return the ChannelDispatchOperationInterface for this ChannelDispatchOperation
 * class. This method is protected since the convenience methods provided by
 * this class should always be used instead of the interface by users of the
 * class.
 *
 * \return A pointer to the existing Client::ChannelDispatchOperationInterface object for this
 *         ChannelDispatchOperation object.
 */
Client::ChannelDispatchOperationInterface *ChannelDispatchOperation::baseInterface() const
{
    return mPriv->baseInterface;
}

void ChannelDispatchOperation::onFinished()
{
    debug() << "ChannelDispatchOperation finished and was removed";
    invalidate(TP_QT_ERROR_OBJECT_REMOVED,
               QLatin1String("ChannelDispatchOperation finished and was removed"));
}

void ChannelDispatchOperation::gotMainProperties(QDBusPendingCallWatcher *watcher)
{
    QDBusPendingReply<QVariantMap> reply = *watcher;

    // Watcher is NULL if we didn't have to introspect at all
    if (!reply.isError()) {
        debug() << "Got reply to Properties::GetAll(ChannelDispatchOperation)";
        mPriv->extractMainProps(reply.value(), false);
    } else {
        mPriv->readinessHelper->setIntrospectCompleted(FeatureCore,
                false, reply.error());
        warning().nospace() << "Properties::GetAll(ChannelDispatchOperation) failed with "
            << reply.error().name() << ": " << reply.error().message();
    }
}

void ChannelDispatchOperation::onChannelLost(
        const QDBusObjectPath &channelObjectPath,
        const QString &errorName, const QString &errorMessage)
{
    foreach (const ChannelPtr &channel, mPriv->channels) {
        if (channel->objectPath() == channelObjectPath.path()) {
            emit channelLost(channel, errorName, errorMessage);
            mPriv->channels.removeOne(channel);
            return;
        }
    }
}

void ChannelDispatchOperation::onProxiesPrepared(Tp::PendingOperation *op)
{
    if (op->isError()) {
        warning() << "Preparing proxies for CDO" << objectPath() << "failed with"
            << op->errorName() << ":" << op->errorMessage();
        mPriv->readinessHelper->setIntrospectCompleted(FeatureCore, false);
    } else {
        mPriv->readinessHelper->setIntrospectCompleted(FeatureCore, true);
    }
}

} // Tp