Changeset b61d47d in mainline for uspace/app/tester/devmap/devmap1.c
- Timestamp:
- 2007-12-02T20:00:14Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 90c35436
- Parents:
- 8df2eab
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/devmap/devmap1.c
r8df2eab rb61d47d 36 36 #include "../tester.h" 37 37 38 #include <time.h> 39 40 #define TEST_DEVICE1 "TestDevice1" 41 #define TEST_DEVICE2 "TestDevice2" 42 43 /** Handle requests from clients 44 * 45 */ 46 static void driver_client_connection(ipc_callid_t iid, ipc_call_t *icall) 47 { 48 ipc_callid_t callid; 49 ipc_call_t call; 50 int retval; 51 52 printf("connected: method=%u arg1=%u, arg2=%u arg3=%u.\n", IPC_GET_METHOD(*icall), 53 IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), IPC_GET_ARG3(*icall)); 54 55 printf("driver_client_connection.\n"); 56 ipc_answer_0(iid, EOK); 57 58 /* Ignore parameters, the connection is already opened */ 59 while (1) { 60 callid = async_get_call(&call); 61 retval = EOK; 62 printf("method=%u arg1=%u, arg2=%u arg3=%u.\n", IPC_GET_METHOD(call), 63 IPC_GET_ARG1(call), IPC_GET_ARG2(call), IPC_GET_ARG3(call)); 64 switch (IPC_GET_METHOD(call)) { 65 case IPC_M_PHONE_HUNGUP: 66 /* TODO: Handle hangup */ 67 return; 68 default: 69 printf("Unknown device method %u.\n", IPC_GET_METHOD(call)); 70 retval = ENOENT; 71 } 72 ipc_answer_0(callid, retval); 73 } 74 return; 75 } 76 77 static int device_client_fibril(void *arg) 78 { 79 int handle; 80 int device_phone; 81 82 handle = (int)arg; 83 84 device_phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, \ 85 DEVMAP_CONNECT_TO_DEVICE, handle); 86 87 if (device_phone < 0) { 88 printf("Failed to connect to devmap as client (handle = %u).\n", 89 handle); 90 return -1; 91 } 92 /* 93 * device_phone = (int) IPC_GET_ARG3(answer); 94 */ 95 printf("Connected to device.\n"); 96 ipc_call_sync_1_0(device_phone, 1024, 1025); 97 /* 98 * ipc_hangup(device_phone); 99 */ 100 ipc_hangup(device_phone); 101 102 return EOK; 103 } 104 105 /** Communication test with device. 106 * @param handle handle to tested instance. 107 */ 108 static int device_client(int handle) 109 { 110 /* fid_t fid; 111 ipc_call_t call; 112 ipc_callid_t callid; 113 114 fid = fibril_create(device_client_fibril, (void *)handle); 115 fibril_add_ready(fid); 116 117 */ 118 return EOK; 119 } 120 121 /** 122 * 123 */ 38 124 static int driver_register(char *name) 39 125 { 40 i nt retval;126 ipcarg_t retval; 41 127 aid_t req; 42 128 ipc_call_t answer; … … 44 130 ipcarg_t callback_phonehash; 45 131 46 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER); 132 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, 133 DEVMAP_DRIVER, 0); 47 134 48 135 while (phone < 0) { 49 136 usleep(100000); 50 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER); 137 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, 138 DEVMAP_DRIVER, 0); 51 139 } 52 140 53 141 req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer); 54 142 55 retval = ipc_data_send(phone, (char *)name, strlen(name) );143 retval = ipc_data_send(phone, (char *)name, strlen(name) + 1); 56 144 57 145 if (retval != EOK) { … … 60 148 } 61 149 150 async_set_client_connection(driver_client_connection); 151 62 152 ipc_connect_to_me(phone, 0, 0, &callback_phonehash); 63 64 async_wait_for(req, NULL); 153 /* 154 if (NULL == async_new_connection(callback_phonehash, 0, NULL, 155 driver_client_connection)) { 156 printf("Failed to create new fibril.\n"); 157 async_wait_for(req, NULL); 158 return -1; 159 } 160 */ 161 async_wait_for(req, &retval); 65 162 printf("Driver '%s' registered.\n", name); 66 163 … … 68 165 } 69 166 70 static int device_ register(int driver_phone, char *name, int *handle)167 static int device_get_handle(int driver_phone, char *name, int *handle) 71 168 { 72 169 ipcarg_t retval; … … 74 171 ipc_call_t answer; 75 172 173 req = async_send_2(driver_phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0, &answer); 174 175 retval = ipc_data_send(driver_phone, name, strlen(name) + 1); 176 177 if (retval != EOK) { 178 printf("Failed to send device name '%s'.\n", name); 179 async_wait_for(req, NULL); 180 return retval; 181 } 182 183 async_wait_for(req, &retval); 184 185 if (NULL != handle) { 186 *handle = -1; 187 } 188 189 if (EOK == retval) { 190 191 if (NULL != handle) { 192 *handle = (int) IPC_GET_ARG1(answer); 193 } 194 printf("Device '%s' has handle %u.\n", name, (int) IPC_GET_ARG1(answer)); 195 } else { 196 printf("Failed to get handle for device '%s'.\n", name); 197 } 198 199 return retval; 200 } 201 202 /** Register new device. 203 * @param driver_phone 204 * @param name Device name. 205 * @param handle Output variable. Handle to the created instance of device. 206 */ 207 static int device_register(int driver_phone, char *name, int *handle) 208 { 209 ipcarg_t retval; 210 aid_t req; 211 ipc_call_t answer; 212 76 213 req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer); 77 214 78 retval = ipc_data_send(driver_phone, (char *)name, strlen(name) );215 retval = ipc_data_send(driver_phone, (char *)name, strlen(name) + 1); 79 216 80 217 if (retval != EOK) { … … 111 248 int dev2_handle; 112 249 int dev3_handle; 250 int handle; 113 251 114 252 /* Register new driver */ … … 120 258 121 259 /* Register new device dev1*/ 122 if (EOK != device_register(driver_phone, "TestDevice1", &dev1_handle)) {260 if (EOK != device_register(driver_phone, TEST_DEVICE1, &dev1_handle)) { 123 261 ipc_hangup(driver_phone); 124 262 return "Error: cannot register device.\n"; 125 263 } 126 127 /* TODO: get handle for dev1*/ 128 129 /* TODO: get handle for dev2 (Should fail unless device is already 264 265 /* Get handle for dev2 (Should fail unless device is already 130 266 * registered by someone else) 131 267 */ 268 if (EOK == device_get_handle(driver_phone, TEST_DEVICE2, &handle)) { 269 ipc_hangup(driver_phone); 270 return "Error: got handle for dev2 before it was registered.\n"; 271 } 132 272 133 273 /* Register new device dev2*/ 134 if (EOK != device_register(driver_phone, "TestDevice2", &dev2_handle)) {274 if (EOK != device_register(driver_phone, TEST_DEVICE2, &dev2_handle)) { 135 275 ipc_hangup(driver_phone); 136 276 return "Error: cannot register device dev2.\n"; 137 277 } 138 278 139 140 279 /* Register again device dev1 */ 141 if (EOK == device_register(driver_phone, "TestDevice1", &dev3_handle)) {280 if (EOK == device_register(driver_phone, TEST_DEVICE1, &dev3_handle)) { 142 281 return "Error: dev1 registered twice.\n"; 143 282 } 144 283 145 /* TODO: get handle for dev2 */ 146 147 /* TODO: */ 284 /* Get handle for dev1*/ 285 if (EOK != device_get_handle(driver_phone, TEST_DEVICE1, &handle)) { 286 ipc_hangup(driver_phone); 287 return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; 288 } 289 290 if (handle != dev1_handle) { 291 ipc_hangup(driver_phone); 292 return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; 293 } 294 295 if (EOK != device_client(dev1_handle)) { 296 ipc_hangup(driver_phone); 297 return "Error: failed client test for 'DEVMAP_DEVICE1'.\n"; 298 } 299 300 /* TODO: */ 148 301 149 302 ipc_hangup(driver_phone);
Note:
See TracChangeset
for help on using the changeset viewer.