Changes in uspace/srv/hid/console/console.c [103ae7f8:30db06c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
r103ae7f8 r30db06c 715 715 } 716 716 717 static int connect_keyboard_or_mouse(const char *devname, 718 async_client_conn_t handler, const char *path) 717 static int connect_keyboard(char *path) 719 718 { 720 719 int fd = open(path, O_RDONLY); … … 729 728 } 730 729 731 int rc = async_connect_to_me(phone, SERVICE_CONSOLE, 0, 0, handler); 730 int rc = async_connect_to_me(phone, SERVICE_CONSOLE, 0, 0, 731 keyboard_events); 732 732 if (rc != EOK) { 733 733 printf(NAME ": " \ … … 737 737 } 738 738 739 printf(NAME ": found %s \"%s\".\n", devname, path);739 printf(NAME ": found keyboard \"%s\".\n", path); 740 740 741 741 return phone; 742 742 } 743 743 744 static int connect_keyboard(const char *path)745 {746 return connect_keyboard_or_mouse("keyboard", keyboard_events, path);747 }748 749 static int connect_mouse(const char *path)750 {751 return connect_keyboard_or_mouse("mouse", mouse_events, path);752 }753 754 struct hid_class_info {755 char *classname;756 int (*connection_func)(const char *);757 };758 744 759 745 /** Periodically check for new keyboards in /dev/class/. … … 762 748 * @return This function should never exit. 763 749 */ 764 static int check_new_ device_fibril(void *arg)765 { 766 struct hid_class_info *dev_info =arg;750 static int check_new_keyboards(void *arg) 751 { 752 char *class_name = (char *) arg; 767 753 768 754 size_t index = 1; … … 772 758 char *path; 773 759 int rc = asprintf(&path, "/dev/class/%s\\%zu", 774 dev_info->classname, index);760 class_name, index); 775 761 if (rc < 0) { 776 762 continue; 777 763 } 778 764 rc = 0; 779 rc = dev_info->connection_func(path);765 rc = connect_keyboard(path); 780 766 if (rc > 0) { 781 767 /* We do not allow unplug. */ … … 792 778 /** Start a fibril monitoring hot-plugged keyboards. 793 779 */ 794 static void check_new_devices_in_background(int (*connection_func)(const char *), 795 const char *classname) 796 { 797 struct hid_class_info *dev_info = malloc(sizeof(struct hid_class_info)); 798 if (dev_info == NULL) { 799 printf(NAME ": " \ 800 "out of memory, will not start hot-plug-watch fibril.\n"); 801 return; 802 } 803 int rc; 804 805 rc = asprintf(&dev_info->classname, "%s", classname); 806 if (rc < 0) { 807 printf(NAME ": failed to format classname: %s.\n", 808 str_error(rc)); 809 return; 810 } 811 dev_info->connection_func = connection_func; 812 813 fid_t fid = fibril_create(check_new_device_fibril, (void *)dev_info); 780 static void check_new_keyboards_in_background() 781 { 782 fid_t fid = fibril_create(check_new_keyboards, (void *)"keyboard"); 814 783 if (!fid) { 815 printf(NAME 816 ": failed to create hot-plug-watch fibril for %s.\n", 817 classname); 784 printf(NAME ": failed to create hot-plug-watch fibril.\n"); 818 785 return; 819 786 } … … 829 796 } 830 797 831 mouse_phone = connect_mouse("/dev/hid_in/mouse"); 798 /* Connect to mouse device */ 799 mouse_phone = -1; 800 int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY); 801 802 if (mouse_fd < 0) { 803 printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse"); 804 goto skip_mouse; 805 } 806 807 mouse_phone = fd_phone(mouse_fd); 832 808 if (mouse_phone < 0) { 833 printf(NAME ": Failed to connect to mouse device: %s.\n", 834 str_error(mouse_phone)); 835 } 809 printf(NAME ": Failed to connect to mouse device\n"); 810 goto skip_mouse; 811 } 812 813 if (async_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, mouse_events) 814 != 0) { 815 printf(NAME ": Failed to create callback from mouse device\n"); 816 mouse_phone = -1; 817 goto skip_mouse; 818 } 819 820 skip_mouse: 836 821 837 822 /* Connect to framebuffer driver */ … … 917 902 918 903 /* Start fibril for checking on hot-plugged keyboards. */ 919 check_new_devices_in_background(connect_keyboard, "keyboard"); 920 check_new_devices_in_background(connect_mouse, "mouse"); 904 check_new_keyboards_in_background(); 921 905 922 906 return true;
Note:
See TracChangeset
for help on using the changeset viewer.