source: mainline/uspace/lib/c/generic/io/input.c@ 28a5ebd

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 28a5ebd was 28a5ebd, checked in by Martin Decky <martin@…>, 5 years ago

Use char32_t instead of wchat_t to represent UTF-32 strings

The intention of the native HelenOS string API has been always to
support Unicode in the UTF-8 and UTF-32 encodings as the sole character
representations and ignore the obsolete mess of older single-byte and
multibyte character encodings. Before C11, the wchar_t type has been
slightly misused for the purpose of the UTF-32 strings. The newer
char32_t type is obviously a much more suitable option. The standard
defines char32_t as uint_least32_t, thus we can take the liberty to fix
it to uint32_t.

To maintain compatilibity with the C Standard, the putwchar(wchar_t)
functions has been replaced by our custom putuchar(char32_t) functions
where appropriate.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Copyright (c) 2012 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/**
33 * @file
34 * @brief Input protocol client stub
35 */
36
37#include <async.h>
38#include <assert.h>
39#include <errno.h>
40#include <io/kbd_event.h>
41#include <io/input.h>
42#include <ipc/input.h>
43#include <stdlib.h>
44
45static void input_cb_conn(ipc_call_t *icall, void *arg);
46
47errno_t input_open(async_sess_t *sess, input_ev_ops_t *ev_ops,
48 void *arg, input_t **rinput)
49{
50 input_t *input = calloc(1, sizeof(input_t));
51 if (input == NULL)
52 return ENOMEM;
53
54 input->sess = sess;
55 input->ev_ops = ev_ops;
56 input->user = arg;
57
58 async_exch_t *exch = async_exchange_begin(sess);
59
60 port_id_t port;
61 errno_t rc = async_create_callback_port(exch, INTERFACE_INPUT_CB, 0, 0,
62 input_cb_conn, input, &port);
63
64 async_exchange_end(exch);
65
66 if (rc != EOK)
67 goto error;
68
69 *rinput = input;
70 return EOK;
71
72error:
73 if (input != NULL)
74 free(input);
75
76 return rc;
77}
78
79void input_close(input_t *input)
80{
81 /* XXX Synchronize with input_cb_conn */
82 free(input);
83}
84
85errno_t input_activate(input_t *input)
86{
87 async_exch_t *exch = async_exchange_begin(input->sess);
88 errno_t rc = async_req_0_0(exch, INPUT_ACTIVATE);
89 async_exchange_end(exch);
90
91 return rc;
92}
93
94static void input_ev_active(input_t *input, ipc_call_t *call)
95{
96 errno_t rc = input->ev_ops->active(input);
97 async_answer_0(call, rc);
98}
99
100static void input_ev_deactive(input_t *input, ipc_call_t *call)
101{
102 errno_t rc = input->ev_ops->deactive(input);
103 async_answer_0(call, rc);
104}
105
106static void input_ev_key(input_t *input, ipc_call_t *call)
107{
108 kbd_event_type_t type;
109 keycode_t key;
110 keymod_t mods;
111 char32_t c;
112 errno_t rc;
113
114 type = ipc_get_arg1(call);
115 key = ipc_get_arg2(call);
116 mods = ipc_get_arg3(call);
117 c = ipc_get_arg4(call);
118
119 rc = input->ev_ops->key(input, type, key, mods, c);
120 async_answer_0(call, rc);
121}
122
123static void input_ev_move(input_t *input, ipc_call_t *call)
124{
125 int dx;
126 int dy;
127 errno_t rc;
128
129 dx = ipc_get_arg1(call);
130 dy = ipc_get_arg2(call);
131
132 rc = input->ev_ops->move(input, dx, dy);
133 async_answer_0(call, rc);
134}
135
136static void input_ev_abs_move(input_t *input, ipc_call_t *call)
137{
138 unsigned x;
139 unsigned y;
140 unsigned max_x;
141 unsigned max_y;
142 errno_t rc;
143
144 x = ipc_get_arg1(call);
145 y = ipc_get_arg2(call);
146 max_x = ipc_get_arg3(call);
147 max_y = ipc_get_arg4(call);
148
149 rc = input->ev_ops->abs_move(input, x, y, max_x, max_y);
150 async_answer_0(call, rc);
151}
152
153static void input_ev_button(input_t *input, ipc_call_t *call)
154{
155 int bnum;
156 int press;
157 errno_t rc;
158
159 bnum = ipc_get_arg1(call);
160 press = ipc_get_arg2(call);
161
162 rc = input->ev_ops->button(input, bnum, press);
163 async_answer_0(call, rc);
164}
165
166static void input_cb_conn(ipc_call_t *icall, void *arg)
167{
168 input_t *input = (input_t *) arg;
169
170 while (true) {
171 ipc_call_t call;
172 async_get_call(&call);
173
174 if (!ipc_get_imethod(&call)) {
175 async_answer_0(&call, EOK);
176 return;
177 }
178
179 switch (ipc_get_imethod(&call)) {
180 case INPUT_EVENT_ACTIVE:
181 input_ev_active(input, &call);
182 break;
183 case INPUT_EVENT_DEACTIVE:
184 input_ev_deactive(input, &call);
185 break;
186 case INPUT_EVENT_KEY:
187 input_ev_key(input, &call);
188 break;
189 case INPUT_EVENT_MOVE:
190 input_ev_move(input, &call);
191 break;
192 case INPUT_EVENT_ABS_MOVE:
193 input_ev_abs_move(input, &call);
194 break;
195 case INPUT_EVENT_BUTTON:
196 input_ev_button(input, &call);
197 break;
198 default:
199 async_answer_0(&call, ENOTSUP);
200 }
201 }
202}
203
204/** @}
205 */
Note: See TracBrowser for help on using the repository browser.