Changeset 1875a0c in mainline for uspace/srv/hid/input/proto/mousedev.c
- Timestamp:
- 2011-06-21T19:10:20Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 022d9f67
- Parents:
- a9d85df
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/proto/mousedev.c
ra9d85df r1875a0c 1 1 /* 2 * Copyright (c) 2011 Jiri Svoboda2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** 30 * @addtogroup inputgen generic 31 * @brief Mouse device handling. 29 /** @addtogroup mouse_proto 32 30 * @ingroup input 33 31 * @{ 34 32 */ 35 /** @file 33 /** 34 * @file 35 * @brief Mouse device connector controller driver. 36 36 */ 37 37 38 #include <adt/list.h> 38 #include <stdio.h> 39 #include <fcntl.h> 40 #include <vfs/vfs_sess.h> 41 #include <malloc.h> 39 42 #include <async.h> 40 43 #include <errno.h> 41 #include < fcntl.h>44 #include <ipc/mouseev.h> 42 45 #include <input.h> 43 #include <ipc/mouse.h>44 46 #include <mouse.h> 45 #include <stdio.h> 46 #include <stdlib.h> 47 #include <vfs/vfs_sess.h> 47 #include <mouse_port.h> 48 #include <mouse_proto.h> 48 49 49 static void mouse_callback_conn(ipc_callid_t, ipc_call_t *, void *); 50 /** Mousedev softstate */ 51 typedef struct { 52 /** Link to generic mouse device */ 53 mouse_dev_t *mouse_dev; 54 55 /** Session to mouse device */ 56 async_sess_t *sess; 57 58 /** File descriptor of open mousedev device */ 59 int fd; 60 } mousedev_t; 50 61 51 static mouse _dev_t *mouse_dev_new(void)62 static mousedev_t *mousedev_new(mouse_dev_t *mdev) 52 63 { 53 mouse_dev_t *mdev; 54 55 mdev = calloc(1, sizeof(mouse_dev_t)); 56 if (mdev == NULL) { 57 printf(NAME ": Error allocating mouse device. " 58 "Out of memory.\n"); 64 mousedev_t *mousedev = calloc(1, sizeof(mousedev_t)); 65 if (mousedev == NULL) 59 66 return NULL; 60 } 61 62 link_initialize(&mdev->mouse_devs); 63 return mdev; 67 68 mousedev->mouse_dev = mdev; 69 mousedev->fd = -1; 70 71 return mousedev; 64 72 } 65 73 66 static int mouse_dev_connect(mouse_dev_t *mdev, const char *dev_path)74 static void mousedev_destroy(mousedev_t *mousedev) 67 75 { 68 async_sess_t *sess; 69 async_exch_t *exch; 70 int fd; 71 int rc; 72 73 fd = open(dev_path, O_RDWR); 74 if (fd < 0) { 75 return -1; 76 } 77 78 sess = fd_session(EXCHANGE_SERIALIZE, fd); 79 if (sess == NULL) { 80 printf(NAME ": Failed starting session with '%s'\n", dev_path); 81 close(fd); 82 return -1; 83 } 84 85 exch = async_exchange_begin(sess); 86 if (exch == NULL) { 87 printf(NAME ": Failed starting exchange with '%s'.\n", dev_path); 88 return -1; 89 } 90 91 rc = async_connect_to_me(exch, 0, 0, 0, mouse_callback_conn, mdev); 92 if (rc != EOK) { 93 printf(NAME ": Failed creating callback connection from '%s'.\n", 94 dev_path); 95 async_exchange_end(exch); 96 return -1; 97 } 98 99 async_exchange_end(exch); 100 101 mdev->dev_path = dev_path; 102 return 0; 76 if (mousedev->sess != NULL) 77 async_hangup(mousedev->sess); 78 79 if (mousedev->fd >= 0) 80 close(mousedev->fd); 81 82 free(mousedev); 103 83 } 104 84 105 /** Add new mouse device. 106 * 107 * @param dev_path Filesystem path to the device (/dev/class/...) 108 */ 109 int mouse_add_dev(const char *dev_path) 85 static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall, 86 void *arg) 110 87 { 111 mouse_dev_t *mdev; 112 int rc; 113 114 mdev = mouse_dev_new(); 115 if (mdev == NULL) 116 return -1; 117 118 rc = mouse_dev_connect(mdev, dev_path); 119 if (rc != EOK) { 120 free(mdev); 121 return -1; 122 } 123 124 list_append(&mdev->mouse_devs, &mouse_devs); 125 return EOK; 126 } 127 128 /** Mouse device callback connection handler. */ 129 static void mouse_callback_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 130 { 131 int retval; 132 88 /* Mousedev device structure */ 89 mousedev_t *mousedev = (mousedev_t *) arg; 90 133 91 while (true) { 134 92 ipc_call_t call; 135 ipc_callid_t callid; 136 137 callid = async_get_call(&call); 93 ipc_callid_t callid = async_get_call(&call); 94 138 95 if (!IPC_GET_IMETHOD(call)) { 139 96 /* XXX Handle hangup */ 140 97 return; 141 98 } 142 99 100 int retval; 101 143 102 switch (IPC_GET_IMETHOD(call)) { 144 case M EVENT_BUTTON:145 input_event_button(IPC_GET_ARG1(call),103 case MOUSEEV_MOVE_EVENT: 104 mouse_push_event_move(mousedev->mouse_dev, IPC_GET_ARG1(call), 146 105 IPC_GET_ARG2(call)); 147 retval = 0;106 retval = EOK; 148 107 break; 149 case M EVENT_MOVE:150 input_event_move(IPC_GET_ARG1(call),108 case MOUSEEV_BUTTON_EVENT: 109 mouse_push_event_button(mousedev->mouse_dev, IPC_GET_ARG1(call), 151 110 IPC_GET_ARG2(call)); 152 retval = 0;111 retval = EOK; 153 112 break; 154 113 default: … … 156 115 break; 157 116 } 158 117 159 118 async_answer_0(callid, retval); 160 119 } 161 120 } 162 121 122 static int mousedev_proto_init(mouse_dev_t *mdev) 123 { 124 const char *pathname = mdev->dev_path; 125 126 int fd = open(pathname, O_RDWR); 127 if (fd < 0) 128 return -1; 129 130 async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd); 131 if (sess == NULL) { 132 printf("%s: Failed starting session with '%s'\n", NAME, pathname); 133 close(fd); 134 return -1; 135 } 136 137 mousedev_t *mousedev = mousedev_new(mdev); 138 if (mousedev == NULL) { 139 printf("%s: Failed allocating device structure for '%s'.\n", 140 NAME, pathname); 141 return -1; 142 } 143 144 mousedev->fd = fd; 145 mousedev->sess = sess; 146 147 async_exch_t *exch = async_exchange_begin(sess); 148 if (exch == NULL) { 149 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname); 150 mousedev_destroy(mousedev); 151 return -1; 152 } 153 154 int rc = async_connect_to_me(exch, 0, 0, 0, mousedev_callback_conn, mousedev); 155 async_exchange_end(exch); 156 157 if (rc != EOK) { 158 printf("%s: Failed creating callback connection from '%s'.\n", 159 NAME, pathname); 160 mousedev_destroy(mousedev); 161 return -1; 162 } 163 164 return 0; 165 } 166 167 mouse_proto_ops_t mousedev_proto = { 168 .init = mousedev_proto_init 169 }; 170 163 171 /** 164 172 * @}
Note:
See TracChangeset
for help on using the changeset viewer.