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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [vnc_server/] [current/] [src/] [vnc_mouse.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      vnc_mouse.c
4
//
5
//
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    Chris Garry <cgarry@sweeneydesign.co.uk>
43
// Contributors:
44
// Date:         2003-08-22
45
// Purpose:
46
// Description:  mouse driver for the VNC serevr
47
//
48
//####DESCRIPTIONEND####
49
//
50
//========================================================================*/
51
 
52
#include <cyg/kernel/kapi.h>
53
#include <cyg/infra/diag.h>   /* diag_printf */
54
#include <cyg/hal/hal_io.h>
55
#include <cyg/hal/hal_arch.h>
56
#include <cyg/hal/drv_api.h>
57
#include <cyg/hal/hal_intr.h>
58
#include <cyg/infra/cyg_type.h>
59
#include <cyg/infra/cyg_ass.h>
60
#include <cyg/fileio/fileio.h>  /*select() functionality */
61
#include <cyg/io/devtab.h>
62
#include <pkgconf/vnc_server.h>
63
 
64
/* Local function prototypes */
65
static Cyg_ErrNo mouse_read(cyg_io_handle_t handle,
66
                         void *buffer,
67
                         cyg_uint32 *len);
68
static cyg_bool  mouse_select(cyg_io_handle_t handle,
69
                           cyg_uint32 which,
70
                           cyg_addrword_t info);
71
static Cyg_ErrNo mouse_set_config(cyg_io_handle_t handle,
72
                               cyg_uint32 key,
73
                               const void *buffer,
74
                               cyg_uint32 *len);
75
static Cyg_ErrNo mouse_get_config(cyg_io_handle_t handle,
76
                               cyg_uint32 key,
77
                               void *buffer,
78
                               cyg_uint32 *len);
79
static bool      mouse_init(struct cyg_devtab_entry *tab);
80
static Cyg_ErrNo mouse_lookup(struct cyg_devtab_entry **tab,
81
                              struct cyg_devtab_entry *st,
82
                              const char *name);
83
 
84
CHAR_DEVIO_TABLE(vnc_mouse_handlers,
85
                 NULL,                    /* Unsupported write() function */
86
                 mouse_read,
87
                 mouse_select,
88
                 mouse_get_config,
89
                 mouse_set_config);
90
 
91
CHAR_DEVTAB_ENTRY(vnc_mouse_device,
92
                  CYGDAT_VNC_SERVER_MOUSE_NAME,
93
                  NULL,                   /* Base device name */
94
                  &vnc_mouse_handlers,
95
                  mouse_init,
96
                  mouse_lookup,
97
                  NULL);                  /* Private data pointer */
98
 
99
#define MAX_EVENTS CYGNUM_VNC_SERVER_MOUSE_EVENTS
100
static cyg_uint8 data_queue[MAX_EVENTS*8];
101
static int queue_put_ptr = 0;
102
static int queue_get_ptr = 0;
103
static int data_in_queue = 0;
104
 
105
static cyg_selinfo      mouse_select_info;
106
static cyg_bool         mouse_select_active;
107
static int mouse_active = 0;
108
 
109
 
110
/*
111
 * Mouse event handler routine - called by main VNC server loop
112
 * when new mouse data is received from client
113
 */
114
void vnc_mouse_handler(cyg_uint8 *data)
115
{
116
    if (!mouse_active)
117
    {
118
        /* Mouse is not active yet - ignore incoming data */
119
        return;
120
    }
121
 
122
    /* Add the single mouse event data to the data queue */
123
    cyg_scheduler_lock();
124
 
125
    if (data_in_queue >= (MAX_EVENTS*8))
126
    {
127
        diag_printf("VNC mouse driver buffer overflow\n");
128
        cyg_scheduler_unlock();
129
        return;
130
    }
131
 
132
    data_queue[queue_put_ptr]   = 0;        /* Button info MSB */
133
    data_queue[queue_put_ptr+1] = data[1];  /* Button info LSB */
134
    data_queue[queue_put_ptr+2] = data[2];  /* x-coord MSB */
135
    data_queue[queue_put_ptr+3] = data[3];  /* x-coord LSB */
136
    data_queue[queue_put_ptr+4] = data[4];  /* y-coord MSB */
137
    data_queue[queue_put_ptr+5] = data[5];  /* y-coord LSB */
138
    data_queue[queue_put_ptr+6] = 0;
139
    data_queue[queue_put_ptr+7] = 0;
140
 
141
    /* Increment pointer */
142
    queue_put_ptr +=8;
143
    if (queue_put_ptr >= (MAX_EVENTS*8))
144
    {
145
        queue_put_ptr = 0;
146
    }
147
 
148
    /* Increment count of data in queue */
149
    data_in_queue += 8;
150
 
151
    /* Wake up select() */
152
    if (mouse_select_active) {
153
        mouse_select_active = false;
154
        cyg_selwakeup(&mouse_select_info);
155
    }
156
 
157
    cyg_scheduler_unlock();
158
}
159
 
160
 
161
static Cyg_ErrNo mouse_read(cyg_io_handle_t handle,
162
                            void *buffer,
163
                            cyg_uint32 *len)
164
{
165
    int total;  /* Total bytes to read */
166
    cyg_uint8 *bp = (unsigned char *)buffer;
167
    int i;
168
 
169
    cyg_scheduler_lock();  /* Prevent interaction with mouse_handler funcion */
170
 
171
    /* Each mouse event generates 8 x cyg_uint8 values in the queue
172
     *   0-1: Mouse button data
173
     *   2-3: x-coord of mouse
174
     *   4-5: y-coord of mouse
175
     *   6-7: always zero
176
 
177
     */
178
    if (*len <= data_in_queue)
179
    {
180
        /* Send all requested data */
181
        total = *len;
182
    }
183
    else
184
    {
185
        /* read() is requesting more data than there is in the queue */
186
        /* Send all data from the queue */
187
        total = data_in_queue;
188
    }
189
 
190
    for (i = 0; i < total; i++)
191
    {
192
        bp[i] = data_queue[queue_get_ptr];
193
        if (++queue_get_ptr >= (MAX_EVENTS*8))
194
        {
195
            queue_get_ptr = 0;
196
        }
197
    }
198
 
199
    data_in_queue -= total;
200
 
201
    cyg_scheduler_unlock(); // Allow DSRs again
202
 
203
    *len = total;
204
    return ENOERR;
205
}
206
 
207
 
208
static cyg_bool mouse_select(cyg_io_handle_t handle,
209
                             cyg_uint32 which,
210
                             cyg_addrword_t info)
211
{
212
    if (which == CYG_FREAD) {
213
        cyg_scheduler_lock();
214
        if (data_in_queue >= 8) {
215
            cyg_scheduler_unlock();
216
            return true;
217
        }
218
 
219
        if (!mouse_select_active) {
220
            mouse_select_active = true;
221
            cyg_selrecord(info, &mouse_select_info);
222
        }
223
 
224
        cyg_scheduler_unlock();
225
    }
226
    return false;
227
}
228
 
229
 
230
static Cyg_ErrNo mouse_set_config(cyg_io_handle_t handle,
231
              cyg_uint32 key,
232
              const void *buffer,
233
              cyg_uint32 *len)
234
{
235
    return EINVAL;
236
}
237
 
238
 
239
static Cyg_ErrNo mouse_get_config(cyg_io_handle_t handle,
240
              cyg_uint32 key,
241
              void *buffer,
242
              cyg_uint32 *len)
243
{
244
    return EINVAL;
245
}
246
 
247
 
248
static bool mouse_init(struct cyg_devtab_entry *tab)
249
{
250
    cyg_selinit(&mouse_select_info);
251
    return true;
252
}
253
 
254
 
255
static Cyg_ErrNo mouse_lookup(struct cyg_devtab_entry **tab,
256
          struct cyg_devtab_entry *st,
257
          const char *name)
258
{
259
    mouse_active = 1;
260
    return ENOERR;
261
}

powered by: WebSVN 2.1.0

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