Subversion Repositories HelenOS

Rev

Rev 4236 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4236 Rev 4462
Line 25... Line 25...
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup kbdgen
29
/** @addtogroup kbdgen
30
 * @brief   HelenOS generic uspace keyboard handler.
30
 * @brief HelenOS generic uspace keyboard handler.
31
 * @ingroup  kbd
31
 * @ingroup kbd
32
 * @{
32
 * @{
33
 */
33
 */
34
/** @file
34
/** @file
35
 */
35
 */
-
 
36
 
36
#include <key_buffer.h>
37
#include <keybuffer.h>
37
#include <futex.h>
38
#include <futex.h>
38
 
39
 
39
atomic_t keybuffer_futex = FUTEX_INITIALIZER;
40
atomic_t keybuffer_futex = FUTEX_INITIALIZER;
40
 
41
 
41
/** Clear key buffer.
42
/** Clear key buffer.
Line 56... Line 57...
56
{
57
{
57
    keybuffer_free(keybuffer);
58
    keybuffer_free(keybuffer);
58
}
59
}
59
 
60
 
60
/** Get free space in buffer.
61
/** Get free space in buffer.
-
 
62
 *
61
 * This function is useful for processing some scancodes that are translated
63
 * This function is useful for processing some scancodes that are translated
62
 * to more than one character.
64
 * to more than one character.
-
 
65
 *
63
 * @return empty buffer space
66
 * @return empty buffer space
-
 
67
 *
64
 */
68
 */
65
int keybuffer_available(keybuffer_t *keybuffer)
69
size_t keybuffer_available(keybuffer_t *keybuffer)
66
{
70
{
67
    return KEYBUFFER_SIZE - keybuffer->items;
71
    return KEYBUFFER_SIZE - keybuffer->items;
68
}
72
}
69
 
73
 
70
/**
74
/**
-
 
75
 *
71
 * @return nonzero, if buffer is not empty.
76
 * @return nonzero, if buffer is not empty.
-
 
77
 *
72
 */
78
 */
73
int keybuffer_empty(keybuffer_t *keybuffer)
79
bool keybuffer_empty(keybuffer_t *keybuffer)
74
{
80
{
75
    return (keybuffer->items == 0);
81
    return (keybuffer->items == 0);
76
}
82
}
77
 
83
 
78
/** Push key event to key buffer.
84
/** Push key event to key buffer.
79
 *
85
 *
80
 * If the buffer is full, the event is ignored.
86
 * If the buffer is full, the event is ignored.
81
 *
87
 *
82
 * @param keybuffer The keybuffer.
88
 * @param keybuffer The keybuffer.
83
 * @param ev        The event to push.
89
 * @param ev        The event to push.
-
 
90
 *
84
 */
91
 */
85
void keybuffer_push(keybuffer_t *keybuffer, const kbd_event_t *ev)
92
void keybuffer_push(keybuffer_t *keybuffer, const console_event_t *ev)
86
{
93
{
87
    futex_down(&keybuffer_futex);
94
    futex_down(&keybuffer_futex);
-
 
95
   
88
    if (keybuffer->items < KEYBUFFER_SIZE) {
96
    if (keybuffer->items < KEYBUFFER_SIZE) {
89
        keybuffer->fifo[keybuffer->tail] = *ev;
97
        keybuffer->fifo[keybuffer->tail] = *ev;
90
        keybuffer->tail = (keybuffer->tail + 1) % KEYBUFFER_SIZE;
98
        keybuffer->tail = (keybuffer->tail + 1) % KEYBUFFER_SIZE;
91
        keybuffer->items++;
99
        keybuffer->items++;
92
    }
100
    }
-
 
101
   
93
    futex_up(&keybuffer_futex);
102
    futex_up(&keybuffer_futex);
94
}
103
}
95
 
104
 
96
/** Pop event from buffer.
105
/** Pop event from buffer.
97
 *
106
 *
98
 * @param edst  Pointer to where the event should be saved.
107
 * @param edst Pointer to where the event should be saved.
-
 
108
 *
99
 * @return  Zero on empty buffer, nonzero otherwise.
109
 * @return True if an event was popped.
-
 
110
 *
100
 */
111
 */
101
int keybuffer_pop(keybuffer_t *keybuffer, kbd_event_t *edst)
112
bool keybuffer_pop(keybuffer_t *keybuffer, console_event_t *edst)
102
{
113
{
103
    futex_down(&keybuffer_futex);
114
    futex_down(&keybuffer_futex);
-
 
115
   
104
    if (keybuffer->items > 0) {
116
    if (keybuffer->items > 0) {
105
        keybuffer->items--;
117
        keybuffer->items--;
106
        *edst = (keybuffer->fifo[keybuffer->head]) ;
118
        *edst = (keybuffer->fifo[keybuffer->head]);
107
        keybuffer->head = (keybuffer->head + 1) % KEYBUFFER_SIZE;
119
        keybuffer->head = (keybuffer->head + 1) % KEYBUFFER_SIZE;
108
        futex_up(&keybuffer_futex);
120
        futex_up(&keybuffer_futex);
-
 
121
       
109
        return 1;
122
        return true;
110
    }
123
    }
-
 
124
   
111
    futex_up(&keybuffer_futex);
125
    futex_up(&keybuffer_futex);
-
 
126
   
112
    return 0;
127
    return false;
113
}
128
}
114
 
129
 
115
/**
130
/**
116
 * @}
131
 * @}
117
 */
132
 */