Changeset 04803bf in mainline for uspace/srv/hid/kbd/generic/kbd.c


Ignore:
Timestamp:
2011-03-21T22:00:17Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
143932e3
Parents:
b50b5af2 (diff), 7308e84 (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 mainline changes (needs fixes).

File:
1 moved

Legend:

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

    rb50b5af2 r04803bf  
    3636 */
    3737
    38 #include <ipc/ipc.h>
    3938#include <ipc/services.h>
    4039#include <ipc/kbd.h>
     
    5049#include <io/console.h>
    5150#include <io/keycode.h>
     51#include <devmap.h>
    5252
    5353#include <kbd.h>
     
    5656#include <layout.h>
    5757
    58 #define NAME "kbd"
    59 
    60 int cons_connected = 0;
    61 int phone2cons = -1;
     58#define NAME       "kbd"
     59#define NAMESPACE  "hid_in"
     60
     61int client_phone = -1;
    6262
    6363/** Currently active modifiers. */
     
    163163        ev.c = layout[active_layout]->parse_ev(&ev);
    164164
    165         async_msg_4(phone2cons, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
    166 }
    167 
    168 static void console_connection(ipc_callid_t iid, ipc_call_t *icall)
     165        async_msg_4(client_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
     166}
     167
     168static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
    169169{
    170170        ipc_callid_t callid;
     
    172172        int retval;
    173173
    174         if (cons_connected) {
    175                 ipc_answer_0(iid, ELIMIT);
    176                 return;
    177         }
    178         cons_connected = 1;
    179         ipc_answer_0(iid, EOK);
     174        async_answer_0(iid, EOK);
    180175
    181176        while (1) {
    182177                callid = async_get_call(&call);
    183                 switch (IPC_GET_METHOD(call)) {
     178                switch (IPC_GET_IMETHOD(call)) {
    184179                case IPC_M_PHONE_HUNGUP:
    185                         cons_connected = 0;
    186                         ipc_hangup(phone2cons);
    187                         phone2cons = -1;
    188                         ipc_answer_0(callid, EOK);
     180                        if (client_phone != -1) {
     181                                async_hangup(client_phone);
     182                                client_phone = -1;
     183                        }
     184                       
     185                        async_answer_0(callid, EOK);
    189186                        return;
    190187                case IPC_M_CONNECT_TO_ME:
    191                         if (phone2cons != -1) {
     188                        if (client_phone != -1) {
    192189                                retval = ELIMIT;
    193190                                break;
    194191                        }
    195                         phone2cons = IPC_GET_ARG5(call);
     192                        client_phone = IPC_GET_ARG5(call);
    196193                        retval = 0;
    197194                        break;
     
    207204                        retval = EINVAL;
    208205                }
    209                 ipc_answer_0(callid, retval);
     206                async_answer_0(callid, retval);
    210207        }       
    211208}
     
    214211int main(int argc, char **argv)
    215212{
    216         printf(NAME ": HelenOS Keyboard service\n");
    217        
    218         ipcarg_t phonead;
    219        
    220         if (sysinfo_value("kbd.cir.fhc") == 1)
     213        printf("%s: HelenOS Keyboard service\n", NAME);
     214       
     215        sysarg_t fhc;
     216        sysarg_t obio;
     217       
     218        if ((sysinfo_get_value("kbd.cir.fhc", &fhc) == EOK) && (fhc))
    221219                cir_service = SERVICE_FHC;
    222         else if (sysinfo_value("kbd.cir.obio") == 1)
     220        else if ((sysinfo_get_value("kbd.cir.obio", &obio) == EOK) && (obio))
    223221                cir_service = SERVICE_OBIO;
    224222       
    225223        if (cir_service) {
    226                 while (cir_phone < 0) {
    227                         cir_phone = ipc_connect_me_to_blocking(PHONE_NS, cir_service,
    228                             0, 0);
    229                 }
     224                while (cir_phone < 0)
     225                        cir_phone = service_connect_blocking(cir_service, 0, 0);
    230226        }
    231227       
     
    241237        layout[active_layout]->reset();
    242238       
    243         async_set_client_connection(console_connection);
    244 
    245         /* Register service at nameserver. */
    246         if (ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, 0, &phonead) != 0)
    247                 return -1;
    248        
     239        /* Register driver */
     240        int rc = devmap_driver_register(NAME, client_connection);
     241        if (rc < 0) {
     242                printf("%s: Unable to register driver (%d)\n", NAME, rc);
     243                return -1;
     244        }
     245       
     246        char kbd[DEVMAP_NAME_MAXLEN + 1];
     247        snprintf(kbd, DEVMAP_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME);
     248       
     249        devmap_handle_t devmap_handle;
     250        if (devmap_device_register(kbd, &devmap_handle) != EOK) {
     251                printf("%s: Unable to register device %s\n", NAME, kbd);
     252                return -1;
     253        }
     254
    249255        printf(NAME ": Accepting connections\n");
    250256        async_manager();
Note: See TracChangeset for help on using the changeset viewer.