Ignore:
Timestamp:
2011-06-21T19:10:20Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
022d9f67
Parents:
a9d85df
Message:

input server improvements

  • integrate legacy port mouse drivers (PS/2, ADB) into the input server (to be on par with the legacy keyboard drivers)
  • create generic port/protocol layers for the mouse in the input server
  • rename the "hid_in" namespace to "hid" namespace (hid_in/input was rather redundant)
  • rename the mouse event IPC messages to be more consistent with the keyboard event messages
  • rename input server ops structure members to be more generic (parse_scancode → parse)
  • cstyle changes (newlines, comments, printouts)
File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/proto/mousedev.c

    ra9d85df r1875a0c  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2011 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /**
    30  * @addtogroup inputgen generic
    31  * @brief Mouse device handling.
     29/** @addtogroup mouse_proto
    3230 * @ingroup input
    3331 * @{
    3432 */
    35 /** @file
     33/**
     34 * @file
     35 * @brief Mouse device connector controller driver.
    3636 */
    3737
    38 #include <adt/list.h>
     38#include <stdio.h>
     39#include <fcntl.h>
     40#include <vfs/vfs_sess.h>
     41#include <malloc.h>
    3942#include <async.h>
    4043#include <errno.h>
    41 #include <fcntl.h>
     44#include <ipc/mouseev.h>
    4245#include <input.h>
    43 #include <ipc/mouse.h>
    4446#include <mouse.h>
    45 #include <stdio.h>
    46 #include <stdlib.h>
    47 #include <vfs/vfs_sess.h>
     47#include <mouse_port.h>
     48#include <mouse_proto.h>
    4849
    49 static void mouse_callback_conn(ipc_callid_t, ipc_call_t *, void *);
     50/** Mousedev softstate */
     51typedef struct {
     52        /** Link to generic mouse device */
     53        mouse_dev_t *mouse_dev;
     54       
     55        /** Session to mouse device */
     56        async_sess_t *sess;
     57       
     58        /** File descriptor of open mousedev device */
     59        int fd;
     60} mousedev_t;
    5061
    51 static mouse_dev_t *mouse_dev_new(void)
     62static mousedev_t *mousedev_new(mouse_dev_t *mdev)
    5263{
    53         mouse_dev_t *mdev;
    54 
    55         mdev = calloc(1, sizeof(mouse_dev_t));
    56         if (mdev == NULL) {
    57                 printf(NAME ": Error allocating mouse device. "
    58                     "Out of memory.\n");
     64        mousedev_t *mousedev = calloc(1, sizeof(mousedev_t));
     65        if (mousedev == NULL)
    5966                return NULL;
    60         }
    61 
    62         link_initialize(&mdev->mouse_devs);
    63         return mdev;
     67       
     68        mousedev->mouse_dev = mdev;
     69        mousedev->fd = -1;
     70       
     71        return mousedev;
    6472}
    6573
    66 static int mouse_dev_connect(mouse_dev_t *mdev, const char *dev_path)
     74static void mousedev_destroy(mousedev_t *mousedev)
    6775{
    68         async_sess_t *sess;
    69         async_exch_t *exch;
    70         int fd;
    71         int rc;
    72 
    73         fd = open(dev_path, O_RDWR);
    74         if (fd < 0) {
    75                 return -1;
    76         }
    77 
    78         sess = fd_session(EXCHANGE_SERIALIZE, fd);
    79         if (sess == NULL) {
    80                 printf(NAME ": Failed starting session with '%s'\n", dev_path);
    81                 close(fd);
    82                 return -1;
    83         }
    84 
    85         exch = async_exchange_begin(sess);
    86         if (exch == NULL) {
    87                 printf(NAME ": Failed starting exchange with '%s'.\n", dev_path);
    88                 return -1;
    89         }
    90 
    91         rc = async_connect_to_me(exch, 0, 0, 0, mouse_callback_conn, mdev);
    92         if (rc != EOK) {
    93                 printf(NAME ": Failed creating callback connection from '%s'.\n",
    94                     dev_path);
    95                 async_exchange_end(exch);
    96                 return -1;
    97         }
    98 
    99         async_exchange_end(exch);
    100 
    101         mdev->dev_path = dev_path;
    102         return 0;
     76        if (mousedev->sess != NULL)
     77                async_hangup(mousedev->sess);
     78       
     79        if (mousedev->fd >= 0)
     80                close(mousedev->fd);
     81       
     82        free(mousedev);
    10383}
    10484
    105 /** Add new mouse device.
    106  *
    107  * @param dev_path      Filesystem path to the device (/dev/class/...)
    108  */
    109 int mouse_add_dev(const char *dev_path)
     85static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall,
     86    void *arg)
    11087{
    111         mouse_dev_t *mdev;
    112         int rc;
    113 
    114         mdev = mouse_dev_new();
    115         if (mdev == NULL)
    116                 return -1;
    117 
    118         rc = mouse_dev_connect(mdev, dev_path);
    119         if (rc != EOK) {
    120                 free(mdev);
    121                 return -1;
    122         }
    123 
    124         list_append(&mdev->mouse_devs, &mouse_devs);
    125         return EOK;
    126 }
    127 
    128 /** Mouse device callback connection handler. */
    129 static void mouse_callback_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    130 {
    131         int retval;
    132 
     88        /* Mousedev device structure */
     89        mousedev_t *mousedev = (mousedev_t *) arg;
     90       
    13391        while (true) {
    13492                ipc_call_t call;
    135                 ipc_callid_t callid;
    136 
    137                 callid = async_get_call(&call);
     93                ipc_callid_t callid = async_get_call(&call);
     94               
    13895                if (!IPC_GET_IMETHOD(call)) {
    13996                        /* XXX Handle hangup */
    14097                        return;
    14198                }
    142 
     99               
     100                int retval;
     101               
    143102                switch (IPC_GET_IMETHOD(call)) {
    144                 case MEVENT_BUTTON:
    145                         input_event_button(IPC_GET_ARG1(call),
     103                case MOUSEEV_MOVE_EVENT:
     104                        mouse_push_event_move(mousedev->mouse_dev, IPC_GET_ARG1(call),
    146105                            IPC_GET_ARG2(call));
    147                         retval = 0;
     106                        retval = EOK;
    148107                        break;
    149                 case MEVENT_MOVE:
    150                         input_event_move(IPC_GET_ARG1(call),
     108                case MOUSEEV_BUTTON_EVENT:
     109                        mouse_push_event_button(mousedev->mouse_dev, IPC_GET_ARG1(call),
    151110                            IPC_GET_ARG2(call));
    152                         retval = 0;
     111                        retval = EOK;
    153112                        break;
    154113                default:
     
    156115                        break;
    157116                }
    158 
     117               
    159118                async_answer_0(callid, retval);
    160119        }
    161120}
    162121
     122static int mousedev_proto_init(mouse_dev_t *mdev)
     123{
     124        const char *pathname = mdev->dev_path;
     125       
     126        int fd = open(pathname, O_RDWR);
     127        if (fd < 0)
     128                return -1;
     129       
     130        async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
     131        if (sess == NULL) {
     132                printf("%s: Failed starting session with '%s'\n", NAME, pathname);
     133                close(fd);
     134                return -1;
     135        }
     136       
     137        mousedev_t *mousedev = mousedev_new(mdev);
     138        if (mousedev == NULL) {
     139                printf("%s: Failed allocating device structure for '%s'.\n",
     140                    NAME, pathname);
     141                return -1;
     142        }
     143       
     144        mousedev->fd = fd;
     145        mousedev->sess = sess;
     146       
     147        async_exch_t *exch = async_exchange_begin(sess);
     148        if (exch == NULL) {
     149                printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname);
     150                mousedev_destroy(mousedev);
     151                return -1;
     152        }
     153       
     154        int rc = async_connect_to_me(exch, 0, 0, 0, mousedev_callback_conn, mousedev);
     155        async_exchange_end(exch);
     156       
     157        if (rc != EOK) {
     158                printf("%s: Failed creating callback connection from '%s'.\n",
     159                    NAME, pathname);
     160                mousedev_destroy(mousedev);
     161                return -1;
     162        }
     163       
     164        return 0;
     165}
     166
     167mouse_proto_ops_t mousedev_proto = {
     168        .init = mousedev_proto_init
     169};
     170
    163171/**
    164172 * @}
Note: See TracChangeset for help on using the changeset viewer.