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
|
/**
* This file is part of TelepathyQt4
*
* @copyright Copyright (C) 2009-2010 Collabora Ltd. <http://www.collabora.co.uk/>
* @copyright Copyright (C) 2009-2010 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 <TelepathyQt4/ChannelFactory>
#include "TelepathyQt4/_gen/channel-factory.moc.hpp"
#include "TelepathyQt4/_gen/future-constants.h"
#include "TelepathyQt4/debug-internal.h"
#include <TelepathyQt4/Channel>
#include <TelepathyQt4/ChannelClassSpec>
#include <TelepathyQt4/ChannelClassFeatures>
#include <TelepathyQt4/Connection>
#include <TelepathyQt4/Constants>
#include <TelepathyQt4/ContactSearchChannel>
#include <TelepathyQt4/FileTransferChannel>
#include <TelepathyQt4/IncomingFileTransferChannel>
#include <TelepathyQt4/IncomingStreamTubeChannel>
#include <TelepathyQt4/OutgoingFileTransferChannel>
#include <TelepathyQt4/OutgoingStreamTubeChannel>
#include <TelepathyQt4/RoomListChannel>
#include <TelepathyQt4/StreamTubeChannel>
#include <TelepathyQt4/StreamedMediaChannel>
#include <TelepathyQt4/TextChannel>
namespace Tp
{
struct TELEPATHY_QT4_NO_EXPORT ChannelFactory::Private
{
Private();
QList<ChannelClassFeatures> features;
typedef QPair<ChannelClassSpec, ConstructorConstPtr> CtorPair;
QList<CtorPair> ctors;
};
ChannelFactory::Private::Private()
{
}
/**
* \class ChannelFactory
* \ingroup utils
* \headerfile TelepathyQt4/channel-factory.h <TelepathyQt4/ChannelFactory>
*
* \brief The ChannelFactory class is responsible for constructing Channel
* objects according to application-defined settings.
*/
/**
* Create a new ChannelFactory object.
*
* The returned factory will construct channel subclasses provided by TelepathyQt4 as appropriate
* for the channel immutable properties, but not make any features ready.
*
* \param bus The QDBusConnection the proxies constructed using this factory should use.
* \return An ChannelFactoryPtr pointing to the newly created factory.
*/
ChannelFactoryPtr ChannelFactory::create(const QDBusConnection &bus)
{
return ChannelFactoryPtr(new ChannelFactory(bus));
}
/**
* Construct a new ChannelFactory object.
*
* The constructed factory will construct channel subclasses provided by TelepathyQt4 as appropriate
* for the channel immutable properties, but not make any features ready.
*
* \param bus The QDBusConnection the proxies constructed using this factory should use.
*/
ChannelFactory::ChannelFactory(const QDBusConnection &bus)
: DBusProxyFactory(bus), mPriv(new Private)
{
setSubclassForTextChats<TextChannel>();
setSubclassForTextChatrooms<TextChannel>();
setSubclassForStreamedMediaCalls<StreamedMediaChannel>();
setSubclassForRoomLists<RoomListChannel>();
setSubclassForIncomingFileTransfers<IncomingFileTransferChannel>();
setSubclassForOutgoingFileTransfers<OutgoingFileTransferChannel>();
setSubclassForIncomingStreamTubes<IncomingStreamTubeChannel>();
setSubclassForOutgoingStreamTubes<OutgoingStreamTubeChannel>();
setSubclassForIncomingRoomStreamTubes<IncomingStreamTubeChannel>();
setSubclassForOutgoingRoomStreamTubes<OutgoingStreamTubeChannel>();
setSubclassForContactSearches<ContactSearchChannel>();
setFallbackSubclass<Channel>();
}
/**
* Class destructor.
*/
ChannelFactory::~ChannelFactory()
{
delete mPriv;
}
Features ChannelFactory::featuresForTextChats(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::textChat(additionalProps));
}
void ChannelFactory::addFeaturesForTextChats(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::textChat(additionalProps), features);
addFeaturesFor(ChannelClassSpec::unnamedTextChat(additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForTextChats(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::textChat(additionalProps));
}
void ChannelFactory::setConstructorForTextChats(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::textChat(additionalProps), ctor);
setConstructorFor(ChannelClassSpec::unnamedTextChat(additionalProps), ctor);
}
Features ChannelFactory::featuresForTextChatrooms(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::textChatroom(additionalProps));
}
void ChannelFactory::addFeaturesForTextChatrooms(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::textChatroom(additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForTextChatrooms(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::textChatroom(additionalProps));
}
void ChannelFactory::setConstructorForTextChatrooms(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::textChatroom(additionalProps), ctor);
}
Features ChannelFactory::featuresForStreamedMediaCalls(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::streamedMediaCall(additionalProps));
}
void ChannelFactory::addFeaturesForStreamedMediaCalls(const Features &features,
const QVariantMap &additionalProps)
{
ChannelClassSpec smSpec = ChannelClassSpec::streamedMediaCall(additionalProps);
ChannelClassSpec unnamedSMSpec = ChannelClassSpec::unnamedStreamedMediaCall(additionalProps);
addFeaturesFor(smSpec, features);
addFeaturesFor(unnamedSMSpec, features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForStreamedMediaCalls(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::streamedMediaCall(additionalProps));
}
void ChannelFactory::setConstructorForStreamedMediaCalls(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
ChannelClassSpec smSpec = ChannelClassSpec::streamedMediaCall(additionalProps);
ChannelClassSpec unnamedSMSpec = ChannelClassSpec::unnamedStreamedMediaCall(additionalProps);
setConstructorFor(smSpec, ctor);
setConstructorFor(unnamedSMSpec, ctor);
}
Features ChannelFactory::featuresForRoomLists(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::roomList(additionalProps));
}
void ChannelFactory::addFeaturesForRoomLists(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::roomList(additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForRoomLists(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::roomList(additionalProps));
}
void ChannelFactory::setConstructorForRoomLists(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::roomList(additionalProps), ctor);
}
Features ChannelFactory::featuresForOutgoingFileTransfers(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::outgoingFileTransfer(additionalProps));
}
void ChannelFactory::addFeaturesForOutgoingFileTransfers(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::outgoingFileTransfer(additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForOutgoingFileTransfers(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::outgoingFileTransfer(additionalProps));
}
void ChannelFactory::setConstructorForOutgoingFileTransfers(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::outgoingFileTransfer(additionalProps), ctor);
}
Features ChannelFactory::featuresForIncomingFileTransfers(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::incomingFileTransfer(additionalProps));
}
void ChannelFactory::addFeaturesForIncomingFileTransfers(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::incomingFileTransfer(additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForIncomingFileTransfers(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::incomingFileTransfer(additionalProps));
}
void ChannelFactory::setConstructorForIncomingFileTransfers(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::incomingFileTransfer(additionalProps), ctor);
}
Features ChannelFactory::featuresForOutgoingStreamTubes(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::outgoingStreamTube(QString(), additionalProps));
}
void ChannelFactory::addFeaturesForOutgoingStreamTubes(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::outgoingStreamTube(QString(), additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForOutgoingStreamTubes(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::outgoingStreamTube(QString(), additionalProps));
}
void ChannelFactory::setConstructorForOutgoingStreamTubes(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::outgoingStreamTube(QString(), additionalProps), ctor);
}
Features ChannelFactory::featuresForIncomingStreamTubes(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::incomingStreamTube(QString(), additionalProps));
}
void ChannelFactory::addFeaturesForIncomingStreamTubes(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::incomingStreamTube(QString(), additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForIncomingStreamTubes(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::incomingStreamTube(QString(), additionalProps));
}
void ChannelFactory::setConstructorForIncomingStreamTubes(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::incomingStreamTube(QString(), additionalProps), ctor);
}
Features ChannelFactory::featuresForOutgoingRoomStreamTubes(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::outgoingRoomStreamTube(QString(), additionalProps));
}
void ChannelFactory::addFeaturesForOutgoingRoomStreamTubes(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::outgoingRoomStreamTube(QString(), additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForOutgoingRoomStreamTubes(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::outgoingRoomStreamTube(QString(), additionalProps));
}
void ChannelFactory::setConstructorForOutgoingRoomStreamTubes(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::outgoingRoomStreamTube(QString(), additionalProps), ctor);
}
Features ChannelFactory::featuresForIncomingRoomStreamTubes(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::incomingRoomStreamTube(QString(), additionalProps));
}
void ChannelFactory::addFeaturesForIncomingRoomStreamTubes(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::incomingRoomStreamTube(QString(), additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForIncomingRoomStreamTubes(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::incomingRoomStreamTube(QString(), additionalProps));
}
void ChannelFactory::setConstructorForIncomingRoomStreamTubes(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::incomingRoomStreamTube(QString(), additionalProps), ctor);
}
Features ChannelFactory::featuresForContactSearches(const QVariantMap &additionalProps) const
{
return featuresFor(ChannelClassSpec::contactSearch(additionalProps));
}
void ChannelFactory::addFeaturesForContactSearches(const Features &features,
const QVariantMap &additionalProps)
{
addFeaturesFor(ChannelClassSpec::contactSearch(additionalProps), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorForContactSearches(
const QVariantMap &additionalProps) const
{
return constructorFor(ChannelClassSpec::contactSearch(additionalProps));
}
void ChannelFactory::setConstructorForContactSearches(const ConstructorConstPtr &ctor,
const QVariantMap &additionalProps)
{
setConstructorFor(ChannelClassSpec::contactSearch(additionalProps), ctor);
}
Features ChannelFactory::commonFeatures() const
{
return featuresFor(ChannelClassSpec());
}
void ChannelFactory::addCommonFeatures(const Features &features)
{
addFeaturesFor(ChannelClassSpec(), features);
}
ChannelFactory::ConstructorConstPtr ChannelFactory::fallbackConstructor() const
{
return constructorFor(ChannelClassSpec());
}
void ChannelFactory::setFallbackConstructor(const ConstructorConstPtr &ctor)
{
setConstructorFor(ChannelClassSpec(), ctor);
}
Features ChannelFactory::featuresFor(const ChannelClassSpec &channelClass) const
{
Features features;
foreach (const ChannelClassFeatures &pair, mPriv->features) {
if (pair.first.isSubsetOf(channelClass)) {
features.unite(pair.second);
}
}
return features;
}
void ChannelFactory::addFeaturesFor(const ChannelClassSpec &channelClass, const Features &features)
{
QList<ChannelClassFeatures>::iterator i;
for (i = mPriv->features.begin(); i != mPriv->features.end(); ++i) {
if (channelClass.allProperties().size() > i->first.allProperties().size()) {
break;
}
if (i->first == channelClass) {
i->second.unite(features);
return;
}
}
// We ran out of feature specifications (for the given size/specificity of a channel class)
// before finding a matching one, so let's create a new entry
mPriv->features.insert(i, qMakePair(channelClass, features));
}
ChannelFactory::ConstructorConstPtr ChannelFactory::constructorFor(const ChannelClassSpec &cc) const
{
QList<Private::CtorPair>::iterator i;
for (i = mPriv->ctors.begin(); i != mPriv->ctors.end(); ++i) {
if (i->first.isSubsetOf(cc)) {
return i->second;
}
}
// If this is reached, we didn't have a proper fallback constructor
Q_ASSERT(false);
return ConstructorConstPtr();
}
void ChannelFactory::setConstructorFor(const ChannelClassSpec &channelClass,
const ConstructorConstPtr &ctor)
{
if (ctor.isNull()) {
warning().nospace() << "Tried to set a NULL ctor for ChannelClass("
<< channelClass.channelType() << ", " << channelClass.targetHandleType() << ", "
<< channelClass.allProperties().size() << "props in total)";
return;
}
QList<Private::CtorPair>::iterator i;
for (i = mPriv->ctors.begin(); i != mPriv->ctors.end(); ++i) {
if (channelClass.allProperties().size() > i->first.allProperties().size()) {
break;
}
if (i->first == channelClass) {
i->second = ctor;
return;
}
}
// We ran out of constructors (for the given size/specificity of a channel class)
// before finding a matching one, so let's create a new entry
mPriv->ctors.insert(i, qMakePair(channelClass, ctor));
}
/**
* Constructs a Channel proxy and begins making it ready.
*
* If a valid proxy already exists in the factory cache for the given combination of \a busName and
* \a objectPath, it is returned instead. All newly created proxies are automatically cached until
* they're either DBusProxy::invalidated() or the last reference to them outside the factory has
* been dropped.
*
* The proxy can be accessed immediately after this function returns using PendingReady::proxy().
*
* \param connection Proxy for the owning connection of the channel.
* \param channelPath The object path of the channel.
* \param immutableProperties The immutable properties of the channel.
* \return A PendingReady operation with the proxy in PendingReady::proxy().
*/
PendingReady *ChannelFactory::proxy(const ConnectionPtr &connection, const QString &channelPath,
const QVariantMap &immutableProperties) const
{
DBusProxyPtr proxy = cachedProxy(connection->busName(), channelPath);
if (proxy.isNull()) {
proxy = constructorFor(ChannelClassSpec(immutableProperties))->construct(connection,
channelPath, immutableProperties);
}
return nowHaveProxy(proxy);
}
/**
* Transforms well-known names to the corresponding unique names, as is appropriate for Channel
*
* \param uniqueOrWellKnown The name to transform.
* \return The unique name corresponding to \a uniqueOrWellKnown (which may be it itself).
*/
QString ChannelFactory::finalBusNameFrom(const QString &uniqueOrWellKnown) const
{
return StatefulDBusProxy::uniqueNameFrom(dbusConnection(), uniqueOrWellKnown);
}
/**
* Return features as configured for the channel class given by the Channel::immutableProperties()
* of \a proxy.
*
* \param proxy The Channel proxy to determine the features for.
* \return A list of Feature objects.
*/
Features ChannelFactory::featuresFor(const DBusProxyPtr &proxy) const
{
ChannelPtr chan = ChannelPtr::qObjectCast(proxy);
Q_ASSERT(!chan.isNull());
return featuresFor(ChannelClassSpec(chan->immutableProperties()));
}
} // Tp
|