[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>
|
---|
[854eddd6] | 45 | #include <input.h>
|
---|
[cc574511] | 46 | #include <loc.h>
|
---|
[854eddd6] | 47 | #include <mouse.h>
|
---|
[1875a0c] | 48 | #include <mouse_port.h>
|
---|
| 49 | #include <mouse_proto.h>
|
---|
[cc574511] | 50 | #include <sys/typefmt.h>
|
---|
[1875a0c] | 51 |
|
---|
| 52 | /** Mousedev softstate */
|
---|
| 53 | typedef struct {
|
---|
| 54 | /** Link to generic mouse device */
|
---|
| 55 | mouse_dev_t *mouse_dev;
|
---|
| 56 |
|
---|
| 57 | /** Session to mouse device */
|
---|
[854eddd6] | 58 | async_sess_t *sess;
|
---|
[1875a0c] | 59 | } mousedev_t;
|
---|
[854eddd6] | 60 |
|
---|
[1875a0c] | 61 | static mousedev_t *mousedev_new(mouse_dev_t *mdev)
|
---|
| 62 | {
|
---|
| 63 | mousedev_t *mousedev = calloc(1, sizeof(mousedev_t));
|
---|
| 64 | if (mousedev == NULL)
|
---|
| 65 | return NULL;
|
---|
| 66 |
|
---|
| 67 | mousedev->mouse_dev = mdev;
|
---|
| 68 |
|
---|
| 69 | return mousedev;
|
---|
[854eddd6] | 70 | }
|
---|
| 71 |
|
---|
[1875a0c] | 72 | static void mousedev_destroy(mousedev_t *mousedev)
|
---|
[854eddd6] | 73 | {
|
---|
[1875a0c] | 74 | if (mousedev->sess != NULL)
|
---|
| 75 | async_hangup(mousedev->sess);
|
---|
| 76 |
|
---|
| 77 | free(mousedev);
|
---|
[854eddd6] | 78 | }
|
---|
| 79 |
|
---|
[1875a0c] | 80 | static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall,
|
---|
| 81 | void *arg)
|
---|
[854eddd6] | 82 | {
|
---|
[1875a0c] | 83 | /* Mousedev device structure */
|
---|
| 84 | mousedev_t *mousedev = (mousedev_t *) arg;
|
---|
| 85 |
|
---|
[854eddd6] | 86 | while (true) {
|
---|
| 87 | ipc_call_t call;
|
---|
[1875a0c] | 88 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 89 |
|
---|
[854eddd6] | 90 | if (!IPC_GET_IMETHOD(call)) {
|
---|
| 91 | /* XXX Handle hangup */
|
---|
| 92 | return;
|
---|
| 93 | }
|
---|
[1875a0c] | 94 |
|
---|
| 95 | int retval;
|
---|
| 96 |
|
---|
[854eddd6] | 97 | switch (IPC_GET_IMETHOD(call)) {
|
---|
[1875a0c] | 98 | case MOUSEEV_MOVE_EVENT:
|
---|
| 99 | mouse_push_event_move(mousedev->mouse_dev, IPC_GET_ARG1(call),
|
---|
[854eddd6] | 100 | IPC_GET_ARG2(call));
|
---|
[1875a0c] | 101 | retval = EOK;
|
---|
[854eddd6] | 102 | break;
|
---|
[1875a0c] | 103 | case MOUSEEV_BUTTON_EVENT:
|
---|
| 104 | mouse_push_event_button(mousedev->mouse_dev, IPC_GET_ARG1(call),
|
---|
[854eddd6] | 105 | IPC_GET_ARG2(call));
|
---|
[1875a0c] | 106 | retval = EOK;
|
---|
[854eddd6] | 107 | break;
|
---|
| 108 | default:
|
---|
| 109 | retval = ENOTSUP;
|
---|
| 110 | break;
|
---|
| 111 | }
|
---|
[1875a0c] | 112 |
|
---|
[854eddd6] | 113 | async_answer_0(callid, retval);
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[1875a0c] | 117 | static int mousedev_proto_init(mouse_dev_t *mdev)
|
---|
| 118 | {
|
---|
[cc574511] | 119 | async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE,
|
---|
[cce8a83] | 120 | mdev->svc_id, 0);
|
---|
[1875a0c] | 121 | if (sess == NULL) {
|
---|
[cce8a83] | 122 | printf("%s: Failed starting session with '%s'\n", NAME,
|
---|
| 123 | mdev->svc_name);
|
---|
[1875a0c] | 124 | return -1;
|
---|
| 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);
|
---|
[1875a0c] | 131 | return -1;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | mousedev->sess = sess;
|
---|
| 135 |
|
---|
| 136 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 137 | if (exch == NULL) {
|
---|
[cc574511] | 138 | printf("%s: Failed starting exchange with '%s'.\n", NAME,
|
---|
[cce8a83] | 139 | mdev->svc_name);
|
---|
[1875a0c] | 140 | mousedev_destroy(mousedev);
|
---|
| 141 | return -1;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | int rc = async_connect_to_me(exch, 0, 0, 0, mousedev_callback_conn, mousedev);
|
---|
| 145 | async_exchange_end(exch);
|
---|
| 146 |
|
---|
| 147 | if (rc != EOK) {
|
---|
| 148 | printf("%s: Failed creating callback connection from '%s'.\n",
|
---|
[cce8a83] | 149 | NAME, mdev->svc_name);
|
---|
[1875a0c] | 150 | mousedev_destroy(mousedev);
|
---|
| 151 | return -1;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | return 0;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | mouse_proto_ops_t mousedev_proto = {
|
---|
| 158 | .init = mousedev_proto_init
|
---|
| 159 | };
|
---|
| 160 |
|
---|
[854eddd6] | 161 | /**
|
---|
| 162 | * @}
|
---|
| 163 | */
|
---|