| 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 Jiri Svoboda
|
|---|
| 3 | * Copyright (c) 2011 Martin Decky
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | /** @addtogroup output
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 |
|
|---|
| 34 | #include <errno.h>
|
|---|
| 35 | #include <stddef.h>
|
|---|
| 36 | #include <stdlib.h>
|
|---|
| 37 | #include <macros.h>
|
|---|
| 38 | #include <as.h>
|
|---|
| 39 | #include <task.h>
|
|---|
| 40 | #include <ipc/output.h>
|
|---|
| 41 | #include <config.h>
|
|---|
| 42 | #include "port/ega.h"
|
|---|
| 43 | #include "port/chardev.h"
|
|---|
| 44 | #include "port/ddev.h"
|
|---|
| 45 | #include "output.h"
|
|---|
| 46 |
|
|---|
| 47 | typedef struct {
|
|---|
| 48 | link_t link;
|
|---|
| 49 |
|
|---|
| 50 | size_t size;
|
|---|
| 51 | unsigned int flags;
|
|---|
| 52 | void *data;
|
|---|
| 53 | } frontbuf_t;
|
|---|
| 54 |
|
|---|
| 55 | static LIST_INITIALIZE(outdevs);
|
|---|
| 56 | static LIST_INITIALIZE(frontbufs);
|
|---|
| 57 |
|
|---|
| 58 | outdev_t *outdev_register(outdev_ops_t *ops, void *data)
|
|---|
| 59 | {
|
|---|
| 60 | assert(ops->get_dimensions);
|
|---|
| 61 |
|
|---|
| 62 | outdev_t *dev = (outdev_t *) malloc(sizeof(outdev_t));
|
|---|
| 63 | if (dev == NULL)
|
|---|
| 64 | return NULL;
|
|---|
| 65 |
|
|---|
| 66 | link_initialize(&dev->link);
|
|---|
| 67 |
|
|---|
| 68 | dev->ops = *ops;
|
|---|
| 69 | dev->data = data;
|
|---|
| 70 |
|
|---|
| 71 | ops->get_dimensions(dev, &dev->cols, &dev->rows);
|
|---|
| 72 | dev->backbuf = chargrid_create(dev->cols, dev->rows,
|
|---|
| 73 | CHARGRID_FLAG_NONE);
|
|---|
| 74 | if (dev->backbuf == NULL) {
|
|---|
| 75 | free(dev);
|
|---|
| 76 | return NULL;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | list_append(&dev->link, &outdevs);
|
|---|
| 80 | return dev;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | static void srv_yield(ipc_call_t *icall)
|
|---|
| 84 | {
|
|---|
| 85 | errno_t ret = EOK;
|
|---|
| 86 |
|
|---|
| 87 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 88 | assert(dev->ops.yield);
|
|---|
| 89 |
|
|---|
| 90 | errno_t rc = dev->ops.yield(dev);
|
|---|
| 91 | if (rc != EOK)
|
|---|
| 92 | ret = rc;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | async_answer_0(icall, ret);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | static void srv_claim(ipc_call_t *icall)
|
|---|
| 99 | {
|
|---|
| 100 | errno_t ret = EOK;
|
|---|
| 101 |
|
|---|
| 102 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 103 | assert(dev->ops.claim);
|
|---|
| 104 |
|
|---|
| 105 | errno_t rc = dev->ops.claim(dev);
|
|---|
| 106 | if (rc != EOK)
|
|---|
| 107 | ret = rc;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | async_answer_0(icall, ret);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | static void srv_get_dimensions(ipc_call_t *icall)
|
|---|
| 114 | {
|
|---|
| 115 | sysarg_t cols = 0;
|
|---|
| 116 | sysarg_t rows = 0;
|
|---|
| 117 | bool first;
|
|---|
| 118 |
|
|---|
| 119 | first = true;
|
|---|
| 120 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 121 | if (first) {
|
|---|
| 122 | cols = dev->cols;
|
|---|
| 123 | rows = dev->rows;
|
|---|
| 124 | first = false;
|
|---|
| 125 | } else {
|
|---|
| 126 | cols = min(cols, dev->cols);
|
|---|
| 127 | rows = min(rows, dev->rows);
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | async_answer_2(icall, EOK, cols, rows);
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | static void srv_get_caps(ipc_call_t *icall)
|
|---|
| 135 | {
|
|---|
| 136 | console_caps_t caps = 0;
|
|---|
| 137 |
|
|---|
| 138 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 139 | assert(dev->ops.get_caps);
|
|---|
| 140 |
|
|---|
| 141 | caps |= dev->ops.get_caps(dev);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | async_answer_1(icall, EOK, caps);
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | static frontbuf_t *resolve_frontbuf(sysarg_t handle, ipc_call_t *icall)
|
|---|
| 148 | {
|
|---|
| 149 | frontbuf_t *frontbuf = NULL;
|
|---|
| 150 | list_foreach(frontbufs, link, frontbuf_t, cur) {
|
|---|
| 151 | if (cur == (frontbuf_t *) handle) {
|
|---|
| 152 | frontbuf = cur;
|
|---|
| 153 | break;
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | if (frontbuf == NULL) {
|
|---|
| 158 | async_answer_0(icall, ENOENT);
|
|---|
| 159 | return NULL;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | return frontbuf;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | static void srv_frontbuf_create(ipc_call_t *icall)
|
|---|
| 166 | {
|
|---|
| 167 | frontbuf_t *frontbuf = (frontbuf_t *) malloc(sizeof(frontbuf_t));
|
|---|
| 168 | if (frontbuf == NULL) {
|
|---|
| 169 | async_answer_0(icall, ENOMEM);
|
|---|
| 170 | return;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | link_initialize(&frontbuf->link);
|
|---|
| 174 |
|
|---|
| 175 | ipc_call_t call;
|
|---|
| 176 | if (!async_share_out_receive(&call, &frontbuf->size,
|
|---|
| 177 | &frontbuf->flags)) {
|
|---|
| 178 | free(frontbuf);
|
|---|
| 179 | async_answer_0(icall, EINVAL);
|
|---|
| 180 | return;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | errno_t rc = async_share_out_finalize(&call, &frontbuf->data);
|
|---|
| 184 | if ((rc != EOK) || (frontbuf->data == AS_MAP_FAILED)) {
|
|---|
| 185 | free(frontbuf);
|
|---|
| 186 | async_answer_0(icall, ENOMEM);
|
|---|
| 187 | return;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | list_append(&frontbuf->link, &frontbufs);
|
|---|
| 191 | async_answer_1(icall, EOK, (sysarg_t) frontbuf);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | static void srv_frontbuf_destroy(ipc_call_t *icall)
|
|---|
| 195 | {
|
|---|
| 196 | frontbuf_t *frontbuf = resolve_frontbuf(ipc_get_arg1(icall), icall);
|
|---|
| 197 | if (frontbuf == NULL)
|
|---|
| 198 | return;
|
|---|
| 199 |
|
|---|
| 200 | list_remove(&frontbuf->link);
|
|---|
| 201 | as_area_destroy(frontbuf->data);
|
|---|
| 202 | free(frontbuf);
|
|---|
| 203 |
|
|---|
| 204 | async_answer_0(icall, EOK);
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | static void srv_cursor_update(ipc_call_t *icall)
|
|---|
| 208 | {
|
|---|
| 209 | frontbuf_t *frontbuf = resolve_frontbuf(ipc_get_arg1(icall), icall);
|
|---|
| 210 | if (frontbuf == NULL)
|
|---|
| 211 | return;
|
|---|
| 212 |
|
|---|
| 213 | chargrid_t *buf = (chargrid_t *) frontbuf->data;
|
|---|
| 214 | bool visible = chargrid_get_cursor_visibility(buf);
|
|---|
| 215 |
|
|---|
| 216 | sysarg_t col;
|
|---|
| 217 | sysarg_t row;
|
|---|
| 218 | chargrid_get_cursor(buf, &col, &row);
|
|---|
| 219 |
|
|---|
| 220 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 221 | assert(dev->ops.cursor_update);
|
|---|
| 222 |
|
|---|
| 223 | sysarg_t prev_col;
|
|---|
| 224 | sysarg_t prev_row;
|
|---|
| 225 | chargrid_get_cursor(dev->backbuf, &prev_col, &prev_row);
|
|---|
| 226 |
|
|---|
| 227 | chargrid_set_cursor(dev->backbuf, col, row);
|
|---|
| 228 | chargrid_set_cursor_visibility(dev->backbuf, visible);
|
|---|
| 229 |
|
|---|
| 230 | dev->ops.cursor_update(dev, prev_col, prev_row, col, row,
|
|---|
| 231 | visible);
|
|---|
| 232 | dev->ops.flush(dev);
|
|---|
| 233 |
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | async_answer_0(icall, EOK);
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | static void srv_set_style(ipc_call_t *icall)
|
|---|
| 240 | {
|
|---|
| 241 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 242 | dev->attrs.type = CHAR_ATTR_STYLE;
|
|---|
| 243 | dev->attrs.val.style =
|
|---|
| 244 | (console_style_t) ipc_get_arg1(icall);
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | async_answer_0(icall, EOK);
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | static void srv_set_color(ipc_call_t *icall)
|
|---|
| 251 | {
|
|---|
| 252 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 253 | dev->attrs.type = CHAR_ATTR_INDEX;
|
|---|
| 254 | dev->attrs.val.index.bgcolor =
|
|---|
| 255 | (console_color_t) ipc_get_arg1(icall);
|
|---|
| 256 | dev->attrs.val.index.fgcolor =
|
|---|
| 257 | (console_color_t) ipc_get_arg2(icall);
|
|---|
| 258 | dev->attrs.val.index.attr =
|
|---|
| 259 | (console_color_attr_t) ipc_get_arg3(icall);
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | async_answer_0(icall, EOK);
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | static void srv_set_rgb_color(ipc_call_t *icall)
|
|---|
| 266 | {
|
|---|
| 267 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 268 | dev->attrs.type = CHAR_ATTR_RGB;
|
|---|
| 269 | dev->attrs.val.rgb.bgcolor = ipc_get_arg1(icall);
|
|---|
| 270 | dev->attrs.val.rgb.fgcolor = ipc_get_arg2(icall);
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | async_answer_0(icall, EOK);
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | static bool srv_update_scroll(outdev_t *dev, chargrid_t *buf)
|
|---|
| 277 | {
|
|---|
| 278 | assert(dev->ops.char_update);
|
|---|
| 279 |
|
|---|
| 280 | sysarg_t top_row = chargrid_get_top_row(buf);
|
|---|
| 281 |
|
|---|
| 282 | if (dev->top_row == top_row)
|
|---|
| 283 | return false;
|
|---|
| 284 |
|
|---|
| 285 | dev->top_row = top_row;
|
|---|
| 286 |
|
|---|
| 287 | for (sysarg_t y = 0; y < dev->rows; y++) {
|
|---|
| 288 | for (sysarg_t x = 0; x < dev->cols; x++) {
|
|---|
| 289 | charfield_t *front_field =
|
|---|
| 290 | chargrid_charfield_at(buf, x, y);
|
|---|
| 291 | charfield_t *back_field =
|
|---|
| 292 | chargrid_charfield_at(dev->backbuf, x, y);
|
|---|
| 293 | bool update = false;
|
|---|
| 294 |
|
|---|
| 295 | if (front_field->ch != back_field->ch) {
|
|---|
| 296 | back_field->ch = front_field->ch;
|
|---|
| 297 | update = true;
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | if (!attrs_same(front_field->attrs, back_field->attrs)) {
|
|---|
| 301 | back_field->attrs = front_field->attrs;
|
|---|
| 302 | update = true;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | front_field->flags &= ~CHAR_FLAG_DIRTY;
|
|---|
| 306 |
|
|---|
| 307 | if (update)
|
|---|
| 308 | dev->ops.char_update(dev, x, y);
|
|---|
| 309 | }
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | return true;
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | static void srv_update(ipc_call_t *icall)
|
|---|
| 316 | {
|
|---|
| 317 | frontbuf_t *frontbuf = resolve_frontbuf(ipc_get_arg1(icall), icall);
|
|---|
| 318 | if (frontbuf == NULL)
|
|---|
| 319 | return;
|
|---|
| 320 |
|
|---|
| 321 | chargrid_t *buf = (chargrid_t *) frontbuf->data;
|
|---|
| 322 |
|
|---|
| 323 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 324 | assert(dev->ops.char_update);
|
|---|
| 325 |
|
|---|
| 326 | if (srv_update_scroll(dev, buf))
|
|---|
| 327 | continue;
|
|---|
| 328 |
|
|---|
| 329 | for (sysarg_t y = 0; y < dev->rows; y++) {
|
|---|
| 330 | for (sysarg_t x = 0; x < dev->cols; x++) {
|
|---|
| 331 | charfield_t *front_field =
|
|---|
| 332 | chargrid_charfield_at(buf, x, y);
|
|---|
| 333 | charfield_t *back_field =
|
|---|
| 334 | chargrid_charfield_at(dev->backbuf, x, y);
|
|---|
| 335 | bool update = false;
|
|---|
| 336 |
|
|---|
| 337 | if ((front_field->flags & CHAR_FLAG_DIRTY) ==
|
|---|
| 338 | CHAR_FLAG_DIRTY) {
|
|---|
| 339 | if (front_field->ch != back_field->ch) {
|
|---|
| 340 | back_field->ch = front_field->ch;
|
|---|
| 341 | update = true;
|
|---|
| 342 | }
|
|---|
| 343 |
|
|---|
| 344 | if (!attrs_same(front_field->attrs,
|
|---|
| 345 | back_field->attrs)) {
|
|---|
| 346 | back_field->attrs = front_field->attrs;
|
|---|
| 347 | update = true;
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | front_field->flags &= ~CHAR_FLAG_DIRTY;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | if (update)
|
|---|
| 354 | dev->ops.char_update(dev, x, y);
|
|---|
| 355 | }
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | dev->ops.flush(dev);
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | async_answer_0(icall, EOK);
|
|---|
| 362 | }
|
|---|
| 363 |
|
|---|
| 364 | static void srv_damage(ipc_call_t *icall)
|
|---|
| 365 | {
|
|---|
| 366 | frontbuf_t *frontbuf = resolve_frontbuf(ipc_get_arg1(icall), icall);
|
|---|
| 367 | if (frontbuf == NULL)
|
|---|
| 368 | return;
|
|---|
| 369 |
|
|---|
| 370 | chargrid_t *buf = (chargrid_t *) frontbuf->data;
|
|---|
| 371 |
|
|---|
| 372 | list_foreach(outdevs, link, outdev_t, dev) {
|
|---|
| 373 | assert(dev->ops.char_update);
|
|---|
| 374 |
|
|---|
| 375 | if (srv_update_scroll(dev, buf))
|
|---|
| 376 | continue;
|
|---|
| 377 |
|
|---|
| 378 | sysarg_t col = ipc_get_arg2(icall);
|
|---|
| 379 | sysarg_t row = ipc_get_arg3(icall);
|
|---|
| 380 |
|
|---|
| 381 | sysarg_t cols = ipc_get_arg4(icall);
|
|---|
| 382 | sysarg_t rows = ipc_get_arg5(icall);
|
|---|
| 383 |
|
|---|
| 384 | for (sysarg_t y = 0; y < rows; y++) {
|
|---|
| 385 | for (sysarg_t x = 0; x < cols; x++) {
|
|---|
| 386 | charfield_t *front_field =
|
|---|
| 387 | chargrid_charfield_at(buf, col + x, row + y);
|
|---|
| 388 | charfield_t *back_field =
|
|---|
| 389 | chargrid_charfield_at(dev->backbuf, col + x, row + y);
|
|---|
| 390 |
|
|---|
| 391 | back_field->ch = front_field->ch;
|
|---|
| 392 | back_field->attrs = front_field->attrs;
|
|---|
| 393 | front_field->flags &= ~CHAR_FLAG_DIRTY;
|
|---|
| 394 | dev->ops.char_update(dev, col + x, row + y);
|
|---|
| 395 | }
|
|---|
| 396 | }
|
|---|
| 397 | dev->ops.flush(dev);
|
|---|
| 398 |
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | async_answer_0(icall, EOK);
|
|---|
| 402 | }
|
|---|
| 403 |
|
|---|
| 404 | static void client_connection(ipc_call_t *icall, void *arg)
|
|---|
| 405 | {
|
|---|
| 406 | /* Accept the connection */
|
|---|
| 407 | async_accept_0(icall);
|
|---|
| 408 |
|
|---|
| 409 | while (true) {
|
|---|
| 410 | ipc_call_t call;
|
|---|
| 411 | async_get_call(&call);
|
|---|
| 412 |
|
|---|
| 413 | if (!ipc_get_imethod(&call)) {
|
|---|
| 414 | async_answer_0(&call, EOK);
|
|---|
| 415 | break;
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | switch (ipc_get_imethod(&call)) {
|
|---|
| 419 | case OUTPUT_YIELD:
|
|---|
| 420 | srv_yield(&call);
|
|---|
| 421 | break;
|
|---|
| 422 | case OUTPUT_CLAIM:
|
|---|
| 423 | srv_claim(&call);
|
|---|
| 424 | break;
|
|---|
| 425 | case OUTPUT_GET_DIMENSIONS:
|
|---|
| 426 | srv_get_dimensions(&call);
|
|---|
| 427 | break;
|
|---|
| 428 | case OUTPUT_GET_CAPS:
|
|---|
| 429 | srv_get_caps(&call);
|
|---|
| 430 | break;
|
|---|
| 431 |
|
|---|
| 432 | case OUTPUT_FRONTBUF_CREATE:
|
|---|
| 433 | srv_frontbuf_create(&call);
|
|---|
| 434 | break;
|
|---|
| 435 | case OUTPUT_FRONTBUF_DESTROY:
|
|---|
| 436 | srv_frontbuf_destroy(&call);
|
|---|
| 437 | break;
|
|---|
| 438 |
|
|---|
| 439 | case OUTPUT_CURSOR_UPDATE:
|
|---|
| 440 | srv_cursor_update(&call);
|
|---|
| 441 | break;
|
|---|
| 442 | case OUTPUT_SET_STYLE:
|
|---|
| 443 | srv_set_style(&call);
|
|---|
| 444 | break;
|
|---|
| 445 | case OUTPUT_SET_COLOR:
|
|---|
| 446 | srv_set_color(&call);
|
|---|
| 447 | break;
|
|---|
| 448 | case OUTPUT_SET_RGB_COLOR:
|
|---|
| 449 | srv_set_rgb_color(&call);
|
|---|
| 450 | break;
|
|---|
| 451 | case OUTPUT_UPDATE:
|
|---|
| 452 | srv_update(&call);
|
|---|
| 453 | break;
|
|---|
| 454 | case OUTPUT_DAMAGE:
|
|---|
| 455 | srv_damage(&call);
|
|---|
| 456 | break;
|
|---|
| 457 |
|
|---|
| 458 | default:
|
|---|
| 459 | async_answer_0(&call, EINVAL);
|
|---|
| 460 | }
|
|---|
| 461 | }
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | static void usage(char *name)
|
|---|
| 465 | {
|
|---|
| 466 | printf("Usage: %s <service_name>\n", name);
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 | int main(int argc, char *argv[])
|
|---|
| 470 | {
|
|---|
| 471 | loc_srv_t *srv;
|
|---|
| 472 |
|
|---|
| 473 | if (argc < 2) {
|
|---|
| 474 | usage(argv[0]);
|
|---|
| 475 | return 1;
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | printf("%s: HelenOS output service\n", NAME);
|
|---|
| 479 |
|
|---|
| 480 | /* Register server */
|
|---|
| 481 | async_set_fallback_port_handler(client_connection, NULL);
|
|---|
| 482 | errno_t rc = loc_server_register(NAME, &srv);
|
|---|
| 483 | if (rc != EOK) {
|
|---|
| 484 | printf("%s: Unable to register driver\n", NAME);
|
|---|
| 485 | return rc;
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 | service_id_t service_id;
|
|---|
| 489 | rc = loc_service_register(srv, argv[1], &service_id);
|
|---|
| 490 | if (rc != EOK) {
|
|---|
| 491 | loc_server_unregister(srv);
|
|---|
| 492 |
|
|---|
| 493 | printf("%s: Unable to register service %s\n", NAME, argv[1]);
|
|---|
| 494 | return rc;
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | if (!config_key_exists("console")) {
|
|---|
| 498 | ega_init();
|
|---|
| 499 | #if defined(CONFIG_FB) && !defined(CONFIG_WINSYS)
|
|---|
| 500 | /*
|
|---|
| 501 | * NOTE: We don't have a good way of detecting the absence
|
|---|
| 502 | * of a KFB display device at run time because of the
|
|---|
| 503 | * asunchronous nature of device discovery
|
|---|
| 504 | */
|
|---|
| 505 | output_ddev_init();
|
|---|
| 506 | #endif
|
|---|
| 507 | }
|
|---|
| 508 |
|
|---|
| 509 | chardev_init();
|
|---|
| 510 |
|
|---|
| 511 | printf("%s: Accepting connections\n", NAME);
|
|---|
| 512 | task_retval(0);
|
|---|
| 513 | async_manager();
|
|---|
| 514 |
|
|---|
| 515 | /* Never reached */
|
|---|
| 516 | return 0;
|
|---|
| 517 | }
|
|---|
| 518 |
|
|---|
| 519 | /** @}
|
|---|
| 520 | */
|
|---|