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

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

Mechanically lowercase IPC_SET_*/IPC_GET_*

  • Property mode set to 100644
File size: 4.3 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
[984a9ba]72static void mousedev_callback_conn(ipc_call_t *icall, void *arg)
[854eddd6]73{
[1875a0c]74 /* Mousedev device structure */
75 mousedev_t *mousedev = (mousedev_t *) arg;
[a35b458]76
[854eddd6]77 while (true) {
78 ipc_call_t call;
[984a9ba]79 async_get_call(&call);
[a35b458]80
[fafb8e5]81 if (!ipc_get_imethod(&call)) {
[889cdb1]82 async_answer_0(&call, EOK);
[5288463]83 mousedev_destroy(mousedev);
[854eddd6]84 return;
85 }
[a35b458]86
[b7fd2a0]87 errno_t retval;
[a35b458]88
[fafb8e5]89 switch (ipc_get_imethod(&call)) {
[1875a0c]90 case MOUSEEV_MOVE_EVENT:
[edb3cf2]91 mouse_push_event_move(mousedev->mouse_dev,
[fafb8e5]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,
[fafb8e5]98 ipc_get_arg1(&call), ipc_get_arg2(&call),
99 ipc_get_arg3(&call), ipc_get_arg4(&call));
[8a99c7e]100 retval = EOK;
101 break;
[1875a0c]102 case MOUSEEV_BUTTON_EVENT:
[edb3cf2]103 mouse_push_event_button(mousedev->mouse_dev,
[fafb8e5]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
[984a9ba]112 async_answer_0(&call, retval);
[854eddd6]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.