Changeset 04803bf in mainline for uspace/srv/hid/adb_mouse/adb_dev.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/adb_mouse/adb_dev.c

    rb50b5af2 r04803bf  
    11/*
    2  * Copyright (c) 2006 Ondrej Palkovsky
     2 * Copyright (c) 2010 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #include <stdio.h>
    30 #include <unistd.h>
     29/** @addtogroup mouse
     30 * @{
     31 */
     32/** @file
     33 * @brief
     34 */
     35
     36#include <ipc/adb.h>
    3137#include <async.h>
     38#include <vfs/vfs.h>
     39#include <fcntl.h>
    3240#include <errno.h>
    33 #include "../tester.h"
    3441
    35 #define MAX_CONNECTIONS  50
     42#include "adb_mouse.h"
     43#include "adb_dev.h"
    3644
    37 static int connections[MAX_CONNECTIONS];
     45static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall);
    3846
    39 static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
     47static int dev_phone;
     48
     49int adb_dev_init(void)
    4050{
    41         unsigned int i;
    42        
    43         TPRINTF("Connected phone %#x accepting\n", icall->in_phone_hash);
    44         ipc_answer_0(iid, EOK);
    45         for (i = 0; i < MAX_CONNECTIONS; i++) {
    46                 if (!connections[i]) {
    47                         connections[i] = icall->in_phone_hash;
    48                         break;
    49                 }
     51        const char *input = "/dev/adb/mouse";
     52        int input_fd;
     53
     54        printf(NAME ": open %s\n", input);
     55
     56        input_fd = open(input, O_RDONLY);
     57        if (input_fd < 0) {
     58                printf(NAME ": Failed opening %s (%d)\n", input, input_fd);
     59                return false;
     60        }
     61
     62        dev_phone = fd_phone(input_fd);
     63        if (dev_phone < 0) {
     64                printf(NAME ": Failed to connect to device\n");
     65                return false;
     66        }
     67
     68        /* NB: The callback connection is slotted for removal */
     69        if (async_connect_to_me(dev_phone, 0, 0, 0, adb_dev_events) != 0) {
     70                printf(NAME ": Failed to create callback from device\n");
     71                return false;
    5072        }
    5173       
     74        return 0;
     75}
     76
     77static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall)
     78{
     79        /* Ignore parameters, the connection is already opened */
    5280        while (true) {
     81
    5382                ipc_call_t call;
    5483                ipc_callid_t callid = async_get_call(&call);
     84
    5585                int retval;
    56                
    57                 switch (IPC_GET_METHOD(call)) {
     86
     87                switch (IPC_GET_IMETHOD(call)) {
    5888                case IPC_M_PHONE_HUNGUP:
    59                         TPRINTF("Phone %#x hung up\n", icall->in_phone_hash);
    60                         retval = 0;
    61                         break;
    62                 case IPC_TEST_METHOD:
    63                         TPRINTF("Received well known message from %#x: %#x\n",
    64                             icall->in_phone_hash, callid);
    65                         ipc_answer_0(callid, EOK);
     89                        /* TODO: Handle hangup */
     90                        return;
     91                case IPC_FIRST_USER_METHOD:
     92                        mouse_handle_data(IPC_GET_ARG1(call));
    6693                        break;
    6794                default:
    68                         TPRINTF("Received unknown message from %#x: %#x\n",
    69                             icall->in_phone_hash, callid);
    70                         ipc_answer_0(callid, ENOENT);
    71                         break;
     95                        retval = ENOENT;
    7296                }
     97                async_answer_0(callid, retval);
    7398        }
    7499}
    75100
    76 char *test_register(void)
    77 {
    78         async_set_client_connection(client_connection);
    79        
    80         ipcarg_t phonead;
    81         int res = ipc_connect_to_me(PHONE_NS, IPC_TEST_SERVICE, 0, 0, &phonead);
    82         if (res != 0)
    83                 return "Failed registering IPC service";
    84        
    85         TPRINTF("Registered as service %u, accepting connections\n", IPC_TEST_SERVICE);
    86         async_manager();
    87        
    88         return NULL;
    89 }
     101/**
     102 * @}
     103 */
Note: See TracChangeset for help on using the changeset viewer.