Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 5f7d96e in mainline for uspace/srv/hid/console/console.c


Ignore:
Timestamp:
2010-12-27T18:18:03Z (11 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master
Children:
43c3937
Parents:
e080332 (diff), e84d65a (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.
Message:

merge from development

File:
1 edited

Legend:

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

    re080332 r5f7d96e  
    317317static void change_console(console_t *cons)
    318318{
    319         if (cons == active_console)
     319        if (cons == active_console) {
    320320                return;
     321        }
    321322       
    322323        fb_pending_flush();
     
    458459                        if (IPC_GET_ARG1(call) == 1) {
    459460                                int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call));
    460                                 if (newcon != -1)
     461                                if (newcon != -1) {
    461462                                        change_console(&consoles[newcon]);
     463                                }
    462464                        }
    463465                        retval = 0;
     
    710712}
    711713
    712 static bool console_init(char *input)
    713 {
    714         /* Connect to input device */
    715         int input_fd = open(input, O_RDONLY);
    716         if (input_fd < 0) {
    717                 printf(NAME ": Failed opening %s\n", input);
    718                 return false;
    719         }
    720        
    721         kbd_phone = fd_phone(input_fd);
    722         if (kbd_phone < 0) {
     714static int connect_keyboard(char *path)
     715{
     716        int fd = open(path, O_RDONLY);
     717        if (fd < 0) {
     718                return fd;
     719        }
     720       
     721        int phone = fd_phone(fd);
     722        if (phone < 0) {
    723723                printf(NAME ": Failed to connect to input device\n");
    724                 return false;
     724                return phone;
    725725        }
    726726       
    727727        /* NB: The callback connection is slotted for removal */
    728728        sysarg_t phonehash;
    729         if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
     729        int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, SERVICE_CONSOLE,
     730            0, 0, NULL, NULL, NULL, NULL, &phonehash);
     731        if (rc != EOK) {
    730732                printf(NAME ": Failed to create callback from input device\n");
     733                return rc;
     734        }
     735       
     736        async_new_connection(phonehash, 0, NULL, keyboard_events);
     737
     738        printf(NAME ": we got a hit (new keyboard \"%s\").\n", path);
     739
     740        return phone;
     741}
     742
     743
     744static int check_new_keyboards(void *arg)
     745{
     746        char *class_name = (char *) arg;
     747
     748        int index = 1;
     749
     750        while (true) {
     751                async_usleep(1 * 500 * 1000);
     752                char *path;
     753                int rc = asprintf(&path, "/dev/class/%s\\%d", class_name, index);
     754                if (rc < 0) {
     755                        continue;
     756                }
     757                rc = 0;
     758                rc = connect_keyboard(path);
     759                if (rc > 0) {
     760                        /* We do not allow unplug. */
     761                        index++;
     762                }
     763
     764                free(path);
     765        }
     766
     767        return EOK;
     768}
     769
     770
     771/** Start a fibril monitoring hot-plugged keyboards.
     772 */
     773static void check_new_keyboards_in_background()
     774{
     775        fid_t fid = fibril_create(check_new_keyboards, (void *)"keyboard");
     776        if (!fid) {
     777                printf(NAME ": failed to create hot-plug-watch fibril.\n");
     778                return;
     779        }
     780        fibril_add_ready(fid);
     781}
     782
     783static bool console_init(char *input)
     784{
     785        /* Connect to input device */
     786        kbd_phone = connect_keyboard(input);
     787        if (kbd_phone < 0) {
    731788                return false;
    732789        }
    733        
    734         async_new_connection(phonehash, 0, NULL, keyboard_events);
    735        
     790
    736791        /* Connect to mouse device */
    737792        mouse_phone = -1;
     
    749804        }
    750805       
     806        sysarg_t phonehash;
    751807        if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
    752808                printf(NAME ": Failed to create callback from mouse device\n");
     
    841897        async_set_interrupt_received(interrupt_received);
    842898       
     899        /* Start fibril for checking on hot-plugged keyboards. */
     900        check_new_keyboards_in_background();
     901
    843902        return true;
    844903}
     
    860919        if (!console_init(argv[1]))
    861920                return -1;
    862        
     921
    863922        printf(NAME ": Accepting connections\n");
    864923        async_manager();
Note: See TracChangeset for help on using the changeset viewer.