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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[854eddd6]1/*
[1875a0c]2 * Copyright (c) 2011 Martin Decky
[854eddd6]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
[1875a0c]29/** @addtogroup mouse_proto
[854eddd6]30 * @ingroup input
31 * @{
32 */
[1875a0c]33/**
34 * @file
35 * @brief Mouse device connector controller driver.
[854eddd6]36 */
37
[1875a0c]38#include <stdio.h>
39#include <vfs/vfs_sess.h>
[854eddd6]40#include <async.h>
41#include <errno.h>
[1875a0c]42#include <ipc/mouseev.h>
[cc574511]43#include <loc.h>
[38d150e]44#include <stdlib.h>
[b6a088f]45#include "../mouse.h"
46#include "../mouse_port.h"
47#include "../mouse_proto.h"
48#include "../input.h"
[1875a0c]49
50/** Mousedev softstate */
51typedef struct {
52 /** Link to generic mouse device */
53 mouse_dev_t *mouse_dev;
54} mousedev_t;
[854eddd6]55
[1875a0c]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;
[a35b458]61
[1875a0c]62 mousedev->mouse_dev = mdev;
[a35b458]63
[1875a0c]64 return mousedev;
[854eddd6]65}
66
[1875a0c]67static void mousedev_destroy(mousedev_t *mousedev)
[854eddd6]68{
[1875a0c]69 free(mousedev);
[854eddd6]70}
71
[1875a0c]72static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall,
73 void *arg)
[854eddd6]74{
[1875a0c]75 /* Mousedev device structure */
76 mousedev_t *mousedev = (mousedev_t *) arg;
[a35b458]77
[854eddd6]78 while (true) {
79 ipc_call_t call;
[1875a0c]80 ipc_callid_t callid = async_get_call(&call);
[a35b458]81
[854eddd6]82 if (!IPC_GET_IMETHOD(call)) {
[5288463]83 mousedev_destroy(mousedev);
[854eddd6]84 return;
85 }
[a35b458]86
[b7fd2a0]87 errno_t retval;
[a35b458]88
[854eddd6]89 switch (IPC_GET_IMETHOD(call)) {
[1875a0c]90 case MOUSEEV_MOVE_EVENT:
[edb3cf2]91 mouse_push_event_move(mousedev->mouse_dev,
92 IPC_GET_ARG1(call), IPC_GET_ARG2(call),
93 IPC_GET_ARG3(call));
[1875a0c]94 retval = EOK;
[854eddd6]95 break;
[8a99c7e]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;
[1875a0c]102 case MOUSEEV_BUTTON_EVENT:
[edb3cf2]103 mouse_push_event_button(mousedev->mouse_dev,
104 IPC_GET_ARG1(call), IPC_GET_ARG2(call));
[1875a0c]105 retval = EOK;
[854eddd6]106 break;
107 default:
108 retval = ENOTSUP;
109 break;
110 }
[a35b458]111
[854eddd6]112 async_answer_0(callid, retval);
113 }
114}
115
[b7fd2a0]116static errno_t mousedev_proto_init(mouse_dev_t *mdev)
[1875a0c]117{
[f9b2cb4c]118 async_sess_t *sess = loc_service_connect(mdev->svc_id, INTERFACE_DDF, 0);
[1875a0c]119 if (sess == NULL) {
[cce8a83]120 printf("%s: Failed starting session with '%s'\n", NAME,
121 mdev->svc_name);
[3123d2a]122 return ENOENT;
[1875a0c]123 }
[a35b458]124
[1875a0c]125 mousedev_t *mousedev = mousedev_new(mdev);
126 if (mousedev == NULL) {
127 printf("%s: Failed allocating device structure for '%s'.\n",
[cce8a83]128 NAME, mdev->svc_name);
[5288463]129 async_hangup(sess);
[3123d2a]130 return ENOMEM;
[1875a0c]131 }
[a35b458]132
[1875a0c]133 async_exch_t *exch = async_exchange_begin(sess);
134 if (exch == NULL) {
[cc574511]135 printf("%s: Failed starting exchange with '%s'.\n", NAME,
[cce8a83]136 mdev->svc_name);
[1875a0c]137 mousedev_destroy(mousedev);
[5288463]138 async_hangup(sess);
[3123d2a]139 return ENOENT;
[1875a0c]140 }
[a35b458]141
[f9b2cb4c]142 port_id_t port;
[b7fd2a0]143 errno_t rc = async_create_callback_port(exch, INTERFACE_MOUSE_CB, 0, 0,
[f9b2cb4c]144 mousedev_callback_conn, mousedev, &port);
[a35b458]145
[1875a0c]146 async_exchange_end(exch);
[5288463]147 async_hangup(sess);
[a35b458]148
[1875a0c]149 if (rc != EOK) {
150 printf("%s: Failed creating callback connection from '%s'.\n",
[cce8a83]151 NAME, mdev->svc_name);
[1875a0c]152 mousedev_destroy(mousedev);
[3123d2a]153 return rc;
[1875a0c]154 }
[a35b458]155
[3123d2a]156 return EOK;
[1875a0c]157}
158
159mouse_proto_ops_t mousedev_proto = {
160 .init = mousedev_proto_init
161};
162
[854eddd6]163/**
164 * @}
165 */
Note: See TracBrowser for help on using the repository browser.