26 #include <TelepathyQt/Debug>
27 #include <TelepathyQt/Contact>
28 #include <TelepathyQt/AccountFactory>
29 #include <TelepathyQt/ConnectionFactory>
30 #include <TelepathyQt/ContactFactory>
31 #include <TelepathyQt/ChannelFactory>
32 #include <TelepathyQt/OutgoingStreamTubeChannel>
33 #include <TelepathyQt/StreamTubeServer>
36 struct TubesRfbServer::Private
38 Tp::StreamTubeServerPtr stubeServer;
39 QHash<quint16, Tp::ContactPtr> contactsPerPort;
40 QHash<quint16, PendingTubesRfbClient*> clientsPerPort;
52 kDebug() <<
"starting";
54 Tp::enableDebug(
true);
55 Tp::enableWarnings(
true);
58 Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(
59 QDBusConnection::sessionBus(), Tp::Account::FeatureCore);
61 Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(
62 QDBusConnection::sessionBus(), Tp::Connection::FeatureCore);
64 Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(
65 QDBusConnection::sessionBus());
67 Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(
68 Tp::Contact::FeatureAlias);
70 d->stubeServer = Tp::StreamTubeServer::create(
71 QStringList() << QLatin1String(
"rfb"),
73 QLatin1String(
"krfb_rfb_handler"),
80 connect(d->stubeServer.data(),
81 SIGNAL(tubeRequested(Tp::AccountPtr,Tp::OutgoingStreamTubeChannelPtr,
82 QDateTime,Tp::ChannelRequestHints)),
83 SLOT(onTubeRequested()));
84 connect(d->stubeServer.data(),
85 SIGNAL(tubeClosed(Tp::AccountPtr,Tp::OutgoingStreamTubeChannelPtr,QString,QString)),
86 SLOT(onTubeClosed()));
88 connect(d->stubeServer.data(),
89 SIGNAL(newTcpConnection(QHostAddress,quint16,Tp::AccountPtr,
90 Tp::ContactPtr,Tp::OutgoingStreamTubeChannelPtr)),
91 SLOT(onNewTcpConnection(QHostAddress,quint16,Tp::AccountPtr,
92 Tp::ContactPtr,Tp::OutgoingStreamTubeChannelPtr)));
93 connect(d->stubeServer.data(),
94 SIGNAL(tcpConnectionClosed(QHostAddress,quint16,Tp::AccountPtr,Tp::ContactPtr,
95 QString,QString,Tp::OutgoingStreamTubeChannelPtr)),
96 SLOT(onTcpConnectionClosed(QHostAddress,quint16,Tp::AccountPtr,Tp::ContactPtr,
97 QString,QString,Tp::OutgoingStreamTubeChannelPtr)));
105 QTimer::singleShot(0,
this, SLOT(startAndCheck()));
114 void TubesRfbServer::startAndCheck()
119 for (
int i=0; !ok && i<5; i++) {
125 kError() <<
"Failed to start tubes rfb server";
131 d->stubeServer->exportTcpSocket(QHostAddress(QString::fromAscii(
listeningAddress())),
135 void TubesRfbServer::onTubeRequested()
137 kDebug() <<
"Got a tube";
140 void TubesRfbServer::onTubeClosed()
142 kDebug() <<
"tube closed";
145 void TubesRfbServer::onNewTcpConnection(
const QHostAddress & sourceAddress,
147 const Tp::AccountPtr & account,
148 const Tp::ContactPtr & contact,
149 const Tp::OutgoingStreamTubeChannelPtr & tube)
154 kDebug() <<
"CM signaled tube connection from" << sourceAddress <<
":" << sourcePort;
156 d->contactsPerPort[sourcePort] = contact;
157 if (d->clientsPerPort.contains(sourcePort)) {
158 kDebug() <<
"client already exists";
159 d->clientsPerPort[sourcePort]->setContact(contact);
163 void TubesRfbServer::onTcpConnectionClosed(
const QHostAddress& sourceAddress,
165 const Tp::AccountPtr& account,
166 const Tp::ContactPtr& contact,
167 const QString& error,
168 const QString& message,
169 const Tp::OutgoingStreamTubeChannelPtr& tube)
175 kDebug() <<
"Connection from" << sourceAddress <<
":" << sourcePort <<
"closed."
178 d->clientsPerPort.remove(sourcePort);
179 d->contactsPerPort.remove(sourcePort);
187 kDebug() <<
"new tube client on port" << port;
189 d->clientsPerPort[port] = c;
190 if (d->contactsPerPort.contains(port)) {
191 kDebug() <<
"already have a contact";
198 #include "tubesrfbserver.moc"
void setListeningPort(int port)
unsigned short peerPort(int sock)
virtual PendingRfbClient * newClient(rfbClientPtr client)
int listeningPort() const
void setPasswordRequired(bool passwordRequired)
virtual ~TubesRfbServer()
void setListeningAddress(const QByteArray &address)
TubesRfbServer(QObject *parent=0)
void setContact(const Tp::ContactPtr &contact)
QByteArray listeningAddress() const