source: mainline/uspace/srv/hid/input/proto/mousedev.c@ 1875a0c

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

input server improvements

  • integrate legacy port mouse drivers (PS/2, ADB) into the input server (to be on par with the legacy keyboard drivers)
  • create generic port/protocol layers for the mouse in the input server
  • rename the "hid_in" namespace to "hid" namespace (hid_in/input was rather redundant)
  • rename the mouse event IPC messages to be more consistent with the keyboard event messages
  • rename input server ops structure members to be more generic (parse_scancode → parse)
  • cstyle changes (newlines, comments, printouts)
  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
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_proto
30 * @ingroup input
31 * @{
32 */
33/**
34 * @file
35 * @brief Mouse device connector controller driver.
36 */
37
38#include <stdio.h>
39#include <fcntl.h>
40#include <vfs/vfs_sess.h>
41#include <malloc.h>
42#include <async.h>
43#include <errno.h>
44#include <ipc/mouseev.h>
45#include <input.h>
46#include <mouse.h>
47#include <mouse_port.h>
48#include <mouse_proto.h>
49
50/** Mousedev softstate */
51typedef struct {
52 /** Link to generic mouse device */
53 mouse_dev_t *mouse_dev;
54
55 /** Session to mouse device */
56 async_sess_t *sess;
57
58 /** File descriptor of open mousedev device */
59 int fd;
60} mousedev_t;
61
62static mousedev_t *mousedev_new(mouse_dev_t *mdev)
63{
64 mousedev_t *mousedev = calloc(1, sizeof(mousedev_t));
65 if (mousedev == NULL)
66 return NULL;
67
68 mousedev->mouse_dev = mdev;
69 mousedev->fd = -1;
70
71 return mousedev;
72}
73
74static void mousedev_destroy(mousedev_t *mousedev)
75{
76 if (mousedev->sess != NULL)
77 async_hangup(mousedev->sess);
78
79 if (mousedev->fd >= 0)
80 close(mousedev->fd);
81
82 free(mousedev);
83}
84
85static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall,
86 void *arg)
87{
88 /* Mousedev device structure */
89 mousedev_t *mousedev = (mousedev_t *) arg;
90
91 while (true) {
92 ipc_call_t call;
93 ipc_callid_t callid = async_get_call(&call);
94
95 if (!IPC_GET_IMETHOD(call)) {
96 /* XXX Handle hangup */
97 return;
98 }
99
100 int retval;
101
102 switch (IPC_GET_IMETHOD(call)) {
103 case MOUSEEV_MOVE_EVENT:
104 mouse_push_event_move(mousedev->mouse_dev, IPC_GET_ARG1(call),
105 IPC_GET_ARG2(call));
106 retval = EOK;
107 break;
108 case MOUSEEV_BUTTON_EVENT:
109 mouse_push_event_button(mousedev->mouse_dev, IPC_GET_ARG1(call),
110 IPC_GET_ARG2(call));
111 retval = EOK;
112 break;
113 default:
114 retval = ENOTSUP;
115 break;
116 }
117
118 async_answer_0(callid, retval);
119 }
120}
121
122static int mousedev_proto_init(mouse_dev_t *mdev)
123{
124 const char *pathname = mdev->dev_path;
125
126 int fd = open(pathname, O_RDWR);
127 if (fd < 0)
128 return -1;
129
130 async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
131 if (sess == NULL) {
132 printf("%s: Failed starting session with '%s'\n", NAME, pathname);
133 close(fd);
134 return -1;
135 }
136
137 mousedev_t *mousedev = mousedev_new(mdev);
138 if (mousedev == NULL) {
139 printf("%s: Failed allocating device structure for '%s'.\n",
140 NAME, pathname);
141 return -1;
142 }
143
144 mousedev->fd = fd;
145 mousedev->sess = sess;
146
147 async_exch_t *exch = async_exchange_begin(sess);
148 if (exch == NULL) {
149 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname);
150 mousedev_destroy(mousedev);
151 return -1;
152 }
153
154 int rc = async_connect_to_me(exch, 0, 0, 0, mousedev_callback_conn, mousedev);
155 async_exchange_end(exch);
156
157 if (rc != EOK) {
158 printf("%s: Failed creating callback connection from '%s'.\n",
159 NAME, pathname);
160 mousedev_destroy(mousedev);
161 return -1;
162 }
163
164 return 0;
165}
166
167mouse_proto_ops_t mousedev_proto = {
168 .init = mousedev_proto_init
169};
170
171/**
172 * @}
173 */
Note: See TracBrowser for help on using the repository browser.