Home · All Classes · All Namespaces · Modules · Functions · Files
stream-tube-server.h
00001 
00023 #ifndef _TelepathyQt4_stream_tube_server_h_HEADER_GUARD_
00024 #define _TelepathyQt4_stream_tube_server_h_HEADER_GUARD_
00025 
00026 #include <QPair>
00027 #include <QSharedDataPointer>
00028 
00029 #include <TelepathyQt4/AccountFactory>
00030 #include <TelepathyQt4/ChannelFactory>
00031 #include <TelepathyQt4/ConnectionFactory>
00032 #include <TelepathyQt4/ContactFactory>
00033 #include <TelepathyQt4/RefCounted>
00034 #include <TelepathyQt4/Types>
00035 
00036 class QHostAddress;
00037 class QTcpServer;
00038 
00039 namespace Tp
00040 {
00041 
00042 class TELEPATHY_QT4_EXPORT StreamTubeServer : public QObject, public RefCounted
00043 {
00044     Q_OBJECT
00045     Q_DISABLE_COPY(StreamTubeServer)
00046 
00047     class TubeWrapper;
00048 
00049 public:
00050 
00051     class ParametersGenerator
00052     {
00053     public:
00054         virtual QVariantMap
00055             nextParameters(const AccountPtr &account, const OutgoingStreamTubeChannelPtr &tube,
00056                     const ChannelRequestHints &hints) = 0;
00057 
00058     protected:
00059         virtual ~ParametersGenerator() {}
00060     };
00061 
00062     class RemoteContact : public QPair<AccountPtr, ContactPtr>
00063     {
00064     public:
00065         RemoteContact();
00066         RemoteContact(const AccountPtr &account, const ContactPtr &contact);
00067         RemoteContact(const RemoteContact &other);
00068         ~RemoteContact();
00069 
00070         bool isValid() const { return mPriv.constData() != 0; }
00071 
00072         RemoteContact &operator=(const RemoteContact &other);
00073 
00074         const AccountPtr &account() const
00075         {
00076             return first;
00077         }
00078 
00079         const ContactPtr &contact() const
00080         {
00081             return second;
00082         }
00083 
00084     private:
00085         struct Private;
00086         friend struct Private;
00087         QSharedDataPointer<Private> mPriv;
00088     };
00089 
00090     class Tube : public QPair<AccountPtr, OutgoingStreamTubeChannelPtr>
00091     {
00092     public:
00093         Tube();
00094         Tube(const AccountPtr &account, const OutgoingStreamTubeChannelPtr &channel);
00095         Tube(const Tube &other);
00096         ~Tube();
00097 
00098         bool isValid() const { return mPriv.constData() != 0; }
00099 
00100         Tube &operator=(const Tube &other);
00101 
00102         const AccountPtr &account() const
00103         {
00104             return first;
00105         }
00106 
00107         const OutgoingStreamTubeChannelPtr &channel() const
00108         {
00109             return second;
00110         }
00111 
00112     private:
00113         struct Private;
00114         friend struct Private;
00115         QSharedDataPointer<Private> mPriv;
00116     };
00117 
00118     static StreamTubeServerPtr create(
00119             const QStringList &p2pServices,
00120             const QStringList &roomServices = QStringList(),
00121             const QString &clientName = QString(),
00122             bool monitorConnections = false,
00123             const AccountFactoryConstPtr &accountFactory =
00124                 AccountFactory::create(QDBusConnection::sessionBus()),
00125             const ConnectionFactoryConstPtr &connectionFactory =
00126                 ConnectionFactory::create(QDBusConnection::sessionBus()),
00127             const ChannelFactoryConstPtr &channelFactory =
00128                 ChannelFactory::create(QDBusConnection::sessionBus()),
00129             const ContactFactoryConstPtr &contactFactory =
00130                 ContactFactory::create());
00131 
00132     static StreamTubeServerPtr create(
00133             const QDBusConnection &bus,
00134             const AccountFactoryConstPtr &accountFactory,
00135             const ConnectionFactoryConstPtr &connectionFactory,
00136             const ChannelFactoryConstPtr &channelFactory,
00137             const ContactFactoryConstPtr &contactFactory,
00138             const QStringList &p2pServices,
00139             const QStringList &roomServices = QStringList(),
00140             const QString &clientName = QString(),
00141             bool monitorConnections = false);
00142 
00143     static StreamTubeServerPtr create(
00144             const AccountManagerPtr &accountManager,
00145             const QStringList &p2pServices,
00146             const QStringList &roomServices = QStringList(),
00147             const QString &clientName = QString(),
00148             bool monitorConnections = false);
00149 
00150     static StreamTubeServerPtr create(
00151             const ClientRegistrarPtr &registrar,
00152             const QStringList &p2pServices,
00153             const QStringList &roomServices = QStringList(),
00154             const QString &clientName = QString(),
00155             bool monitorConnections = false);
00156 
00157     virtual ~StreamTubeServer();
00158 
00159     ClientRegistrarPtr registrar() const;
00160     QString clientName() const;
00161     bool isRegistered() const;
00162     bool monitorsConnections() const;
00163 
00164     QPair<QHostAddress, quint16> exportedTcpSocketAddress() const;
00165     QVariantMap exportedParameters() const;
00166 
00167     void exportTcpSocket(
00168             const QHostAddress &address,
00169             quint16 port,
00170             const QVariantMap &parameters = QVariantMap());
00171     void exportTcpSocket(
00172             const QTcpServer *server,
00173             const QVariantMap &parameters = QVariantMap());
00174 
00175     void exportTcpSocket(
00176             const QHostAddress &address,
00177             quint16 port,
00178             ParametersGenerator *generator);
00179     void exportTcpSocket(
00180             const QTcpServer *server,
00181             ParametersGenerator *generator);
00182 
00183     QList<Tube> tubes() const;
00184 
00185     QHash<QPair<QHostAddress, quint16>, RemoteContact> tcpConnections() const;
00186 
00187 Q_SIGNALS:
00188 
00189     void tubeRequested(
00190             const Tp::AccountPtr &account,
00191             const Tp::OutgoingStreamTubeChannelPtr &tube,
00192             const QDateTime &userActionTime,
00193             const Tp::ChannelRequestHints &hints);
00194     void tubeClosed(
00195             const Tp::AccountPtr &account,
00196             const Tp::OutgoingStreamTubeChannelPtr &tube,
00197             const QString &error,
00198             const QString &message);
00199 
00200     void newTcpConnection(
00201             const QHostAddress &sourceAddress,
00202             quint16 sourcePort,
00203             const Tp::AccountPtr &account,
00204             const Tp::ContactPtr &contact,
00205             const Tp::OutgoingStreamTubeChannelPtr &tube);
00206     void tcpConnectionClosed(
00207             const QHostAddress &sourceAddress,
00208             quint16 sourcePort,
00209             const Tp::AccountPtr &account,
00210             const Tp::ContactPtr &contact,
00211             const QString &error,
00212             const QString &message,
00213             const Tp::OutgoingStreamTubeChannelPtr &tube);
00214 
00215 private Q_SLOTS:
00216     TELEPATHY_QT4_NO_EXPORT void onInvokedForTube(
00217             const Tp::AccountPtr &account,
00218             const Tp::StreamTubeChannelPtr &tube,
00219             const QDateTime &userActionTime,
00220             const Tp::ChannelRequestHints &requestHints);
00221 
00222     TELEPATHY_QT4_NO_EXPORT void onOfferFinished(
00223             TubeWrapper *wrapper,
00224             Tp::PendingOperation *op);
00225     TELEPATHY_QT4_NO_EXPORT void onTubeInvalidated(
00226             Tp::DBusProxy *proxy,
00227             const QString &error,
00228             const QString &message);
00229 
00230     TELEPATHY_QT4_NO_EXPORT void onNewConnection(
00231             TubeWrapper *wrapper,
00232             uint conn);
00233     TELEPATHY_QT4_NO_EXPORT void onConnectionClosed(
00234             TubeWrapper *wrapper,
00235             uint conn,
00236             const QString &error,
00237             const QString &message);
00238 
00239 private:
00240     TELEPATHY_QT4_NO_EXPORT StreamTubeServer(
00241             const ClientRegistrarPtr &registrar,
00242             const QStringList &p2pServices,
00243             const QStringList &roomServices,
00244             const QString &clientName,
00245             bool monitorConnections);
00246 
00247     struct Private;
00248     Private *mPriv;
00249 };
00250 
00251 } // Tp
00252 
00253 #endif


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