[telepathy-qt4/master] Channel: Make constructor protected and added public create method that returns a SharedPtr.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Tue Mar 31 12:06:31 PDT 2009
---
TelepathyQt4/Client/channel.cpp | 29 +++++++++++--------
TelepathyQt4/Client/channel.h | 12 +++++---
TelepathyQt4/Client/file-transfer.cpp | 4 ++-
TelepathyQt4/Client/pending-channel.cpp | 35 +++++++++++++----------
TelepathyQt4/Client/pending-channel.h | 6 ++--
TelepathyQt4/Client/room-list.cpp | 4 ++-
TelepathyQt4/Client/streamed-media-channel.cpp | 2 +-
TelepathyQt4/Client/text-channel.cpp | 2 +-
examples/call/call-handler.cpp | 2 +-
examples/call/farsight-channel.cpp | 2 +-
10 files changed, 57 insertions(+), 41 deletions(-)
diff --git a/TelepathyQt4/Client/channel.cpp b/TelepathyQt4/Client/channel.cpp
index 9ee2af6..54988db 100644
--- a/TelepathyQt4/Client/channel.cpp
+++ b/TelepathyQt4/Client/channel.cpp
@@ -66,7 +66,7 @@ namespace Client
struct Channel::Private
{
- Private(Channel *parent, Connection *connection);
+ Private(Channel *parent, const ConnectionPtr &connection);
~Private();
static void introspectMain(Private *self);
@@ -102,8 +102,9 @@ struct Channel::Private
// Instance of generated interface class
ChannelInterface *baseInterface;
- // Owning connection
- Connection *connection;
+ // Owning connection - it can be a SharedPtr as Connection does not cache
+ // channels
+ ConnectionPtr connection;
// Optional interface proxies
ChannelInterfaceGroupInterface *group;
@@ -197,7 +198,7 @@ struct Channel::Private::GroupMembersChangedInfo
QString message;
};
-Channel::Private::Private(Channel *parent, Connection *connection)
+Channel::Private::Private(Channel *parent, const ConnectionPtr &connection)
: parent(parent),
baseInterface(new ChannelInterface(parent->dbusConnection(),
parent->busName(), parent->objectPath(), parent)),
@@ -228,12 +229,12 @@ Channel::Private::Private(Channel *parent, Connection *connection)
SLOT(onClosed()));
debug() << " Connection to owning connection's lifetime signals";
- parent->connect(connection,
+ parent->connect(connection.data(),
SIGNAL(invalidated(Telepathy::Client::DBusProxy *,
const QString &, const QString &)),
SLOT(onConnectionInvalidated()));
- parent->connect(connection,
+ parent->connect(connection.data(),
SIGNAL(destroyed()),
SLOT(onConnectionDestroyed()));
}
@@ -951,6 +952,12 @@ void Channel::Private::setReady()
const Feature Channel::FeatureCore = Feature(Channel::staticMetaObject.className(), 0, true);
+ChannelPtr Channel::create(const ConnectionPtr &connection,
+ const QString &objectPath, const QVariantMap &immutableProperties)
+{
+ return ChannelPtr(new Channel(connection, objectPath, immutableProperties));
+}
+
/**
* Construct a new Channel object.
*
@@ -960,14 +967,12 @@ const Feature Channel::FeatureCore = Feature(Channel::staticMetaObject.className
* \param immutableProperties The immutable properties of the channel, as
* signalled by NewChannels or returned by
* CreateChannel or EnsureChannel
- * \param parent Object parent.
*/
-Channel::Channel(Connection *connection,
+Channel::Channel(const ConnectionPtr &connection,
const QString &objectPath,
- const QVariantMap &immutableProperties,
- QObject *parent)
+ const QVariantMap &immutableProperties)
: StatefulDBusProxy(connection->dbusConnection(), connection->busName(),
- objectPath, parent),
+ objectPath),
OptionalInterfaceFactory<Channel>(this),
ReadyObject(this, FeatureCore),
mPriv(new Private(this, connection))
@@ -990,7 +995,7 @@ Channel::~Channel()
*
* \return A pointer to the Connection object that owns this Channel.
*/
-Connection *Channel::connection() const
+ConnectionPtr Channel::connection() const
{
return mPriv->connection;
}
diff --git a/TelepathyQt4/Client/channel.h b/TelepathyQt4/Client/channel.h
index 7208946..6793536 100644
--- a/TelepathyQt4/Client/channel.h
+++ b/TelepathyQt4/Client/channel.h
@@ -61,13 +61,12 @@ class Channel : public StatefulDBusProxy,
public:
static const Feature FeatureCore;
- Channel(Connection *connection,
- const QString &objectPath,
- const QVariantMap &immutableProperties,
- QObject *parent = 0);
+ static ChannelPtr create(const ConnectionPtr &connection,
+ const QString &objectPath, const QVariantMap &immutableProperties);
+
~Channel();
- Connection *connection() const;
+ ConnectionPtr connection() const;
QString channelType() const;
QStringList interfaces() const;
@@ -264,6 +263,9 @@ public:
}
protected:
+ Channel(const ConnectionPtr &connection,const QString &objectPath,
+ const QVariantMap &immutableProperties);
+
ChannelInterface *baseInterface() const;
inline ChannelInterfaceGroupInterface *groupInterface(
diff --git a/TelepathyQt4/Client/file-transfer.cpp b/TelepathyQt4/Client/file-transfer.cpp
index cf14eb6..9987ca8 100644
--- a/TelepathyQt4/Client/file-transfer.cpp
+++ b/TelepathyQt4/Client/file-transfer.cpp
@@ -23,6 +23,8 @@
#include "TelepathyQt4/Client/_gen/file-transfer.moc.hpp"
#include "TelepathyQt4/debug-internal.h"
+#include <TelepathyQt4/Client/Connection>
+
namespace Telepathy
{
namespace Client
@@ -71,7 +73,7 @@ FileTransfer::FileTransfer(Connection *connection,
const QString &objectPath,
const QVariantMap &immutableProperties,
QObject *parent)
- : Channel(connection, objectPath, immutableProperties, parent),
+ : Channel(connection, objectPath, immutableProperties),
mPriv(new Private())
{
}
diff --git a/TelepathyQt4/Client/pending-channel.cpp b/TelepathyQt4/Client/pending-channel.cpp
index 7e70706..b92b008 100644
--- a/TelepathyQt4/Client/pending-channel.cpp
+++ b/TelepathyQt4/Client/pending-channel.cpp
@@ -51,6 +51,12 @@ namespace Client
struct PendingChannel::Private
{
+ Private(const ConnectionPtr &connection) :
+ connection(connection)
+ {
+ }
+
+ ConnectionPtr connection;
bool yours;
QString channelType;
uint handleType;
@@ -77,10 +83,10 @@ struct PendingChannel::Private
* \param errorName The error name.
* \param errorMessage The error message.
*/
-PendingChannel::PendingChannel(Connection *connection, const QString &errorName,
+PendingChannel::PendingChannel(const ConnectionPtr &connection, const QString &errorName,
const QString &errorMessage)
- : PendingOperation(connection),
- mPriv(new Private)
+ : PendingOperation(connection.data()),
+ mPriv(new Private(connection))
{
mPriv->yours = false;
mPriv->handleType = 0;
@@ -96,10 +102,10 @@ PendingChannel::PendingChannel(Connection *connection, const QString &errorName,
* \param request A dictionary containing the desirable properties.
* \param create Whether createChannel or ensureChannel should be called.
*/
-PendingChannel::PendingChannel(Connection *connection,
+PendingChannel::PendingChannel(const ConnectionPtr &connection,
const QVariantMap &request, bool create)
- : PendingOperation(connection),
- mPriv(new Private)
+ : PendingOperation(connection.data()),
+ mPriv(new Private(connection))
{
mPriv->yours = create;
mPriv->channelType = request.value(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")).toString();
@@ -135,9 +141,9 @@ PendingChannel::~PendingChannel()
*
* \return Pointer to the Connection.
*/
-Connection *PendingChannel::connection() const
+ConnectionPtr PendingChannel::connection() const
{
- return qobject_cast<Connection *>(parent());
+ return mPriv->connection;
}
/**
@@ -252,30 +258,29 @@ ChannelPtr PendingChannel::channel() const
if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) {
mPriv->channel = ChannelPtr(
- new TextChannel(connection(), mPriv->objectPath.path(),
+ new TextChannel(mPriv->connection.data(), mPriv->objectPath.path(),
mPriv->immutableProperties));
}
else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) {
mPriv->channel = ChannelPtr(
- new StreamedMediaChannel(connection(), mPriv->objectPath.path(),
+ new StreamedMediaChannel(mPriv->connection.data(), mPriv->objectPath.path(),
mPriv->immutableProperties));
}
else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_ROOM_LIST) {
mPriv->channel = ChannelPtr(
- new RoomList(connection(), mPriv->objectPath.path(),
+ new RoomList(mPriv->connection.data(), mPriv->objectPath.path(),
mPriv->immutableProperties));
}
// FIXME: update spec so we can do this properly
else if (channelType() == "org.freedesktop.Telepathy.Channel.Type.FileTransfer") {
mPriv->channel = ChannelPtr(
- new FileTransfer(connection(), mPriv->objectPath.path(),
+ new FileTransfer(mPriv->connection.data(), mPriv->objectPath.path(),
mPriv->immutableProperties));
}
else {
// ContactList, old-style Tubes, or a future channel type
- mPriv->channel = ChannelPtr(
- new Channel(connection(), mPriv->objectPath.path(),
- mPriv->immutableProperties));
+ mPriv->channel = Channel::create(mPriv->connection,
+ mPriv->objectPath.path(), mPriv->immutableProperties);
}
return mPriv->channel;
}
diff --git a/TelepathyQt4/Client/pending-channel.h b/TelepathyQt4/Client/pending-channel.h
index cceb57f..b63f50d 100644
--- a/TelepathyQt4/Client/pending-channel.h
+++ b/TelepathyQt4/Client/pending-channel.h
@@ -49,7 +49,7 @@ class PendingChannel : public PendingOperation
public:
~PendingChannel();
- Connection *connection() const;
+ ConnectionPtr connection() const;
bool yours() const;
@@ -72,9 +72,9 @@ private Q_SLOTS:
private:
friend class Connection;
- PendingChannel(Connection *connection,
+ PendingChannel(const ConnectionPtr &connection,
const QString &errorName, const QString &errorMessage);
- PendingChannel(Connection *connection,
+ PendingChannel(const ConnectionPtr &connection,
const QVariantMap &request, bool create);
struct Private;
diff --git a/TelepathyQt4/Client/room-list.cpp b/TelepathyQt4/Client/room-list.cpp
index 2d96c3a..afa5030 100644
--- a/TelepathyQt4/Client/room-list.cpp
+++ b/TelepathyQt4/Client/room-list.cpp
@@ -23,6 +23,8 @@
#include "TelepathyQt4/Client/_gen/room-list.moc.hpp"
#include "TelepathyQt4/debug-internal.h"
+#include <TelepathyQt4/Client/Connection>
+
namespace Telepathy
{
namespace Client
@@ -70,7 +72,7 @@ RoomList::RoomList(Connection *connection,
const QString &objectPath,
const QVariantMap &immutableProperties,
QObject *parent)
- : Channel(connection, objectPath, immutableProperties, parent),
+ : Channel(connection, objectPath, immutableProperties),
mPriv(new Private())
{
}
diff --git a/TelepathyQt4/Client/streamed-media-channel.cpp b/TelepathyQt4/Client/streamed-media-channel.cpp
index 864453e..4f21bd2 100644
--- a/TelepathyQt4/Client/streamed-media-channel.cpp
+++ b/TelepathyQt4/Client/streamed-media-channel.cpp
@@ -528,7 +528,7 @@ StreamedMediaChannel::StreamedMediaChannel(Connection *connection,
const QString &objectPath,
const QVariantMap &immutableProperties,
QObject *parent)
- : Channel(connection, objectPath, immutableProperties, parent),
+ : Channel(connection, objectPath, immutableProperties),
mPriv(new Private(this))
{
}
diff --git a/TelepathyQt4/Client/text-channel.cpp b/TelepathyQt4/Client/text-channel.cpp
index 4a534e4..8575eb5 100644
--- a/TelepathyQt4/Client/text-channel.cpp
+++ b/TelepathyQt4/Client/text-channel.cpp
@@ -406,7 +406,7 @@ TextChannel::TextChannel(Connection *connection,
const QString &objectPath,
const QVariantMap &immutableProperties,
QObject *parent)
- : Channel(connection, objectPath, immutableProperties, parent),
+ : Channel(connection, objectPath, immutableProperties),
mPriv(new Private(this))
{
}
diff --git a/examples/call/call-handler.cpp b/examples/call/call-handler.cpp
index 0729306..25660df 100644
--- a/examples/call/call-handler.cpp
+++ b/examples/call/call-handler.cpp
@@ -88,7 +88,7 @@ void CallHandler::onOutgoingChannelCreated(PendingOperation *op)
PendingChannel *pc = qobject_cast<PendingChannel *>(op);
- StreamedMediaChannel *chan = new StreamedMediaChannel(pc->connection(),
+ StreamedMediaChannel *chan = new StreamedMediaChannel(pc->connection().data(),
pc->objectPath(), pc->immutableProperties());
mChannels.append(chan);
connect(chan->becomeReady(),
diff --git a/examples/call/farsight-channel.cpp b/examples/call/farsight-channel.cpp
index e7afbd5..6ee1397 100644
--- a/examples/call/farsight-channel.cpp
+++ b/examples/call/farsight-channel.cpp
@@ -90,7 +90,7 @@ FarsightChannel::Private::Private(FarsightChannel *parent,
return;
}
- Connection *connection = channel->connection();
+ ConnectionPtr connection = channel->connection();
TpConnection *gconnection = tp_connection_new(dbus,
connection->busName().toAscii(),
--
1.5.6.5
More information about the telepathy-commits
mailing list