Ignore:
File:
1 edited

Legend:

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

    r99ac5cf r10a5479d  
    3939#include <adt/list.h>
    4040#include <bool.h>
     41#include <fibril_synch.h>
    4142#include <ipc/services.h>
    4243#include <ipc/input.h>
     
    4748#include <stdio.h>
    4849#include <ns.h>
    49 #include <ns_obsolete.h>
    5050#include <async.h>
    51 #include <async_obsolete.h>
    5251#include <errno.h>
    5352#include <adt/fifo.h>
     
    6362#include <mouse.h>
    6463
    65 // FIXME: remove this header
    66 #include <abi/ipc/methods.h>
    67 
    6864#define NUM_LAYOUTS  3
    6965
     
    7773static void kbd_devs_reclaim(void);
    7874
    79 int client_phone = -1;
     75async_sess_t *client_sess = NULL;
    8076
    8177/** List of keyboard devices */
     
    8682
    8783bool irc_service = false;
    88 int irc_phone = -1;
     84async_sess_t *irc_sess = NULL;
     85
     86static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
    8987
    9088void kbd_push_data(kbd_dev_t *kdev, sysarg_t data)
     
    170168       
    171169        ev.c = layout_parse_ev(kdev->active_layout, &ev);
    172         async_obsolete_msg_4(client_phone, INPUT_EVENT_KEY, ev.type, ev.key,
    173             ev.mods, ev.c);
     170       
     171        async_exch_t *exch = async_exchange_begin(client_sess);
     172        async_msg_4(exch, INPUT_EVENT_KEY, ev.type, ev.key, ev.mods, ev.c);
     173        async_exchange_end(exch);
    174174}
    175175
    176176/** Mouse pointer has moved. */
    177 void mouse_push_event_move(mouse_dev_t *mdev, int dx, int dy)
    178 {
    179         async_obsolete_msg_2(client_phone, INPUT_EVENT_MOVE, dx, dy);
     177void mouse_push_event_move(mouse_dev_t *mdev, int dx, int dy, int dz)
     178{
     179        async_exch_t *exch = async_exchange_begin(client_sess);
     180        if (dx || dy)
     181                async_msg_2(exch, INPUT_EVENT_MOVE, dx, dy);
     182        if (dz) {
     183                // TODO: Implement proper wheel support
     184                keycode_t code = dz > 0 ? KC_UP : KC_DOWN;
     185                for (int i = 0; i < 3; ++i) {
     186                        async_msg_4(exch, INPUT_EVENT_KEY, KEY_PRESS, code, 0, 0);
     187                }
     188                async_msg_4(exch, INPUT_EVENT_KEY, KEY_RELEASE, code, 0, 0);
     189        }
     190        async_exchange_end(exch);
    180191}
    181192
     
    183194void mouse_push_event_button(mouse_dev_t *mdev, int bnum, int press)
    184195{
    185         async_obsolete_msg_2(client_phone, INPUT_EVENT_BUTTON, bnum, press);
     196        async_exch_t *exch = async_exchange_begin(client_sess);
     197        async_msg_2(exch, INPUT_EVENT_BUTTON, bnum, press);
     198        async_exchange_end(exch);
    186199}
    187200
    188201static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    189202{
    190         ipc_callid_t callid;
    191         ipc_call_t call;
    192         int retval;
    193        
    194203        async_answer_0(iid, EOK);
    195204       
    196205        while (true) {
    197                 callid = async_get_call(&call);
     206                ipc_call_t call;
     207                ipc_callid_t callid = async_get_call(&call);
    198208               
    199209                if (!IPC_GET_IMETHOD(call)) {
    200                         if (client_phone != -1) {
    201                                 async_obsolete_hangup(client_phone);
    202                                 client_phone = -1;
     210                        if (client_sess != NULL) {
     211                                async_hangup(client_sess);
     212                                client_sess = NULL;
    203213                        }
    204214                       
     
    207217                }
    208218               
    209                 switch (IPC_GET_IMETHOD(call)) {
    210                 case IPC_M_CONNECT_TO_ME:
    211                         if (client_phone != -1) {
    212                                 retval = ELIMIT;
     219                async_sess_t *sess =
     220                    async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
     221                if (sess != NULL) {
     222                        if (client_sess == NULL) {
     223                                client_sess = sess;
     224                                async_answer_0(callid, EOK);
     225                        } else
     226                                async_answer_0(callid, ELIMIT);
     227                } else {
     228                        switch (IPC_GET_IMETHOD(call)) {
     229                        case INPUT_YIELD:
     230                                kbd_devs_yield();
     231                                async_answer_0(callid, EOK);
    213232                                break;
     233                        case INPUT_RECLAIM:
     234                                kbd_devs_reclaim();
     235                                async_answer_0(callid, EOK);
     236                                break;
     237                        default:
     238                                async_answer_0(callid, EINVAL);
    214239                        }
    215                         client_phone = IPC_GET_ARG5(call);
    216                         retval = 0;
    217                         break;
    218                 case INPUT_YIELD:
    219                         kbd_devs_yield();
    220                         retval = 0;
    221                         break;
    222                 case INPUT_RECLAIM:
    223                         kbd_devs_reclaim();
    224                         retval = 0;
    225                         break;
    226                 default:
    227                         retval = EINVAL;
    228                 }
    229                
    230                 async_answer_0(callid, retval);
     240                }
    231241        }
    232242}
     
    399409         * them automatically.
    400410         */
    401 #if defined(UARCH_amd64)
    402         kbd_add_dev(&chardev_port, &pc_ctl);
    403 #endif
    404411#if defined(UARCH_arm32) && defined(MACHINE_gta02)
    405412        kbd_add_dev(&chardev_port, &stty_ctl);
     
    413420#if defined(UARCH_arm32) && defined(MACHINE_integratorcp)
    414421        kbd_add_dev(&pl050_port, &pc_ctl);
    415 #endif
    416 #if defined(UARCH_ia32)
    417         kbd_add_dev(&chardev_port, &pc_ctl);
    418 #endif
    419 #if defined(MACHINE_i460GX)
    420         kbd_add_dev(&chardev_port, &pc_ctl);
    421422#endif
    422423#if defined(MACHINE_ski)
     
    452453         * them automatically.
    453454         */
    454 #if defined(UARCH_amd64)
    455         mouse_add_dev(&chardev_mouse_port, &ps2_proto);
    456 #endif
    457 #if defined(UARCH_ia32)
    458         mouse_add_dev(&chardev_mouse_port, &ps2_proto);
    459 #endif
    460 #if defined(MACHINE_i460GX)
    461         mouse_add_dev(&chardev_mouse_port, &ps2_proto);
    462 #endif
    463455#if defined(UARCH_ppc32)
    464456        mouse_add_dev(&adb_mouse_port, &adb_proto);
     
    604596        int rc;
    605597       
     598        fibril_mutex_lock(&discovery_lock);
     599       
    606600        rc = dev_check_new_kbdevs();
    607         if (rc != EOK)
     601        if (rc != EOK) {
     602                fibril_mutex_unlock(&discovery_lock);
    608603                return rc;
     604        }
    609605       
    610606        rc = dev_check_new_mousedevs();
    611         if (rc != EOK)
     607        if (rc != EOK) {
     608                fibril_mutex_unlock(&discovery_lock);
    612609                return rc;
    613 
     610        }
     611       
     612        fibril_mutex_unlock(&discovery_lock);
     613       
    614614        return EOK;
    615615}
     
    648648       
    649649        if (irc_service) {
    650                 while (irc_phone < 0)
    651                         irc_phone = service_obsolete_connect_blocking(SERVICE_IRC, 0, 0);
     650                while (irc_sess == NULL)
     651                        irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
     652                            SERVICE_IRC, 0, 0);
    652653        }
    653654       
     
    659660       
    660661        /* Register driver */
    661         int rc = loc_server_register(NAME, client_connection);
     662        async_set_client_connection(client_connection);
     663        int rc = loc_server_register(NAME);
    662664        if (rc < 0) {
    663665                printf("%s: Unable to register server (%d)\n", NAME, rc);
Note: See TracChangeset for help on using the changeset viewer.