Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ServiceLibVNCServer.cpp
1#include "ServiceLibVNCServer.h"
2
3#include "RabbitCommonTools.h"
4
5#include <rfb/keysym.h>
6#include <QScreen>
7#include <QCoreApplication>
8
9#ifdef HAVE_GUI
10#include "FrmParameterServiceLibVNC.h"
11#endif
12
13#include "ParameterServiceLibVNC.h"
14#include "Screen.h"
15
16#include <QLoggingCategory>
17Q_DECLARE_LOGGING_CATEGORY(LibVNCServer)
18
19CServiceLibVNCServer::CServiceLibVNCServer(CPluginService *plugin) : CService(plugin)
20{
21 m_pPara = new CParameterServiceLibVNC(this);
22}
23
24CServiceLibVNCServer::~CServiceLibVNCServer()
25{
26 qDebug(LibVNCServer) << "CServiceLibVNCServer::~CServiceLibVNCServer()";
27}
28
29#ifdef HAVE_GUI
30QWidget* CServiceLibVNCServer::GetParameterWidget(QWidget* parent)
31{
33 dynamic_cast<CParameterServiceLibVNC*>(GetParameters()), parent);
34}
35#endif
36
37static rfbBool checkPassword(struct _rfbClientRec* cl,
38 const char* encryptedPassWord, int len)
39{
40 qDebug(LibVNCServer) << "Password:" << encryptedPassWord;
41 CServiceLibVNCServer* pThis = reinterpret_cast<CServiceLibVNCServer*>(cl->screen->screenData);
42 if(pThis->GetParameters()->getPassword() == encryptedPassWord)
43 return true;
44 return false;
45}
46
47static void dokey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
48{
49 qDebug(LibVNCServer) << "key:" << key <<";down:" << down;
50}
51
52static void doptr(int buttonMask,int x,int y,rfbClientPtr cl)
53{
54 qDebug(LibVNCServer) << "Mouse: button:" << buttonMask
55 << ";x:" << x << ";y:" << y;
56}
57
58static enum rfbNewClientAction newclient(rfbClientPtr cl)
59{
60 qDebug(LibVNCServer) << "New client:" << cl->host;
61// cl->clientData = (void*)calloc(sizeof(ClientData),1);
62// cl->clientGoneHook = clientgone;
63 return RFB_CLIENT_ACCEPT;
64}
65
67{
68 qDebug(LibVNCServer) << "CServiceLibVNCServer Init ......";
69
70 int w = 640;
71 int h = 480;
72 int bpp = 4;
73
74 CScreen* screen = CScreen::Instance();
75 w = screen->Width();
76 h = screen->Height();
77
78 m_rfbScreen = rfbGetScreen(0, nullptr, w, h, 8, 3, bpp);
79 if(!m_rfbScreen)
80 return -1;
81 QString name = RabbitCommon::CTools::GetHostName()
82 + "@" + RabbitCommon::CTools::GetCurrentUser();
83 m_rfbScreen->desktopName = strdup(name.toStdString().c_str());
84 m_rfbScreen->port = GetParameters()->getPort();
85 m_rfbScreen->frameBuffer = (char*)malloc(w * h * bpp);
86 m_rfbScreen->alwaysShared = TRUE;
87 m_rfbScreen->ptrAddEvent = doptr;
88 m_rfbScreen->kbdAddEvent = dokey;
89 m_rfbScreen->newClientHook = newclient;
90 m_rfbScreen->passwordCheck = checkPassword;
91// m_rfbScreen->httpDir = "../webclients";
92// m_rfbScreen->httpEnableProxyConnect = TRUE;
93
94 m_rfbScreen->screenData = this;
95
96 /* initialize the server */
97 rfbInitServer(m_rfbScreen);
98 return 0; //Use OnProcess (non-Qt event loop)
99}
100
102{
103 qDebug(LibVNCServer) << "CServiceLibVNCServer Clean ......";
104 free(m_rfbScreen->frameBuffer);
105 rfbScreenCleanup(m_rfbScreen);
106 return 0;
107}
108
110{
111 //LOG_MODEL_DEBUG("CServiceLibVNCServer", "Process...");
112 if(rfbIsActive(m_rfbScreen))
113 rfbProcessEvents(m_rfbScreen, 100000);
114 return 0;
115}
The service plugin interface.
The CScreen class.
Definition Screen.h:14
int OnProcess() override
Process service.
int OnInit() override
Init service.
virtual int OnClean() override
Clean service.
The service interface.
Definition Service.h:38