Changeset 371bd7d in mainline for uspace/srv/hid/console/console.c
- Timestamp:
- 2010-03-27T09:22:17Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 36a75a2
- Parents:
- cd82bb1 (diff), eaf22d4 (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
-
uspace/srv/hid/console/console.c (moved) (moved from uspace/srv/console/console.c ) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
rcd82bb1 r371bd7d 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> … … 46 47 #include <sys/mman.h> 47 48 #include <stdio.h> 48 #include <str ing.h>49 #include <str.h> 49 50 #include <sysinfo.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; /**< Color capabilities (FB_CCAP_xxx) */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 ipc_callid_t callid;477 void *buf; 430 478 size_t size; 431 if (!async_data_write_receive(&callid, &size)) { 432 ipc_answer_0(callid, EINVAL); 433 ipc_answer_0(rid, EINVAL); 479 int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size); 480 481 if (rc != EOK) { 482 ipc_answer_0(rid, rc); 434 483 return; 435 484 } 436 437 char *buf = (char *) malloc(size);438 if (buf == NULL) {439 ipc_answer_0(callid, ENOMEM);440 ipc_answer_0(rid, ENOMEM);441 return;442 }443 444 (void) async_data_write_finalize(callid, buf, size);445 485 446 486 async_serialize_start(); … … 666 706 } 667 707 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); 708 static bool console_init(char *input) 709 { 710 /* Connect to input device */ 711 int input_fd = open(input, O_RDONLY); 712 if (input_fd < 0) { 713 printf(NAME ": Failed opening %s\n", input); 714 return false; 715 } 716 717 kbd_phone = fd_phone(input_fd); 674 718 if (kbd_phone < 0) { 675 printf(NAME ": Failed to connect to keyboard service\n");719 printf(NAME ": Failed to connect to input device\n"); 676 720 return false; 677 721 } 678 722 723 /* NB: The callback connection is slotted for removal */ 679 724 ipcarg_t phonehash; 680 725 if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 681 printf(NAME ": Failed to create callback from keyboard service\n");726 printf(NAME ": Failed to create callback from input device\n"); 682 727 return false; 683 728 } 684 729 685 730 async_new_connection(phonehash, 0, NULL, keyboard_events); 731 732 /* Connect to mouse device */ 733 mouse_phone = -1; 734 int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY); 735 736 if (mouse_fd < 0) { 737 printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse"); 738 goto skip_mouse; 739 } 740 741 mouse_phone = fd_phone(mouse_fd); 742 if (mouse_phone < 0) { 743 printf(NAME ": Failed to connect to mouse device\n"); 744 goto skip_mouse; 745 } 746 747 if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 748 printf(NAME ": Failed to create callback from mouse device\n"); 749 mouse_phone = -1; 750 goto skip_mouse; 751 } 752 753 async_new_connection(phonehash, 0, NULL, mouse_events); 754 skip_mouse: 686 755 687 756 /* Connect to framebuffer driver */ … … 691 760 return -1; 692 761 } 693 762 694 763 /* Register driver */ 695 764 int rc = devmap_driver_register(NAME, client_connection); … … 703 772 704 773 /* Synchronize, the gcons could put something in queue */ 774 ipcarg_t color_cap; 705 775 async_req_0_0(fb_info.phone, FB_FLUSH); 706 776 async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows); … … 740 810 consoles[i].refcount = 0; 741 811 742 char vc[ MAX_DEVICE_NAME];743 snprintf(vc, MAX_DEVICE_NAME, "vc%u", i);812 char vc[DEVMAP_NAME_MAXLEN + 1]; 813 snprintf(vc, DEVMAP_NAME_MAXLEN, "%s/vc%u", NAMESPACE, i); 744 814 745 815 if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) { … … 772 842 } 773 843 844 static void usage(void) 845 { 846 printf("Usage: console <input>\n"); 847 } 848 774 849 int main(int argc, char *argv[]) 775 850 { 851 if (argc < 2) { 852 usage(); 853 return -1; 854 } 855 776 856 printf(NAME ": HelenOS Console service\n"); 777 857 778 if (!console_init( ))858 if (!console_init(argv[1])) 779 859 return -1; 780 860
Note:
See TracChangeset
for help on using the changeset viewer.
