source: mainline/uspace/srv/hid/input/proto/mousedev.c@ 711e7fe5

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 711e7fe5 was 711e7fe5, checked in by Prutkov Alex <prutkov.alex@…>, 14 years ago

Added printf module

  • Property mode set to 100755
File size: 4.0 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 <loc.h>
47#include <mouse.h>
48#include <mouse_port.h>
49#include <mouse_proto.h>
50#include <sys/typefmt.h>
51
52/** Mousedev softstate */
53typedef struct {
54 /** Link to generic mouse device */
55 mouse_dev_t *mouse_dev;
56} mousedev_t;
57
58static mousedev_t *mousedev_new(mouse_dev_t *mdev)
59{
60 mousedev_t *mousedev = calloc(1, sizeof(mousedev_t));
61 if (mousedev == NULL)
62 return NULL;
63
64 mousedev->mouse_dev = mdev;
65
66 return mousedev;
67}
68
69static void mousedev_destroy(mousedev_t *mousedev)
70{
71 free(mousedev);
72}
73
74static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall,
75 void *arg)
76{
77 /* Mousedev device structure */
78 mousedev_t *mousedev = (mousedev_t *) arg;
79
80 while (true) {
81 ipc_call_t call;
82 ipc_callid_t callid = async_get_call(&call);
83
84 if (!IPC_GET_IMETHOD(call)) {
85 mousedev_destroy(mousedev);
86 return;
87 }
88
89 int retval;
90
91 switch (IPC_GET_IMETHOD(call)) {
92 case MOUSEEV_MOVE_EVENT:
93 mouse_push_event_move(mousedev->mouse_dev,
94 IPC_GET_ARG1(call), IPC_GET_ARG2(call),
95 IPC_GET_ARG3(call));
96 retval = EOK;
97 break;
98 case MOUSEEV_BUTTON_EVENT:
99 mouse_push_event_button(mousedev->mouse_dev,
100 IPC_GET_ARG1(call), IPC_GET_ARG2(call));
101 retval = EOK;
102 break;
103 default:
104 retval = ENOTSUP;
105 break;
106 }
107
108 async_answer_0(callid, retval);
109 }
110}
111
112static int mousedev_proto_init(mouse_dev_t *mdev)
113{
114 async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE,
115 mdev->svc_id, 0);
116 if (sess == NULL) {
117 printf("%s: Failed starting session with '%s'\n", NAME,
118 mdev->svc_name);
119 return -1;
120 }
121
122 mousedev_t *mousedev = mousedev_new(mdev);
123 if (mousedev == NULL) {
124 printf("%s: Failed allocating device structure for '%s'.\n",
125 NAME, mdev->svc_name);
126 async_hangup(sess);
127 return -1;
128 }
129
130 async_exch_t *exch = async_exchange_begin(sess);
131 if (exch == NULL) {
132 printf("%s: Failed starting exchange with '%s'.\n", NAME,
133 mdev->svc_name);
134 mousedev_destroy(mousedev);
135 async_hangup(sess);
136 return -1;
137 }
138
139 int rc = async_connect_to_me(exch, 0, 0, 0, mousedev_callback_conn, mousedev);
140 async_exchange_end(exch);
141 async_hangup(sess);
142
143 if (rc != EOK) {
144 printf("%s: Failed creating callback connection from '%s'.\n",
145 NAME, mdev->svc_name);
146 mousedev_destroy(mousedev);
147 return -1;
148 }
149
150 return 0;
151}
152
153mouse_proto_ops_t mousedev_proto = {
154 .init = mousedev_proto_init
155};
156
157/**
158 * @}
159 */
Note: See TracBrowser for help on using the repository browser.