Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/console.c

    r103ae7f8 r30db06c  
    715715}
    716716
    717 static int connect_keyboard_or_mouse(const char *devname,
    718     async_client_conn_t handler, const char *path)
     717static int connect_keyboard(char *path)
    719718{
    720719        int fd = open(path, O_RDONLY);
     
    729728        }
    730729       
    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);
    732732        if (rc != EOK) {
    733733                printf(NAME ": " \
     
    737737        }
    738738       
    739         printf(NAME ": found %s \"%s\".\n", devname, path);
     739        printf(NAME ": found keyboard \"%s\".\n", path);
    740740
    741741        return phone;
    742742}
    743743
    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 };
    758744
    759745/** Periodically check for new keyboards in /dev/class/.
     
    762748 * @return This function should never exit.
    763749 */
    764 static int check_new_device_fibril(void *arg)
    765 {
    766         struct hid_class_info *dev_info = arg;
     750static int check_new_keyboards(void *arg)
     751{
     752        char *class_name = (char *) arg;
    767753
    768754        size_t index = 1;
     
    772758                char *path;
    773759                int rc = asprintf(&path, "/dev/class/%s\\%zu",
    774                     dev_info->classname, index);
     760                    class_name, index);
    775761                if (rc < 0) {
    776762                        continue;
    777763                }
    778764                rc = 0;
    779                 rc = dev_info->connection_func(path);
     765                rc = connect_keyboard(path);
    780766                if (rc > 0) {
    781767                        /* We do not allow unplug. */
     
    792778/** Start a fibril monitoring hot-plugged keyboards.
    793779 */
    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);
     780static void check_new_keyboards_in_background()
     781{
     782        fid_t fid = fibril_create(check_new_keyboards, (void *)"keyboard");
    814783        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");
    818785                return;
    819786        }
     
    829796        }
    830797
    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);
    832808        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       
     820skip_mouse:
    836821       
    837822        /* Connect to framebuffer driver */
     
    917902       
    918903        /* 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();
    921905
    922906        return true;
Note: See TracChangeset for help on using the changeset viewer.