Ignore:
Timestamp:
2011-08-17T13:39:53Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e280857
Parents:
45058baa
Message:

Notifications on changes in loc categories. Limitations:

  • cannot specify single category to watch
  • max one task can register notifications with loc service
  • max one user callback function can be registered with C library

Remove devman tests as they are not applicable anymore.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/generic/input.c

    r45058baa r12f9f0d0  
    6666#include <abi/ipc/methods.h>
    6767
    68 /* In microseconds */
    69 #define DISCOVERY_POLL_INTERVAL  (10 * 1000 * 1000)
    70 
    7168#define NUM_LAYOUTS  3
    7269
     
    497494}
    498495
    499 /** Periodically check for new input devices.
    500  *
    501  * Looks under /loc/class/keyboard and /loc/class/mouse.
    502  *
    503  * @param arg Ignored
    504  *
    505  */
    506 static int dev_discovery_fibril(void *arg)
    507 {
    508         category_id_t keyboard_cat, mouse_cat;
     496static int dev_check_new_kbdevs(void)
     497{
     498        category_id_t keyboard_cat;
    509499        service_id_t *svcs;
    510500        size_t count, i;
     
    518508        }
    519509       
     510        /*
     511         * Check for new keyboard devices
     512         */
     513        rc = loc_category_get_svcs(keyboard_cat, &svcs, &count);
     514        if (rc != EOK) {
     515                printf("%s: Failed getting list of keyboard devices.\n",
     516                    NAME);
     517                return EIO;
     518        }
     519
     520        for (i = 0; i < count; i++) {
     521                already_known = false;
     522               
     523                /* Determine whether we already know this device. */
     524                list_foreach(kbd_devs, kdev_link) {
     525                        kbd_dev_t *kdev = list_get_instance(kdev_link,
     526                            kbd_dev_t, kbd_devs);
     527                        if (kdev->svc_id == svcs[i]) {
     528                                already_known = true;
     529                                break;
     530                        }
     531                }
     532               
     533                if (!already_known) {
     534                        kbd_dev_t *kdev;
     535                        if (kbd_add_kbdev(svcs[i], &kdev) == EOK) {
     536                                printf("%s: Connected keyboard device '%s'\n",
     537                                    NAME, kdev->svc_name);
     538                        }
     539                }
     540        }
     541       
     542        /* XXX Handle device removal */
     543       
     544        return EOK;
     545}
     546
     547static int dev_check_new_mousedevs(void)
     548{
     549        category_id_t mouse_cat;
     550        service_id_t *svcs;
     551        size_t count, i;
     552        bool already_known;
     553        int rc;
     554       
    520555        rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING);
    521556        if (rc != EOK) {
     
    524559        }
    525560       
    526         while (true) {
    527                 async_usleep(DISCOVERY_POLL_INTERVAL);
    528                
    529                 /*
    530                  * Check for new keyboard devices
    531                  */
    532                 rc = loc_category_get_svcs(keyboard_cat, &svcs, &count);
    533                 if (rc != EOK) {
    534                         printf("%s: Failed getting list of keyboard devices.\n",
    535                             NAME);
    536                         continue;
    537                 }
    538 
    539                 for (i = 0; i < count; i++) {
    540                         already_known = false;
    541                        
    542                         /* Determine whether we already know this device. */
    543                         list_foreach(kbd_devs, kdev_link) {
    544                                 kbd_dev_t *kdev = list_get_instance(kdev_link,
    545                                     kbd_dev_t, kbd_devs);
    546                                 if (kdev->svc_id == svcs[i]) {
    547                                         already_known = true;
    548                                         break;
    549                                 }
    550                         }
    551 
    552                         if (!already_known) {
    553                                 kbd_dev_t *kdev;
    554                                 if (kbd_add_kbdev(svcs[i], &kdev) == EOK) {
    555                                         printf("%s: Connected keyboard device '%s'\n",
    556                                             NAME, kdev->svc_name);
    557                                 }
     561        /*
     562         * Check for new mouse devices
     563         */
     564        rc = loc_category_get_svcs(mouse_cat, &svcs, &count);
     565        if (rc != EOK) {
     566                printf("%s: Failed getting list of mouse devices.\n",
     567                    NAME);
     568                return EIO;
     569        }
     570       
     571        for (i = 0; i < count; i++) {
     572                already_known = false;
     573               
     574                /* Determine whether we already know this device. */
     575                list_foreach(mouse_devs, mdev_link) {
     576                        mouse_dev_t *mdev = list_get_instance(mdev_link,
     577                            mouse_dev_t, mouse_devs);
     578                        if (mdev->svc_id == svcs[i]) {
     579                                already_known = true;
     580                                break;
    558581                        }
    559582                }
    560583               
    561                 /* XXX Handle device removal */
    562                
    563                 /*
    564                  * Check for new mouse devices
    565                  */
    566                 rc = loc_category_get_svcs(mouse_cat, &svcs, &count);
    567                 if (rc != EOK) {
    568                         printf("%s: Failed getting list of mouse devices.\n",
    569                             NAME);
    570                         continue;
    571                 }
    572 
    573                 for (i = 0; i < count; i++) {
    574                         already_known = false;
    575                        
    576                         /* Determine whether we already know this device. */
    577                         list_foreach(mouse_devs, mdev_link) {
    578                                 mouse_dev_t *mdev = list_get_instance(mdev_link,
    579                                     mouse_dev_t, mouse_devs);
    580                                 if (mdev->svc_id == svcs[i]) {
    581                                         already_known = true;
    582                                         break;
    583                                 }
    584                         }
    585 
    586                         if (!already_known) {
    587                                 mouse_dev_t *mdev;
    588                                 if (mouse_add_mousedev(svcs[i], &mdev) == EOK) {
    589                                         printf("%s: Connected mouse device '%s'\n",
    590                                             NAME, mdev->svc_name);
    591                                 }
     584                if (!already_known) {
     585                        mouse_dev_t *mdev;
     586                        if (mouse_add_mousedev(svcs[i], &mdev) == EOK) {
     587                                printf("%s: Connected mouse device '%s'\n",
     588                                    NAME, mdev->svc_name);
    592589                        }
    593590                }
    594                
    595                 /* XXX Handle device removal */
    596         }
     591        }
     592       
     593        /* XXX Handle device removal */
    597594       
    598595        return EOK;
    599596}
    600597
    601 /** Start a fibril for discovering new devices. */
    602 static void input_start_dev_discovery(void)
    603 {
    604         fid_t fid = fibril_create(dev_discovery_fibril, NULL);
    605         if (!fid) {
    606                 printf("%s: Failed to create device discovery fibril.\n",
    607                     NAME);
    608                 return;
    609         }
    610        
    611         fibril_add_ready(fid);
     598static int dev_check_new(void)
     599{
     600        int rc;
     601       
     602        rc = dev_check_new_kbdevs();
     603        if (rc != EOK)
     604                return rc;
     605       
     606        rc = dev_check_new_mousedevs();
     607        if (rc != EOK)
     608                return rc;
     609
     610        return EOK;
     611}
     612
     613static void cat_change_cb(void)
     614{
     615        dev_check_new();
     616}
     617
     618/** Start listening for new devices. */
     619static int input_start_dev_discovery(void)
     620{
     621        int rc;
     622
     623        rc = loc_register_cat_change_cb(cat_change_cb);
     624        if (rc != EOK) {
     625                printf("%s: Failed registering callback for device discovery. "
     626                    "(%d)\n", NAME, rc);
     627                return rc;
     628        }
     629
     630        return dev_check_new();
    612631}
    613632
Note: See TracChangeset for help on using the changeset viewer.