1 | /*
|
---|
2 | * Copyright (c) 2010 Jiri Svoboda
|
---|
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 |
|
---|
36 | #include <ipc/ipc.h>
|
---|
37 | #include <ipc/adb.h>
|
---|
38 | #include <async.h>
|
---|
39 | #include <vfs/vfs.h>
|
---|
40 | #include <fcntl.h>
|
---|
41 | #include <errno.h>
|
---|
42 |
|
---|
43 | #include "adb_mouse.h"
|
---|
44 | #include "adb_dev.h"
|
---|
45 |
|
---|
46 | static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall);
|
---|
47 |
|
---|
48 | static int dev_phone;
|
---|
49 |
|
---|
50 | int adb_dev_init(void)
|
---|
51 | {
|
---|
52 | const char *input = "/dev/adb/mouse";
|
---|
53 | int input_fd;
|
---|
54 |
|
---|
55 | printf(NAME ": open %s\n", input);
|
---|
56 |
|
---|
57 | input_fd = open(input, O_RDONLY);
|
---|
58 | if (input_fd < 0) {
|
---|
59 | printf(NAME ": Failed opening %s (%d)\n", input, input_fd);
|
---|
60 | return false;
|
---|
61 | }
|
---|
62 |
|
---|
63 | dev_phone = fd_phone(input_fd);
|
---|
64 | if (dev_phone < 0) {
|
---|
65 | printf(NAME ": Failed to connect to device\n");
|
---|
66 | return false;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /* NB: The callback connection is slotted for removal */
|
---|
70 | sysarg_t taskhash;
|
---|
71 | sysarg_t phonehash;
|
---|
72 | if (ipc_connect_to_me(dev_phone, 0, 0, 0, &taskhash, &phonehash) != 0) {
|
---|
73 | printf(NAME ": Failed to create callback from device\n");
|
---|
74 | return false;
|
---|
75 | }
|
---|
76 |
|
---|
77 | async_new_connection(taskhash, phonehash, 0, NULL, adb_dev_events);
|
---|
78 |
|
---|
79 | return 0;
|
---|
80 | }
|
---|
81 |
|
---|
82 | static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall)
|
---|
83 | {
|
---|
84 | /* Ignore parameters, the connection is already opened */
|
---|
85 | while (true) {
|
---|
86 |
|
---|
87 | ipc_call_t call;
|
---|
88 | ipc_callid_t callid = async_get_call(&call);
|
---|
89 |
|
---|
90 | int retval;
|
---|
91 |
|
---|
92 | switch (IPC_GET_IMETHOD(call)) {
|
---|
93 | case IPC_M_PHONE_HUNGUP:
|
---|
94 | /* TODO: Handle hangup */
|
---|
95 | return;
|
---|
96 | case IPC_FIRST_USER_METHOD:
|
---|
97 | mouse_handle_data(IPC_GET_ARG1(call));
|
---|
98 | break;
|
---|
99 | default:
|
---|
100 | retval = ENOENT;
|
---|
101 | }
|
---|
102 | ipc_answer_0(callid, retval);
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * @}
|
---|
108 | */
|
---|