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

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

unify interface API

  • introduce new interfaces
  • unify location service clients to always expect service ID as the second argument
  • remove obsolete methods that take explicit exchange management arguments (first phase)
  • use interfaces in device drivers, devman, location service, logger, inet
  • 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 <fcntl.h>
40#include <vfs/vfs_sess.h>
41#include <malloc.h>
[854eddd6]42#include <async.h>
43#include <errno.h>
[1875a0c]44#include <ipc/mouseev.h>
[cc574511]45#include <loc.h>
46#include <sys/typefmt.h>
[b6a088f]47#include "../mouse.h"
48#include "../mouse_port.h"
49#include "../mouse_proto.h"
50#include "../input.h"
[1875a0c]51
52/** Mousedev softstate */
53typedef struct {
54 /** Link to generic mouse device */
55 mouse_dev_t *mouse_dev;
56} mousedev_t;
[854eddd6]57
[1875a0c]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;
[854eddd6]67}
68
[1875a0c]69static void mousedev_destroy(mousedev_t *mousedev)
[854eddd6]70{
[1875a0c]71 free(mousedev);
[854eddd6]72}
73
[1875a0c]74static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall,
75 void *arg)
[854eddd6]76{
[1875a0c]77 /* Mousedev device structure */
78 mousedev_t *mousedev = (mousedev_t *) arg;
79
[854eddd6]80 while (true) {
81 ipc_call_t call;
[1875a0c]82 ipc_callid_t callid = async_get_call(&call);
83
[854eddd6]84 if (!IPC_GET_IMETHOD(call)) {
[5288463]85 mousedev_destroy(mousedev);
[854eddd6]86 return;
87 }
[1875a0c]88
89 int retval;
90
[854eddd6]91 switch (IPC_GET_IMETHOD(call)) {
[1875a0c]92 case MOUSEEV_MOVE_EVENT:
[edb3cf2]93 mouse_push_event_move(mousedev->mouse_dev,
94 IPC_GET_ARG1(call), IPC_GET_ARG2(call),
95 IPC_GET_ARG3(call));
[1875a0c]96 retval = EOK;
[854eddd6]97 break;
[8a99c7e]98 case MOUSEEV_ABS_MOVE_EVENT:
99 mouse_push_event_abs_move(mousedev->mouse_dev,
100 IPC_GET_ARG1(call), IPC_GET_ARG2(call),
101 IPC_GET_ARG3(call), IPC_GET_ARG4(call));
102 retval = EOK;
103 break;
[1875a0c]104 case MOUSEEV_BUTTON_EVENT:
[edb3cf2]105 mouse_push_event_button(mousedev->mouse_dev,
106 IPC_GET_ARG1(call), IPC_GET_ARG2(call));
[1875a0c]107 retval = EOK;
[854eddd6]108 break;
109 default:
110 retval = ENOTSUP;
111 break;
112 }
[1875a0c]113
[854eddd6]114 async_answer_0(callid, retval);
115 }
116}
117
[1875a0c]118static int mousedev_proto_init(mouse_dev_t *mdev)
119{
[f9b2cb4c]120 async_sess_t *sess = loc_service_connect(mdev->svc_id, INTERFACE_DDF, 0);
[1875a0c]121 if (sess == NULL) {
[cce8a83]122 printf("%s: Failed starting session with '%s'\n", NAME,
123 mdev->svc_name);
[3123d2a]124 return ENOENT;
[1875a0c]125 }
126
127 mousedev_t *mousedev = mousedev_new(mdev);
128 if (mousedev == NULL) {
129 printf("%s: Failed allocating device structure for '%s'.\n",
[cce8a83]130 NAME, mdev->svc_name);
[5288463]131 async_hangup(sess);
[3123d2a]132 return ENOMEM;
[1875a0c]133 }
134
135 async_exch_t *exch = async_exchange_begin(sess);
136 if (exch == NULL) {
[cc574511]137 printf("%s: Failed starting exchange with '%s'.\n", NAME,
[cce8a83]138 mdev->svc_name);
[1875a0c]139 mousedev_destroy(mousedev);
[5288463]140 async_hangup(sess);
[3123d2a]141 return ENOENT;
[1875a0c]142 }
143
[f9b2cb4c]144 port_id_t port;
145 int rc = async_create_callback_port(exch, INTERFACE_MOUSE_CB, 0, 0,
146 mousedev_callback_conn, mousedev, &port);
147
[1875a0c]148 async_exchange_end(exch);
[5288463]149 async_hangup(sess);
[1875a0c]150
151 if (rc != EOK) {
152 printf("%s: Failed creating callback connection from '%s'.\n",
[cce8a83]153 NAME, mdev->svc_name);
[1875a0c]154 mousedev_destroy(mousedev);
[3123d2a]155 return rc;
[1875a0c]156 }
157
[3123d2a]158 return EOK;
[1875a0c]159}
160
161mouse_proto_ops_t mousedev_proto = {
162 .init = mousedev_proto_init
163};
164
[854eddd6]165/**
166 * @}
167 */
Note: See TracBrowser for help on using the repository browser.