Changeset 5f70118 in mainline for uspace/srv/hid/console/console.c
- Timestamp:
- 2010-01-10T12:16:59Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c77a64f
- Parents:
- 309ede1 (diff), 1ac3a52 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
r309ede1 r5f70118 37 37 #include <ipc/kbd.h> 38 38 #include <io/keycode.h> 39 #include <ipc/mouse.h> 39 40 #include <ipc/fb.h> 40 41 #include <ipc/services.h> 41 42 #include <errno.h> 42 #include <keybuffer.h>43 43 #include <ipc/console.h> 44 44 #include <unistd.h> … … 51 51 #include <event.h> 52 52 #include <devmap.h> 53 #include <fibril_sync.h> 53 #include <fcntl.h> 54 #include <vfs/vfs.h> 55 #include <fibril_synch.h> 54 56 55 57 #include "console.h" 56 58 #include "gcons.h" 59 #include "keybuffer.h" 57 60 #include "screenbuffer.h" 58 61 59 #define NAME "console" 60 61 #define MAX_DEVICE_NAME 32 62 #define NAME "console" 63 #define NAMESPACE "term" 62 64 63 65 /** Phone to the keyboard driver. */ 64 66 static int kbd_phone; 67 68 /** Phone to the mouse driver. */ 69 static int mouse_phone; 65 70 66 71 /** Information about framebuffer */ … … 69 74 ipcarg_t cols; /**< Framebuffer columns */ 70 75 ipcarg_t rows; /**< Framebuffer rows */ 71 int color_cap; 76 int color_cap; /**< Color capabilities (FB_CCAP_xxx) */ 72 77 } fb_info; 73 78 … … 425 430 } 426 431 432 /** Handler for mouse events */ 433 static void mouse_events(ipc_callid_t iid, ipc_call_t *icall) 434 { 435 int button, press; 436 int dx, dy; 437 int newcon; 438 439 /* Ignore parameters, the connection is already opened */ 440 while (true) { 441 442 ipc_call_t call; 443 ipc_callid_t callid = async_get_call(&call); 444 445 int retval; 446 447 switch (IPC_GET_METHOD(call)) { 448 case IPC_M_PHONE_HUNGUP: 449 /* TODO: Handle hangup */ 450 return; 451 case MEVENT_BUTTON: 452 button = IPC_GET_ARG1(call); 453 press = IPC_GET_ARG2(call); 454 if (button == 1) { 455 newcon = gcons_mouse_btn(press); 456 if (newcon != -1) 457 change_console(&consoles[newcon]); 458 } 459 retval = 0; 460 break; 461 case MEVENT_MOVE: 462 dx = IPC_GET_ARG1(call); 463 dy = IPC_GET_ARG2(call); 464 gcons_mouse_move(dx, dy); 465 retval = 0; 466 break; 467 default: 468 retval = ENOENT; 469 } 470 471 ipc_answer_0(callid, retval); 472 } 473 } 474 427 475 static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request) 428 476 { 429 477 ipc_callid_t callid; 430 478 size_t size; 431 if (! ipc_data_write_receive(&callid, &size)) {479 if (!async_data_write_receive(&callid, &size)) { 432 480 ipc_answer_0(callid, EINVAL); 433 481 ipc_answer_0(rid, EINVAL); … … 442 490 } 443 491 444 (void) ipc_data_write_finalize(callid, buf, size);492 (void) async_data_write_finalize(callid, buf, size); 445 493 446 494 async_serialize_start(); … … 464 512 ipc_callid_t callid; 465 513 size_t size; 466 if (! ipc_data_read_receive(&callid, &size)) {514 if (!async_data_read_receive(&callid, &size)) { 467 515 ipc_answer_0(callid, EINVAL); 468 516 ipc_answer_0(rid, EINVAL); … … 489 537 490 538 if (pos == size) { 491 (void) ipc_data_read_finalize(callid, buf, size);539 (void) async_data_read_finalize(callid, buf, size); 492 540 ipc_answer_1(rid, EOK, size); 493 541 free(buf); … … 601 649 IPC_GET_ARG2(call)); 602 650 break; 651 case CONSOLE_GET_POS: 652 arg1 = cons->scr.position_x; 653 arg2 = cons->scr.position_y; 654 break; 603 655 case CONSOLE_GET_SIZE: 604 656 arg1 = fb_info.cols; … … 662 714 } 663 715 664 static bool console_init(void) 665 { 666 ipcarg_t color_cap; 667 668 /* Connect to keyboard driver */ 669 kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0); 716 static bool console_init(char *input) 717 { 718 /* Connect to input device */ 719 int input_fd = open(input, O_RDONLY); 720 if (input_fd < 0) { 721 printf(NAME ": Failed opening %s\n", input); 722 return false; 723 } 724 725 kbd_phone = fd_phone(input_fd); 670 726 if (kbd_phone < 0) { 671 printf(NAME ": Failed to connect to keyboard service\n");727 printf(NAME ": Failed to connect to input device\n"); 672 728 return false; 673 729 } 674 730 731 /* NB: The callback connection is slotted for removal */ 675 732 ipcarg_t phonehash; 676 733 if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 677 printf(NAME ": Failed to create callback from keyboard service\n");734 printf(NAME ": Failed to create callback from input device\n"); 678 735 return false; 679 736 } 680 737 681 738 async_new_connection(phonehash, 0, NULL, keyboard_events); 739 740 /* Connect to mouse device */ 741 mouse_phone = -1; 742 int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY); 743 744 if (mouse_fd < 0) { 745 printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse"); 746 goto skip_mouse; 747 } 748 749 mouse_phone = fd_phone(mouse_fd); 750 if (mouse_phone < 0) { 751 printf(NAME ": Failed to connect to mouse device\n"); 752 goto skip_mouse; 753 } 754 755 if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 756 printf(NAME ": Failed to create callback from mouse device\n"); 757 mouse_phone = -1; 758 goto skip_mouse; 759 } 760 761 async_new_connection(phonehash, 0, NULL, mouse_events); 762 skip_mouse: 682 763 683 764 /* Connect to framebuffer driver */ … … 687 768 return -1; 688 769 } 689 770 690 771 /* Register driver */ 691 772 int rc = devmap_driver_register(NAME, client_connection); … … 699 780 700 781 /* Synchronize, the gcons could put something in queue */ 782 ipcarg_t color_cap; 701 783 async_req_0_0(fb_info.phone, FB_FLUSH); 702 784 async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows); … … 713 795 714 796 if (interbuffer) { 715 if ( ipc_share_out_start(fb_info.phone, interbuffer,797 if (async_share_out_start(fb_info.phone, interbuffer, 716 798 AS_AREA_READ) != EOK) { 717 799 as_area_destroy(interbuffer); … … 736 818 consoles[i].refcount = 0; 737 819 738 char vc[ MAX_DEVICE_NAME];739 snprintf(vc, MAX_DEVICE_NAME, "vc%u", i);820 char vc[DEVMAP_NAME_MAXLEN + 1]; 821 snprintf(vc, DEVMAP_NAME_MAXLEN, "%s/vc%u", NAMESPACE, i); 740 822 741 823 if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) { … … 768 850 } 769 851 852 static void usage(void) 853 { 854 printf("Usage: console <input>\n"); 855 } 856 770 857 int main(int argc, char *argv[]) 771 858 { 859 if (argc < 2) { 860 usage(); 861 return -1; 862 } 863 772 864 printf(NAME ": HelenOS Console service\n"); 773 865 774 if (!console_init( ))866 if (!console_init(argv[1])) 775 867 return -1; 776 868
Note:
See TracChangeset
for help on using the changeset viewer.