summaryrefslogtreecommitdiffstats
path: root/libvncclient
diff options
context:
space:
mode:
authordscho <dscho>2004-06-07 08:31:57 +0000
committerdscho <dscho>2004-06-07 08:31:57 +0000
commit2b8c2a5c3a71364e402b4df334a6f5aff5ed77a9 (patch)
tree66e59b58f919f5848780d5c7d6c954160e289cff /libvncclient
parent98e4f89569587c143a56e4dcf8162a035efc361e (diff)
downloadlibtdevnc-2b8c2a5c3a71364e402b4df334a6f5aff5ed77a9.tar.gz
libtdevnc-2b8c2a5c3a71364e402b4df334a6f5aff5ed77a9.zip
add client_examples/, add SDLvncviewer, libvncclient API changes, suppress automake CFLAGS nagging
Diffstat (limited to 'libvncclient')
-rw-r--r--libvncclient/Makefile.am7
-rw-r--r--libvncclient/client_test.c128
-rw-r--r--libvncclient/sockets.c21
-rw-r--r--libvncclient/vncviewer.c61
4 files changed, 78 insertions, 139 deletions
diff --git a/libvncclient/Makefile.am b/libvncclient/Makefile.am
index 78b5620..88bd363 100644
--- a/libvncclient/Makefile.am
+++ b/libvncclient/Makefile.am
@@ -1,4 +1,4 @@
-CFLAGS=-g -I.. -I. -Wall
+DEFINES=-g -I.. -I. -Wall
libvncclient_a_SOURCES=cursor.c listen.c rfbproto.c sockets.c vncviewer.c
@@ -10,9 +10,4 @@ $(libvncclient_a_OBJECTS): ../rfb/rfbclient.h
lib_LIBRARIES=libvncclient.a
-client_test_SOURCES=client_test.c
-noinst_PROGRAMS=client_test
-
-#client_test_LDADD=libvncclient.a ../libvncserver.a
-client_test_LDADD=libvncclient.a
diff --git a/libvncclient/client_test.c b/libvncclient/client_test.c
deleted file mode 100644
index 16429b0..0000000
--- a/libvncclient/client_test.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* A simple example of an RFB client */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <errno.h>
-#include <rfb/rfbclient.h>
-
-void PrintRect(rfbClient* client, int x, int y, int w, int h) {
- rfbClientLog("Received an update for %d,%d,%d,%d.\n",x,y,w,h);
-}
-
-void SaveFramebufferAsPGM(rfbClient* client, int x, int y, int w, int h) {
- static time_t t=0,t1;
- FILE* f;
- int i,j;
- int bpp=client->format.bitsPerPixel/8;
- int row_stride=client->width*bpp;
-
- /* save one picture only if the last is older than 2 seconds */
- t1=time(0);
- if(t1-t>2)
- t=t1;
- else
- return;
-
- /* assert bpp=4 */
- if(bpp!=4) {
- rfbClientLog("bpp = %d (!=4)\n",bpp);
- return;
- }
-
- f=fopen("/tmp/framebuffer.ppm","wb");
-
- fprintf(f,"P6\n# %s\n%d %d\n255\n",client->desktopName,client->width,client->height);
- for(j=0;j<client->height*row_stride;j+=row_stride)
- for(i=0;i<client->width*bpp;i+=bpp) {
- if(client->format.bigEndian) {
- fputc(client->frameBuffer[j+i+bpp-1],f);
- fputc(client->frameBuffer[j+i+bpp-2],f);
- fputc(client->frameBuffer[j+i+bpp-3],f);
- } else {
- fputc(client->frameBuffer[j+i+0],f);
- fputc(client->frameBuffer[j+i+1],f);
- fputc(client->frameBuffer[j+i+2],f);
- }
- }
- fclose(f);
-}
-
-int WaitForMessage(rfbClient* client,unsigned int usecs)
-{
- fd_set fds;
- struct timeval timeout;
- int num;
-
- timeout.tv_sec=(usecs/1000000);
- timeout.tv_usec=(usecs%1000000);
-
- FD_ZERO(&fds);
- FD_SET(client->sock,&fds);
-
- num=select(client->sock+1, &fds, NULL, NULL, &timeout);
- if(num<0)
- rfbClientLog("Waiting for message failed: %d (%s)\n",errno,strerror(errno));
-
- return num;
-}
-
-int
-main(int argc, char **argv)
-{
- int i;
- rfbClient* client = rfbGetClient(&argc,argv,8,3,4);
- const char* vncServerHost="";
- int vncServerPort=5900;
- time_t t=time(0);
-
- client->GotFrameBufferUpdate = PrintRect;
- //client->GotFrameBufferUpdate = SaveFramebufferAsPGM;
-
- /* The -listen option is used to make us a daemon process which listens for
- incoming connections from servers, rather than actively connecting to a
- given server. The -tunnel and -via options are useful to create
- connections tunneled via SSH port forwarding. We must test for the
- -listen option before invoking any Xt functions - this is because we use
- forking, and Xt doesn't seem to cope with forking very well. For -listen
- option, when a successful incoming connection has been accepted,
- listenForIncomingConnections() returns, setting the listenSpecified
- flag. */
-
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-listen") == 0) {
- listenForIncomingConnections(client);
- break;
- } else {
- char* colon=strchr(argv[i],':');
-
- vncServerHost=argv[i];
- if(colon) {
- *colon=0;
- vncServerPort=atoi(colon+1);
- } else
- vncServerPort=0;
- vncServerPort+=5900;
- }
- }
-
- client->appData.encodingsString="tight";
- if(!rfbInitClient(client,vncServerHost,vncServerPort)) {
- rfbClientCleanup(client);
- return 1;
- }
-
- while (time(0)-t<5) {
- static int i=0;
- fprintf(stderr,"\r%d",i++);
- if(WaitForMessage(client,500)<0)
- break;
- if(!HandleRFBServerMessage(client))
- break;
- }
-
- rfbClientCleanup(client);
-
- return 0;
-}
-
diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c
index 77dec7c..6954ed3 100644
--- a/libvncclient/sockets.c
+++ b/libvncclient/sockets.c
@@ -422,3 +422,24 @@ PrintInHex(char *buf, int len)
fflush(stderr);
}
+
+int WaitForMessage(rfbClient* client,unsigned int usecs)
+{
+ fd_set fds;
+ struct timeval timeout;
+ int num;
+
+ timeout.tv_sec=(usecs/1000000);
+ timeout.tv_usec=(usecs%1000000);
+
+ FD_ZERO(&fds);
+ FD_SET(client->sock,&fds);
+
+ num=select(client->sock+1, &fds, NULL, NULL, &timeout);
+ if(num<0)
+ rfbClientLog("Waiting for message failed: %d (%s)\n",errno,strerror(errno));
+
+ return num;
+}
+
+
diff --git a/libvncclient/vncviewer.c b/libvncclient/vncviewer.c
index 6288485..6a58e78 100644
--- a/libvncclient/vncviewer.c
+++ b/libvncclient/vncviewer.c
@@ -43,15 +43,35 @@ static rfbBool MallocFrameBuffer(rfbClient* client) {
return client->frameBuffer?TRUE:FALSE;
}
-rfbClient* rfbGetClient(int* argc,char** argv,
- int bitsPerSample,int samplesPerPixel,
+static void initAppData(AppData* data) {
+ data->shareDesktop=TRUE;
+ data->viewOnly=FALSE;
+ data->encodingsString="tight hextile zlib corre rre raw";
+ data->useBGR233=FALSE;
+ data->nColours=0;
+ data->forceOwnCmap=FALSE;
+ data->forceTrueColour=FALSE;
+ data->requestedDepth=0;
+ data->compressLevel=3;
+ data->qualityLevel=5;
+#ifdef LIBVNCSERVER_HAVE_LIBJPEG
+ data->enableJPEG=TRUE;
+#else
+ data->enableJPEG=FALSE;
+#endif
+ data->useRemoteCursor=FALSE;
+}
+
+rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,
int bytesPerPixel) {
rfbClient* client=(rfbClient*)calloc(sizeof(rfbClient),1);
- client->programName = argv[0];
+ initAppData(&client->appData);
+ client->programName = 0;
client->endianTest = 1;
client->format.bitsPerPixel = bytesPerPixel*8;
client->format.depth = bitsPerSample*samplesPerPixel;
+ client->appData.requestedDepth=client->format.depth;
client->format.bigEndian = *(char *)&client->endianTest?FALSE:TRUE;
client->format.trueColour = TRUE;
@@ -94,13 +114,13 @@ rfbClient* rfbGetClient(int* argc,char** argv,
return client;
}
-rfbBool rfbInitClient(rfbClient* client,const char* vncServerHost,int vncServerPort)
+static rfbBool rfbInitConnection(rfbClient* client)
{
/* Unless we accepted an incoming connection, make a TCP connection to the
given VNC server */
if (!client->listenSpecified) {
- if (!ConnectToRFBServer(client,vncServerHost, vncServerPort))
+ if (!client->serverHost || !ConnectToRFBServer(client,client->serverHost,client->serverPort))
return FALSE;
}
@@ -122,6 +142,37 @@ rfbBool rfbInitClient(rfbClient* client,const char* vncServerHost,int vncServerP
return TRUE;
}
+rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv) {
+ int i;
+
+ if(client->programName==0)
+ client->programName=argv[0];
+
+ for (i = 1; i < *argc; i++) {
+ if (strcmp(argv[i], "-listen") == 0) {
+ listenForIncomingConnections(client);
+ break;
+ } else {
+ char* colon=strchr(argv[i],':');
+
+ client->serverHost=argv[i];
+ if(colon) {
+ *colon=0;
+ client->serverPort=atoi(colon+1);
+ } else
+ client->serverPort=0;
+ client->serverPort+=5900;
+ }
+ }
+
+ if(!rfbInitConnection(client)) {
+ rfbClientCleanup(client);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
void rfbClientCleanup(rfbClient* client) {
free(client);
}