source: mainline/uspace/srv/hid/adb_mouse/adb_dev.c@ ffa2c8ef

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ffa2c8ef was ffa2c8ef, checked in by Martin Decky <martin@…>, 14 years ago

do not intermix low-level IPC methods with async framework methods

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[9f51afc]1/*
[b73c26d]2 * Copyright (c) 2010 Jiri Svoboda
[9f51afc]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup mouse
30 * @{
31 */
32/** @file
33 * @brief
34 */
35
[b73c26d]36#include <ipc/adb.h>
[9f51afc]37#include <async.h>
38#include <vfs/vfs.h>
39#include <fcntl.h>
40#include <errno.h>
41
[b73c26d]42#include "adb_mouse.h"
43#include "adb_dev.h"
[9f51afc]44
[b73c26d]45static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall);
[9f51afc]46
47static int dev_phone;
48
[b73c26d]49int adb_dev_init(void)
[9f51afc]50{
[a000878c]51 const char *input = "/dev/adb/mouse";
[9f51afc]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 */
[ffa2c8ef]69 if (async_connect_to_me(dev_phone, 0, 0, 0, adb_dev_events) != 0) {
[9f51afc]70 printf(NAME ": Failed to create callback from device\n");
71 return false;
72 }
[ffa2c8ef]73
[9f51afc]74 return 0;
75}
76
[b73c26d]77static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall)
[9f51afc]78{
79 /* Ignore parameters, the connection is already opened */
80 while (true) {
81
82 ipc_call_t call;
83 ipc_callid_t callid = async_get_call(&call);
84
85 int retval;
86
[228e490]87 switch (IPC_GET_IMETHOD(call)) {
[9f51afc]88 case IPC_M_PHONE_HUNGUP:
89 /* TODO: Handle hangup */
90 return;
91 case IPC_FIRST_USER_METHOD:
[b73c26d]92 mouse_handle_data(IPC_GET_ARG1(call));
[9f51afc]93 break;
94 default:
95 retval = ENOENT;
96 }
[ffa2c8ef]97 async_answer_0(callid, retval);
[9f51afc]98 }
99}
100
101/**
102 * @}
103 */
Note: See TracBrowser for help on using the repository browser.