OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [demos/] [vnc/] [vncviewer/] [vncviewer.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 *  Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
3
 *
4
 *  This is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
8
 *
9
 *  This software is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this software; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
17
 *  USA.
18
 */
19
 
20
/*
21
 * vncviewer.c - VNC viewer for nano-X.
22
 */
23
 
24
#include <vncviewer.h>
25
 
26
static void HandleEvents(GR_EVENT *ev);
27
 
28
int
29
main(int argc, char **argv)
30
{
31
#ifndef NANOX
32
    fd_set fds;
33
    struct timeval tv, *tvp;
34
    int msWait;
35
#endif
36
    processArgs(argc, argv);
37
 
38
    if (listenSpecified) {
39
 
40
#ifndef NANOX
41
        listenForIncomingConnections();
42
        /* returns only with a succesful connection */
43
#endif
44
 
45
    } else {
46
        if (!ConnectToRFBServer(hostname, port)) exit(1);
47
    }
48
 
49
    if (!InitialiseRFBConnection(rfbsock)) exit(1);
50
 
51
    if (!CreateXWindow()) exit(1);
52
 
53
    if (!SetFormatAndEncodings()) {
54
        ShutdownX();
55
        exit(1);
56
    }
57
 
58
    if (!SendFramebufferUpdateRequest(updateRequestX, updateRequestY,
59
                                      updateRequestW, updateRequestH, False)) {
60
        ShutdownX();
61
        exit(1);
62
    }
63
 
64
    printf("nanox fd = %d, rfbsock = %d\n", ConnectionNumber(dpy), rfbsock);
65
#ifdef NANOX
66
    /* register the RFB socket */
67
    GrRegisterInput(rfbsock);
68
    /* call the nanox main loop to wait for all events */
69
    while (True) {
70
        GrMainLoop(HandleEvents);
71
    }
72
 
73
#else
74
    while (True) {
75
        /*
76
         * Always handle all X events before doing select.  This is the
77
         * simplest way of ensuring that we don't block in select while
78
         * Xlib has some events on its queue.
79
         */
80
 
81
        if (!HandleXEvents()) {
82
            ShutdownX();
83
            exit(1);
84
        }
85
 
86
        tvp = NULL;
87
 
88
        if (sendUpdateRequest) {
89
            gettimeofday(&tv, NULL);
90
 
91
            msWait = (updateRequestPeriodms +
92
                      ((updateRequestTime.tv_sec - tv.tv_sec) * 1000) +
93
                      ((updateRequestTime.tv_usec - tv.tv_usec) / 1000));
94
 
95
            if (msWait > 0) {
96
                tv.tv_sec = msWait / 1000;
97
                tv.tv_usec = (msWait % 1000) * 1000;
98
 
99
                tvp = &tv;
100
            } else {
101
                if (!SendIncrementalFramebufferUpdateRequest()) {
102
                    ShutdownX();
103
                    exit(1);
104
                }
105
            }
106
        }
107
 
108
        FD_ZERO(&fds);
109
        FD_SET(ConnectionNumber(dpy),&fds);
110
        FD_SET(rfbsock,&fds);
111
 
112
        if (select(FD_SETSIZE, &fds, NULL, NULL, tvp) < 0) {
113
            perror("select");
114
            ShutdownX();
115
            exit(1);
116
        }
117
 
118
        if (FD_ISSET(rfbsock, &fds)) {
119
            if (!HandleRFBServerMessage()) {
120
                ShutdownX();
121
                exit(1);
122
            }
123
        }
124
    }
125
#endif  /* NANOX */
126
 
127
    return 0;
128
}
129
 
130
#ifdef NANOX
131
/*
132
 * call-back routine to handle all events
133
 */
134
void
135
HandleEvents(GR_EVENT *ev)
136
{
137
        struct timeval tv, *tvp;
138
        int msWait;
139
 
140
/*      printf("%2d ", ev->type);
141
        fflush(stdout);
142
 */
143
        if (ev->type == GR_EVENT_TYPE_FDINPUT) {
144
                if (!HandleRFBServerMessage()) {
145
                        ShutdownX();
146
                        exit(1);
147
                }
148
        } else {
149
                if (!HandleXEvents(ev)) {
150
                    ShutdownX();
151
                    exit(1);
152
                }
153
        }
154
        if (sendUpdateRequest) {
155
            gettimeofday(&tv, NULL);
156
 
157
            msWait = (updateRequestPeriodms +
158
                      ((updateRequestTime.tv_sec - tv.tv_sec) * 1000) +
159
                      ((updateRequestTime.tv_usec - tv.tv_usec) / 1000));
160
 
161
            if (msWait > 0) {
162
                tv.tv_sec = msWait / 1000;
163
                tv.tv_usec = (msWait % 1000) * 1000;
164
 
165
                tvp = &tv;
166
            } else {
167
                if (!SendIncrementalFramebufferUpdateRequest()) {
168
                    ShutdownX();
169
                    exit(1);
170
                }
171
            }
172
        }
173
}
174
#endif  /* NANOX */
175
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.