Changeset 61c0402 in mainline for uspace/srv/hid/console/console.c


Ignore:
Timestamp:
2010-01-15T19:36:53Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
92bee46
Parents:
50f9c3a (diff), 963462af (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 moved

Legend:

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

    r50f9c3a r61c0402  
    3737#include <ipc/kbd.h>
    3838#include <io/keycode.h>
     39#include <ipc/mouse.h>
    3940#include <ipc/fb.h>
    4041#include <ipc/services.h>
     
    5051#include <event.h>
    5152#include <devmap.h>
    52 #include <fibril_sync.h>
     53#include <fcntl.h>
     54#include <vfs/vfs.h>
     55#include <fibril_synch.h>
    5356
    5457#include "console.h"
     
    5760#include "screenbuffer.h"
    5861
    59 #define NAME  "console"
    60 
    61 #define MAX_DEVICE_NAME  32
     62#define NAME       "console"
     63#define NAMESPACE  "term"
    6264
    6365/** Phone to the keyboard driver. */
    6466static int kbd_phone;
     67
     68/** Phone to the mouse driver. */
     69static int mouse_phone;
    6570
    6671/** Information about framebuffer */
     
    6974        ipcarg_t cols;  /**< Framebuffer columns */
    7075        ipcarg_t rows;  /**< Framebuffer rows */
    71         int color_cap;  /**< Color capabilities (FB_CCAP_xxx) */
     76        int color_cap;  /**< Color capabilities (FB_CCAP_xxx) */
    7277} fb_info;
    7378
     
    425430}
    426431
     432/** Handler for mouse events */
     433static void mouse_events(ipc_callid_t iid, ipc_call_t *icall)
     434{
     435        int button, press;
     436        int dx, dy;
     437        int newcon;
     438
     439        /* Ignore parameters, the connection is already opened */
     440        while (true) {
     441
     442                ipc_call_t call;
     443                ipc_callid_t callid = async_get_call(&call);
     444
     445                int retval;
     446
     447                switch (IPC_GET_METHOD(call)) {
     448                case IPC_M_PHONE_HUNGUP:
     449                        /* TODO: Handle hangup */
     450                        return;
     451                case MEVENT_BUTTON:
     452                        button = IPC_GET_ARG1(call);
     453                        press = IPC_GET_ARG2(call);
     454                        if (button == 1) {
     455                                newcon = gcons_mouse_btn(press);
     456                                if (newcon != -1)
     457                                        change_console(&consoles[newcon]);
     458                        }
     459                        retval = 0;
     460                        break;
     461                case MEVENT_MOVE:
     462                        dx = IPC_GET_ARG1(call);
     463                        dy = IPC_GET_ARG2(call);
     464                        gcons_mouse_move(dx, dy);
     465                        retval = 0;
     466                        break;
     467                default:
     468                        retval = ENOENT;
     469                }
     470
     471                ipc_answer_0(callid, retval);
     472        }
     473}
     474
    427475static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
    428476{
     
    601649                                    IPC_GET_ARG2(call));
    602650                        break;
     651                case CONSOLE_GET_POS:
     652                        arg1 = cons->scr.position_x;
     653                        arg2 = cons->scr.position_y;
     654                        break;
    603655                case CONSOLE_GET_SIZE:
    604656                        arg1 = fb_info.cols;
     
    662714}
    663715
    664 static bool console_init(void)
    665 {
    666         ipcarg_t color_cap;
    667 
    668         /* Connect to keyboard driver */
    669         kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
     716static bool console_init(char *input)
     717{
     718        /* Connect to input device */
     719        int input_fd = open(input, O_RDONLY);
     720        if (input_fd < 0) {
     721                printf(NAME ": Failed opening %s\n", input);
     722                return false;
     723        }
     724
     725        kbd_phone = fd_phone(input_fd);
    670726        if (kbd_phone < 0) {
    671                 printf(NAME ": Failed to connect to keyboard service\n");
     727                printf(NAME ": Failed to connect to input device\n");
    672728                return false;
    673729        }
    674        
     730
     731        /* NB: The callback connection is slotted for removal */
    675732        ipcarg_t phonehash;
    676733        if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
    677                 printf(NAME ": Failed to create callback from keyboard service\n");
     734                printf(NAME ": Failed to create callback from input device\n");
    678735                return false;
    679736        }
    680        
     737
    681738        async_new_connection(phonehash, 0, NULL, keyboard_events);
     739
     740        /* Connect to mouse device */
     741        mouse_phone = -1;
     742        int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY);
     743
     744        if (mouse_fd < 0) {
     745                printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse");
     746                goto skip_mouse;
     747        }
     748
     749        mouse_phone = fd_phone(mouse_fd);
     750        if (mouse_phone < 0) {
     751                printf(NAME ": Failed to connect to mouse device\n");
     752                goto skip_mouse;
     753        }
     754
     755        if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
     756                printf(NAME ": Failed to create callback from mouse device\n");
     757                mouse_phone = -1;
     758                goto skip_mouse;
     759        }
     760
     761        async_new_connection(phonehash, 0, NULL, mouse_events);
     762skip_mouse:
    682763
    683764        /* Connect to framebuffer driver */
     
    687768                return -1;
    688769        }
    689        
     770
    690771        /* Register driver */
    691772        int rc = devmap_driver_register(NAME, client_connection);
     
    699780       
    700781        /* Synchronize, the gcons could put something in queue */
     782        ipcarg_t color_cap;
    701783        async_req_0_0(fb_info.phone, FB_FLUSH);
    702784        async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
     
    736818                        consoles[i].refcount = 0;
    737819                       
    738                         char vc[MAX_DEVICE_NAME];
    739                         snprintf(vc, MAX_DEVICE_NAME, "vc%u", i);
     820                        char vc[DEVMAP_NAME_MAXLEN + 1];
     821                        snprintf(vc, DEVMAP_NAME_MAXLEN, "%s/vc%u", NAMESPACE, i);
    740822                       
    741823                        if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) {
     
    768850}
    769851
     852static void usage(void)
     853{
     854        printf("Usage: console <input>\n");
     855}
     856
    770857int main(int argc, char *argv[])
    771858{
     859        if (argc < 2) {
     860                usage();
     861                return -1;
     862        }
     863       
    772864        printf(NAME ": HelenOS Console service\n");
    773865       
    774         if (!console_init())
     866        if (!console_init(argv[1]))
    775867                return -1;
    776868       
Note: See TracChangeset for help on using the changeset viewer.