[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdenetwork/krfb
From: George Goldberg <grundleborg () googlemail ! com>
Date: 2010-10-23 19:30:33
Message-ID: 20101023193033.6464CAC89C () svn ! kde ! org
[Download RAW message or body]
SVN commit 1189033 by gberg:
Make RFB server and COnnectionCOntroller classes abstract and make one implementation \
of them for the standard rfb use case.
M +4 -2 CMakeLists.txt
A abstractconnectioncontroller.cpp [License: GPL (v2+)]
A abstractconnectioncontroller.h [License: GPL (v2+)]
A abstractrfbserver.cpp [License: GPL (v2+)]
A abstractrfbserver.h [License: GPL (v2+)]
D connectioncontroller.cpp
D connectioncontroller.h
M +3 -1 events.cpp
M +3 -3 events.h
A krfbconnectioncontroller.cpp connectioncontroller.cpp#1189032 \
[License: GPL (v2+)] A krfbconnectioncontroller.h [License: GPL (v2+)]
M +32 -254 krfbserver.cpp
M +25 -32 krfbserver.h
--- trunk/KDE/kdenetwork/krfb/CMakeLists.txt #1189032:1189033
@@ -83,18 +83,20 @@
set(krfb_SRCS
main.cpp
trayicon.cpp
- krfbserver.cpp
manageinvitationsdialog.cpp
invitationmanager.cpp
invitedialog.cpp
invitation.cpp
connectiondialog.cpp
personalinvitedialog.cpp
- connectioncontroller.cpp
events.cpp
framebuffermanager.cpp
servermanager.cpp
sockethelpers.cpp
+ abstractrfbserver.cpp
+ abstractconnectioncontroller.cpp
+ krfbserver.cpp
+ krfbconnectioncontroller.cpp
)
kde4_add_kcfg_files(krfb_SRCS krfbconfig.kcfgc)
--- trunk/KDE/kdenetwork/krfb/events.cpp #1189032:1189033
@@ -10,6 +10,8 @@
#include "events.h"
+#include "abstractconnectioncontroller.h"
+
#include <QApplication>
#include <QX11Info>
@@ -171,7 +173,7 @@
}
-ClipboardEvent::ClipboardEvent(ConnectionController *c, const QString &ctext)
+ClipboardEvent::ClipboardEvent(AbstractConnectionController *c, const QString \
&ctext) :controller(c),text(ctext)
{
}
--- trunk/KDE/kdenetwork/krfb/events.h #1189032:1189033
@@ -17,7 +17,7 @@
#include <X11/Xlib.h>
-class ConnectionController;
+class AbstractConnectionController;
class QCursor;
@@ -60,10 +60,10 @@
};
class ClipboardEvent : public VNCEvent {
- ConnectionController *controller;
+ AbstractConnectionController *controller;
QString text;
public:
- ClipboardEvent(ConnectionController *c, const QString &text);
+ ClipboardEvent(AbstractConnectionController *c, const QString &text);
virtual void exec();
};
--- trunk/KDE/kdenetwork/krfb/krfbserver.cpp #1189032:1189033
@@ -8,10 +8,14 @@
version 2 of the License, or (at your option) any later version.
*/
+// FUCKING RFB.H POS FUCK YOU
+#include "servermanager.h"
#include "krfbserver.h"
#include "krfbserver.moc"
+#include "krfbconnectioncontroller.h"
+
#include <QTcpServer>
#include <QTcpSocket>
#include <QTimer>
@@ -27,117 +31,27 @@
#include <KMessageBox>
#include <dnssd/publicservice.h>
-#include "connectioncontroller.h"
+#include "abstractconnectioncontroller.h"
#include "framebuffer.h"
#include "framebuffermanager.h"
#include "krfbconfig.h"
#include "invitationmanager.h"
-#include "servermanager.h"
#include "sockethelpers.h"
-#include <X11/Xutil.h>
-#include <X11/extensions/XTest.h>
+class KrfbServer::KrfbServerPrivate {
-static const char* cur=
- " "
- " x "
- " xx "
- " xxx "
- " xxxx "
- " xxxxx "
- " xxxxxx "
- " xxxxxxx "
- " xxxxxxxx "
- " xxxxxxxxx "
- " xxxxxxxxxx "
- " xxxxx "
- " xx xxx "
- " x xxx "
- " xxx "
- " xxx "
- " xxx "
- " xxx "
- " ";
-
-static const char* mask=
- "xx "
- "xxx "
- "xxxx "
- "xxxxx "
- "xxxxxx "
- "xxxxxxx "
- "xxxxxxxx "
- "xxxxxxxxx "
- "xxxxxxxxxx "
- "xxxxxxxxxxx "
- "xxxxxxxxxxxx "
- "xxxxxxxxxx "
- "xxxxxxxx "
- "xxxxxxxx "
- "xx xxxxx "
- " xxxxx "
- " xxxxx "
- " xxxxx "
- " xxx ";
-
-static rfbCursorPtr myCursor;
-
-
-static enum rfbNewClientAction newClientHook(struct _rfbClientRec *cl)
-{
- KrfbServer *server = ServerManager::instance()->serverForClient(cl);
- return server->handleNewClient(cl);
-}
-
-static rfbBool passwordCheck(rfbClientPtr cl,
- const char* encryptedPassword,
- int len)
-{
- ConnectionController *cc = static_cast<ConnectionController *>(cl->clientData);
- return cc->handleCheckPassword(cl, encryptedPassword, len);
-}
-
-static void keyboardHook(rfbBool down, rfbKeySym keySym, rfbClientPtr cl)
-{
- ConnectionController *cc = static_cast<ConnectionController *>(cl->clientData);
- cc->handleKeyEvent(down ? true : false, keySym);
-}
-
-static void pointerHook(int bm, int x, int y, rfbClientPtr cl)
-{
- ConnectionController *cc = static_cast<ConnectionController *>(cl->clientData);
- cc->handlePointerEvent(bm, x, y);
-}
-
-static void clipboardHook(char* str,int len, rfbClientPtr cl)
-{
- ConnectionController *cc = static_cast<ConnectionController *>(cl->clientData);
- cc->clipboardToServer(QString::fromUtf8(str, len));
-}
-
-
-class KrfbServer::KrfbServerP {
-
public:
- KrfbServerP() : screen(0), numClients(0), listeningPort(0) {};
-
- QSharedPointer<FrameBuffer> fb;
- QList< QPointer<ConnectionController> > controllers;
- rfbScreenInfoPtr screen;
- int numClients;
- QByteArray desktopName;
- QTimer rfbProcessEventTimer;
- QString listeningAddress;
- unsigned int listeningPort;
+ KrfbServerPrivate() {};
};
KrfbServer::KrfbServer()
- :d(new KrfbServerP)
+ : AbstractRfbServer(),
+ d(new KrfbServerPrivate)
+
{
kDebug() << "starting ";
- d->fb = FrameBufferManager::instance()->frameBuffer(QApplication::desktop()->winId());
- QTimer::singleShot(0, this, SLOT(startListening()));
+ QTimer::singleShot(0, this, SLOT(doStartListening()));
connect(InvitationManager::self(), \
SIGNAL(invitationNumChanged(int)),SLOT(updatePassword())); }
@@ -147,184 +61,48 @@
}
-void KrfbServer::startListening()
+void KrfbServer::doStartListening()
{
- rfbScreenInfoPtr screen;
+ // Set up the parameters for the server before we get it to start listening.
+ setFrameBuffer(FrameBufferManager::instance()->frameBuffer(QApplication::desktop()->winId()));
+ setListeningPort(KrfbConfig::port());
+ setListeningAddress("0.0.0.0"); // Listen on all available network addresses
+ setDesktopName(i18n("%1@%2 (shared desktop)",
+ KUser().loginName(),
+ QHostInfo::localHostName()).toLatin1());
- int port = KrfbConfig::port();
-
- int w = d->fb->width();
- int h = d->fb->height();
- int depth = d->fb->depth();
-
- int bpp = depth >> 3;
- if (bpp != 1 && bpp != 2 && bpp != 4) bpp = 4;
- kDebug() << "bpp: " << bpp;
-
- rfbLogEnable(0);
- screen = rfbGetScreen(0, 0, w, h, 8, 3, bpp);
-
- screen->paddedWidthInBytes = d->fb->paddedWidth();
-
- d->fb->getServerFormat(screen->serverFormat);
-
- screen->frameBuffer = d->fb->data();
- d->screen = screen;
- screen->autoPort = 0;
- screen->port = port;
-
- // server hooks
- screen->newClientHook = newClientHook;
-
- screen->kbdAddEvent = keyboardHook;
- screen->ptrAddEvent = pointerHook;
- screen->newClientHook = newClientHook;
- screen->passwordCheck = passwordCheck;
- screen->setXCutText = clipboardHook;
-
- d->desktopName = i18n("%1@%2 (shared desktop)", KUser().loginName(), \
QHostInfo::localHostName()).toLatin1();
- screen->desktopName = d->desktopName.constData();
-
- if (!myCursor) {
- myCursor = rfbMakeXCursor(19, 19, (char*) cur, (char*) mask);
- }
- screen->cursor = myCursor;
-
- // configure passwords and desktop control here
- updateSettings();
-
- rfbInitServer(screen);
- if (!rfbIsActive(screen)) {
- KMessageBox::error(0,i18n("Address already in use"),"krfb");
- shutdown();
- qApp->quit();
- return;
- };
-
- d->listeningPort = localPort(screen->listenSock);
- d->listeningAddress = localAddress(screen->listenSock);
-
- kDebug() << "Listen port:" << d->listeningPort << "Listen Address:" << \
d->listeningAddress;
-
if (KrfbConfig::publishService()) {
- DNSSD::PublicService *service = new DNSSD::PublicService(i18n("%1@%2 (shared \
desktop)", KUser().loginName(), QHostInfo::localHostName()),"_rfb._tcp",port); + \
DNSSD::PublicService *service = new DNSSD::PublicService(i18n("%1@%2 (shared \
desktop)", + \
KUser().loginName(), + \
QHostInfo::localHostName()), + \
"_rfb._tcp", + \
listeningPort()); service->publishAsync();
}
- /* Integrate the rfb event mechanism with qt's event loop.
- * Call processRfbEvents() every time the qt event loop is run,
- * so that it also processes and delivers rfb events and call
- * shutdown() when QApplication exits to shutdown the rfb server
- * before the X11 connection goes down.
- */
- connect(&d->rfbProcessEventTimer, SIGNAL(timeout()), SLOT(processRfbEvents()));
- connect(qApp, SIGNAL(aboutToQuit()), SLOT(shutdown()));
- d->rfbProcessEventTimer.start(0);
-}
+ startListening();
-void KrfbServer::processRfbEvents()
-{
- foreach(const QRect &r, d->fb->modifiedTiles()) {
- rfbMarkRectAsModified(d->screen, r.x(), r.y(), r.right(), r.bottom());
+ // configure passwords and desktop control here
+ updateSettings();
}
- rfbProcessEvents(d->screen, 100);
-}
-void KrfbServer::shutdown()
+void KrfbServer::updateSettings()
{
- rfbShutdownServer(d->screen, true);
- // framebuffer has to be deleted before X11 connection goes down
- d->fb.clear();
-
- d->listeningPort = 0;
- d->listeningAddress.clear();
+ enableDesktopControl(KrfbConfig::allowDesktopControl());
+ updatePassword();
}
-
-void KrfbServer::enableDesktopControl(bool enable)
-{
- foreach (QPointer<ConnectionController> ptr, d->controllers) {
- if (ptr) {
- if (ptr->controlCanBeEnabled()) {
- ptr->setControlEnabled(enable);
- }
- }
- }
-}
-
enum rfbNewClientAction KrfbServer::handleNewClient(struct _rfbClientRec * cl)
{
- ConnectionController *cc = new ConnectionController(cl, this);
- if (d->numClients++ == 0)
- d->fb->startMonitor();
+ KrfbConnectionController *cc = new KrfbConnectionController(cl, this);
- d->controllers.append(cc);
cc->setControlEnabled(KrfbConfig::allowDesktopControl());
cc->setControlCanBeEnabled(KrfbConfig::allowDesktopControl());
connect(cc, SIGNAL(sessionEstablished(QString)), \
SIGNAL(sessionEstablished(QString)));
- connect(cc, SIGNAL(clientDisconnected(ConnectionController \
*)),SLOT(clientDisconnected(ConnectionController *))); + connect(cc, \
SIGNAL(clientDisconnected(AbstractConnectionController \
*)),SLOT(clientDisconnected(AbstractConnectionController *)));
return cc->handleNewClient();
}
-void KrfbServer::updateSettings()
-{
- enableDesktopControl(KrfbConfig::allowDesktopControl());
- updatePassword();
-}
-void KrfbServer::updatePassword()
-{
-
- if (!d->screen) return;
- QString pw = KrfbConfig::uninvitedConnectionPassword();
- kDebug() << "password: " << pw << " allow " <<
- KrfbConfig::allowUninvitedConnections() <<
- " invitations " << InvitationManager::self()->activeInvitations() << \
endl;
-
- if (pw.isEmpty() && InvitationManager::self()->activeInvitations() == 0) {
- kDebug() << "no password from now on";
- d->screen->authPasswdData = (void *)0;
- } else {
- kDebug() << "Ask for password to accept connections";
- d->screen->authPasswdData = (void *)1;
- }
-}
-
-bool KrfbServer::checkX11Capabilities() {
- int bp1, bp2, majorv, minorv;
- Bool r = XTestQueryExtension(QX11Info::display(), &bp1, &bp2,
- &majorv, &minorv);
- if ((!r) || (((majorv*1000)+minorv) < 2002)) {
- KMessageBox::error(0,
- i18n("Your X11 Server does not support the required XTest \
extension version 2.2. Sharing your desktop is not possible."),
- i18n("Desktop Sharing Error"));
- return false;
- }
-
- return true;
-}
-
-void KrfbServer::clientDisconnected(ConnectionController *cc)
-{
- kDebug() << "clients--: " << d->numClients;
- if (!--d->numClients) {
- d->fb->stopMonitor();
- kDebug() << "stopMonitor: d->numClients = " << d->numClients;
- }
- disconnect(cc, SIGNAL(clientDisconnected(ConnectionController*)),this, \
SLOT(clientDisconnected(ConnectionController*)));
-
- Q_EMIT sessionFinished();
-}
-
-QString KrfbServer::listeningAddress() const
-{
- return d->listeningAddress;
-}
-
-unsigned int KrfbServer::listeningPort() const
-{
- return d->listeningPort;
-}
-
--- trunk/KDE/kdenetwork/krfb/krfbserver.h #1189032:1189033
@@ -1,58 +1,51 @@
/* This file is part of the KDE project
+ Copyright (C) 2009 Collabora Ltd <info@collabora.co.uk>
+ @author George Goldberg <george.goldberg@collabora.co.uk>
Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
-*/
-#ifndef KRFBSERVER_H
-#define KRFBSERVER_H
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
-#include <QObject>
-#include <rfb/rfb.h>
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
-class ConnectionController;
-/**
-This class implements the listening server for the RFB protocol.
+#ifndef KRFB_KRFBSERVER_H
+#define KRFB_KRFBSERVER_H
- @author Alessandro Praduroux <pradu@pradu.it>
-*/
-class KrfbServer : public QObject
+#include "abstractrfbserver.h"
+
+class KrfbServer : public AbstractRfbServer
{
Q_OBJECT
friend class ServerManager;
public:
- ~KrfbServer();
+ virtual ~KrfbServer();
- enum rfbNewClientAction handleNewClient(struct _rfbClientRec *cl);
- bool checkX11Capabilities();
+ virtual enum rfbNewClientAction handleNewClient(struct _rfbClientRec *cl);
-signals:
- void sessionEstablished(QString);
- void sessionFinished();
- void desktopControlSettingChanged(bool);
-
public Q_SLOTS:
+ void doStartListening();
- void startListening();
- void processRfbEvents();
- void shutdown();
- void enableDesktopControl(bool);
- void updateSettings();
- void updatePassword();
- void clientDisconnected(ConnectionController *);
+ virtual void updateSettings();
- QString listeningAddress() const;
- unsigned int listeningPort() const;
-
private:
KrfbServer();
- class KrfbServerP;
- KrfbServerP * const d;
+ class KrfbServerPrivate;
+ KrfbServerPrivate * const d;
};
-#endif
+
+#endif // Header guard
+
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic