source: mainline/uspace/srv/hid/c_mouse/c_mouse.c@ 6ef2c11

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

restructure servers into a more well-arranged hierarchy

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[9f51afc]1/*
2 * Copyright (c) 2009 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/**
30 * @addtogroup mouse
31 * @brief Chardev mouse driver.
32 *
33 * This is a common driver for mice attached to simple character devices
34 * (PS/2 mice, serial mice).
35 *
36 * @{
37 */
38/** @file
39 */
40
41#include <ipc/ipc.h>
42#include <ipc/mouse.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <async.h>
46#include <errno.h>
47#include <devmap.h>
48
49#include <c_mouse.h>
50#include <mouse_port.h>
51#include <mouse_proto.h>
52
53#define NAME "mouse"
54#define NAMESPACE "hid_in"
55
56int client_phone = -1;
57
58void mouse_handle_byte(int byte)
59{
60/* printf("mouse byte: 0x%x\n", byte);*/
61 mouse_proto_parse_byte(byte);
62}
63
64void mouse_ev_btn(int button, int press)
65{
66/* printf("ev_btn: button %d, press %d\n", button, press);*/
67 if (client_phone != -1) {
68 async_msg_2(client_phone, MEVENT_BUTTON, button, press);
69 }
70}
71
72void mouse_ev_move(int dx, int dy)
73{
74/* printf("ev_move: dx %d, dy %d\n", dx, dy);*/
75 if (client_phone != -1)
76 async_msg_2(client_phone, MEVENT_MOVE, dx, dy);
77}
78
79static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
80{
81 ipc_callid_t callid;
82 ipc_call_t call;
83 int retval;
84
85 ipc_answer_0(iid, EOK);
86
87 while (1) {
88 callid = async_get_call(&call);
89 switch (IPC_GET_METHOD(call)) {
90 case IPC_M_PHONE_HUNGUP:
91 if (client_phone != -1) {
92 ipc_hangup(client_phone);
93 client_phone = -1;
94 }
95
96 ipc_answer_0(callid, EOK);
97 return;
98 case IPC_M_CONNECT_TO_ME:
99 if (client_phone != -1) {
100 retval = ELIMIT;
101 break;
102 }
103 client_phone = IPC_GET_ARG5(call);
104 retval = 0;
105 break;
106 default:
107 retval = EINVAL;
108 }
109 ipc_answer_0(callid, retval);
110 }
111}
112
113
114int main(int argc, char **argv)
115{
116 printf(NAME ": Chardev mouse driver\n");
117
118 /* Initialize port. */
119 if (mouse_port_init() != 0)
120 return -1;
121
122 /* Initialize protocol driver. */
123 if (mouse_proto_init() != 0)
124 return -1;
125
126 /* Register driver */
127 int rc = devmap_driver_register(NAME, client_connection);
128 if (rc < 0) {
129 printf(NAME ": Unable to register driver (%d)\n", rc);
130 return -1;
131 }
132
133 char dev_path[DEVMAP_NAME_MAXLEN + 1];
134 snprintf(dev_path, DEVMAP_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME);
135
136 dev_handle_t dev_handle;
137 if (devmap_device_register(dev_path, &dev_handle) != EOK) {
138 printf(NAME ": Unable to register device %s\n", dev_path);
139 return -1;
140 }
141
142 printf(NAME ": Accepting connections\n");
143 task_retval(0);
144 async_manager();
145
146 /* Not reached. */
147 return 0;
148}
149
150/**
151 * @}
152 */
Note: See TracBrowser for help on using the repository browser.