Home · All Classes · All Namespaces · Modules · Functions · Files
stream-tube-client.h
00001 
00023 #ifndef _TelepathyQt4_stream_tube_client_h_HEADER_GUARD_
00024 #define _TelepathyQt4_stream_tube_client_h_HEADER_GUARD_
00025 
00026 #include <TelepathyQt4/AccountFactory>
00027 #include <TelepathyQt4/ChannelFactory>
00028 #include <TelepathyQt4/ConnectionFactory>
00029 #include <TelepathyQt4/ContactFactory>
00030 #include <TelepathyQt4/RefCounted>
00031 #include <TelepathyQt4/Types>
00032 
00033 class QHostAddress;
00034 
00035 namespace Tp
00036 {
00037 
00038 class PendingStreamTubeConnection;
00039 
00040 class TELEPATHY_QT4_EXPORT StreamTubeClient : public QObject, public RefCounted
00041 {
00042     Q_OBJECT
00043     Q_DISABLE_COPY(StreamTubeClient)
00044 
00045     class TubeWrapper;
00046 
00047 public:
00048 
00049     class TcpSourceAddressGenerator
00050     {
00051     public:
00052         virtual QPair<QHostAddress, quint16>
00053             nextSourceAddress(const AccountPtr &account, const IncomingStreamTubeChannelPtr &tube) = 0;
00054 
00055     protected:
00056         virtual ~TcpSourceAddressGenerator() {}
00057     };
00058 
00059     class Tube : public QPair<AccountPtr, IncomingStreamTubeChannelPtr>
00060     {
00061     public:
00062         Tube();
00063         Tube(const AccountPtr &account, const IncomingStreamTubeChannelPtr &channel);
00064         Tube(const Tube &other);
00065         ~Tube();
00066 
00067         bool isValid() const { return mPriv.constData() != 0; }
00068 
00069         Tube &operator=(const Tube &other);
00070 
00071         const AccountPtr &account() const
00072         {
00073             return first;
00074         }
00075 
00076         const IncomingStreamTubeChannelPtr &channel() const
00077         {
00078             return second;
00079         }
00080 
00081     private:
00082         struct Private;
00083         friend struct Private;
00084         QSharedDataPointer<Private> mPriv;
00085     };
00086 
00087     static StreamTubeClientPtr create(
00088             const QStringList &p2pServices,
00089             const QStringList &roomServices = QStringList(),
00090             const QString &clientName = QString(),
00091             bool monitorConnections = false,
00092             bool bypassApproval = false,
00093             const AccountFactoryConstPtr &accountFactory =
00094                 AccountFactory::create(QDBusConnection::sessionBus()),
00095             const ConnectionFactoryConstPtr &connectionFactory =
00096                 ConnectionFactory::create(QDBusConnection::sessionBus()),
00097             const ChannelFactoryConstPtr &channelFactory =
00098                 ChannelFactory::create(QDBusConnection::sessionBus()),
00099             const ContactFactoryConstPtr &contactFactory =
00100                 ContactFactory::create());
00101 
00102     static StreamTubeClientPtr create(
00103             const QDBusConnection &bus,
00104             const AccountFactoryConstPtr &accountFactory,
00105             const ConnectionFactoryConstPtr &connectionFactory,
00106             const ChannelFactoryConstPtr &channelFactory,
00107             const ContactFactoryConstPtr &contactFactory,
00108             const QStringList &p2pServices,
00109             const QStringList &roomServices = QStringList(),
00110             const QString &clientName = QString(),
00111             bool monitorConnections = false,
00112             bool bypassApproval = false);
00113 
00114     static StreamTubeClientPtr create(
00115             const AccountManagerPtr &accountManager,
00116             const QStringList &p2pServices,
00117             const QStringList &roomServices = QStringList(),
00118             const QString &clientName = QString(),
00119             bool monitorConnections = false,
00120             bool bypassApproval = false);
00121 
00122     static StreamTubeClientPtr create(
00123             const ClientRegistrarPtr &registrar,
00124             const QStringList &p2pServices,
00125             const QStringList &roomServices = QStringList(),
00126             const QString &clientName = QString(),
00127             bool monitorConnections = false,
00128             bool bypassApproval = false);
00129 
00130     virtual ~StreamTubeClient();
00131 
00132     ClientRegistrarPtr registrar() const;
00133     QString clientName() const;
00134     bool isRegistered() const;
00135     bool monitorsConnections() const;
00136 
00137     bool acceptsAsTcp() const;
00138     TcpSourceAddressGenerator *tcpGenerator() const;
00139     bool acceptsAsUnix() const;
00140 
00141     void setToAcceptAsTcp(TcpSourceAddressGenerator *generator = 0);
00142     void setToAcceptAsUnix(bool requireCredentials = false);
00143 
00144     QList<Tube> tubes() const;
00145     QHash<Tube, QSet<uint> > connections() const;
00146 
00147 Q_SIGNALS:
00148     void tubeOffered(
00149             const Tp::AccountPtr &account,
00150             const Tp::IncomingStreamTubeChannelPtr &tube);
00151     void tubeClosed(
00152             const Tp::AccountPtr &account,
00153             const Tp::IncomingStreamTubeChannelPtr &tube,
00154             const QString &error,
00155             const QString &message);
00156 
00157     void tubeAcceptedAsTcp(
00158             const QHostAddress &listenAddress,
00159             quint16 listenPort,
00160             const QHostAddress &sourceAddress,
00161             quint16 sourcePort,
00162             const Tp::AccountPtr &account,
00163             const Tp::IncomingStreamTubeChannelPtr &tube);
00164     void tubeAcceptedAsUnix(
00165             const QString &listenAddress,
00166             bool requiresCredentials,
00167             uchar credentialByte,
00168             const Tp::AccountPtr &account,
00169             const Tp::IncomingStreamTubeChannelPtr &tube);
00170 
00171     void newConnection(
00172             const Tp::AccountPtr &account,
00173             const Tp::IncomingStreamTubeChannelPtr &tube,
00174             uint connectionId);
00175     void connectionClosed(
00176             const Tp::AccountPtr &account,
00177             const Tp::IncomingStreamTubeChannelPtr &tube,
00178             uint connectionId,
00179             const QString &error,
00180             const QString &message);
00181 
00182 private Q_SLOTS:
00183 
00184     TELEPATHY_QT4_NO_EXPORT void onInvokedForTube(
00185             const Tp::AccountPtr &account,
00186             const Tp::StreamTubeChannelPtr &tube,
00187             const QDateTime &userActionTime,
00188             const Tp::ChannelRequestHints &requestHints);
00189 
00190     TELEPATHY_QT4_NO_EXPORT void onAcceptFinished(TubeWrapper *, Tp::PendingStreamTubeConnection *);
00191     TELEPATHY_QT4_NO_EXPORT void onTubeInvalidated(Tp::DBusProxy *, const QString &, const QString &);
00192 
00193     TELEPATHY_QT4_NO_EXPORT void onNewConnection(
00194             TubeWrapper *wrapper,
00195             uint conn);
00196     TELEPATHY_QT4_NO_EXPORT void onConnectionClosed(
00197             TubeWrapper *wrapper,
00198             uint conn,
00199             const QString &error,
00200             const QString &message);
00201 
00202 private:
00203     TELEPATHY_QT4_NO_EXPORT StreamTubeClient(
00204             const ClientRegistrarPtr &registrar,
00205             const QStringList &p2pServices,
00206             const QStringList &roomServices,
00207             const QString &clientName,
00208             bool monitorConnections,
00209             bool bypassApproval);
00210 
00211     struct Private;
00212     Private *mPriv;
00213 };
00214 
00215 } // Tp
00216 
00217 #endif


Copyright © 2008-2011 Collabora Ltd. and Nokia Corporation
Telepathy-Qt4 0.8.0