Changeset cc574511 in mainline for uspace/srv/hid


Ignore:
Timestamp:
2011-08-16T12:37:58Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
16dc887
Parents:
86ffa27f
Message:

Basic category support in location service. Devman adds device services
to categories. Switch over input server device discovery from using
/dev/class to loc categories.

Location:
uspace/srv/hid/input
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/ctl/kbdev.c

    r86ffa27f rcc574511  
    4848#include <kbd_ctl.h>
    4949#include <kbd_port.h>
     50#include <loc.h>
    5051#include <stdlib.h>
     52#include <sys/typefmt.h>
    5153#include <vfs/vfs_sess.h>
    5254
     
    7072        /** Session with kbdev device */
    7173        async_sess_t *sess;
    72 
    73         /** File descriptor of open kbdev device */
    74         int fd;
    7574} kbdev_t;
    7675
     
    8483
    8584        kbdev->kbd_dev = kdev;
    86         kbdev->fd = -1;
    8785
    8886        return kbdev;
     
    9391        if (kbdev->sess != NULL)
    9492                async_hangup(kbdev->sess);
    95         if (kbdev->fd >= 0)
    96                 close(kbdev->fd);
    9793        free(kbdev);
    9894}
     
    10096static int kbdev_ctl_init(kbd_dev_t *kdev)
    10197{
    102         const char *pathname;
    10398        async_sess_t *sess;
    10499        async_exch_t *exch;
    105100        kbdev_t *kbdev;
    106         int fd;
     101        char *svc_name;
    107102        int rc;
    108103
    109         pathname = kdev->dev_path;
     104        if (asprintf(&svc_name, "devname%" PRIun, kdev->service_id) > 0)
     105                svc_name = (char *) "unknown";
    110106
    111         fd = open(pathname, O_RDWR);
    112         if (fd < 0) {
    113                 return -1;
    114         }
    115 
    116         sess = fd_session(EXCHANGE_SERIALIZE, fd);
     107        sess = loc_service_connect(EXCHANGE_SERIALIZE, kdev->service_id, 0);
    117108        if (sess == NULL) {
    118                 printf("%s: Failed starting session with '%s'\n", NAME, pathname);
    119                 close(fd);
     109                printf("%s: Failed starting session with '%s.'\n", NAME,
     110                    svc_name);
    120111                return -1;
    121112        }
     
    124115        if (kbdev == NULL) {
    125116                printf("%s: Failed allocating device structure for '%s'.\n",
    126                     NAME, pathname);
     117                    NAME, svc_name);
    127118                return -1;
    128119        }
    129120
    130         kbdev->fd = fd;
    131121        kbdev->sess = sess;
    132122
    133123        exch = async_exchange_begin(sess);
    134124        if (exch == NULL) {
    135                 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname);
     125                printf("%s: Failed starting exchange with '%s'.\n", NAME,
     126                    svc_name);
    136127                kbdev_destroy(kbdev);
    137128                return -1;
     
    141132        if (rc != EOK) {
    142133                printf("%s: Failed creating callback connection from '%s'.\n",
    143                     NAME, pathname);
     134                    NAME, svc_name);
    144135                async_exchange_end(exch);
    145136                kbdev_destroy(kbdev);
  • uspace/srv/hid/input/generic/input.c

    r86ffa27f rcc574511  
    3838
    3939#include <adt/list.h>
     40#include <bool.h>
    4041#include <ipc/services.h>
    4142#include <ipc/input.h>
     
    275276        kdev->port_ops = port;
    276277        kdev->ctl_ops = ctl;
    277         kdev->dev_path = NULL;
     278        kdev->service_id = 0;
    278279       
    279280        /* Initialize port driver. */
     
    303304        mdev->port_ops = port;
    304305        mdev->proto_ops = proto;
    305         mdev->dev_path = NULL;
     306        mdev->service_id = 0;
    306307       
    307308        /* Initialize port driver. */
     
    324325/** Add new kbdev device.
    325326 *
    326  * @param dev_path Filesystem path to the device (/loc/class/...)
     327 * @param service_id    Service ID of the keyboard device
    327328 *
    328329 */
    329 static int kbd_add_kbdev(const char *dev_path)
     330static int kbd_add_kbdev(service_id_t service_id)
    330331{
    331332        kbd_dev_t *kdev = kbd_dev_new();
     
    333334                return -1;
    334335       
    335         kdev->dev_path = dev_path;
     336        kdev->service_id = service_id;
    336337        kdev->port_ops = NULL;
    337338        kdev->ctl_ops = &kbdev_ctl;
     
    352353/** Add new mousedev device.
    353354 *
    354  * @param dev_path Filesystem path to the device (/loc/class/...)
     355 * @param service_id    Service ID of the mouse device
    355356 *
    356357 */
    357 static int mouse_add_mousedev(const char *dev_path)
     358static int mouse_add_mousedev(service_id_t service_id)
    358359{
    359360        mouse_dev_t *mdev = mouse_dev_new();
     
    361362                return -1;
    362363       
    363         mdev->dev_path = dev_path;
     364        mdev->service_id = service_id;
    364365        mdev->port_ops = NULL;
    365366        mdev->proto_ops = &mousedev_proto;
     
    487488 *
    488489 */
     490#include <sys/typefmt.h>
    489491static int dev_discovery_fibril(void *arg)
    490492{
    491         char *dev_path;
    492         size_t kbd_id = 1;
    493         size_t mouse_id = 1;
     493        category_id_t keyboard_cat, mouse_cat;
     494        service_id_t *svcs;
     495        size_t count, i;
     496        bool already_known;
     497        const char *dev_name = "todo";
    494498        int rc;
     499       
     500        rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING);
     501        if (rc != EOK) {
     502                printf("%s: Failed resolving category 'keyboard'.\n", NAME);
     503                return ENOENT;
     504        }
     505       
     506        rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING);
     507        if (rc != EOK) {
     508                printf("%s: Failed resolving category 'mouse'.\n", NAME);
     509                return ENOENT;
     510        }
    495511       
    496512        while (true) {
     
    498514               
    499515                /*
    500                  * Check for new keyboard device
     516                 * Check for new keyboard devices
    501517                 */
    502                 rc = asprintf(&dev_path, "/loc/class/keyboard\\%zu", kbd_id);
    503                 if (rc < 0)
     518                rc = loc_category_get_svcs(keyboard_cat, &svcs, &count);
     519                if (rc != EOK) {
     520                        printf("%s: Failed getting list of keyboard devices.\n",
     521                            NAME);
    504522                        continue;
    505                
    506                 if (kbd_add_kbdev(dev_path) == EOK) {
    507                         printf("%s: Connected keyboard device '%s'\n",
    508                             NAME, dev_path);
     523                }
     524
     525                for (i = 0; i < count; i++) {
     526                        already_known = false;
    509527                       
    510                         /* XXX Handle device removal */
    511                         ++kbd_id;
     528                        /* Determine whether we already know this device. */
     529                        list_foreach(kbd_devs, kdev_link) {
     530                                kbd_dev_t *kdev = list_get_instance(kdev_link,
     531                                    kbd_dev_t, kbd_devs);
     532                                if (kdev->service_id == svcs[i]) {
     533                                        already_known = true;
     534                                        break;
     535                                }
     536                        }
     537
     538                        if (!already_known) {
     539                                if (kbd_add_kbdev(svcs[i]) == EOK) {
     540                                        printf("%s: Connected keyboard device '%s'\n",
     541                                            NAME, dev_name);
     542                                }
     543                        }
    512544                }
    513545               
    514                 free(dev_path);
     546                /* XXX Handle device removal */
    515547               
    516548                /*
    517                  * Check for new mouse device
     549                 * Check for new mouse devices
    518550                 */
    519                 rc = asprintf(&dev_path, "/loc/class/mouse\\%zu", mouse_id);
    520                 if (rc < 0)
     551                rc = loc_category_get_svcs(mouse_cat, &svcs, &count);
     552                if (rc != EOK) {
     553                        printf("%s: Failed getting list of mouse devices.\n",
     554                            NAME);
    521555                        continue;
    522                
    523                 if (mouse_add_mousedev(dev_path) == EOK) {
    524                         printf("%s: Connected mouse device '%s'\n",
    525                             NAME, dev_path);
     556                }
     557
     558                for (i = 0; i < count; i++) {
     559                        already_known = false;
    526560                       
    527                         /* XXX Handle device removal */
    528                         ++mouse_id;
     561                        /* Determine whether we already know this device. */
     562                        list_foreach(mouse_devs, mdev_link) {
     563                                mouse_dev_t *mdev = list_get_instance(mdev_link,
     564                                    mouse_dev_t, mouse_devs);
     565                                if (mdev->service_id == svcs[i]) {
     566                                        already_known = true;
     567                                        break;
     568                                }
     569                        }
     570
     571                        if (!already_known) {
     572                                if (mouse_add_mousedev(svcs[i]) == EOK) {
     573                                        printf("%s: Connected mouse device '%s'\n",
     574                                            NAME, dev_name);
     575                                }
     576                        }
    529577                }
    530578               
    531                 free(dev_path);
     579                /* XXX Handle device removal */
    532580        }
    533581       
  • uspace/srv/hid/input/include/kbd.h

    r86ffa27f rcc574511  
    4040
    4141#include <adt/list.h>
     42#include <ipc/loc.h>
    4243
    4344struct kbd_port_ops;
     
    4950        link_t kbd_devs;
    5051
    51         /** Path to the device (only for kbdev devices) */
    52         const char *dev_path;
     52        /** Service ID (only for kbdev devices) */
     53        service_id_t service_id;
    5354
    5455        /** Port ops */
  • uspace/srv/hid/input/include/mouse.h

    r86ffa27f rcc574511  
    3939
    4040#include <adt/list.h>
     41#include <ipc/loc.h>
    4142
    4243struct mouse_port_ops;
     
    4748        link_t mouse_devs;
    4849       
    49         /** Path to the device (only for mouseev devices) */
    50         const char *dev_path;
     50        /** Service ID (only for mousedev devices) */
     51        service_id_t service_id;
    5152       
    5253        /** Port ops */
  • uspace/srv/hid/input/proto/mousedev.c

    r86ffa27f rcc574511  
    4444#include <ipc/mouseev.h>
    4545#include <input.h>
     46#include <loc.h>
    4647#include <mouse.h>
    4748#include <mouse_port.h>
    4849#include <mouse_proto.h>
     50#include <sys/typefmt.h>
    4951
    5052/** Mousedev softstate */
     
    5557        /** Session to mouse device */
    5658        async_sess_t *sess;
    57        
    58         /** File descriptor of open mousedev device */
    59         int fd;
    6059} mousedev_t;
    6160
     
    6766       
    6867        mousedev->mouse_dev = mdev;
    69         mousedev->fd = -1;
    7068       
    7169        return mousedev;
     
    7674        if (mousedev->sess != NULL)
    7775                async_hangup(mousedev->sess);
    78        
    79         if (mousedev->fd >= 0)
    80                 close(mousedev->fd);
    8176       
    8277        free(mousedev);
     
    122117static int mousedev_proto_init(mouse_dev_t *mdev)
    123118{
    124         const char *pathname = mdev->dev_path;
     119        char *svc_name;
    125120       
    126         int fd = open(pathname, O_RDWR);
    127         if (fd < 0)
    128                 return -1;
     121        if (asprintf(&svc_name, "devname%" PRIun, mdev->service_id) > 0)
     122                svc_name = (char *) "unknown";
    129123       
    130         async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
     124        async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE,
     125            mdev->service_id, 0);
    131126        if (sess == NULL) {
    132                 printf("%s: Failed starting session with '%s'\n", NAME, pathname);
    133                 close(fd);
     127                printf("%s: Failed starting session with '%s'\n", NAME, svc_name);
    134128                return -1;
    135129        }
     
    138132        if (mousedev == NULL) {
    139133                printf("%s: Failed allocating device structure for '%s'.\n",
    140                     NAME, pathname);
     134                    NAME, svc_name);
    141135                return -1;
    142136        }
    143137       
    144         mousedev->fd = fd;
    145138        mousedev->sess = sess;
    146139       
    147140        async_exch_t *exch = async_exchange_begin(sess);
    148141        if (exch == NULL) {
    149                 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname);
     142                printf("%s: Failed starting exchange with '%s'.\n", NAME,
     143                    svc_name);
    150144                mousedev_destroy(mousedev);
    151145                return -1;
     
    157151        if (rc != EOK) {
    158152                printf("%s: Failed creating callback connection from '%s'.\n",
    159                     NAME, pathname);
     153                    NAME, svc_name);
    160154                mousedev_destroy(mousedev);
    161155                return -1;
Note: See TracChangeset for help on using the changeset viewer.