diff options
author | Olli Salli <ollisal@gmail.com> | 2011-08-12 16:32:16 +0300 |
---|---|---|
committer | Olli Salli <ollisal@gmail.com> | 2011-10-10 19:17:40 +0300 |
commit | 311b5f1395362a6d67dbc527b8ac63bdb2ac1c94 (patch) | |
tree | 983afc7b263af8a8d318a9e24a8b1aefd9c9d0b7 /examples | |
parent | cb990d8e2573f3b3bdc626de8215c1834dd95728 (diff) |
tube-receiver example: Port to StreamTubeClient
Diffstat (limited to 'examples')
-rw-r--r-- | examples/stream-tubes/tube-receiver.cpp | 146 | ||||
-rw-r--r-- | examples/stream-tubes/tube-receiver.h | 15 |
2 files changed, 15 insertions, 146 deletions
diff --git a/examples/stream-tubes/tube-receiver.cpp b/examples/stream-tubes/tube-receiver.cpp index d3d0e83b..87fc28d9 100644 --- a/examples/stream-tubes/tube-receiver.cpp +++ b/examples/stream-tubes/tube-receiver.cpp @@ -21,155 +21,40 @@ #include "tube-receiver.h" -// FIXME: This example is quite non-exemplary, as it uses RequestConnection and the Requests -// low-level interface (!!!) directly! -#define TP_QT4_ENABLE_LOWLEVEL_API - -#include <TelepathyQt4/Account> #include <TelepathyQt4/Debug> -#include <TelepathyQt4/Connection> -#include <TelepathyQt4/ConnectionLowlevel> -#include <TelepathyQt4/ConnectionManager> -#include <TelepathyQt4/ConnectionManagerLowlevel> -#include <TelepathyQt4/Constants> #include <TelepathyQt4/IncomingStreamTubeChannel> -#include <TelepathyQt4/PendingConnection> -#include <TelepathyQt4/PendingOperation> -#include <TelepathyQt4/PendingReady> -#include <TelepathyQt4/PendingStreamTubeConnection> +#include <TelepathyQt4/StreamTubeClient> #include <QDebug> #include <QIODevice> +#include <QStringList> TubeReceiver::TubeReceiver(const QString &accountName, QObject *parent) : QObject(parent) { - // We only care about CONNECTED connections, so let's specify that in a Connection Factory - ConnectionFactoryPtr connectionFactory = ConnectionFactory::create( - QDBusConnection::sessionBus(), Connection::FeatureConnected); - - mAccount = Account::create(TP_QT4_ACCOUNT_MANAGER_BUS_NAME, - TP_QT4_ACCOUNT_OBJECT_PATH_BASE + QLatin1Char('/') + accountName, - connectionFactory); - - connect(mAccount->becomeReady(Account::FeatureCore), - SIGNAL(finished(Tp::PendingOperation *)), - SLOT(onAccountReady(Tp::PendingOperation *))); + mTubeClient = StreamTubeClient::create(QStringList() << QLatin1String("tp-qt4-stube-example")); + connect(mTubeClient.data(), + SIGNAL(tubeAcceptedAsUnix(Tp::AccountPtr,Tp::IncomingStreamTubeChannelPtr,QString, + bool,uchar)), + SLOT(onTubeAccepted(Tp::AccountPtr,Tp::IncomingStreamTubeChannelPtr,QString))); + mTubeClient->setToAcceptAsUnix(false); // no SCM_CREDENTIALS required } TubeReceiver::~TubeReceiver() { } -void TubeReceiver::onAccountReady(Tp::PendingOperation *op) -{ - if (op->isError()) { - qWarning() << "Account cannot become ready - " << - op->errorName() << '-' << op->errorMessage(); - QCoreApplication::exit(1); - return; - } - - qDebug() << "Account ready"; - connect(mAccount.data(), - SIGNAL(connectionChanged(Tp::ConnectionPtr)), - SLOT(onAccountConnectionChanged(Tp::ConnectionPtr))); - - if (mAccount->connection().isNull()) { - qDebug() << "The account given has no Connection. Please set it online to continue."; - } else { - onAccountConnectionChanged(mAccount->connection()); - } -} - -void TubeReceiver::onAccountConnectionChanged(const ConnectionPtr &conn) +void TubeReceiver::onTubeAccepted(const Tp::AccountPtr &acc, + const Tp::IncomingStreamTubeChannelPtr &tube, const QString &listenAddress) { - if (!conn) { - return; - } - - Q_ASSERT(conn->isValid()); - Q_ASSERT(conn->status() == ConnectionStatusConnected); - - qDebug() << "Got a Connected Connection!"; - mConn = conn; - - QMap<QString, QDBusVariant> filter; - filter[QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")] = - QDBusVariant(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAM_TUBE)); - filter[QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType")] = - QDBusVariant(uint(1)); - HandlerCapabilities capabilities; - capabilities.channelClasses << Tp::ChannelClass(filter); - - Client::ConnectionInterfaceContactCapabilitiesInterface *contactCapabilitiesInterface = - mConn->optionalInterface<Client::ConnectionInterfaceContactCapabilitiesInterface>(); - contactCapabilitiesInterface->UpdateCapabilities(HandlerCapabilitiesList() << - capabilities); - - connect(mConn->optionalInterface<Client::ConnectionInterfaceRequestsInterface>(), - SIGNAL(NewChannels(const Tp::ChannelDetailsList&)), - SLOT(onNewChannels(const Tp::ChannelDetailsList&))); -} - -void TubeReceiver::onNewChannels(const Tp::ChannelDetailsList &channels) -{ - foreach (const Tp::ChannelDetails &details, channels) { - QString channelType = details.properties.value(QLatin1String(TELEPATHY_INTERFACE_CHANNEL - ".ChannelType")).toString(); - bool requested = details.properties.value(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".Requested")).toBool(); - qDebug() << " channelType:" << channelType; - qDebug() << " requested :" << requested; - - if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAM_TUBE) && - !requested) { - mChan = IncomingStreamTubeChannel::create(mConn, - details.channel.path(), - details.properties); - connect(mChan.data(), - SIGNAL(invalidated(Tp::DBusProxy *, const QString &, const QString &)), - SLOT(onInvalidated())); - Features features = Features() << TubeChannel::FeatureTube - << StreamTubeChannel::FeatureStreamTube; - connect(mChan->becomeReady(features), - SIGNAL(finished(Tp::PendingOperation *)), - SLOT(onStreamTubeChannelReady(Tp::PendingOperation*))); - } - } -} - -void TubeReceiver::onStreamTubeChannelReady(PendingOperation* op) -{ - if (op->isError()) { - qWarning() << "Unable to make stream tube channel ready -" << - op->errorName() << ": " << op->errorMessage(); - onInvalidated(); - return; - } - - qDebug() << "Stream tube channel ready!"; - - connect(mChan->acceptTubeAsUnixSocket(), - SIGNAL(finished(Tp::PendingOperation*)), - SLOT(onStreamTubeAccepted(Tp::PendingOperation*))); -} - -void TubeReceiver::onStreamTubeAccepted(PendingOperation* op) -{ - if (op->isError()) { - qWarning() << "Unable to accept stream tube channel -" << - op->errorName() << ": " << op->errorMessage(); - onInvalidated(); - return; - } - - qDebug() << "Stream tube channel accepted and opened!"; + qDebug() << "Stream tube channel" << tube->objectPath() << "accepted and opened!"; mDevice = new QLocalSocket(this); - mDevice->connectToServer(mChan->localAddress()); + mDevice->connectToServer(listenAddress); connect(mDevice, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)), this, SLOT(onStateChanged(QLocalSocket::LocalSocketState))); + onStateChanged(mDevice->state()); } void TubeReceiver::onStateChanged(QLocalSocket::LocalSocketState state) @@ -202,11 +87,6 @@ void TubeReceiver::onTimerTimeout() mDevice->write(QByteArray("ping, I'm alive\n")); } -void TubeReceiver::onInvalidated() -{ - QCoreApplication::exit(1); -} - int main(int argc, char **argv) { QCoreApplication app(argc, argv); diff --git a/examples/stream-tubes/tube-receiver.h b/examples/stream-tubes/tube-receiver.h index 7cdb6c9c..67087d20 100644 --- a/examples/stream-tubes/tube-receiver.h +++ b/examples/stream-tubes/tube-receiver.h @@ -22,8 +22,6 @@ #ifndef _TelepathyQt4_examples_stream_tubes_tube_receiver_h_HEADER_GUARD_ #define _TelepathyQt4_examples_stream_tubes_tube_receiver_h_HEADER_GUARD_ -#include <TelepathyQt4/Constants> -#include <TelepathyQt4/Contact> #include <TelepathyQt4/Types> #include <QLocalSocket> @@ -44,23 +42,14 @@ public: ~TubeReceiver(); private Q_SLOTS: - void onAccountReady(Tp::PendingOperation *op); - void onAccountConnectionChanged(const Tp::ConnectionPtr &); - void onNewChannels(const Tp::ChannelDetailsList &channels); - void onStreamTubeChannelReady(Tp::PendingOperation*); - void onStreamTubeAccepted(Tp::PendingOperation*); + void onTubeAccepted(const Tp::AccountPtr &, const Tp::IncomingStreamTubeChannelPtr &, const QString &); void onStateChanged(QLocalSocket::LocalSocketState); void onTimerTimeout(); void onDataFromSocket(); - void onInvalidated(); private: - AccountPtr mAccount; + StreamTubeClientPtr mTubeClient; QLocalSocket *mDevice; - - ConnectionManagerPtr mCM; - ConnectionPtr mConn; - IncomingStreamTubeChannelPtr mChan; }; #endif |