[111d2d6] | 1 | /*
|
---|
[60ebe63] | 2 | * Copyright (c) 2022 Jiri Svoboda
|
---|
[111d2d6] | 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 |
|
---|
[984a9ba] | 45 | static void input_cb_conn(ipc_call_t *icall, void *arg);
|
---|
[111d2d6] | 46 |
|
---|
[b7fd2a0] | 47 | errno_t input_open(async_sess_t *sess, input_ev_ops_t *ev_ops,
|
---|
[111d2d6] | 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 |
|
---|
[f9b2cb4c] | 60 | port_id_t port;
|
---|
[b7fd2a0] | 61 | errno_t rc = async_create_callback_port(exch, INTERFACE_INPUT_CB, 0, 0,
|
---|
[f9b2cb4c] | 62 | input_cb_conn, input, &port);
|
---|
[a35b458] | 63 |
|
---|
[111d2d6] | 64 | async_exchange_end(exch);
|
---|
| 65 |
|
---|
| 66 | if (rc != EOK)
|
---|
| 67 | goto error;
|
---|
| 68 |
|
---|
| 69 | *rinput = input;
|
---|
| 70 | return EOK;
|
---|
| 71 |
|
---|
| 72 | error:
|
---|
| 73 | if (input != NULL)
|
---|
| 74 | free(input);
|
---|
| 75 |
|
---|
| 76 | return rc;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | void input_close(input_t *input)
|
---|
| 80 | {
|
---|
| 81 | /* XXX Synchronize with input_cb_conn */
|
---|
| 82 | free(input);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[b7fd2a0] | 85 | errno_t input_activate(input_t *input)
|
---|
[111d2d6] | 86 | {
|
---|
| 87 | async_exch_t *exch = async_exchange_begin(input->sess);
|
---|
[b7fd2a0] | 88 | errno_t rc = async_req_0_0(exch, INPUT_ACTIVATE);
|
---|
[111d2d6] | 89 | async_exchange_end(exch);
|
---|
[a35b458] | 90 |
|
---|
[111d2d6] | 91 | return rc;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[984a9ba] | 94 | static void input_ev_active(input_t *input, ipc_call_t *call)
|
---|
[111d2d6] | 95 | {
|
---|
[b7fd2a0] | 96 | errno_t rc = input->ev_ops->active(input);
|
---|
[984a9ba] | 97 | async_answer_0(call, rc);
|
---|
[593e023] | 98 | }
|
---|
[111d2d6] | 99 |
|
---|
[984a9ba] | 100 | static void input_ev_deactive(input_t *input, ipc_call_t *call)
|
---|
[593e023] | 101 | {
|
---|
[b7fd2a0] | 102 | errno_t rc = input->ev_ops->deactive(input);
|
---|
[984a9ba] | 103 | async_answer_0(call, rc);
|
---|
[111d2d6] | 104 | }
|
---|
| 105 |
|
---|
[984a9ba] | 106 | static void input_ev_key(input_t *input, ipc_call_t *call)
|
---|
[111d2d6] | 107 | {
|
---|
[60ebe63] | 108 | unsigned kbd_id;
|
---|
[111d2d6] | 109 | kbd_event_type_t type;
|
---|
| 110 | keycode_t key;
|
---|
| 111 | keymod_t mods;
|
---|
[28a5ebd] | 112 | char32_t c;
|
---|
[b7fd2a0] | 113 | errno_t rc;
|
---|
[111d2d6] | 114 |
|
---|
[60ebe63] | 115 | kbd_id = ipc_get_arg1(call);
|
---|
| 116 | type = ipc_get_arg2(call);
|
---|
| 117 | key = ipc_get_arg3(call);
|
---|
| 118 | mods = ipc_get_arg4(call);
|
---|
| 119 | c = ipc_get_arg5(call);
|
---|
[111d2d6] | 120 |
|
---|
[60ebe63] | 121 | rc = input->ev_ops->key(input, kbd_id, type, key, mods, c);
|
---|
[984a9ba] | 122 | async_answer_0(call, rc);
|
---|
[111d2d6] | 123 | }
|
---|
| 124 |
|
---|
[984a9ba] | 125 | static void input_ev_move(input_t *input, ipc_call_t *call)
|
---|
[111d2d6] | 126 | {
|
---|
[60ebe63] | 127 | unsigned pos_id;
|
---|
[111d2d6] | 128 | int dx;
|
---|
| 129 | int dy;
|
---|
[b7fd2a0] | 130 | errno_t rc;
|
---|
[111d2d6] | 131 |
|
---|
[60ebe63] | 132 | pos_id = ipc_get_arg1(call);
|
---|
| 133 | dx = ipc_get_arg2(call);
|
---|
| 134 | dy = ipc_get_arg3(call);
|
---|
[111d2d6] | 135 |
|
---|
[60ebe63] | 136 | rc = input->ev_ops->move(input, pos_id, dx, dy);
|
---|
[984a9ba] | 137 | async_answer_0(call, rc);
|
---|
[111d2d6] | 138 | }
|
---|
| 139 |
|
---|
[984a9ba] | 140 | static void input_ev_abs_move(input_t *input, ipc_call_t *call)
|
---|
[111d2d6] | 141 | {
|
---|
[60ebe63] | 142 | unsigned pos_id;
|
---|
[111d2d6] | 143 | unsigned x;
|
---|
| 144 | unsigned y;
|
---|
| 145 | unsigned max_x;
|
---|
| 146 | unsigned max_y;
|
---|
[b7fd2a0] | 147 | errno_t rc;
|
---|
[111d2d6] | 148 |
|
---|
[60ebe63] | 149 | pos_id = ipc_get_arg1(call);
|
---|
| 150 | x = ipc_get_arg2(call);
|
---|
| 151 | y = ipc_get_arg3(call);
|
---|
| 152 | max_x = ipc_get_arg4(call);
|
---|
| 153 | max_y = ipc_get_arg5(call);
|
---|
[111d2d6] | 154 |
|
---|
[60ebe63] | 155 | rc = input->ev_ops->abs_move(input, pos_id, x, y, max_x, max_y);
|
---|
[984a9ba] | 156 | async_answer_0(call, rc);
|
---|
[111d2d6] | 157 | }
|
---|
| 158 |
|
---|
[984a9ba] | 159 | static void input_ev_button(input_t *input, ipc_call_t *call)
|
---|
[111d2d6] | 160 | {
|
---|
[60ebe63] | 161 | unsigned pos_id;
|
---|
[111d2d6] | 162 | int bnum;
|
---|
| 163 | int press;
|
---|
[b7fd2a0] | 164 | errno_t rc;
|
---|
[111d2d6] | 165 |
|
---|
[60ebe63] | 166 | pos_id = ipc_get_arg1(call);
|
---|
| 167 | bnum = ipc_get_arg2(call);
|
---|
| 168 | press = ipc_get_arg3(call);
|
---|
[111d2d6] | 169 |
|
---|
[60ebe63] | 170 | rc = input->ev_ops->button(input, pos_id, bnum, press);
|
---|
[984a9ba] | 171 | async_answer_0(call, rc);
|
---|
[111d2d6] | 172 | }
|
---|
| 173 |
|
---|
[8edec53] | 174 | static void input_ev_dclick(input_t *input, ipc_call_t *call)
|
---|
| 175 | {
|
---|
[60ebe63] | 176 | unsigned pos_id;
|
---|
[8edec53] | 177 | int bnum;
|
---|
| 178 | errno_t rc;
|
---|
| 179 |
|
---|
[60ebe63] | 180 | pos_id = ipc_get_arg1(call);
|
---|
| 181 | bnum = ipc_get_arg2(call);
|
---|
[8edec53] | 182 |
|
---|
[60ebe63] | 183 | rc = input->ev_ops->dclick(input, pos_id, bnum);
|
---|
[8edec53] | 184 | async_answer_0(call, rc);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[984a9ba] | 187 | static void input_cb_conn(ipc_call_t *icall, void *arg)
|
---|
[111d2d6] | 188 | {
|
---|
[984a9ba] | 189 | input_t *input = (input_t *) arg;
|
---|
[111d2d6] | 190 |
|
---|
| 191 | while (true) {
|
---|
| 192 | ipc_call_t call;
|
---|
[984a9ba] | 193 | async_get_call(&call);
|
---|
[111d2d6] | 194 |
|
---|
[fafb8e5] | 195 | if (!ipc_get_imethod(&call)) {
|
---|
[889cdb1] | 196 | async_answer_0(&call, EOK);
|
---|
[111d2d6] | 197 | return;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[fafb8e5] | 200 | switch (ipc_get_imethod(&call)) {
|
---|
[593e023] | 201 | case INPUT_EVENT_ACTIVE:
|
---|
[984a9ba] | 202 | input_ev_active(input, &call);
|
---|
[593e023] | 203 | break;
|
---|
| 204 | case INPUT_EVENT_DEACTIVE:
|
---|
[984a9ba] | 205 | input_ev_deactive(input, &call);
|
---|
[593e023] | 206 | break;
|
---|
[111d2d6] | 207 | case INPUT_EVENT_KEY:
|
---|
[984a9ba] | 208 | input_ev_key(input, &call);
|
---|
[111d2d6] | 209 | break;
|
---|
| 210 | case INPUT_EVENT_MOVE:
|
---|
[984a9ba] | 211 | input_ev_move(input, &call);
|
---|
[111d2d6] | 212 | break;
|
---|
| 213 | case INPUT_EVENT_ABS_MOVE:
|
---|
[984a9ba] | 214 | input_ev_abs_move(input, &call);
|
---|
[111d2d6] | 215 | break;
|
---|
| 216 | case INPUT_EVENT_BUTTON:
|
---|
[984a9ba] | 217 | input_ev_button(input, &call);
|
---|
[111d2d6] | 218 | break;
|
---|
[8edec53] | 219 | case INPUT_EVENT_DCLICK:
|
---|
| 220 | input_ev_dclick(input, &call);
|
---|
| 221 | break;
|
---|
[111d2d6] | 222 | default:
|
---|
[984a9ba] | 223 | async_answer_0(&call, ENOTSUP);
|
---|
[111d2d6] | 224 | }
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | /** @}
|
---|
| 229 | */
|
---|