Changeset 2568c94 in mainline for uspace/srv/hid/console/console.c


Ignore:
Timestamp:
2012-08-17T17:15:19Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1789023
Parents:
4f351432 (diff), 01e397ac (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/console.c

    r4f351432 r2568c94  
    3636#include <stdio.h>
    3737#include <adt/prodcons.h>
    38 #include <ipc/input.h>
     38#include <io/input.h>
    3939#include <ipc/console.h>
    4040#include <ipc/vfs.h>
     
    4343#include <loc.h>
    4444#include <event.h>
     45#include <io/kbd_event.h>
    4546#include <io/keycode.h>
    4647#include <io/chargrid.h>
     
    8182} console_t;
    8283
    83 /** Session to the input server */
    84 static async_sess_t *input_sess;
     84/** Input server proxy */
     85static input_t *input;
    8586
    8687/** Session to the output server */
     
    100101static console_t *active_console = &consoles[0];
    101102static console_t *kernel_console = &consoles[KERNEL_CONSOLE];
     103
     104static int input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t);
     105static int input_ev_move(input_t *, int, int);
     106static int input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned);
     107static int input_ev_button(input_t *, int, int);
     108
     109static input_ev_ops_t input_ev_ops = {
     110        .key = input_ev_key,
     111        .move = input_ev_move,
     112        .abs_move = input_ev_abs_move,
     113        .button = input_ev_button
     114};
    102115
    103116static void cons_update(console_t *cons)
     
    195208}
    196209
    197 static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    198 {
    199         /* Ignore parameters, the connection is already opened */
    200         while (true) {
    201                 ipc_call_t call;
    202                 ipc_callid_t callid = async_get_call(&call);
    203                
    204                 if (!IPC_GET_IMETHOD(call)) {
    205                         /* TODO: Handle hangup */
    206                         async_hangup(input_sess);
    207                         return;
    208                 }
    209                
    210                 kbd_event_type_t type;
    211                 keycode_t key;
    212                 keymod_t mods;
    213                 wchar_t c;
    214                
    215                 switch (IPC_GET_IMETHOD(call)) {
    216                 case INPUT_EVENT_KEY:
    217                         type = IPC_GET_ARG1(call);
    218                         key = IPC_GET_ARG2(call);
    219                         mods = IPC_GET_ARG3(call);
    220                         c = IPC_GET_ARG4(call);
    221                        
    222                         if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) &&
    223                             ((mods & KM_CTRL) == 0))
    224                                 cons_switch(&consoles[key - KC_F1]);
    225                         else {
    226                                 /* Got key press/release event */
    227                                 kbd_event_t *event =
    228                                     (kbd_event_t *) malloc(sizeof(kbd_event_t));
    229                                 if (event == NULL) {
    230                                         async_answer_0(callid, ENOMEM);
    231                                         break;
    232                                 }
    233                                
    234                                 link_initialize(&event->link);
    235                                 event->type = type;
    236                                 event->key = key;
    237                                 event->mods = mods;
    238                                 event->c = c;
    239                                
    240                                 /*
    241                                  * Kernel console does not read events
    242                                  * from us, so we will redirect them
    243                                  * to the (last) active userspace console
    244                                  * if necessary.
    245                                  */
    246                                 console_t *target_console = cons_get_active_uspace();
    247                                
    248                                 prodcons_produce(&target_console->input_pc,
    249                                     &event->link);
    250                         }
    251                        
    252                         async_answer_0(callid, EOK);
    253                         break;
    254                 case INPUT_EVENT_MOVE:
    255                         async_answer_0(callid, EOK);
    256                         break;
    257                 case INPUT_EVENT_BUTTON:
    258                         async_answer_0(callid, EOK);
    259                         break;
    260                 default:
    261                         async_answer_0(callid, EINVAL);
    262                 }
    263         }
     210static int input_ev_key(input_t *input, kbd_event_type_t type, keycode_t key,
     211    keymod_t mods, wchar_t c)
     212{
     213        if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) &&
     214            ((mods & KM_CTRL) == 0)) {
     215                cons_switch(&consoles[key - KC_F1]);
     216        } else {
     217                /* Got key press/release event */
     218                kbd_event_t *event =
     219                    (kbd_event_t *) malloc(sizeof(kbd_event_t));
     220                if (event == NULL) {
     221                        return ENOMEM;
     222                }
     223               
     224                link_initialize(&event->link);
     225                event->type = type;
     226                event->key = key;
     227                event->mods = mods;
     228                event->c = c;
     229               
     230                /*
     231                 * Kernel console does not read events
     232                 * from us, so we will redirect them
     233                 * to the (last) active userspace console
     234                 * if necessary.
     235                 */
     236                console_t *target_console = cons_get_active_uspace();
     237               
     238                prodcons_produce(&target_console->input_pc,
     239                    &event->link);
     240        }
     241       
     242        return EOK;
     243}
     244
     245static int input_ev_move(input_t *input, int dx, int dy)
     246{
     247        return EOK;
     248}
     249
     250static int input_ev_abs_move(input_t *input, unsigned x , unsigned y,
     251    unsigned max_x, unsigned max_y)
     252{
     253        return EOK;
     254}
     255
     256static int input_ev_button(input_t *input, int bnum, int bpress)
     257{
     258        return EOK;
    264259}
    265260
     
    518513}
    519514
    520 static async_sess_t *input_connect(const char *svc)
     515static int input_connect(const char *svc)
    521516{
    522517        async_sess_t *sess;
     
    524519       
    525520        int rc = loc_service_get_id(svc, &dsid, 0);
    526         if (rc == EOK) {
    527                 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0);
    528                 if (sess == NULL) {
    529                         printf("%s: Unable to connect to input service %s\n", NAME,
    530                             svc);
    531                         return NULL;
    532                 }
    533         } else
    534                 return NULL;
    535        
    536         async_exch_t *exch = async_exchange_begin(sess);
    537         rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL);
    538         async_exchange_end(exch);
    539        
     521        if (rc != EOK) {
     522                printf("%s: Input service %s not found\n", NAME, svc);
     523                return rc;
     524        }
     525
     526        sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0);
     527        if (sess == NULL) {
     528                printf("%s: Unable to connect to input service %s\n", NAME,
     529                    svc);
     530                return EIO;
     531        }
     532       
     533        rc = input_open(sess, &input_ev_ops, NULL, &input);
    540534        if (rc != EOK) {
    541535                async_hangup(sess);
    542                 printf("%s: Unable to create callback connection to service %s (%s)\n",
     536                printf("%s: Unable to communicate with service %s (%s)\n",
    543537                    NAME, svc, str_error(rc));
    544                 return NULL;
    545         }
    546        
    547         return sess;
     538                return rc;
     539        }
     540       
     541        return EOK;
    548542}
    549543
     
    574568static bool console_srv_init(char *input_svc, char *output_svc)
    575569{
     570        int rc;
     571       
    576572        /* Connect to input service */
    577         input_sess = input_connect(input_svc);
    578         if (input_sess == NULL)
     573        rc = input_connect(input_svc);
     574        if (rc != EOK)
    579575                return false;
    580576       
     
    586582        /* Register server */
    587583        async_set_client_connection(client_connection);
    588         int rc = loc_server_register(NAME);
     584        rc = loc_server_register(NAME);
    589585        if (rc != EOK) {
    590586                printf("%s: Unable to register server (%s)\n", NAME,
Note: See TracChangeset for help on using the changeset viewer.