[5d94b16c] | 1 | /*
|
---|
[68a552f] | 2 | * Copyright (c) 2021 Jiri Svoboda
|
---|
[5d94b16c] | 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 |
|
---|
[a635535] | 29 | /** @addtogroup libconsole
|
---|
[5d94b16c] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief Console protocol server stub
|
---|
| 35 | */
|
---|
[68a552f] | 36 | #include <as.h>
|
---|
[5d94b16c] | 37 | #include <errno.h>
|
---|
[902f0906] | 38 | #include <io/cons_event.h>
|
---|
[5d94b16c] | 39 | #include <ipc/console.h>
|
---|
| 40 | #include <stdlib.h>
|
---|
[8d2dd7f2] | 41 | #include <stddef.h>
|
---|
[5d94b16c] | 42 |
|
---|
| 43 | #include <io/con_srv.h>
|
---|
| 44 |
|
---|
[984a9ba] | 45 | static errno_t console_ev_encode(cons_event_t *event, ipc_call_t *icall)
|
---|
[902f0906] | 46 | {
|
---|
[fafb8e5] | 47 | ipc_set_arg1(icall, event->type);
|
---|
[902f0906] | 48 |
|
---|
| 49 | switch (event->type) {
|
---|
| 50 | case CEV_KEY:
|
---|
[fafb8e5] | 51 | ipc_set_arg2(icall, event->ev.key.type);
|
---|
| 52 | ipc_set_arg3(icall, event->ev.key.key);
|
---|
| 53 | ipc_set_arg4(icall, event->ev.key.mods);
|
---|
| 54 | ipc_set_arg5(icall, event->ev.key.c);
|
---|
[899bdfd] | 55 | return EOK;
|
---|
[902f0906] | 56 | case CEV_POS:
|
---|
[fafb8e5] | 57 | ipc_set_arg2(icall, (event->ev.pos.pos_id << 16) | (event->ev.pos.type & 0xffff));
|
---|
| 58 | ipc_set_arg3(icall, event->ev.pos.btn_num);
|
---|
| 59 | ipc_set_arg4(icall, event->ev.pos.hpos);
|
---|
| 60 | ipc_set_arg5(icall, event->ev.pos.vpos);
|
---|
[899bdfd] | 61 | return EOK;
|
---|
| 62 | case CEV_RESIZE:
|
---|
| 63 | ipc_set_arg2(icall, 0);
|
---|
| 64 | ipc_set_arg3(icall, 0);
|
---|
| 65 | ipc_set_arg4(icall, 0);
|
---|
| 66 | ipc_set_arg5(icall, 0);
|
---|
| 67 | return EOK;
|
---|
[902f0906] | 68 | }
|
---|
| 69 |
|
---|
[899bdfd] | 70 | return EIO;
|
---|
[902f0906] | 71 | }
|
---|
| 72 |
|
---|
[984a9ba] | 73 | static void con_read_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 74 | {
|
---|
| 75 | void *buf;
|
---|
| 76 | size_t size;
|
---|
[b7fd2a0] | 77 | errno_t rc;
|
---|
[5d94b16c] | 78 |
|
---|
[984a9ba] | 79 | ipc_call_t call;
|
---|
| 80 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 81 | async_answer_0(icall, EINVAL);
|
---|
[5d94b16c] | 82 | return;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | buf = malloc(size);
|
---|
| 86 | if (buf == NULL) {
|
---|
[984a9ba] | 87 | async_answer_0(&call, ENOMEM);
|
---|
| 88 | async_answer_0(icall, ENOMEM);
|
---|
[5d94b16c] | 89 | return;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | if (srv->srvs->ops->read == NULL) {
|
---|
[984a9ba] | 93 | async_answer_0(&call, ENOTSUP);
|
---|
| 94 | async_answer_0(icall, ENOTSUP);
|
---|
[ccfe9c3] | 95 | free(buf);
|
---|
[5d94b16c] | 96 | return;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[c8211849] | 99 | size_t nread;
|
---|
| 100 | rc = srv->srvs->ops->read(srv, buf, size, &nread);
|
---|
| 101 | if (rc != EOK) {
|
---|
[984a9ba] | 102 | async_answer_0(&call, rc);
|
---|
| 103 | async_answer_0(icall, rc);
|
---|
[ccfe9c3] | 104 | free(buf);
|
---|
[5d94b16c] | 105 | return;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[984a9ba] | 108 | async_data_read_finalize(&call, buf, nread);
|
---|
[5d94b16c] | 109 | free(buf);
|
---|
| 110 |
|
---|
[984a9ba] | 111 | async_answer_1(icall, EOK, nread);
|
---|
[5d94b16c] | 112 | }
|
---|
| 113 |
|
---|
[984a9ba] | 114 | static void con_write_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 115 | {
|
---|
| 116 | void *data;
|
---|
| 117 | size_t size;
|
---|
[b7fd2a0] | 118 | errno_t rc;
|
---|
[5d94b16c] | 119 |
|
---|
| 120 | rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
|
---|
| 121 | if (rc != EOK) {
|
---|
[984a9ba] | 122 | async_answer_0(icall, rc);
|
---|
[5d94b16c] | 123 | return;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | if (srv->srvs->ops->write == NULL) {
|
---|
[984a9ba] | 127 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 128 | return;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[c8211849] | 131 | size_t nwritten = 0;
|
---|
| 132 | rc = srv->srvs->ops->write(srv, data, size, &nwritten);
|
---|
[5d94b16c] | 133 | free(data);
|
---|
| 134 |
|
---|
[984a9ba] | 135 | async_answer_1(icall, rc, nwritten);
|
---|
[5d94b16c] | 136 | }
|
---|
| 137 |
|
---|
[984a9ba] | 138 | static void con_sync_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 139 | {
|
---|
| 140 | if (srv->srvs->ops->sync == NULL) {
|
---|
[984a9ba] | 141 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 142 | return;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | srv->srvs->ops->sync(srv);
|
---|
[984a9ba] | 146 | async_answer_0(icall, EOK);
|
---|
[5d94b16c] | 147 | }
|
---|
| 148 |
|
---|
[984a9ba] | 149 | static void con_clear_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 150 | {
|
---|
| 151 | if (srv->srvs->ops->clear == NULL) {
|
---|
[984a9ba] | 152 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 153 | return;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | srv->srvs->ops->clear(srv);
|
---|
[984a9ba] | 157 | async_answer_0(icall, EOK);
|
---|
[5d94b16c] | 158 | }
|
---|
| 159 |
|
---|
[984a9ba] | 160 | static void con_set_pos_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 161 | {
|
---|
| 162 | sysarg_t col;
|
---|
| 163 | sysarg_t row;
|
---|
| 164 |
|
---|
[fafb8e5] | 165 | col = ipc_get_arg1(icall);
|
---|
| 166 | row = ipc_get_arg2(icall);
|
---|
[5d94b16c] | 167 |
|
---|
| 168 | if (srv->srvs->ops->set_pos == NULL) {
|
---|
[984a9ba] | 169 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 170 | return;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | srv->srvs->ops->set_pos(srv, col, row);
|
---|
[984a9ba] | 174 | async_answer_0(icall, EOK);
|
---|
[5d94b16c] | 175 | }
|
---|
| 176 |
|
---|
[984a9ba] | 177 | static void con_get_pos_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 178 | {
|
---|
[b7fd2a0] | 179 | errno_t rc;
|
---|
[5d94b16c] | 180 | sysarg_t col;
|
---|
| 181 | sysarg_t row;
|
---|
| 182 |
|
---|
| 183 | if (srv->srvs->ops->get_pos == NULL) {
|
---|
[984a9ba] | 184 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 185 | return;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | rc = srv->srvs->ops->get_pos(srv, &col, &row);
|
---|
[984a9ba] | 189 | async_answer_2(icall, rc, col, row);
|
---|
[5d94b16c] | 190 | }
|
---|
| 191 |
|
---|
[984a9ba] | 192 | static void con_get_size_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 193 | {
|
---|
[b7fd2a0] | 194 | errno_t rc;
|
---|
[5d94b16c] | 195 | sysarg_t cols;
|
---|
| 196 | sysarg_t rows;
|
---|
| 197 |
|
---|
| 198 | if (srv->srvs->ops->get_size == NULL) {
|
---|
[984a9ba] | 199 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 200 | return;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | rc = srv->srvs->ops->get_size(srv, &cols, &rows);
|
---|
[984a9ba] | 204 | async_answer_2(icall, rc, cols, rows);
|
---|
[5d94b16c] | 205 | }
|
---|
| 206 |
|
---|
[984a9ba] | 207 | static void con_get_color_cap_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 208 | {
|
---|
[b7fd2a0] | 209 | errno_t rc;
|
---|
[5d94b16c] | 210 | console_caps_t ccap;
|
---|
| 211 |
|
---|
| 212 | if (srv->srvs->ops->get_color_cap == NULL) {
|
---|
[984a9ba] | 213 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 214 | return;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | rc = srv->srvs->ops->get_color_cap(srv, &ccap);
|
---|
[984a9ba] | 218 | async_answer_1(icall, rc, (sysarg_t)ccap);
|
---|
[5d94b16c] | 219 | }
|
---|
| 220 |
|
---|
[984a9ba] | 221 | static void con_set_style_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 222 | {
|
---|
| 223 | console_style_t style;
|
---|
| 224 |
|
---|
[fafb8e5] | 225 | style = ipc_get_arg1(icall);
|
---|
[5d94b16c] | 226 |
|
---|
| 227 | if (srv->srvs->ops->set_style == NULL) {
|
---|
[984a9ba] | 228 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 229 | return;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | srv->srvs->ops->set_style(srv, style);
|
---|
[984a9ba] | 233 | async_answer_0(icall, EOK);
|
---|
[5d94b16c] | 234 | }
|
---|
| 235 |
|
---|
[984a9ba] | 236 | static void con_set_color_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 237 | {
|
---|
| 238 | console_color_t bgcolor;
|
---|
| 239 | console_color_t fgcolor;
|
---|
| 240 | console_color_attr_t flags;
|
---|
| 241 |
|
---|
[fafb8e5] | 242 | bgcolor = ipc_get_arg1(icall);
|
---|
| 243 | fgcolor = ipc_get_arg2(icall);
|
---|
| 244 | flags = ipc_get_arg3(icall);
|
---|
[5d94b16c] | 245 |
|
---|
| 246 | if (srv->srvs->ops->set_color == NULL) {
|
---|
[984a9ba] | 247 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 248 | return;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | srv->srvs->ops->set_color(srv, bgcolor, fgcolor, flags);
|
---|
[984a9ba] | 252 | async_answer_0(icall, EOK);
|
---|
[5d94b16c] | 253 | }
|
---|
| 254 |
|
---|
[984a9ba] | 255 | static void con_set_rgb_color_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 256 | {
|
---|
| 257 | pixel_t bgcolor;
|
---|
| 258 | pixel_t fgcolor;
|
---|
| 259 |
|
---|
[fafb8e5] | 260 | bgcolor = ipc_get_arg1(icall);
|
---|
| 261 | fgcolor = ipc_get_arg2(icall);
|
---|
[5d94b16c] | 262 |
|
---|
| 263 | if (srv->srvs->ops->set_rgb_color == NULL) {
|
---|
[984a9ba] | 264 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 265 | return;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | srv->srvs->ops->set_rgb_color(srv, bgcolor, fgcolor);
|
---|
[984a9ba] | 269 | async_answer_0(icall, EOK);
|
---|
[5d94b16c] | 270 | }
|
---|
| 271 |
|
---|
[984a9ba] | 272 | static void con_set_cursor_visibility_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 273 | {
|
---|
| 274 | bool show;
|
---|
| 275 |
|
---|
[fafb8e5] | 276 | show = ipc_get_arg1(icall);
|
---|
[5d94b16c] | 277 |
|
---|
| 278 | if (srv->srvs->ops->set_cursor_visibility == NULL) {
|
---|
[984a9ba] | 279 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 280 | return;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | srv->srvs->ops->set_cursor_visibility(srv, show);
|
---|
[984a9ba] | 284 | async_answer_0(icall, EOK);
|
---|
[5d94b16c] | 285 | }
|
---|
| 286 |
|
---|
[b48e680f] | 287 | static void con_set_caption_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
| 288 | {
|
---|
| 289 | char *caption;
|
---|
| 290 | errno_t rc;
|
---|
| 291 |
|
---|
| 292 | rc = async_data_write_accept((void **) &caption, true, 0,
|
---|
| 293 | CON_CAPTION_MAXLEN, 0, NULL);
|
---|
| 294 | if (rc != EOK) {
|
---|
| 295 | async_answer_0(icall, rc);
|
---|
| 296 | return;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | if (srv->srvs->ops->set_caption == NULL) {
|
---|
| 300 | async_answer_0(icall, ENOTSUP);
|
---|
| 301 | return;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | srv->srvs->ops->set_caption(srv, caption);
|
---|
| 305 | free(caption);
|
---|
| 306 | async_answer_0(icall, EOK);
|
---|
| 307 | }
|
---|
| 308 |
|
---|
[984a9ba] | 309 | static void con_get_event_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
[5d94b16c] | 310 | {
|
---|
[b7fd2a0] | 311 | errno_t rc;
|
---|
[902f0906] | 312 | cons_event_t event;
|
---|
| 313 | ipc_call_t result;
|
---|
[5d94b16c] | 314 |
|
---|
| 315 | if (srv->srvs->ops->get_event == NULL) {
|
---|
[984a9ba] | 316 | async_answer_0(icall, ENOTSUP);
|
---|
[5d94b16c] | 317 | return;
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | rc = srv->srvs->ops->get_event(srv, &event);
|
---|
[902f0906] | 321 | if (rc != EOK) {
|
---|
[984a9ba] | 322 | async_answer_0(icall, rc);
|
---|
[902f0906] | 323 | return;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | rc = console_ev_encode(&event, &result);
|
---|
| 327 | if (rc != EOK) {
|
---|
[984a9ba] | 328 | async_answer_0(icall, rc);
|
---|
[902f0906] | 329 | return;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
[fafb8e5] | 332 | async_answer_5(icall, rc, ipc_get_arg1(&result), ipc_get_arg2(&result),
|
---|
| 333 | ipc_get_arg3(&result), ipc_get_arg4(&result), ipc_get_arg5(&result));
|
---|
[5d94b16c] | 334 | }
|
---|
| 335 |
|
---|
[68a552f] | 336 | /** Create shared buffer for efficient rendering */
|
---|
| 337 | static void con_map_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
| 338 | {
|
---|
| 339 | errno_t rc;
|
---|
| 340 | charfield_t *buf;
|
---|
| 341 | sysarg_t cols, rows;
|
---|
| 342 | ipc_call_t call;
|
---|
| 343 | size_t size;
|
---|
| 344 |
|
---|
| 345 | if (srv->srvs->ops->map == NULL || srv->srvs->ops->unmap == NULL) {
|
---|
| 346 | async_answer_0(icall, ENOTSUP);
|
---|
| 347 | return;
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | cols = ipc_get_arg1(icall);
|
---|
| 351 | rows = ipc_get_arg2(icall);
|
---|
| 352 |
|
---|
| 353 | if (!async_share_in_receive(&call, &size)) {
|
---|
| 354 | async_answer_0(icall, EINVAL);
|
---|
| 355 | return;
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | /* Check size */
|
---|
| 359 | if (size != PAGES2SIZE(SIZE2PAGES(cols * rows * sizeof(charfield_t)))) {
|
---|
| 360 | async_answer_0(&call, EINVAL);
|
---|
| 361 | async_answer_0(icall, EINVAL);
|
---|
| 362 | return;
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | rc = srv->srvs->ops->map(srv, cols, rows, &buf);
|
---|
| 366 | if (rc != EOK) {
|
---|
| 367 | async_answer_0(&call, rc);
|
---|
| 368 | async_answer_0(icall, rc);
|
---|
| 369 | return;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | rc = async_share_in_finalize(&call, buf, AS_AREA_READ |
|
---|
| 373 | AS_AREA_WRITE | AS_AREA_CACHEABLE);
|
---|
| 374 | if (rc != EOK) {
|
---|
| 375 | srv->srvs->ops->unmap(srv);
|
---|
| 376 | async_answer_0(icall, EIO);
|
---|
| 377 | return;
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 | async_answer_0(icall, EOK);
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | /** Delete shared buffer */
|
---|
| 384 | static void con_unmap_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
| 385 | {
|
---|
| 386 | if (srv->srvs->ops->unmap == NULL) {
|
---|
| 387 | async_answer_0(icall, ENOTSUP);
|
---|
| 388 | return;
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 | srv->srvs->ops->unmap(srv);
|
---|
| 392 | async_answer_0(icall, EOK);
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | /** Update console area from shared buffer */
|
---|
| 396 | static void con_update_srv(con_srv_t *srv, ipc_call_t *icall)
|
---|
| 397 | {
|
---|
| 398 | sysarg_t c0, r0, c1, r1;
|
---|
| 399 |
|
---|
| 400 | c0 = ipc_get_arg1(icall);
|
---|
| 401 | r0 = ipc_get_arg2(icall);
|
---|
| 402 | c1 = ipc_get_arg3(icall);
|
---|
| 403 | r1 = ipc_get_arg4(icall);
|
---|
| 404 |
|
---|
| 405 | if (srv->srvs->ops->update == NULL) {
|
---|
| 406 | async_answer_0(icall, ENOTSUP);
|
---|
| 407 | return;
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | srv->srvs->ops->update(srv, c0, r0, c1, r1);
|
---|
| 411 | async_answer_0(icall, EOK);
|
---|
| 412 | }
|
---|
| 413 |
|
---|
[5d94b16c] | 414 | static con_srv_t *con_srv_create(con_srvs_t *srvs)
|
---|
| 415 | {
|
---|
| 416 | con_srv_t *srv;
|
---|
| 417 |
|
---|
| 418 | srv = calloc(1, sizeof(*srv));
|
---|
| 419 | if (srv == NULL)
|
---|
| 420 | return NULL;
|
---|
| 421 |
|
---|
| 422 | srv->srvs = srvs;
|
---|
| 423 | return srv;
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | void con_srvs_init(con_srvs_t *srvs)
|
---|
| 427 | {
|
---|
| 428 | srvs->ops = NULL;
|
---|
| 429 | srvs->sarg = NULL;
|
---|
| 430 | srvs->abort_timeout = 0;
|
---|
| 431 | srvs->aborted = false;
|
---|
| 432 | }
|
---|
| 433 |
|
---|
[984a9ba] | 434 | errno_t con_conn(ipc_call_t *icall, con_srvs_t *srvs)
|
---|
[5d94b16c] | 435 | {
|
---|
| 436 | con_srv_t *srv;
|
---|
[b7fd2a0] | 437 | errno_t rc;
|
---|
[5d94b16c] | 438 |
|
---|
| 439 | /* Accept the connection */
|
---|
[beb83c1] | 440 | async_accept_0(icall);
|
---|
[5d94b16c] | 441 |
|
---|
| 442 | srv = con_srv_create(srvs);
|
---|
| 443 | if (srv == NULL)
|
---|
| 444 | return ENOMEM;
|
---|
| 445 |
|
---|
| 446 | srv->client_sess = NULL;
|
---|
| 447 |
|
---|
| 448 | rc = srvs->ops->open(srvs, srv);
|
---|
| 449 | if (rc != EOK)
|
---|
| 450 | return rc;
|
---|
| 451 |
|
---|
| 452 | while (true) {
|
---|
| 453 | ipc_call_t call;
|
---|
[984a9ba] | 454 | bool received = false;
|
---|
[5d94b16c] | 455 |
|
---|
[984a9ba] | 456 | while (!received) {
|
---|
[5d94b16c] | 457 | /* XXX Need to be able to abort immediately */
|
---|
[984a9ba] | 458 | received = async_get_call_timeout(&call,
|
---|
[5d94b16c] | 459 | srvs->abort_timeout);
|
---|
| 460 |
|
---|
| 461 | if (srv->srvs->aborted) {
|
---|
[984a9ba] | 462 | if (received)
|
---|
| 463 | async_answer_0(&call, EINTR);
|
---|
[5d94b16c] | 464 | break;
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 |
|
---|
[5be5396] | 468 | if (!received || srv->srvs->aborted)
|
---|
[5d94b16c] | 469 | break;
|
---|
| 470 |
|
---|
[fafb8e5] | 471 | sysarg_t method = ipc_get_imethod(&call);
|
---|
[5d94b16c] | 472 |
|
---|
| 473 | if (!method) {
|
---|
| 474 | /* The other side has hung up */
|
---|
[984a9ba] | 475 | async_answer_0(&call, EOK);
|
---|
[5d94b16c] | 476 | break;
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | switch (method) {
|
---|
| 480 | case VFS_OUT_READ:
|
---|
[984a9ba] | 481 | con_read_srv(srv, &call);
|
---|
[5d94b16c] | 482 | break;
|
---|
| 483 | case VFS_OUT_WRITE:
|
---|
[984a9ba] | 484 | con_write_srv(srv, &call);
|
---|
[5d94b16c] | 485 | break;
|
---|
| 486 | case VFS_OUT_SYNC:
|
---|
[984a9ba] | 487 | con_sync_srv(srv, &call);
|
---|
[5d94b16c] | 488 | break;
|
---|
| 489 | case CONSOLE_CLEAR:
|
---|
[984a9ba] | 490 | con_clear_srv(srv, &call);
|
---|
[5d94b16c] | 491 | break;
|
---|
| 492 | case CONSOLE_SET_POS:
|
---|
[984a9ba] | 493 | con_set_pos_srv(srv, &call);
|
---|
[5d94b16c] | 494 | break;
|
---|
| 495 | case CONSOLE_GET_POS:
|
---|
[984a9ba] | 496 | con_get_pos_srv(srv, &call);
|
---|
[5d94b16c] | 497 | break;
|
---|
| 498 | case CONSOLE_GET_SIZE:
|
---|
[984a9ba] | 499 | con_get_size_srv(srv, &call);
|
---|
[5d94b16c] | 500 | break;
|
---|
| 501 | case CONSOLE_GET_COLOR_CAP:
|
---|
[984a9ba] | 502 | con_get_color_cap_srv(srv, &call);
|
---|
[5d94b16c] | 503 | break;
|
---|
| 504 | case CONSOLE_SET_STYLE:
|
---|
[984a9ba] | 505 | con_set_style_srv(srv, &call);
|
---|
[5d94b16c] | 506 | break;
|
---|
| 507 | case CONSOLE_SET_COLOR:
|
---|
[984a9ba] | 508 | con_set_color_srv(srv, &call);
|
---|
[5d94b16c] | 509 | break;
|
---|
| 510 | case CONSOLE_SET_RGB_COLOR:
|
---|
[984a9ba] | 511 | con_set_rgb_color_srv(srv, &call);
|
---|
[5d94b16c] | 512 | break;
|
---|
| 513 | case CONSOLE_SET_CURSOR_VISIBILITY:
|
---|
[984a9ba] | 514 | con_set_cursor_visibility_srv(srv, &call);
|
---|
[5d94b16c] | 515 | break;
|
---|
[b48e680f] | 516 | case CONSOLE_SET_CAPTION:
|
---|
| 517 | con_set_caption_srv(srv, &call);
|
---|
| 518 | break;
|
---|
[5d94b16c] | 519 | case CONSOLE_GET_EVENT:
|
---|
[984a9ba] | 520 | con_get_event_srv(srv, &call);
|
---|
[5d94b16c] | 521 | break;
|
---|
[68a552f] | 522 | case CONSOLE_MAP:
|
---|
| 523 | con_map_srv(srv, &call);
|
---|
| 524 | break;
|
---|
| 525 | case CONSOLE_UNMAP:
|
---|
| 526 | con_unmap_srv(srv, &call);
|
---|
| 527 | break;
|
---|
| 528 | case CONSOLE_UPDATE:
|
---|
| 529 | con_update_srv(srv, &call);
|
---|
| 530 | break;
|
---|
[5d94b16c] | 531 | default:
|
---|
[984a9ba] | 532 | async_answer_0(&call, ENOTSUP);
|
---|
[5d94b16c] | 533 | }
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | rc = srvs->ops->close(srv);
|
---|
| 537 | free(srv);
|
---|
| 538 |
|
---|
| 539 | return rc;
|
---|
| 540 | }
|
---|
| 541 |
|
---|
| 542 | /** @}
|
---|
| 543 | */
|
---|