[telepathy-qt4/master] shared-ptr: Make SharedPtr(T*) constructor explicit.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Mon Apr 6 10:36:10 PDT 2009


---
 TelepathyQt4/Client/account-manager.cpp        |    2 +-
 TelepathyQt4/Client/channel.cpp                |    2 +-
 TelepathyQt4/Client/connection-manager.cpp     |    3 +-
 TelepathyQt4/Client/connection.cpp             |   33 +++++++++++++++--------
 TelepathyQt4/Client/message.cpp                |    1 -
 TelepathyQt4/Client/streamed-media-channel.cpp |   10 ++++---
 TelepathyQt4/Client/text-channel.cpp           |    8 +++---
 TelepathyQt4/shared-ptr.h                      |    2 +-
 tests/dbus/text-chan.cpp                       |    2 +-
 9 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/TelepathyQt4/Client/account-manager.cpp b/TelepathyQt4/Client/account-manager.cpp
index 05cfda0..dc94f61 100644
--- a/TelepathyQt4/Client/account-manager.cpp
+++ b/TelepathyQt4/Client/account-manager.cpp
@@ -362,7 +362,7 @@ PendingAccount *AccountManager::createAccount(const QString &connectionManager,
         const QString &protocol, const QString &displayName,
         const QVariantMap &parameters)
 {
-    return new PendingAccount(this, connectionManager,
+    return new PendingAccount(AccountManagerPtr(this), connectionManager,
             protocol, displayName, parameters);
 }
 
diff --git a/TelepathyQt4/Client/channel.cpp b/TelepathyQt4/Client/channel.cpp
index 54988db..4f2cecc 100644
--- a/TelepathyQt4/Client/channel.cpp
+++ b/TelepathyQt4/Client/channel.cpp
@@ -1914,7 +1914,7 @@ void Channel::onConnectionInvalidated()
 void Channel::onConnectionDestroyed()
 {
     debug() << "Owning connection destroyed, cutting off dangling pointer";
-    mPriv->connection = 0;
+    mPriv->connection.reset();
     invalidate(TELEPATHY_ERROR_CANCELLED,
                "Connection given as the owner of this channel was destroyed");
 }
diff --git a/TelepathyQt4/Client/connection-manager.cpp b/TelepathyQt4/Client/connection-manager.cpp
index 3b356ef..f803e7f 100644
--- a/TelepathyQt4/Client/connection-manager.cpp
+++ b/TelepathyQt4/Client/connection-manager.cpp
@@ -458,7 +458,8 @@ const ProtocolInfoList &ConnectionManager::protocols() const
 PendingConnection *ConnectionManager::requestConnection(const QString &protocol,
         const QVariantMap &parameters)
 {
-    return new PendingConnection(this, protocol, parameters);
+    return new PendingConnection(ConnectionManagerPtr(this),
+            protocol, parameters);
 }
 
 /**
diff --git a/TelepathyQt4/Client/connection.cpp b/TelepathyQt4/Client/connection.cpp
index 7449ba7..e08bdf5 100644
--- a/TelepathyQt4/Client/connection.cpp
+++ b/TelepathyQt4/Client/connection.cpp
@@ -290,7 +290,8 @@ void Connection::Private::init()
 void Connection::Private::introspectMain(Connection::Private *self)
 {
     if (!self->contactManager) {
-        self->contactManager = new ContactManager(self->parent);
+        self->contactManager = new ContactManager(
+                ConnectionPtr(self->parent));
     }
 
     // Introspecting the main interface is currently just calling
@@ -1064,24 +1065,28 @@ PendingChannel *Connection::createChannel(const QVariantMap &request)
 {
     if (mPriv->pendingStatus != StatusConnected) {
         warning() << "Calling createChannel with connection not yet connected";
-        return new PendingChannel(this, TELEPATHY_ERROR_NOT_AVAILABLE,
+        return new PendingChannel(ConnectionPtr(this),
+                TELEPATHY_ERROR_NOT_AVAILABLE,
                 "Connection not yet connected");
     }
 
     if (!mPriv->interfaces.contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_REQUESTS)) {
         warning() << "Requests interface is not support by this connection";
-        return new PendingChannel(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
+        return new PendingChannel(ConnectionPtr(this),
+                TELEPATHY_ERROR_NOT_IMPLEMENTED,
                 "Connection does not support Requests Interface");
     }
 
     if (!request.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"))) {
-        return new PendingChannel(this, TELEPATHY_ERROR_INVALID_ARGUMENT,
+        return new PendingChannel(ConnectionPtr(this),
+                TELEPATHY_ERROR_INVALID_ARGUMENT,
                 "Invalid 'request' argument");
     }
 
     debug() << "Creating a Channel";
     PendingChannel *channel =
-        new PendingChannel(this, request, true);
+        new PendingChannel(ConnectionPtr(this),
+                request, true);
     return channel;
 }
 
@@ -1115,24 +1120,27 @@ PendingChannel *Connection::ensureChannel(const QVariantMap &request)
 {
     if (mPriv->pendingStatus != StatusConnected) {
         warning() << "Calling ensureChannel with connection not yet connected";
-        return new PendingChannel(this, TELEPATHY_ERROR_NOT_AVAILABLE,
+        return new PendingChannel(ConnectionPtr(this),
+                TELEPATHY_ERROR_NOT_AVAILABLE,
                 "Connection not yet connected");
     }
 
     if (!mPriv->interfaces.contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_REQUESTS)) {
         warning() << "Requests interface is not support by this connection";
-        return new PendingChannel(this, TELEPATHY_ERROR_NOT_IMPLEMENTED,
+        return new PendingChannel(ConnectionPtr(this),
+                TELEPATHY_ERROR_NOT_IMPLEMENTED,
                 "Connection does not support Requests Interface");
     }
 
     if (!request.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"))) {
-        return new PendingChannel(this, TELEPATHY_ERROR_INVALID_ARGUMENT,
+        return new PendingChannel(ConnectionPtr(this),
+                TELEPATHY_ERROR_INVALID_ARGUMENT,
                 "Invalid 'request' argument");
     }
 
     debug() << "Creating a Channel";
     PendingChannel *channel =
-        new PendingChannel(this, request, false);
+        new PendingChannel(ConnectionPtr(this), request, false);
     return channel;
 }
 
@@ -1172,7 +1180,7 @@ PendingHandles *Connection::requestHandles(uint handleType, const QStringList &n
     }
 
     PendingHandles *pending =
-        new PendingHandles(this, handleType, names);
+        new PendingHandles(ConnectionPtr(this), handleType, names);
     return pending;
 }
 
@@ -1226,7 +1234,7 @@ PendingHandles *Connection::referenceHandles(uint handleType, const UIntList &ha
         "of the handles -" << notYetHeld.size() << "to go";
 
     PendingHandles *pending =
-        new PendingHandles(this, handleType, handles,
+        new PendingHandles(ConnectionPtr(this), handleType, handles,
                 alreadyHeld, notYetHeld);
     return pending;
 }
@@ -1297,7 +1305,8 @@ PendingContactAttributes *Connection::getContactAttributes(const UIntList &handl
     debug() << "Request for attributes for" << handles.size() << "contacts";
 
     PendingContactAttributes *pending =
-        new PendingContactAttributes(this, handles, interfaces, reference);
+        new PendingContactAttributes(ConnectionPtr(this),
+                handles, interfaces, reference);
     if (!isReady()) {
         warning() << "Connection::getContactAttributes() used when not ready";
         pending->failImmediately(TELEPATHY_ERROR_NOT_AVAILABLE, "The connection isn't ready");
diff --git a/TelepathyQt4/Client/message.cpp b/TelepathyQt4/Client/message.cpp
index 590ce2b..bdba1c1 100644
--- a/TelepathyQt4/Client/message.cpp
+++ b/TelepathyQt4/Client/message.cpp
@@ -63,7 +63,6 @@ public:
 Message::Private::Private(const MessagePartList &parts)
     : parts(parts),
       forceNonText(false),
-      textChannel(0),
       sender(0)
 {
 }
diff --git a/TelepathyQt4/Client/streamed-media-channel.cpp b/TelepathyQt4/Client/streamed-media-channel.cpp
index 7576ec1..b54a862 100644
--- a/TelepathyQt4/Client/streamed-media-channel.cpp
+++ b/TelepathyQt4/Client/streamed-media-channel.cpp
@@ -637,7 +637,8 @@ PendingMediaStreams *StreamedMediaChannel::requestStream(
         const ContactPtr &contact,
         Telepathy::MediaStreamType type)
 {
-    return new PendingMediaStreams(this, contact,
+    return new PendingMediaStreams(StreamedMediaChannelPtr(this),
+            contact,
             QList<Telepathy::MediaStreamType>() << type);
 }
 
@@ -645,7 +646,8 @@ PendingMediaStreams *StreamedMediaChannel::requestStreams(
         const ContactPtr &contact,
         QList<Telepathy::MediaStreamType> types)
 {
-    return new PendingMediaStreams(this, contact, types);
+    return new PendingMediaStreams(StreamedMediaChannelPtr(this),
+            contact, types);
 }
 
 void StreamedMediaChannel::gotStreams(QDBusPendingCallWatcher *watcher)
@@ -669,7 +671,7 @@ void StreamedMediaChannel::gotStreams(QDBusPendingCallWatcher *watcher)
             MediaStreamPtr stream = lookupStreamById(streamInfo.identifier);
             if (!stream) {
                 addStream(MediaStreamPtr(
-                            new MediaStream(this,
+                            new MediaStream(StreamedMediaChannelPtr(this),
                                 streamInfo.identifier,
                                 streamInfo.contact,
                                 (Telepathy::MediaStreamType) streamInfo.type,
@@ -734,7 +736,7 @@ void StreamedMediaChannel::onStreamAdded(uint streamId,
     }
 
     MediaStreamPtr stream = MediaStreamPtr(
-            new MediaStream(this, streamId,
+            new MediaStream(StreamedMediaChannelPtr(this), streamId,
                 contactHandle,
                 (Telepathy::MediaStreamType) streamType,
                 // TODO where to get this info from?
diff --git a/TelepathyQt4/Client/text-channel.cpp b/TelepathyQt4/Client/text-channel.cpp
index bffe7e9..9d268df 100644
--- a/TelepathyQt4/Client/text-channel.cpp
+++ b/TelepathyQt4/Client/text-channel.cpp
@@ -579,7 +579,7 @@ void TextChannel::acknowledge(const QList<ReceivedMessage> &messages)
     UIntList ids;
 
     foreach (const ReceivedMessage &m, messages) {
-        if (m.isFromChannel(this)) {
+        if (m.isFromChannel(TextChannelPtr(this))) {
             ids << m.pendingId();
         } else {
             warning() << "message did not come from this channel, ignoring";
@@ -619,7 +619,7 @@ void TextChannel::acknowledge(const QList<ReceivedMessage> &messages)
 void TextChannel::forget(const QList<ReceivedMessage> &messages)
 {
     foreach (const ReceivedMessage &m, messages) {
-        if (!m.isFromChannel(this)) {
+        if (!m.isFromChannel(TextChannelPtr(this))) {
             warning() << "message did not come from this channel, ignoring";
         } else if (mPriv->messages.removeOne(m)) {
             emit pendingMessageRemoved(m);
@@ -809,7 +809,7 @@ void TextChannel::onMessageReceived(const Telepathy::MessagePartList &parts)
     }
 
     mPriv->incompleteMessages << new Private::QueuedEvent(
-            ReceivedMessage(parts, this));
+            ReceivedMessage(parts, TextChannelPtr(this)));
     processQueue();
 }
 
@@ -870,7 +870,7 @@ void TextChannel::onTextReceived(uint id, uint timestamp, uint sender,
     parts << header;
     parts << body;
 
-    ReceivedMessage m(parts, this);
+    ReceivedMessage m(parts, TextChannelPtr(this));
 
     if (flags & ChannelTextMessageFlagNonTextContent) {
         // set the "you are not expected to understand this" flag
diff --git a/TelepathyQt4/shared-ptr.h b/TelepathyQt4/shared-ptr.h
index d90f012..95431ca 100644
--- a/TelepathyQt4/shared-ptr.h
+++ b/TelepathyQt4/shared-ptr.h
@@ -67,7 +67,7 @@ class SharedPtr
 {
 public:
     inline SharedPtr() : d(0) { }
-    inline SharedPtr(T *d) : d(d) { if (d) { d->ref(); } }
+    explicit inline SharedPtr(T *d) : d(d) { if (d) { d->ref(); } }
     inline SharedPtr(const SharedPtr<T> &o) : d(o.d) { if (d) { d->ref(); } }
     template<class X>
     inline SharedPtr(const SharedPtr<X> &o) : d(static_cast<T *>(o.data())) { if (d) { d->ref(); } }
diff --git a/tests/dbus/text-chan.cpp b/tests/dbus/text-chan.cpp
index dacca68..e529a36 100644
--- a/tests/dbus/text-chan.cpp
+++ b/tests/dbus/text-chan.cpp
@@ -189,7 +189,7 @@ void TestTextChan::init()
 {
     initImpl();
 
-    mChan = 0;
+    mChan.reset();
 }
 
 void TestTextChan::commonTest(bool withMessages)
-- 
1.5.6.5




More information about the telepathy-commits mailing list