source: mainline/uspace/srv/hid/input/proto/mousedev.c@ 3be9d10

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3be9d10 was 3be9d10, checked in by Jakub Jermar <jakub@…>, 7 years ago

Get rid of ipc_callid_t

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