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