Changeset 103ae7f8 in mainline


Ignore:
Timestamp:
2011-03-02T20:14:40Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
21bb58d
Parents:
fd5fed8
Message:

Console looks for mice as well

File:
1 edited

Legend:

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

    rfd5fed8 r103ae7f8  
    715715}
    716716
    717 static int connect_keyboard(char *path)
     717static int connect_keyboard_or_mouse(const char *devname,
     718    async_client_conn_t handler, const char *path)
    718719{
    719720        int fd = open(path, O_RDONLY);
     
    728729        }
    729730       
    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);
    732732        if (rc != EOK) {
    733733                printf(NAME ": " \
     
    737737        }
    738738       
    739         printf(NAME ": found keyboard \"%s\".\n", path);
     739        printf(NAME ": found %s \"%s\".\n", devname, path);
    740740
    741741        return phone;
    742742}
    743743
     744static int connect_keyboard(const char *path)
     745{
     746        return connect_keyboard_or_mouse("keyboard", keyboard_events, path);
     747}
     748
     749static int connect_mouse(const char *path)
     750{
     751        return connect_keyboard_or_mouse("mouse", mouse_events, path);
     752}
     753
     754struct hid_class_info {
     755        char *classname;
     756        int (*connection_func)(const char *);
     757};
    744758
    745759/** Periodically check for new keyboards in /dev/class/.
     
    748762 * @return This function should never exit.
    749763 */
    750 static int check_new_keyboards(void *arg)
    751 {
    752         char *class_name = (char *) arg;
     764static int check_new_device_fibril(void *arg)
     765{
     766        struct hid_class_info *dev_info = arg;
    753767
    754768        size_t index = 1;
     
    758772                char *path;
    759773                int rc = asprintf(&path, "/dev/class/%s\\%zu",
    760                     class_name, index);
     774                    dev_info->classname, index);
    761775                if (rc < 0) {
    762776                        continue;
    763777                }
    764778                rc = 0;
    765                 rc = connect_keyboard(path);
     779                rc = dev_info->connection_func(path);
    766780                if (rc > 0) {
    767781                        /* We do not allow unplug. */
     
    778792/** Start a fibril monitoring hot-plugged keyboards.
    779793 */
    780 static void check_new_keyboards_in_background()
    781 {
    782         fid_t fid = fibril_create(check_new_keyboards, (void *)"keyboard");
     794static 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);
    783814        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);
    785818                return;
    786819        }
     
    796829        }
    797830
    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");
    808832        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        }
    821836       
    822837        /* Connect to framebuffer driver */
     
    902917       
    903918        /* 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");
    905921
    906922        return true;
Note: See TracChangeset for help on using the changeset viewer.