Changes in uspace/lib/gui/terminal.c [5d94b16c:6d5e378] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gui/terminal.c
r5d94b16c r6d5e378 39 39 #include <surface.h> 40 40 #include <gfx/font-8x16.h> 41 #include <io/con_srv.h>42 #include <io/concaps.h>43 41 #include <io/console.h> 42 #include <ipc/console.h> 44 43 #include <task.h> 45 44 #include <adt/list.h> … … 61 60 62 61 static LIST_INITIALIZE(terms); 63 64 static int term_open(con_srvs_t *, con_srv_t *);65 static int term_close(con_srv_t *);66 static int term_read(con_srv_t *, void *, size_t);67 static int term_write(con_srv_t *, void *, size_t);68 static void term_sync(con_srv_t *);69 static void term_clear(con_srv_t *);70 static void term_set_pos(con_srv_t *, sysarg_t col, sysarg_t row);71 static int term_get_pos(con_srv_t *, sysarg_t *, sysarg_t *);72 static int term_get_size(con_srv_t *, sysarg_t *, sysarg_t *);73 static int term_get_color_cap(con_srv_t *, console_caps_t *);74 static void term_set_style(con_srv_t *, console_style_t);75 static void term_set_color(con_srv_t *, console_color_t, console_color_t,76 console_color_attr_t);77 static void term_set_rgb_color(con_srv_t *, pixel_t, pixel_t);78 static void term_set_cursor_visibility(con_srv_t *, bool);79 static int term_get_event(con_srv_t *, kbd_event_t *);80 81 static con_ops_t con_ops = {82 .open = term_open,83 .close = term_close,84 .read = term_read,85 .write = term_write,86 .sync = term_sync,87 .clear = term_clear,88 .set_pos = term_set_pos,89 .get_pos = term_get_pos,90 .get_size = term_get_size,91 .get_color_cap = term_get_color_cap,92 .set_style = term_set_style,93 .set_color = term_set_color,94 .set_rgb_color = term_set_rgb_color,95 .set_cursor_visibility = term_set_cursor_visibility,96 .get_event = term_get_event97 };98 99 static terminal_t *srv_to_terminal(con_srv_t *srv)100 {101 return srv->srvs->sarg;102 }103 62 104 63 static void getterm(const char *svc, const char *app) … … 382 341 } 383 342 384 static int term_open(con_srvs_t *srvs, con_srv_t *srv) 385 { 386 return EOK; 387 } 388 389 static int term_close(con_srv_t *srv) 390 { 391 return EOK; 392 } 393 394 static int term_read(con_srv_t *srv, void *buf, size_t size) 395 { 396 terminal_t *term = srv_to_terminal(srv); 397 uint8_t *bbuf = buf; 343 static void term_set_cursor(terminal_t *term, sysarg_t col, sysarg_t row) 344 { 345 fibril_mutex_lock(&term->mtx); 346 chargrid_set_cursor(term->frontbuf, col, row); 347 fibril_mutex_unlock(&term->mtx); 348 349 term_update(term); 350 } 351 352 static void term_set_cursor_visibility(terminal_t *term, bool visible) 353 { 354 fibril_mutex_lock(&term->mtx); 355 chargrid_set_cursor_visibility(term->frontbuf, visible); 356 fibril_mutex_unlock(&term->mtx); 357 358 term_update(term); 359 } 360 361 static void term_read(terminal_t *term, ipc_callid_t iid, ipc_call_t *icall) 362 { 363 ipc_callid_t callid; 364 size_t size; 365 if (!async_data_read_receive(&callid, &size)) { 366 async_answer_0(callid, EINVAL); 367 async_answer_0(iid, EINVAL); 368 return; 369 } 370 371 char *buf = (char *) malloc(size); 372 if (buf == NULL) { 373 async_answer_0(callid, ENOMEM); 374 async_answer_0(iid, ENOMEM); 375 return; 376 } 377 398 378 size_t pos = 0; 399 379 … … 406 386 /* Copy to the buffer remaining characters. */ 407 387 while ((pos < size) && (term->char_remains_len > 0)) { 408 b buf[pos] = term->char_remains[0];388 buf[pos] = term->char_remains[0]; 409 389 pos++; 410 390 … … 436 416 } 437 417 438 return size; 418 (void) async_data_read_finalize(callid, buf, size); 419 async_answer_1(iid, EOK, size); 420 free(buf); 439 421 } 440 422 … … 467 449 } 468 450 469 static int term_write(con_srv_t *srv, void *data, size_t size) 470 { 471 terminal_t *term = srv_to_terminal(srv); 451 static void term_write(terminal_t *term, ipc_callid_t iid, ipc_call_t *icall) 452 { 453 void *buf; 454 size_t size; 455 int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size); 456 457 if (rc != EOK) { 458 async_answer_0(iid, rc); 459 return; 460 } 472 461 473 462 size_t off = 0; 474 463 while (off < size) 475 term_write_char(term, str_decode(data, &off, size)); 476 477 return size; 478 } 479 480 static void term_sync(con_srv_t *srv) 481 { 482 terminal_t *term = srv_to_terminal(srv); 464 term_write_char(term, str_decode(buf, &off, size)); 465 466 async_answer_1(iid, EOK, size); 467 free(buf); 468 } 469 470 static void term_clear(terminal_t *term) 471 { 472 fibril_mutex_lock(&term->mtx); 473 chargrid_clear(term->frontbuf); 474 fibril_mutex_unlock(&term->mtx); 483 475 484 476 term_update(term); 485 477 } 486 478 487 static void term_clear(con_srv_t *srv) 488 { 489 terminal_t *term = srv_to_terminal(srv); 490 491 fibril_mutex_lock(&term->mtx); 492 chargrid_clear(term->frontbuf); 493 fibril_mutex_unlock(&term->mtx); 494 495 term_update(term); 496 } 497 498 static void term_set_pos(con_srv_t *srv, sysarg_t col, sysarg_t row) 499 { 500 terminal_t *term = srv_to_terminal(srv); 501 502 fibril_mutex_lock(&term->mtx); 503 chargrid_set_cursor(term->frontbuf, col, row); 504 fibril_mutex_unlock(&term->mtx); 505 506 term_update(term); 507 } 508 509 static int term_get_pos(con_srv_t *srv, sysarg_t *col, sysarg_t *row) 510 { 511 terminal_t *term = srv_to_terminal(srv); 512 513 fibril_mutex_lock(&term->mtx); 514 chargrid_get_cursor(term->frontbuf, col, row); 515 fibril_mutex_unlock(&term->mtx); 516 517 return EOK; 518 } 519 520 static int term_get_size(con_srv_t *srv, sysarg_t *cols, sysarg_t *rows) 521 { 522 terminal_t *term = srv_to_terminal(srv); 523 524 fibril_mutex_lock(&term->mtx); 525 *cols = term->cols; 526 *rows = term->rows; 527 fibril_mutex_unlock(&term->mtx); 528 529 return EOK; 530 } 531 532 static int term_get_color_cap(con_srv_t *srv, console_caps_t *caps) 533 { 534 (void) srv; 535 *caps = TERM_CAPS; 536 537 return EOK; 538 } 539 540 static void term_set_style(con_srv_t *srv, console_style_t style) 541 { 542 terminal_t *term = srv_to_terminal(srv); 543 479 static void term_get_cursor(terminal_t *term, ipc_callid_t iid, ipc_call_t *icall) 480 { 481 sysarg_t col; 482 sysarg_t row; 483 484 fibril_mutex_lock(&term->mtx); 485 chargrid_get_cursor(term->frontbuf, &col, &row); 486 fibril_mutex_unlock(&term->mtx); 487 488 async_answer_2(iid, EOK, col, row); 489 } 490 491 static void term_set_style(terminal_t *term, console_style_t style) 492 { 544 493 fibril_mutex_lock(&term->mtx); 545 494 chargrid_set_style(term->frontbuf, style); … … 547 496 } 548 497 549 static void term_set_color( con_srv_t *srv, console_color_t bgcolor,498 static void term_set_color(terminal_t *term, console_color_t bgcolor, 550 499 console_color_t fgcolor, console_color_attr_t attr) 551 500 { 552 terminal_t *term = srv_to_terminal(srv);553 554 501 fibril_mutex_lock(&term->mtx); 555 502 chargrid_set_color(term->frontbuf, bgcolor, fgcolor, attr); … … 557 504 } 558 505 559 static void term_set_rgb_color( con_srv_t *srv, pixel_t bgcolor,506 static void term_set_rgb_color(terminal_t *term, pixel_t bgcolor, 560 507 pixel_t fgcolor) 561 508 { 562 terminal_t *term = srv_to_terminal(srv);563 564 509 fibril_mutex_lock(&term->mtx); 565 510 chargrid_set_rgb_color(term->frontbuf, bgcolor, fgcolor); … … 567 512 } 568 513 569 static void term_set_cursor_visibility(con_srv_t *srv, bool visible) 570 { 571 terminal_t *term = srv_to_terminal(srv); 572 573 fibril_mutex_lock(&term->mtx); 574 chargrid_set_cursor_visibility(term->frontbuf, visible); 575 fibril_mutex_unlock(&term->mtx); 576 577 term_update(term); 578 } 579 580 static int term_get_event(con_srv_t *srv, kbd_event_t *event) 581 { 582 terminal_t *term = srv_to_terminal(srv); 514 static void term_get_event(terminal_t *term, ipc_callid_t iid, ipc_call_t *icall) 515 { 583 516 link_t *link = prodcons_consume(&term->input_pc); 584 kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link); 585 586 *event = *kevent; 587 free(kevent); 588 return EOK; 517 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 518 519 async_answer_4(iid, EOK, event->type, event->key, event->mods, event->c); 520 free(event); 589 521 } 590 522 … … 680 612 681 613 if (atomic_postinc(&term->refcnt) == 0) 682 chargrid_set_cursor_visibility(term->frontbuf, true); 683 684 con_conn(iid, icall, &term->srvs); 614 term_set_cursor_visibility(term, true); 615 616 /* Accept the connection */ 617 async_answer_0(iid, EOK); 618 619 while (true) { 620 ipc_call_t call; 621 ipc_callid_t callid = async_get_call(&call); 622 623 if (!IPC_GET_IMETHOD(call)) 624 return; 625 626 switch (IPC_GET_IMETHOD(call)) { 627 case VFS_OUT_READ: 628 term_read(term, callid, &call); 629 break; 630 case VFS_OUT_WRITE: 631 term_write(term, callid, &call); 632 break; 633 case VFS_OUT_SYNC: 634 term_update(term); 635 async_answer_0(callid, EOK); 636 break; 637 case CONSOLE_CLEAR: 638 term_clear(term); 639 async_answer_0(callid, EOK); 640 break; 641 case CONSOLE_GOTO: 642 term_set_cursor(term, IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 643 async_answer_0(callid, EOK); 644 break; 645 case CONSOLE_GET_POS: 646 term_get_cursor(term, callid, &call); 647 break; 648 case CONSOLE_GET_SIZE: 649 async_answer_2(callid, EOK, term->cols, term->rows); 650 break; 651 case CONSOLE_GET_COLOR_CAP: 652 async_answer_1(callid, EOK, TERM_CAPS); 653 break; 654 case CONSOLE_SET_STYLE: 655 term_set_style(term, IPC_GET_ARG1(call)); 656 async_answer_0(callid, EOK); 657 break; 658 case CONSOLE_SET_COLOR: 659 term_set_color(term, IPC_GET_ARG1(call), IPC_GET_ARG2(call), 660 IPC_GET_ARG3(call)); 661 async_answer_0(callid, EOK); 662 break; 663 case CONSOLE_SET_RGB_COLOR: 664 term_set_rgb_color(term, IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 665 async_answer_0(callid, EOK); 666 break; 667 case CONSOLE_CURSOR_VISIBILITY: 668 term_set_cursor_visibility(term, IPC_GET_ARG1(call)); 669 async_answer_0(callid, EOK); 670 break; 671 case CONSOLE_GET_EVENT: 672 term_get_event(term, callid, &call); 673 break; 674 default: 675 async_answer_0(callid, EINVAL); 676 } 677 } 685 678 } 686 679 … … 734 727 735 728 async_set_client_connection(term_connection); 736 con_srvs_init(&term->srvs);737 term->srvs.ops = &con_ops;738 term->srvs.sarg = term;739 740 729 int rc = loc_server_register(NAME); 741 730 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.