Changeset 5eb5dcf in mainline for uspace/srv/hid/console/console.c
- Timestamp:
- 2010-01-06T20:56:04Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fccc236
- Parents:
- 002252a (diff), eca2435 (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
r002252a r5eb5dcf 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> … … 50 51 #include <event.h> 51 52 #include <devmap.h> 52 #include <fibril_sync.h> 53 #include <fcntl.h> 54 #include <vfs/vfs.h> 55 #include <fibril_synch.h> 53 56 54 57 #include "console.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 { … … 666 714 } 667 715 668 static bool console_init(void) 669 { 670 ipcarg_t color_cap; 671 672 /* Connect to keyboard driver */ 673 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); 674 726 if (kbd_phone < 0) { 675 printf(NAME ": Failed to connect to keyboard service\n");727 printf(NAME ": Failed to connect to input device\n"); 676 728 return false; 677 729 } 678 730 731 /* NB: The callback connection is slotted for removal */ 679 732 ipcarg_t phonehash; 680 733 if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 681 printf(NAME ": Failed to create callback from keyboard service\n");734 printf(NAME ": Failed to create callback from input device\n"); 682 735 return false; 683 736 } 684 737 685 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: 686 763 687 764 /* Connect to framebuffer driver */ … … 691 768 return -1; 692 769 } 693 770 694 771 /* Register driver */ 695 772 int rc = devmap_driver_register(NAME, client_connection); … … 703 780 704 781 /* Synchronize, the gcons could put something in queue */ 782 ipcarg_t color_cap; 705 783 async_req_0_0(fb_info.phone, FB_FLUSH); 706 784 async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows); … … 740 818 consoles[i].refcount = 0; 741 819 742 char vc[ MAX_DEVICE_NAME];743 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); 744 822 745 823 if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) { … … 772 850 } 773 851 852 static void usage(void) 853 { 854 printf("Usage: console <input>\n"); 855 } 856 774 857 int main(int argc, char *argv[]) 775 858 { 859 if (argc < 2) { 860 usage(); 861 return -1; 862 } 863 776 864 printf(NAME ": HelenOS Console service\n"); 777 865 778 if (!console_init( ))866 if (!console_init(argv[1])) 779 867 return -1; 780 868
Note:
See TracChangeset
for help on using the changeset viewer.