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

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

do not expose the call capability handler from the async framework

Keep the call capability handler encapsulated within the async framework
and do not expose it explicitly via its API. Use the pointer to
ipc_call_t as the sole object identifying an IPC call in the code that
uses the async framework.

This plugs a major leak in the abstraction and also simplifies both the
async framework (slightly) and all IPC servers.

  • 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 <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(ipc_call_t *icall, void *arg)
73{
74 /* Mousedev device structure */
75 mousedev_t *mousedev = (mousedev_t *) arg;
76
77 while (true) {
78 ipc_call_t call;
79 async_get_call(&call);
80
81 if (!IPC_GET_IMETHOD(call)) {
82 mousedev_destroy(mousedev);
83 return;
84 }
85
86 errno_t retval;
87
88 switch (IPC_GET_IMETHOD(call)) {
89 case MOUSEEV_MOVE_EVENT:
90 mouse_push_event_move(mousedev->mouse_dev,
91 IPC_GET_ARG1(call), IPC_GET_ARG2(call),
92 IPC_GET_ARG3(call));
93 retval = EOK;
94 break;
95 case MOUSEEV_ABS_MOVE_EVENT:
96 mouse_push_event_abs_move(mousedev->mouse_dev,
97 IPC_GET_ARG1(call), IPC_GET_ARG2(call),
98 IPC_GET_ARG3(call), IPC_GET_ARG4(call));
99 retval = EOK;
100 break;
101 case MOUSEEV_BUTTON_EVENT:
102 mouse_push_event_button(mousedev->mouse_dev,
103 IPC_GET_ARG1(call), IPC_GET_ARG2(call));
104 retval = EOK;
105 break;
106 default:
107 retval = ENOTSUP;
108 break;
109 }
110
111 async_answer_0(&call, retval);
112 }
113}
114
115static errno_t mousedev_proto_init(mouse_dev_t *mdev)
116{
117 async_sess_t *sess = loc_service_connect(mdev->svc_id, INTERFACE_DDF, 0);
118 if (sess == NULL) {
119 printf("%s: Failed starting session with '%s'\n", NAME,
120 mdev->svc_name);
121 return ENOENT;
122 }
123
124 mousedev_t *mousedev = mousedev_new(mdev);
125 if (mousedev == NULL) {
126 printf("%s: Failed allocating device structure for '%s'.\n",
127 NAME, mdev->svc_name);
128 async_hangup(sess);
129 return ENOMEM;
130 }
131
132 async_exch_t *exch = async_exchange_begin(sess);
133 if (exch == NULL) {
134 printf("%s: Failed starting exchange with '%s'.\n", NAME,
135 mdev->svc_name);
136 mousedev_destroy(mousedev);
137 async_hangup(sess);
138 return ENOENT;
139 }
140
141 port_id_t port;
142 errno_t rc = async_create_callback_port(exch, INTERFACE_MOUSE_CB, 0, 0,
143 mousedev_callback_conn, mousedev, &port);
144
145 async_exchange_end(exch);
146 async_hangup(sess);
147
148 if (rc != EOK) {
149 printf("%s: Failed creating callback connection from '%s'.\n",
150 NAME, mdev->svc_name);
151 mousedev_destroy(mousedev);
152 return rc;
153 }
154
155 return EOK;
156}
157
158mouse_proto_ops_t mousedev_proto = {
159 .init = mousedev_proto_init
160};
161
162/**
163 * @}
164 */
Note: See TracBrowser for help on using the repository browser.