Changeset 26e7d6d in mainline for uspace/srv/hid/input/proto/mousedev.c
- Timestamp:
- 2011-09-19T16:31:00Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a347a11
- Parents:
- 3842a955 (diff), 086290d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/proto/mousedev.c
r3842a955 r26e7d6d 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>46 #include <loc.h> 44 47 #include <mouse.h> 45 #include < stdio.h>46 #include < stdlib.h>47 #include < vfs/vfs_sess.h>48 #include <mouse_port.h> 49 #include <mouse_proto.h> 50 #include <sys/typefmt.h> 48 51 49 static void mouse_callback_conn(ipc_callid_t, ipc_call_t *, void *); 52 /** Mousedev softstate */ 53 typedef struct { 54 /** Link to generic mouse device */ 55 mouse_dev_t *mouse_dev; 56 57 /** Session to mouse device */ 58 async_sess_t *sess; 59 } mousedev_t; 50 60 51 static mouse _dev_t *mouse_dev_new(void)61 static mousedev_t *mousedev_new(mouse_dev_t *mdev) 52 62 { 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"); 63 mousedev_t *mousedev = calloc(1, sizeof(mousedev_t)); 64 if (mousedev == NULL) 59 65 return NULL; 60 }61 62 link_initialize(&mdev->mouse_devs);63 return m dev;66 67 mousedev->mouse_dev = mdev; 68 69 return mousedev; 64 70 } 65 71 66 static int mouse_dev_connect(mouse_dev_t *mdev, const char *dev_path)72 static void mousedev_destroy(mousedev_t *mousedev) 67 73 { 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; 74 if (mousedev->sess != NULL) 75 async_hangup(mousedev->sess); 76 77 free(mousedev); 103 78 } 104 79 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) 80 static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall, 81 void *arg) 110 82 { 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 83 /* Mousedev device structure */ 84 mousedev_t *mousedev = (mousedev_t *) arg; 85 133 86 while (true) { 134 87 ipc_call_t call; 135 ipc_callid_t callid; 136 137 callid = async_get_call(&call); 88 ipc_callid_t callid = async_get_call(&call); 89 138 90 if (!IPC_GET_IMETHOD(call)) { 139 91 /* XXX Handle hangup */ 140 92 return; 141 93 } 142 94 95 int retval; 96 143 97 switch (IPC_GET_IMETHOD(call)) { 144 case M EVENT_BUTTON:145 input_event_button(IPC_GET_ARG1(call),98 case MOUSEEV_MOVE_EVENT: 99 mouse_push_event_move(mousedev->mouse_dev, IPC_GET_ARG1(call), 146 100 IPC_GET_ARG2(call)); 147 retval = 0;101 retval = EOK; 148 102 break; 149 case M EVENT_MOVE:150 input_event_move(IPC_GET_ARG1(call),103 case MOUSEEV_BUTTON_EVENT: 104 mouse_push_event_button(mousedev->mouse_dev, IPC_GET_ARG1(call), 151 105 IPC_GET_ARG2(call)); 152 retval = 0;106 retval = EOK; 153 107 break; 154 108 default: … … 156 110 break; 157 111 } 158 112 159 113 async_answer_0(callid, retval); 160 114 } 161 115 } 162 116 117 static int mousedev_proto_init(mouse_dev_t *mdev) 118 { 119 async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE, 120 mdev->svc_id, 0); 121 if (sess == NULL) { 122 printf("%s: Failed starting session with '%s'\n", NAME, 123 mdev->svc_name); 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", 130 NAME, mdev->svc_name); 131 return -1; 132 } 133 134 mousedev->sess = sess; 135 136 async_exch_t *exch = async_exchange_begin(sess); 137 if (exch == NULL) { 138 printf("%s: Failed starting exchange with '%s'.\n", NAME, 139 mdev->svc_name); 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", 149 NAME, mdev->svc_name); 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 163 161 /** 164 162 * @}
Note:
See TracChangeset
for help on using the changeset viewer.