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_kbd.c] - Blame information for rev 792

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      vnc_kbd.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:  Keyboard driver for the VNC serevr
47
//
48
//####DESCRIPTIONEND####
49
//
50
//========================================================================*/
51
 
52
 
53
#include <cyg/kernel/kapi.h>
54
#include <cyg/infra/diag.h>   /* diag_printf */
55
#include <cyg/hal/hal_io.h>
56
#include <cyg/hal/hal_arch.h>
57
#include <cyg/hal/drv_api.h>
58
#include <cyg/hal/hal_intr.h>
59
#include <cyg/infra/cyg_type.h>
60
#include <cyg/infra/cyg_ass.h>
61
#include <cyg/fileio/fileio.h>  // For select() functionality
62
#include <cyg/io/devtab.h>
63
#include <pkgconf/vnc_server.h>
64
 
65
/* Local function prototypes */
66
static Cyg_ErrNo kbd_read(cyg_io_handle_t handle,
67
                          void *buffer,
68
                          cyg_uint32 *len);
69
static cyg_bool  kbd_select(cyg_io_handle_t handle,
70
                            cyg_uint32 which,
71
                            cyg_addrword_t info);
72
static Cyg_ErrNo kbd_set_config(cyg_io_handle_t handle,
73
                                cyg_uint32 key,
74
                                const void *buffer,
75
                                cyg_uint32 *len);
76
static Cyg_ErrNo kbd_get_config(cyg_io_handle_t handle,
77
                                cyg_uint32 key,
78
                                void *buffer,
79
                                cyg_uint32 *len);
80
static bool      kbd_init(struct cyg_devtab_entry *tab);
81
static Cyg_ErrNo kbd_lookup(struct cyg_devtab_entry **tab,
82
                            struct cyg_devtab_entry *st,
83
                            const char *name);
84
 
85
CHAR_DEVIO_TABLE(vnc_kbd_handlers,
86
                 NULL,                    /* Unsupported write() function */
87
                 kbd_read,
88
                 kbd_select,
89
                 kbd_get_config,
90
                 kbd_set_config);
91
 
92
CHAR_DEVTAB_ENTRY(vnc_kbd_device,
93
                  CYGDAT_VNC_SERVER_KEYBOARD_NAME,
94
                  NULL,                   /* Base device name */
95
                  &vnc_kbd_handlers,
96
                  kbd_init,
97
                  kbd_lookup,
98
                  NULL);                  /* Private data pointer */
99
 
100
#define MAX_EVENTS CYGNUM_VNC_SERVER_KEYBOARD_EVENTS
101
static cyg_uint8 data_queue[MAX_EVENTS*4];
102
static int queue_put_ptr = 0;
103
static int queue_get_ptr = 0;
104
static int data_in_queue = 0;
105
 
106
static cyg_selinfo  kbd_select_info;
107
static cyg_bool     kbd_select_active;
108
static int kbd_active = 0;
109
 
110
 
111
/*
112
 * Keystroke event handler routine - called by main VNC server loop
113
 * when new keystroke data is received from client
114
 */
115
void vnc_kbd_handler(cyg_uint8 *data)
116
{
117
    if (!kbd_active)
118
    {
119
        /* Keyboard is not active yet - ignore incoming data */
120
        return;
121
    }
122
 
123
    /* Add the keystroke event data to the data queue */
124
    cyg_scheduler_lock();
125
 
126
    if (data_in_queue >= (MAX_EVENTS*4))
127
    {
128
        diag_printf("VNC mouse driver buffer overflow\n");
129
        cyg_scheduler_unlock();
130
        return;
131
    }
132
 
133
    data_queue[queue_put_ptr]   = 0;        /* Padding */
134
    data_queue[queue_put_ptr+1] = data[1];  /* Key pressed (1 when pressed) */
135
    data_queue[queue_put_ptr+2] = data[6];  /* Keysym value for key MSB */
136
    data_queue[queue_put_ptr+3] = data[7];  /* Keysym value for key LSB */
137
 
138
    /* Increment pointer */
139
    queue_put_ptr +=4;
140
    if (queue_put_ptr >= (MAX_EVENTS*4))
141
    {
142
        queue_put_ptr = 0;
143
    }
144
 
145
    /* Increment count of data in queue */
146
    data_in_queue += 4;
147
 
148
    /* Wake up select() */
149
    if (kbd_select_active) {
150
        kbd_select_active = false;
151
        cyg_selwakeup(&kbd_select_info);
152
    }
153
 
154
    cyg_scheduler_unlock();
155
}
156
 
157
 
158
static Cyg_ErrNo kbd_read(cyg_io_handle_t handle,
159
                          void *buffer,
160
                          cyg_uint32 *len)
161
{
162
    int total;  /* Total bytes to read */
163
    cyg_uint8 *bp = (unsigned char *)buffer;
164
    int i;
165
 
166
    cyg_scheduler_lock();
167
 
168
    /* Each keystroke event generates 4 x cyg_uint8 values in the queue
169
     *   0: Padding - always zero
170
     *   1: Key pressed (1 when key is pressed)
171
     *   2: Keysym value MSB
172
     *   3: Keysym value LSB
173
     */
174
    if (*len <= data_in_queue)
175
    {
176
        /* Send all requested data */
177
        total = *len;
178
    }
179
    else
180
    {
181
        /* read() is requesting more data than there is in the queue */
182
        /* Send all data from the queue */
183
        total = data_in_queue;
184
    }
185
 
186
    for (i = 0; i < total; i++)
187
    {
188
        bp[i] = data_queue[queue_get_ptr];
189
        if (++queue_get_ptr >= (MAX_EVENTS*4))
190
        {
191
            queue_get_ptr = 0;
192
        }
193
    }
194
 
195
    data_in_queue -= total;
196
 
197
    cyg_scheduler_unlock();
198
 
199
    *len = total;
200
    return ENOERR;
201
}
202
 
203
 
204
static cyg_bool kbd_select(cyg_io_handle_t handle,
205
           cyg_uint32 which,
206
           cyg_addrword_t info)
207
{
208
    if (which == CYG_FREAD) {
209
        cyg_scheduler_lock();
210
        if (data_in_queue >= 4) {
211
            cyg_scheduler_unlock();
212
            return true;
213
        }
214
 
215
        if (!kbd_select_active) {
216
            kbd_select_active = true;
217
            cyg_selrecord(info, &kbd_select_info);
218
        }
219
 
220
        cyg_scheduler_unlock();
221
    }
222
    return false;
223
}
224
 
225
 
226
static Cyg_ErrNo kbd_set_config(cyg_io_handle_t handle,
227
               cyg_uint32 key,
228
               const void *buffer,
229
               cyg_uint32 *len)
230
{
231
    return EINVAL;
232
}
233
 
234
 
235
static Cyg_ErrNo kbd_get_config(cyg_io_handle_t handle,
236
               cyg_uint32 key,
237
               void *buffer,
238
               cyg_uint32 *len)
239
{
240
    return EINVAL;
241
}
242
 
243
 
244
static bool kbd_init(struct cyg_devtab_entry *tab)
245
{
246
    cyg_selinit(&kbd_select_info);
247
    return true;
248
}
249
 
250
 
251
static Cyg_ErrNo kbd_lookup(struct cyg_devtab_entry **tab,
252
           struct cyg_devtab_entry *st,
253
           const char *name)
254
{
255
    kbd_active = 1;
256
    return ENOERR;
257
}

powered by: WebSVN 2.1.0

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