Home · Modules · All Classes · All Namespaces
stream-tube-server.h
1 
23 #ifndef _TelepathyQt_stream_tube_server_h_HEADER_GUARD_
24 #define _TelepathyQt_stream_tube_server_h_HEADER_GUARD_
25 
26 #include <QPair>
27 #include <QSharedDataPointer>
28 
29 #include <TelepathyQt/AccountFactory>
30 #include <TelepathyQt/ChannelFactory>
31 #include <TelepathyQt/ConnectionFactory>
32 #include <TelepathyQt/ContactFactory>
33 #include <TelepathyQt/RefCounted>
34 #include <TelepathyQt/Types>
35 
36 class QHostAddress;
37 class QTcpServer;
38 
39 namespace Tp
40 {
41 
42 class TP_QT_EXPORT StreamTubeServer : public QObject, public RefCounted
43 {
44  Q_OBJECT
45  Q_DISABLE_COPY(StreamTubeServer)
46 
47  class TubeWrapper;
48 
49 public:
50 
52  {
53  public:
54  virtual QVariantMap
55  nextParameters(const AccountPtr &account, const OutgoingStreamTubeChannelPtr &tube,
56  const ChannelRequestHints &hints) = 0;
57 
58  protected:
59  virtual ~ParametersGenerator() {}
60  };
61 
62  class RemoteContact : public QPair<AccountPtr, ContactPtr>
63  {
64  public:
65  RemoteContact();
66  RemoteContact(const AccountPtr &account, const ContactPtr &contact);
67  RemoteContact(const RemoteContact &other);
68  ~RemoteContact();
69 
70  bool isValid() const { return mPriv.constData() != 0; }
71 
72  RemoteContact &operator=(const RemoteContact &other);
73 
74  const AccountPtr &account() const
75  {
76  return first;
77  }
78 
79  const ContactPtr &contact() const
80  {
81  return second;
82  }
83 
84  private:
85  struct Private;
86  friend struct Private;
87  QSharedDataPointer<Private> mPriv;
88  };
89 
90  class Tube : public QPair<AccountPtr, OutgoingStreamTubeChannelPtr>
91  {
92  public:
93  Tube();
94  Tube(const AccountPtr &account, const OutgoingStreamTubeChannelPtr &channel);
95  Tube(const Tube &other);
96  ~Tube();
97 
98  bool isValid() const { return mPriv.constData() != 0; }
99 
100  Tube &operator=(const Tube &other);
101 
102  const AccountPtr &account() const
103  {
104  return first;
105  }
106 
107  const OutgoingStreamTubeChannelPtr &channel() const
108  {
109  return second;
110  }
111 
112  private:
113  struct Private;
114  friend struct Private;
115  QSharedDataPointer<Private> mPriv;
116  };
117 
118  static StreamTubeServerPtr create(
119  const QStringList &p2pServices,
120  const QStringList &roomServices = QStringList(),
121  const QString &clientName = QString(),
122  bool monitorConnections = false,
123  const AccountFactoryConstPtr &accountFactory =
124  AccountFactory::create(QDBusConnection::sessionBus()),
125  const ConnectionFactoryConstPtr &connectionFactory =
126  ConnectionFactory::create(QDBusConnection::sessionBus()),
127  const ChannelFactoryConstPtr &channelFactory =
128  ChannelFactory::create(QDBusConnection::sessionBus()),
129  const ContactFactoryConstPtr &contactFactory =
131 
132  static StreamTubeServerPtr create(
133  const QDBusConnection &bus,
134  const AccountFactoryConstPtr &accountFactory,
135  const ConnectionFactoryConstPtr &connectionFactory,
136  const ChannelFactoryConstPtr &channelFactory,
137  const ContactFactoryConstPtr &contactFactory,
138  const QStringList &p2pServices,
139  const QStringList &roomServices = QStringList(),
140  const QString &clientName = QString(),
141  bool monitorConnections = false);
142 
143  static StreamTubeServerPtr create(
144  const AccountManagerPtr &accountManager,
145  const QStringList &p2pServices,
146  const QStringList &roomServices = QStringList(),
147  const QString &clientName = QString(),
148  bool monitorConnections = false);
149 
150  static StreamTubeServerPtr create(
151  const ClientRegistrarPtr &registrar,
152  const QStringList &p2pServices,
153  const QStringList &roomServices = QStringList(),
154  const QString &clientName = QString(),
155  bool monitorConnections = false);
156 
157  virtual ~StreamTubeServer();
158 
159  ClientRegistrarPtr registrar() const;
160  QString clientName() const;
161  bool isRegistered() const;
162  bool monitorsConnections() const;
163 
164  QPair<QHostAddress, quint16> exportedTcpSocketAddress() const;
165  QVariantMap exportedParameters() const;
166 
167  void exportTcpSocket(
168  const QHostAddress &address,
169  quint16 port,
170  const QVariantMap &parameters = QVariantMap());
171  void exportTcpSocket(
172  const QTcpServer *server,
173  const QVariantMap &parameters = QVariantMap());
174 
175  void exportTcpSocket(
176  const QHostAddress &address,
177  quint16 port,
178  ParametersGenerator *generator);
179  void exportTcpSocket(
180  const QTcpServer *server,
181  ParametersGenerator *generator);
182 
183  QList<Tube> tubes() const;
184 
185  QHash<QPair<QHostAddress, quint16>, RemoteContact> tcpConnections() const;
186 
187 Q_SIGNALS:
188 
189  void tubeRequested(
190  const Tp::AccountPtr &account,
191  const Tp::OutgoingStreamTubeChannelPtr &tube,
192  const QDateTime &userActionTime,
193  const Tp::ChannelRequestHints &hints);
194  void tubeClosed(
195  const Tp::AccountPtr &account,
196  const Tp::OutgoingStreamTubeChannelPtr &tube,
197  const QString &error,
198  const QString &message);
199 
200  void newTcpConnection(
201  const QHostAddress &sourceAddress,
202  quint16 sourcePort,
203  const Tp::AccountPtr &account,
204  const Tp::ContactPtr &contact,
205  const Tp::OutgoingStreamTubeChannelPtr &tube);
206  void tcpConnectionClosed(
207  const QHostAddress &sourceAddress,
208  quint16 sourcePort,
209  const Tp::AccountPtr &account,
210  const Tp::ContactPtr &contact,
211  const QString &error,
212  const QString &message,
213  const Tp::OutgoingStreamTubeChannelPtr &tube);
214 
215 private Q_SLOTS:
216  TP_QT_NO_EXPORT void onInvokedForTube(
217  const Tp::AccountPtr &account,
218  const Tp::StreamTubeChannelPtr &tube,
219  const QDateTime &userActionTime,
220  const Tp::ChannelRequestHints &requestHints);
221 
222  TP_QT_NO_EXPORT void onOfferFinished(
223  TubeWrapper *wrapper,
225  TP_QT_NO_EXPORT void onTubeInvalidated(
226  Tp::DBusProxy *proxy,
227  const QString &error,
228  const QString &message);
229 
230  TP_QT_NO_EXPORT void onNewConnection(
231  TubeWrapper *wrapper,
232  uint conn);
233  TP_QT_NO_EXPORT void onConnectionClosed(
234  TubeWrapper *wrapper,
235  uint conn,
236  const QString &error,
237  const QString &message);
238 
239 private:
240  TP_QT_NO_EXPORT StreamTubeServer(
241  const ClientRegistrarPtr &registrar,
242  const QStringList &p2pServices,
243  const QStringList &roomServices,
244  const QString &clientName,
245  bool monitorConnections);
246 
247  struct Private;
248  Private *mPriv;
249 };
250 
251 } // Tp
252 
253 #endif
const OutgoingStreamTubeChannelPtr & channel() const
Definition: stream-tube-server.h:107
The StreamTubeServer::Tube class represents a tube being handled by the server.
Definition: stream-tube-server.h:90
static ConnectionFactoryPtr create(const QDBusConnection &bus, const Features &features=Features())
Definition: connection-factory.cpp:57
const AccountPtr & account() const
Definition: stream-tube-server.h:102
static ContactFactoryPtr create(const Features &features=Features())
Definition: contact-factory.cpp:48
static AccountFactoryPtr create(const QDBusConnection &bus, const Features &features=Features())
Definition: account-factory.cpp:58
bool isValid() const
Definition: stream-tube-server.h:98
const ContactPtr & contact() const
Definition: stream-tube-server.h:79
const AccountPtr & account() const
Definition: stream-tube-server.h:74
virtual ~ParametersGenerator()
Definition: stream-tube-server.h:59
The StreamTubeServer class is a Handler implementation for outgoing Stream Tube channels,...
Definition: stream-tube-server.h:42
The ChannelRequestHints class represents a dictionary of metadata provided by the channel requester w...
Definition: channel-request.h:121
The RefCounted class is a base class for shared objects used by SharedPtr.
Definition: shared-ptr.h:42
The StreamTubeServer::RemoteContact class represents a contact from which a socket connection to our ...
Definition: stream-tube-server.h:62
static ChannelFactoryPtr create(const QDBusConnection &bus)
Definition: channel-factory.cpp:86
Definition: abstract-adaptor.cpp:31
bool isValid() const
Definition: stream-tube-server.h:70
The DBusProxy class is a base class representing a remote object available over D-Bus.
Definition: dbus-proxy.h:42
The PendingOperation class is a base class for pending asynchronous operations.
Definition: pending-operation.h:45
The StreamTubeServer::ParametersGenerator abstract interface allows sending a different set of parame...
Definition: stream-tube-server.h:51