Changeset 5d94b16c in mainline for uspace/srv/hid/console/console.c
- Timestamp:
- 2012-08-25T19:42:45Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4c84ada5, 5c702a8
- Parents:
- 070ad12
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
r070ad12 r5d94b16c 37 37 #include <adt/prodcons.h> 38 38 #include <io/input.h> 39 #include <ipc/console.h>40 39 #include <ipc/vfs.h> 41 40 #include <errno.h> … … 43 42 #include <loc.h> 44 43 #include <event.h> 44 #include <io/con_srv.h> 45 45 #include <io/kbd_event.h> 46 46 #include <io/keycode.h> 47 47 #include <io/chargrid.h> 48 #include <io/console.h>49 48 #include <io/output.h> 50 49 #include <align.h> … … 80 79 chargrid_t *frontbuf; /**< Front buffer */ 81 80 frontbuf_handle_t fbid; /**< Front buffer handle */ 81 con_srvs_t srvs; /**< Console service setup */ 82 82 } console_t; 83 83 … … 114 114 }; 115 115 116 static int cons_open(con_srvs_t *, con_srv_t *); 117 static int cons_close(con_srv_t *); 118 static int cons_read(con_srv_t *, void *, size_t); 119 static int cons_write(con_srv_t *, void *, size_t); 120 static void cons_sync(con_srv_t *); 121 static void cons_clear(con_srv_t *); 122 static void cons_set_pos(con_srv_t *, sysarg_t col, sysarg_t row); 123 static int cons_get_pos(con_srv_t *, sysarg_t *, sysarg_t *); 124 static int cons_get_size(con_srv_t *, sysarg_t *, sysarg_t *); 125 static int cons_get_color_cap(con_srv_t *, console_caps_t *); 126 static void cons_set_style(con_srv_t *, console_style_t); 127 static void cons_set_color(con_srv_t *, console_color_t, console_color_t, 128 console_color_attr_t); 129 static void cons_set_rgb_color(con_srv_t *, pixel_t, pixel_t); 130 static void cons_set_cursor_visibility(con_srv_t *, bool); 131 static int cons_get_event(con_srv_t *, kbd_event_t *); 132 133 static con_ops_t con_ops = { 134 .open = cons_open, 135 .close = cons_close, 136 .read = cons_read, 137 .write = cons_write, 138 .sync = cons_sync, 139 .clear = cons_clear, 140 .set_pos = cons_set_pos, 141 .get_pos = cons_get_pos, 142 .get_size = cons_get_size, 143 .get_color_cap = cons_get_color_cap, 144 .set_style = cons_set_style, 145 .set_color = cons_set_color, 146 .set_rgb_color = cons_set_rgb_color, 147 .set_cursor_visibility = cons_set_cursor_visibility, 148 .get_event = cons_get_event 149 }; 150 151 static console_t *srv_to_console(con_srv_t *srv) 152 { 153 return srv->srvs->sarg; 154 } 155 116 156 static void cons_update(console_t *cons) 117 157 { … … 138 178 fibril_mutex_unlock(&cons->mtx); 139 179 fibril_mutex_unlock(&switch_mtx); 140 }141 142 static void cons_clear(console_t *cons)143 {144 fibril_mutex_lock(&cons->mtx);145 chargrid_clear(cons->frontbuf);146 fibril_mutex_unlock(&cons->mtx);147 148 cons_update(cons);149 180 } 150 181 … … 288 319 } 289 320 290 static void cons_set_cursor (console_t *cons, sysarg_t col, sysarg_t row)291 { 292 fibril_mutex_lock(&cons->mtx); 293 chargrid_set_cursor (cons->frontbuf, col, row);321 static void cons_set_cursor_vis(console_t *cons, bool visible) 322 { 323 fibril_mutex_lock(&cons->mtx); 324 chargrid_set_cursor_visibility(cons->frontbuf, visible); 294 325 fibril_mutex_unlock(&cons->mtx); 295 326 … … 297 328 } 298 329 299 static void cons_set_cursor_visibility(console_t *cons, bool visible) 300 { 301 fibril_mutex_lock(&cons->mtx); 302 chargrid_set_cursor_visibility(cons->frontbuf, visible); 303 fibril_mutex_unlock(&cons->mtx); 304 305 cons_update_cursor(cons); 306 } 307 308 static void cons_get_cursor(console_t *cons, ipc_callid_t iid, ipc_call_t *icall) 309 { 310 sysarg_t col; 311 sysarg_t row; 312 313 fibril_mutex_lock(&cons->mtx); 314 chargrid_get_cursor(cons->frontbuf, &col, &row); 315 fibril_mutex_unlock(&cons->mtx); 316 317 async_answer_2(iid, EOK, col, row); 318 } 319 320 static void cons_write(console_t *cons, ipc_callid_t iid, ipc_call_t *icall) 321 { 322 void *buf; 323 size_t size; 324 int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size); 325 326 if (rc != EOK) { 327 async_answer_0(iid, rc); 328 return; 329 } 330 331 size_t off = 0; 332 while (off < size) 333 cons_write_char(cons, str_decode(buf, &off, size)); 334 335 async_answer_1(iid, EOK, size); 336 free(buf); 337 } 338 339 static void cons_read(console_t *cons, ipc_callid_t iid, ipc_call_t *icall) 340 { 341 ipc_callid_t callid; 342 size_t size; 343 if (!async_data_read_receive(&callid, &size)) { 344 async_answer_0(callid, EINVAL); 345 async_answer_0(iid, EINVAL); 346 return; 347 } 348 349 char *buf = (char *) malloc(size); 350 if (buf == NULL) { 351 async_answer_0(callid, ENOMEM); 352 async_answer_0(iid, ENOMEM); 353 return; 354 } 355 330 static int cons_open(con_srvs_t *srvs, con_srv_t *srv) 331 { 332 return EOK; 333 } 334 335 static int cons_close(con_srv_t *srv) 336 { 337 return EOK; 338 } 339 340 static int cons_read(con_srv_t *srv, void *buf, size_t size) 341 { 342 uint8_t *bbuf = buf; 343 console_t *cons = srv_to_console(srv); 356 344 size_t pos = 0; 357 345 … … 364 352 /* Copy to the buffer remaining characters. */ 365 353 while ((pos < size) && (cons->char_remains_len > 0)) { 366 b uf[pos] = cons->char_remains[0];354 bbuf[pos] = cons->char_remains[0]; 367 355 pos++; 368 356 … … 389 377 } 390 378 } 391 392 (void) async_data_read_finalize(callid, buf, size); 393 async_answer_1(iid, EOK, size); 394 free(buf); 395 } 396 397 static void cons_set_style(console_t *cons, console_style_t style) 398 { 379 380 return size; 381 } 382 383 static int cons_write(con_srv_t *srv, void *data, size_t size) 384 { 385 console_t *cons = srv_to_console(srv); 386 387 size_t off = 0; 388 while (off < size) 389 cons_write_char(cons, str_decode(data, &off, size)); 390 return size; 391 } 392 393 static void cons_sync(con_srv_t *srv) 394 { 395 console_t *cons = srv_to_console(srv); 396 397 cons_update(cons); 398 } 399 400 static void cons_clear(con_srv_t *srv) 401 { 402 console_t *cons = srv_to_console(srv); 403 404 fibril_mutex_lock(&cons->mtx); 405 chargrid_clear(cons->frontbuf); 406 fibril_mutex_unlock(&cons->mtx); 407 408 cons_update(cons); 409 } 410 411 static void cons_set_pos(con_srv_t *srv, sysarg_t col, sysarg_t row) 412 { 413 console_t *cons = srv_to_console(srv); 414 415 fibril_mutex_lock(&cons->mtx); 416 chargrid_set_cursor(cons->frontbuf, col, row); 417 fibril_mutex_unlock(&cons->mtx); 418 419 cons_update_cursor(cons); 420 } 421 422 static int cons_get_pos(con_srv_t *srv, sysarg_t *col, sysarg_t *row) 423 { 424 console_t *cons = srv_to_console(srv); 425 426 fibril_mutex_lock(&cons->mtx); 427 chargrid_get_cursor(cons->frontbuf, col, row); 428 fibril_mutex_unlock(&cons->mtx); 429 430 return EOK; 431 } 432 433 static int cons_get_size(con_srv_t *srv, sysarg_t *cols, sysarg_t *rows) 434 { 435 console_t *cons = srv_to_console(srv); 436 437 fibril_mutex_lock(&cons->mtx); 438 *cols = cons->cols; 439 *rows = cons->rows; 440 fibril_mutex_unlock(&cons->mtx); 441 442 return EOK; 443 } 444 445 static int cons_get_color_cap(con_srv_t *srv, console_caps_t *ccaps) 446 { 447 console_t *cons = srv_to_console(srv); 448 449 fibril_mutex_lock(&cons->mtx); 450 *ccaps = cons->ccaps; 451 fibril_mutex_unlock(&cons->mtx); 452 453 return EOK; 454 } 455 456 static void cons_set_style(con_srv_t *srv, console_style_t style) 457 { 458 console_t *cons = srv_to_console(srv); 459 399 460 fibril_mutex_lock(&cons->mtx); 400 461 chargrid_set_style(cons->frontbuf, style); … … 402 463 } 403 464 404 static void cons_set_color(con sole_t *cons, console_color_t bgcolor,465 static void cons_set_color(con_srv_t *srv, console_color_t bgcolor, 405 466 console_color_t fgcolor, console_color_attr_t attr) 406 467 { 468 console_t *cons = srv_to_console(srv); 469 407 470 fibril_mutex_lock(&cons->mtx); 408 471 chargrid_set_color(cons->frontbuf, bgcolor, fgcolor, attr); … … 410 473 } 411 474 412 static void cons_set_rgb_color(con sole_t *cons, pixel_t bgcolor,475 static void cons_set_rgb_color(con_srv_t *srv, pixel_t bgcolor, 413 476 pixel_t fgcolor) 414 477 { 478 console_t *cons = srv_to_console(srv); 479 415 480 fibril_mutex_lock(&cons->mtx); 416 481 chargrid_set_rgb_color(cons->frontbuf, bgcolor, fgcolor); … … 418 483 } 419 484 420 static void cons_get_event(console_t *cons, ipc_callid_t iid, ipc_call_t *icall) 421 { 485 static void cons_set_cursor_visibility(con_srv_t *srv, bool visible) 486 { 487 console_t *cons = srv_to_console(srv); 488 489 cons_set_cursor_vis(cons, visible); 490 } 491 492 static int cons_get_event(con_srv_t *srv, kbd_event_t *event) 493 { 494 console_t *cons = srv_to_console(srv); 422 495 link_t *link = prodcons_consume(&cons->input_pc); 423 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 424 425 async_answer_4(iid, EOK, event->type, event->key, event->mods, event->c); 426 free(event); 496 kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link); 497 498 *event = *kevent; 499 free(kevent); 500 return EOK; 427 501 } 428 502 … … 447 521 448 522 if (atomic_postinc(&cons->refcnt) == 0) 449 cons_set_cursor_visibility(cons, true); 450 451 /* Accept the connection */ 452 async_answer_0(iid, EOK); 453 454 while (true) { 455 ipc_call_t call; 456 ipc_callid_t callid = async_get_call(&call); 457 458 if (!IPC_GET_IMETHOD(call)) 459 return; 460 461 switch (IPC_GET_IMETHOD(call)) { 462 case VFS_OUT_READ: 463 cons_read(cons, callid, &call); 464 break; 465 case VFS_OUT_WRITE: 466 cons_write(cons, callid, &call); 467 break; 468 case VFS_OUT_SYNC: 469 cons_update(cons); 470 async_answer_0(callid, EOK); 471 break; 472 case CONSOLE_CLEAR: 473 cons_clear(cons); 474 async_answer_0(callid, EOK); 475 break; 476 case CONSOLE_GOTO: 477 cons_set_cursor(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 478 async_answer_0(callid, EOK); 479 break; 480 case CONSOLE_GET_POS: 481 cons_get_cursor(cons, callid, &call); 482 break; 483 case CONSOLE_GET_SIZE: 484 async_answer_2(callid, EOK, cons->cols, cons->rows); 485 break; 486 case CONSOLE_GET_COLOR_CAP: 487 async_answer_1(callid, EOK, cons->ccaps); 488 break; 489 case CONSOLE_SET_STYLE: 490 cons_set_style(cons, IPC_GET_ARG1(call)); 491 async_answer_0(callid, EOK); 492 break; 493 case CONSOLE_SET_COLOR: 494 cons_set_color(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call), 495 IPC_GET_ARG3(call)); 496 async_answer_0(callid, EOK); 497 break; 498 case CONSOLE_SET_RGB_COLOR: 499 cons_set_rgb_color(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 500 async_answer_0(callid, EOK); 501 break; 502 case CONSOLE_CURSOR_VISIBILITY: 503 cons_set_cursor_visibility(cons, IPC_GET_ARG1(call)); 504 async_answer_0(callid, EOK); 505 break; 506 case CONSOLE_GET_EVENT: 507 cons_get_event(cons, callid, &call); 508 break; 509 default: 510 async_answer_0(callid, EINVAL); 511 } 512 } 513 } 523 cons_set_cursor_vis(cons, true); 524 525 con_conn(iid, icall, &cons->srvs); 526 } 527 514 528 515 529 static int input_connect(const char *svc) … … 624 638 } 625 639 640 con_srvs_init(&consoles[i].srvs); 641 consoles[i].srvs.ops = &con_ops; 642 consoles[i].srvs.sarg = &consoles[i]; 643 626 644 char vc[LOC_NAME_MAXLEN + 1]; 627 645 snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
Note:
See TracChangeset
for help on using the changeset viewer.