[telepathy-qt4/master] StreamedMediaChannel: 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:18:07 PDT 2009


---
 TelepathyQt4/Client/pending-channel.cpp        |    5 ++---
 TelepathyQt4/Client/streamed-media-channel.cpp |   13 +++++++++----
 TelepathyQt4/Client/streamed-media-channel.h   |    9 +++++++--
 examples/call/call-handler.cpp                 |    7 +++----
 examples/call/call-handler.h                   |    4 ++--
 examples/call/call-widget.cpp                  |   16 ++++++++--------
 examples/call/call-widget.h                    |    6 +++---
 examples/call/call-window.cpp                  |    2 +-
 examples/call/farsight-channel.cpp             |    9 +++++----
 examples/call/farsight-channel.h               |    5 +++--
 tests/dbus/streamed-media-chan.cpp             |    4 ++--
 11 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/TelepathyQt4/Client/pending-channel.cpp b/TelepathyQt4/Client/pending-channel.cpp
index b92b008..479c1d9 100644
--- a/TelepathyQt4/Client/pending-channel.cpp
+++ b/TelepathyQt4/Client/pending-channel.cpp
@@ -262,9 +262,8 @@ ChannelPtr PendingChannel::channel() const
                     mPriv->immutableProperties));
     }
     else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) {
-        mPriv->channel = ChannelPtr(
-                new StreamedMediaChannel(mPriv->connection.data(), mPriv->objectPath.path(),
-                    mPriv->immutableProperties));
+        mPriv->channel = StreamedMediaChannel::create(mPriv->connection,
+                mPriv->objectPath.path(), mPriv->immutableProperties);
     }
     else if (channelType() == TELEPATHY_INTERFACE_CHANNEL_TYPE_ROOM_LIST) {
         mPriv->channel = ChannelPtr(
diff --git a/TelepathyQt4/Client/streamed-media-channel.cpp b/TelepathyQt4/Client/streamed-media-channel.cpp
index 4f21bd2..07aa186 100644
--- a/TelepathyQt4/Client/streamed-media-channel.cpp
+++ b/TelepathyQt4/Client/streamed-media-channel.cpp
@@ -512,6 +512,13 @@ void StreamedMediaChannel::Private::introspectStreams(StreamedMediaChannel::Priv
 
 const Feature StreamedMediaChannel::FeatureStreams = Feature(StreamedMediaChannel::staticMetaObject.className(), 0);
 
+StreamedMediaChannelPtr StreamedMediaChannel::create(const ConnectionPtr &connection,
+        const QString &objectPath, const QVariantMap &immutableProperties)
+{
+    return StreamedMediaChannelPtr(new StreamedMediaChannel(connection,
+                objectPath, immutableProperties));
+}
+
 /**
  * Creates a StreamedMediaChannel associated with the given object on the same
  * service as the given connection.
@@ -522,12 +529,10 @@ const Feature StreamedMediaChannel::FeatureStreams = Feature(StreamedMediaChanne
  * \param immutableProperties  The immutable properties of the channel, as
  *                             signalled by NewChannels or returned by
  *                             CreateChannel or EnsureChannel
- * \param parent      Passed to the parent class constructor.
  */
-StreamedMediaChannel::StreamedMediaChannel(Connection *connection,
+StreamedMediaChannel::StreamedMediaChannel(const ConnectionPtr &connection,
         const QString &objectPath,
-        const QVariantMap &immutableProperties,
-        QObject *parent)
+        const QVariantMap &immutableProperties)
     : Channel(connection, objectPath, immutableProperties),
       mPriv(new Private(this))
 {
diff --git a/TelepathyQt4/Client/streamed-media-channel.h b/TelepathyQt4/Client/streamed-media-channel.h
index f5d2b90..d003e12 100644
--- a/TelepathyQt4/Client/streamed-media-channel.h
+++ b/TelepathyQt4/Client/streamed-media-channel.h
@@ -133,8 +133,9 @@ class StreamedMediaChannel : public Channel
 public:
     static const Feature FeatureStreams;
 
-    StreamedMediaChannel(Connection *connection, const QString &objectPath,
-            const QVariantMap &immutableProperties, QObject *parent = 0);
+    static StreamedMediaChannelPtr create(const ConnectionPtr &connection,
+            const QString &objectPath, const QVariantMap &immutableProperties);
+
     ~StreamedMediaChannel();
 
     MediaStreams streams() const;
@@ -167,6 +168,10 @@ Q_SIGNALS:
             Telepathy::MediaStreamError errorCode,
             const QString &errorMessage);
 
+protected:
+    StreamedMediaChannel(const ConnectionPtr &connection,
+            const QString &objectPath, const QVariantMap &immutableProperties);
+
 private Q_SLOTS:
     void gotStreams(QDBusPendingCallWatcher *);
     void onStreamReady(Telepathy::Client::PendingOperation *);
diff --git a/examples/call/call-handler.cpp b/examples/call/call-handler.cpp
index 25660df..abae6a1 100644
--- a/examples/call/call-handler.cpp
+++ b/examples/call/call-handler.cpp
@@ -66,7 +66,7 @@ void CallHandler::addOutgoingCall(const ContactPtr &contact)
             SLOT(onOutgoingChannelCreated(Telepathy::Client::PendingOperation*)));
 }
 
-void CallHandler::addIncomingCall(StreamedMediaChannel *chan)
+void CallHandler::addIncomingCall(const StreamedMediaChannelPtr &chan)
 {
     mChannels.append(chan);
     connect(chan->becomeReady(),
@@ -88,7 +88,7 @@ void CallHandler::onOutgoingChannelCreated(PendingOperation *op)
 
     PendingChannel *pc = qobject_cast<PendingChannel *>(op);
 
-    StreamedMediaChannel *chan = new StreamedMediaChannel(pc->connection().data(),
+    StreamedMediaChannelPtr chan = StreamedMediaChannel::create(pc->connection(),
             pc->objectPath(), pc->immutableProperties());
     mChannels.append(chan);
     connect(chan->becomeReady(),
@@ -166,8 +166,7 @@ void CallHandler::onIncomingChannelReady(PendingOperation *op)
 void CallHandler::onCallTerminated(QObject *obj)
 {
     CallWidget *call = (CallWidget *) obj;
-    StreamedMediaChannel *chan = call->channel();
+    StreamedMediaChannelPtr chan = call->channel();
     mCalls.removeOne(call);
     mChannels.removeOne(chan);
-    delete chan;
 }
diff --git a/examples/call/call-handler.h b/examples/call/call-handler.h
index a4ed503..72be3b7 100644
--- a/examples/call/call-handler.h
+++ b/examples/call/call-handler.h
@@ -45,7 +45,7 @@ public:
     virtual ~CallHandler();
 
     void addOutgoingCall(const Telepathy::Client::ContactPtr &contact);
-    void addIncomingCall(Telepathy::Client::StreamedMediaChannel *chan);
+    void addIncomingCall(const Telepathy::Client::StreamedMediaChannelPtr &chan);
 
 private Q_SLOTS:
     void onOutgoingChannelCreated(Telepathy::Client::PendingOperation *);
@@ -54,7 +54,7 @@ private Q_SLOTS:
     void onCallTerminated(QObject *);
 
 private:
-    QList<Telepathy::Client::StreamedMediaChannel *> mChannels;
+    QList<Telepathy::Client::StreamedMediaChannelPtr> mChannels;
     QList<CallWidget *> mCalls;
 };
 
diff --git a/examples/call/call-widget.cpp b/examples/call/call-widget.cpp
index df47c76..879704e 100644
--- a/examples/call/call-widget.cpp
+++ b/examples/call/call-widget.cpp
@@ -41,7 +41,7 @@
 
 using namespace Telepathy::Client;
 
-CallWidget::CallWidget(StreamedMediaChannel *chan,
+CallWidget::CallWidget(const StreamedMediaChannelPtr &chan,
         const ContactPtr &contact,
         QWidget *parent)
     : QWidget(parent),
@@ -60,7 +60,7 @@ CallWidget::CallWidget(StreamedMediaChannel *chan,
     connect(mChan->becomeReady(StreamedMediaChannel::FeatureStreams),
             SIGNAL(finished(Telepathy::Client::PendingOperation*)),
             SLOT(onChannelReady(Telepathy::Client::PendingOperation*)));
-    connect(mChan,
+    connect(mChan.data(),
             SIGNAL(invalidated(Telepathy::Client::DBusProxy *, const QString &, const QString &)),
             SLOT(onChannelInvalidated(Telepathy::Client::DBusProxy *, const QString &, const QString &)));
 
@@ -177,20 +177,20 @@ void CallWidget::onChannelReady(PendingOperation *op)
         return;
     }
 
-    connect(mChan,
+    connect(mChan.data(),
             SIGNAL(streamAdded(const Telepathy::Client::MediaStreamPtr &)),
             SLOT(onStreamAdded(const Telepathy::Client::MediaStreamPtr &)));
-    connect(mChan,
+    connect(mChan.data(),
             SIGNAL(streamRemoved(const Telepathy::Client::MediaStreamPtr &)),
             SLOT(onStreamRemoved(const Telepathy::Client::MediaStreamPtr &)));
-    connect(mChan,
+    connect(mChan.data(),
             SIGNAL(streamDirectionChanged(const Telepathy::Client::MediaStreamPtr &,
                                           Telepathy::MediaStreamDirection,
                                           Telepathy::MediaStreamPendingSend)),
             SLOT(onStreamDirectionChanged(const Telepathy::Client::MediaStreamPtr &,
                                           Telepathy::MediaStreamDirection,
                                           Telepathy::MediaStreamPendingSend)));
-    connect(mChan,
+    connect(mChan.data(),
             SIGNAL(streamStateChanged(const Telepathy::Client::MediaStreamPtr &,
                                       Telepathy::MediaStreamState)),
             SLOT(onStreamStateChanged(const Telepathy::Client::MediaStreamPtr &,
@@ -220,7 +220,7 @@ void CallWidget::onChannelReady(PendingOperation *op)
 void CallWidget::onChannelInvalidated(DBusProxy *proxy,
         const QString &errorName, const QString &errorMessage)
 {
-    qDebug() << "CallWindow::onChannelInvalidated: channel became invalid:" <<
+    qDebug() << "CallWidget::onChannelInvalidated: channel became invalid:" <<
         errorName << "-" << errorMessage;
     callEnded(errorMessage);
 }
@@ -464,7 +464,7 @@ void CallWidget::updateStreamDirection(const MediaStreamPtr &stream)
 void CallWidget::callEnded(const QString &message)
 {
     mStatusBar->showMessage(message);
-    disconnect(mChan,
+    disconnect(mChan.data(),
                SIGNAL(invalidated(Telepathy::Client::DBusProxy *, const QString &, const QString &)),
                this,
                SLOT(onChannelInvalidated(Telepathy::Client::DBusProxy *, const QString &, const QString &)));
diff --git a/examples/call/call-widget.h b/examples/call/call-widget.h
index a587c90..10a8a57 100644
--- a/examples/call/call-widget.h
+++ b/examples/call/call-widget.h
@@ -49,12 +49,12 @@ class CallWidget : public QWidget
     Q_OBJECT
 
 public:
-    CallWidget(Telepathy::Client::StreamedMediaChannel *channel,
+    CallWidget(const Telepathy::Client::StreamedMediaChannelPtr &channel,
                const Telepathy::Client::ContactPtr &contact,
                QWidget *parent = 0);
     virtual ~CallWidget();
 
-    Telepathy::Client::StreamedMediaChannel *channel() const { return mChan; }
+    Telepathy::Client::StreamedMediaChannelPtr channel() const { return mChan; }
     Telepathy::Client::ContactPtr contact() const { return mContact; }
 
 private Q_SLOTS:
@@ -84,7 +84,7 @@ private:
 
     void callEnded(const QString &message);
 
-    Telepathy::Client::StreamedMediaChannel *mChan;
+    Telepathy::Client::StreamedMediaChannelPtr mChan;
     Telepathy::Client::ContactPtr mContact;
     Telepathy::Client::FarsightChannel *mTfChan;
 
diff --git a/examples/call/call-window.cpp b/examples/call/call-window.cpp
index 902e3fd..c881f3c 100644
--- a/examples/call/call-window.cpp
+++ b/examples/call/call-window.cpp
@@ -161,7 +161,7 @@ void CallWindow::onNewChannels(const Telepathy::ChannelDetailsList &channels)
 
         if (channelType == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA &&
             !requested) {
-            StreamedMediaChannel *channel = new StreamedMediaChannel(mConn.data(),
+            StreamedMediaChannelPtr channel = StreamedMediaChannel::create(mConn,
                         details.channel.path(),
                         details.properties);
             mCallHandler->addIncomingCall(channel);
diff --git a/examples/call/farsight-channel.cpp b/examples/call/farsight-channel.cpp
index 6ee1397..49006aa 100644
--- a/examples/call/farsight-channel.cpp
+++ b/examples/call/farsight-channel.cpp
@@ -38,7 +38,7 @@ namespace Client {
 
 struct FarsightChannel::Private
 {
-    Private(FarsightChannel *parent, StreamedMediaChannel *channel);
+    Private(FarsightChannel *parent, const StreamedMediaChannelPtr &channel);
     ~Private();
 
     static gboolean busWatch(GstBus *bus,
@@ -56,7 +56,7 @@ struct FarsightChannel::Private
             guint direction, gpointer data);
 
     FarsightChannel *parent;
-    StreamedMediaChannel *channel;
+    StreamedMediaChannelPtr channel;
     Status status;
     TfChannel *tfChannel;
     GstBus *bus;
@@ -70,7 +70,7 @@ struct FarsightChannel::Private
 };
 
 FarsightChannel::Private::Private(FarsightChannel *parent,
-        StreamedMediaChannel *channel)
+        const StreamedMediaChannelPtr &channel)
     : parent(parent),
       channel(channel),
       status(StatusDisconnected),
@@ -324,7 +324,8 @@ gboolean FarsightChannel::Private::onRequestResource(TfStream *stream,
     return TRUE;
 }
 
-FarsightChannel::FarsightChannel(StreamedMediaChannel *channel, QObject *parent)
+FarsightChannel::FarsightChannel(const StreamedMediaChannelPtr &channel,
+        QObject *parent)
     : QObject(parent),
       mPriv(new Private(this, channel))
 {
diff --git a/examples/call/farsight-channel.h b/examples/call/farsight-channel.h
index 9a2573c..0ed81bb 100644
--- a/examples/call/farsight-channel.h
+++ b/examples/call/farsight-channel.h
@@ -22,6 +22,8 @@
 #ifndef _TelepathyQt4_examples_call_farsight_channel_h_HEADER_GUARD_
 #define _TelepathyQt4_examples_call_farsight_channel_h_HEADER_GUARD_
 
+#include <TelepathyQt4/Client/Types>
+
 #include <QObject>
 #include <QMetaType>
 
@@ -31,7 +33,6 @@ namespace Telepathy {
 namespace Client {
 
 class Connection;
-class StreamedMediaChannel;
 class VideoWidget;
 
 class FarsightChannel : public QObject
@@ -46,7 +47,7 @@ public:
         StatusConnected = 2
     };
 
-    FarsightChannel(StreamedMediaChannel *channel, QObject *parent = 0);
+    FarsightChannel(const StreamedMediaChannelPtr &channel, QObject *parent = 0);
     virtual ~FarsightChannel();
 
     Status status() const;
diff --git a/tests/dbus/streamed-media-chan.cpp b/tests/dbus/streamed-media-chan.cpp
index 74ec755..4367b8a 100644
--- a/tests/dbus/streamed-media-chan.cpp
+++ b/tests/dbus/streamed-media-chan.cpp
@@ -218,9 +218,9 @@ void TestStreamedMediaChan::onNewChannels(const Telepathy::ChannelDetailsList &c
 
         if (channelType == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA &&
             !requested) {
-            mChan = StreamedMediaChannelPtr(new StreamedMediaChannel(mConn.data(),
+            mChan = StreamedMediaChannel::create(mConn.data(),
                         details.channel.path(),
-                        details.properties));
+                        details.properties);
             mLoop->exit(0);
         }
     }
-- 
1.5.6.5




More information about the telepathy-commits mailing list