[111d2d6] | 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 |
|
---|
| 45 | static void input_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
|
---|
| 46 |
|
---|
[5a6cc679] | 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;
|
---|
[5a6cc679] | 61 | errno_t rc = async_create_callback_port(exch, INTERFACE_INPUT_CB, 0, 0,
|
---|
[f9b2cb4c] | 62 | input_cb_conn, input, &port);
|
---|
| 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 |
|
---|
[5a6cc679] | 85 | errno_t input_activate(input_t *input)
|
---|
[111d2d6] | 86 | {
|
---|
| 87 | async_exch_t *exch = async_exchange_begin(input->sess);
|
---|
[5a6cc679] | 88 | errno_t rc = async_req_0_0(exch, INPUT_ACTIVATE);
|
---|
[111d2d6] | 89 | async_exchange_end(exch);
|
---|
[ce3efa0] | 90 |
|
---|
[111d2d6] | 91 | return rc;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[593e023] | 94 | static void input_ev_active(input_t *input, ipc_callid_t callid,
|
---|
| 95 | ipc_call_t *call)
|
---|
[111d2d6] | 96 | {
|
---|
[5a6cc679] | 97 | errno_t rc = input->ev_ops->active(input);
|
---|
[593e023] | 98 | async_answer_0(callid, rc);
|
---|
| 99 | }
|
---|
[111d2d6] | 100 |
|
---|
[593e023] | 101 | static void input_ev_deactive(input_t *input, ipc_callid_t callid,
|
---|
| 102 | ipc_call_t *call)
|
---|
| 103 | {
|
---|
[5a6cc679] | 104 | errno_t rc = input->ev_ops->deactive(input);
|
---|
[593e023] | 105 | async_answer_0(callid, rc);
|
---|
[111d2d6] | 106 | }
|
---|
| 107 |
|
---|
| 108 | static void input_ev_key(input_t *input, ipc_callid_t callid,
|
---|
| 109 | ipc_call_t *call)
|
---|
| 110 | {
|
---|
| 111 | kbd_event_type_t type;
|
---|
| 112 | keycode_t key;
|
---|
| 113 | keymod_t mods;
|
---|
| 114 | wchar_t c;
|
---|
[5a6cc679] | 115 | errno_t rc;
|
---|
[111d2d6] | 116 |
|
---|
| 117 | type = IPC_GET_ARG1(*call);
|
---|
| 118 | key = IPC_GET_ARG2(*call);
|
---|
| 119 | mods = IPC_GET_ARG3(*call);
|
---|
| 120 | c = IPC_GET_ARG4(*call);
|
---|
| 121 |
|
---|
| 122 | rc = input->ev_ops->key(input, type, key, mods, c);
|
---|
| 123 | async_answer_0(callid, rc);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | static void input_ev_move(input_t *input, ipc_callid_t callid,
|
---|
| 127 | ipc_call_t *call)
|
---|
| 128 | {
|
---|
| 129 | int dx;
|
---|
| 130 | int dy;
|
---|
[5a6cc679] | 131 | errno_t rc;
|
---|
[111d2d6] | 132 |
|
---|
| 133 | dx = IPC_GET_ARG1(*call);
|
---|
| 134 | dy = IPC_GET_ARG2(*call);
|
---|
| 135 |
|
---|
| 136 | rc = input->ev_ops->move(input, dx, dy);
|
---|
| 137 | async_answer_0(callid, rc);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | static void input_ev_abs_move(input_t *input, ipc_callid_t callid,
|
---|
| 141 | ipc_call_t *call)
|
---|
| 142 | {
|
---|
| 143 | unsigned x;
|
---|
| 144 | unsigned y;
|
---|
| 145 | unsigned max_x;
|
---|
| 146 | unsigned max_y;
|
---|
[5a6cc679] | 147 | errno_t rc;
|
---|
[111d2d6] | 148 |
|
---|
| 149 | x = IPC_GET_ARG1(*call);
|
---|
| 150 | y = IPC_GET_ARG2(*call);
|
---|
[6af521c] | 151 | max_x = IPC_GET_ARG3(*call);
|
---|
| 152 | max_y = IPC_GET_ARG4(*call);
|
---|
[111d2d6] | 153 |
|
---|
| 154 | rc = input->ev_ops->abs_move(input, x, y, max_x, max_y);
|
---|
| 155 | async_answer_0(callid, rc);
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | static void input_ev_button(input_t *input, ipc_callid_t callid,
|
---|
| 159 | ipc_call_t *call)
|
---|
| 160 | {
|
---|
| 161 | int bnum;
|
---|
| 162 | int press;
|
---|
[5a6cc679] | 163 | errno_t rc;
|
---|
[111d2d6] | 164 |
|
---|
| 165 | bnum = IPC_GET_ARG1(*call);
|
---|
| 166 | press = IPC_GET_ARG2(*call);
|
---|
| 167 |
|
---|
| 168 | rc = input->ev_ops->button(input, bnum, press);
|
---|
| 169 | async_answer_0(callid, rc);
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | static void input_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
| 173 | {
|
---|
| 174 | input_t *input = (input_t *)arg;
|
---|
| 175 |
|
---|
| 176 | while (true) {
|
---|
| 177 | ipc_call_t call;
|
---|
| 178 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 179 |
|
---|
| 180 | if (!IPC_GET_IMETHOD(call)) {
|
---|
| 181 | /* TODO: Handle hangup */
|
---|
| 182 | return;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | switch (IPC_GET_IMETHOD(call)) {
|
---|
[593e023] | 186 | case INPUT_EVENT_ACTIVE:
|
---|
| 187 | input_ev_active(input, callid, &call);
|
---|
| 188 | break;
|
---|
| 189 | case INPUT_EVENT_DEACTIVE:
|
---|
| 190 | input_ev_deactive(input, callid, &call);
|
---|
| 191 | break;
|
---|
[111d2d6] | 192 | case INPUT_EVENT_KEY:
|
---|
| 193 | input_ev_key(input, callid, &call);
|
---|
| 194 | break;
|
---|
| 195 | case INPUT_EVENT_MOVE:
|
---|
| 196 | input_ev_move(input, callid, &call);
|
---|
| 197 | break;
|
---|
| 198 | case INPUT_EVENT_ABS_MOVE:
|
---|
| 199 | input_ev_abs_move(input, callid, &call);
|
---|
| 200 | break;
|
---|
| 201 | case INPUT_EVENT_BUTTON:
|
---|
| 202 | input_ev_button(input, callid, &call);
|
---|
| 203 | break;
|
---|
| 204 | default:
|
---|
| 205 | async_answer_0(callid, ENOTSUP);
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | /** @}
|
---|
| 211 | */
|
---|