Rev 2598 | Rev 2622 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2598 | Rev 2619 | ||
---|---|---|---|
Line 111... | Line 111... | ||
111 | } |
111 | } |
112 | item = item->next; |
112 | item = item->next; |
113 | } |
113 | } |
114 | 114 | ||
115 | if (item == &devices_list) { |
115 | if (item == &devices_list) { |
116 | printf("DevMap: no device named %s.\n", name); |
116 | printf("DEVMAP: no device named %s.\n", name); |
117 | return NULL; |
117 | return NULL; |
118 | } |
118 | } |
119 | 119 | ||
120 | device = list_get_instance(item, devmap_device_t, devices); |
120 | device = list_get_instance(item, devmap_device_t, devices); |
121 | return device; |
121 | return device; |
Line 187... | Line 187... | ||
187 | *odriver = NULL; |
187 | *odriver = NULL; |
188 | 188 | ||
189 | iid = async_get_call(&icall); |
189 | iid = async_get_call(&icall); |
190 | 190 | ||
191 | if (IPC_GET_METHOD(icall) != DEVMAP_DRIVER_REGISTER) { |
191 | if (IPC_GET_METHOD(icall) != DEVMAP_DRIVER_REGISTER) { |
192 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
192 | ipc_answer_0(iid, EREFUSED); |
193 | return; |
193 | return; |
194 | } |
194 | } |
195 | 195 | ||
196 | if (NULL == |
196 | if (NULL == |
197 | (driver = (devmap_driver_t *)malloc(sizeof(devmap_driver_t)))) { |
197 | (driver = (devmap_driver_t *)malloc(sizeof(devmap_driver_t)))) { |
198 | ipc_answer_fast(iid, ENOMEM, 0, 0); |
198 | ipc_answer_0(iid, ENOMEM); |
199 | return; |
199 | return; |
200 | } |
200 | } |
201 | 201 | ||
202 | /* |
202 | /* |
203 | * Get driver name |
203 | * Get driver name |
204 | */ |
204 | */ |
205 | if (!ipc_data_receive(&callid, &call, NULL, &name_size)) { |
205 | if (!ipc_data_receive(&callid, NULL, &name_size)) { |
206 | printf("Unexpected request: %u.\n", IPC_GET_METHOD(call)); |
206 | printf("Unexpected request.\n"); |
207 | free(driver); |
207 | free(driver); |
208 | ipc_answer_fast(callid, EREFUSED, 0, 0); |
208 | ipc_answer_0(callid, EREFUSED); |
209 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
209 | ipc_answer_0(iid, EREFUSED); |
210 | return; |
210 | return; |
211 | } |
211 | } |
212 | 212 | ||
213 | if (name_size > DEVMAP_NAME_MAXLEN) { |
213 | if (name_size > DEVMAP_NAME_MAXLEN) { |
214 | printf("Too logn name: %u: maximum is %u.\n", name_size, |
214 | printf("Too logn name: %u: maximum is %u.\n", name_size, |
215 | DEVMAP_NAME_MAXLEN); |
215 | DEVMAP_NAME_MAXLEN); |
216 | free(driver); |
216 | free(driver); |
217 | ipc_answer_fast(callid, EINVAL, 0, 0); |
217 | ipc_answer_0(callid, EINVAL); |
218 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
218 | ipc_answer_0(iid, EREFUSED); |
219 | return; |
219 | return; |
220 | } |
220 | } |
221 | 221 | ||
222 | /* |
222 | /* |
223 | * Allocate buffer for device name. |
223 | * Allocate buffer for device name. |
224 | */ |
224 | */ |
225 | if (NULL == (driver->name = (char *)malloc(name_size + 1))) { |
225 | if (NULL == (driver->name = (char *)malloc(name_size + 1))) { |
226 | printf("Cannot allocate space for driver name.\n"); |
226 | printf("Cannot allocate space for driver name.\n"); |
227 | free(driver); |
227 | free(driver); |
228 | ipc_answer_fast(callid, ENOMEM, 0, 0); |
228 | ipc_answer_0(callid, ENOMEM); |
229 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
229 | ipc_answer_0(iid, EREFUSED); |
230 | return; |
230 | return; |
231 | } |
231 | } |
232 | 232 | ||
233 | /* |
233 | /* |
234 | * Send confirmation to sender and get data into buffer. |
234 | * Send confirmation to sender and get data into buffer. |
235 | */ |
235 | */ |
236 | if (EOK != ipc_data_deliver(callid, &call, driver->name, name_size)) { |
236 | if (EOK != ipc_data_deliver(callid, driver->name, name_size)) { |
237 | printf("Cannot read driver name.\n"); |
237 | printf("Cannot read driver name.\n"); |
238 | free(driver->name); |
238 | free(driver->name); |
239 | free(driver); |
239 | free(driver); |
240 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
240 | ipc_answer_0(iid, EREFUSED); |
241 | return; |
241 | return; |
242 | } |
242 | } |
243 | 243 | ||
244 | driver->name[name_size] = 0; |
244 | driver->name[name_size] = 0; |
245 | 245 | ||
Line 248... | Line 248... | ||
248 | /* Initialize futex for list of devices owned by this driver */ |
248 | /* Initialize futex for list of devices owned by this driver */ |
249 | futex_initialize(&(driver->devices_futex), 1); |
249 | futex_initialize(&(driver->devices_futex), 1); |
250 | 250 | ||
251 | /* |
251 | /* |
252 | * Initialize list of asociated devices |
252 | * Initialize list of asociated devices |
253 | */ |
253 | */ |
254 | list_initialize(&(driver->devices)); |
254 | list_initialize(&(driver->devices)); |
255 | 255 | ||
256 | /* |
256 | /* |
257 | * Create connection to the driver |
257 | * Create connection to the driver |
258 | */ |
258 | */ |
259 | callid = async_get_call(&call); |
259 | callid = async_get_call(&call); |
260 | 260 | ||
261 | if (IPC_M_CONNECT_TO_ME != IPC_GET_METHOD(call)) { |
261 | if (IPC_M_CONNECT_TO_ME != IPC_GET_METHOD(call)) { |
262 | printf("DevMap: Unexpected method: %u.\n", |
262 | printf("DEVMAP: Unexpected method: %u.\n", |
263 | IPC_GET_METHOD(call)); |
263 | IPC_GET_METHOD(call)); |
264 | ipc_answer_fast(callid, ENOTSUP, 0, 0); |
264 | ipc_answer_0(callid, ENOTSUP); |
265 | 265 | ||
266 | free(driver->name); |
266 | free(driver->name); |
267 | free(driver); |
267 | free(driver); |
268 | ipc_answer_fast(iid, ENOTSUP, 0, 0); |
268 | ipc_answer_0(iid, ENOTSUP); |
269 | return; |
269 | return; |
270 | } |
270 | } |
271 | 271 | ||
272 | driver->phone = IPC_GET_ARG3(call); |
272 | driver->phone = IPC_GET_ARG3(call); |
273 | 273 | ||
274 | ipc_answer_fast(callid, EOK, 0, 0); |
274 | ipc_answer_0(callid, EOK); |
275 | 275 | ||
276 | list_initialize(&(driver->drivers)); |
276 | list_initialize(&(driver->drivers)); |
277 | 277 | ||
278 | futex_down(&drivers_list_futex); |
278 | futex_down(&drivers_list_futex); |
279 | 279 | ||
Line 285... | Line 285... | ||
285 | * Insert new driver into list of registered drivers |
285 | * Insert new driver into list of registered drivers |
286 | */ |
286 | */ |
287 | list_append(&(driver->drivers), &drivers_list); |
287 | list_append(&(driver->drivers), &drivers_list); |
288 | futex_up(&drivers_list_futex); |
288 | futex_up(&drivers_list_futex); |
289 | 289 | ||
290 | ipc_answer_fast(iid, EOK, 0, 0); |
290 | ipc_answer_0(iid, EOK); |
291 | printf("Driver registered.\n"); |
291 | printf("Driver registered.\n"); |
292 | 292 | ||
293 | *odriver = driver; |
293 | *odriver = driver; |
294 | return; |
294 | return; |
295 | } |
295 | } |
296 | 296 | ||
297 | /** Unregister device driver, unregister all its devices and free driver structure. |
297 | /** Unregister device driver, unregister all its devices and free driver |
298 | * |
298 | * structure. |
299 | */ |
299 | */ |
300 | static int devmap_driver_unregister(devmap_driver_t *driver) |
300 | static int devmap_driver_unregister(devmap_driver_t *driver) |
301 | { |
301 | { |
302 | devmap_device_t *device; |
302 | devmap_device_t *device; |
303 | 303 | ||
Line 345... | Line 345... | ||
345 | 345 | ||
346 | /** Register instance of device |
346 | /** Register instance of device |
347 | * |
347 | * |
348 | */ |
348 | */ |
349 | static void devmap_device_register(ipc_callid_t iid, ipc_call_t *icall, |
349 | static void devmap_device_register(ipc_callid_t iid, ipc_call_t *icall, |
350 | devmap_driver_t *driver) |
350 | devmap_driver_t *driver) |
351 | { |
351 | { |
352 | ipc_callid_t callid; |
352 | ipc_callid_t callid; |
353 | ipc_call_t call; |
- | |
354 | size_t size; |
353 | size_t size; |
355 | devmap_device_t *device; |
354 | devmap_device_t *device; |
356 | 355 | ||
357 | if (NULL == driver) { |
356 | if (NULL == driver) { |
358 | printf("Invalid driver registration.\n"); |
357 | printf("Invalid driver registration.\n"); |
359 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
358 | ipc_answer_0(iid, EREFUSED); |
360 | return; |
359 | return; |
361 | } |
360 | } |
362 | 361 | ||
363 | /* Create new device entry */ |
362 | /* Create new device entry */ |
364 | if (NULL == |
363 | if (NULL == |
365 | (device = (devmap_device_t *)malloc(sizeof(devmap_device_t)))) { |
364 | (device = (devmap_device_t *)malloc(sizeof(devmap_device_t)))) { |
366 | printf("Cannot allocate new device.\n"); |
365 | printf("Cannot allocate new device.\n"); |
367 | ipc_answer_fast(iid, ENOMEM, 0, 0); |
366 | ipc_answer_0(iid, ENOMEM); |
368 | return; |
367 | return; |
369 | } |
368 | } |
370 | 369 | ||
371 | /* Get device name */ |
370 | /* Get device name */ |
372 | if (!ipc_data_receive(&callid, &call, NULL, &size)) { |
371 | if (!ipc_data_receive(&callid, NULL, &size)) { |
373 | free(device); |
372 | free(device); |
374 | printf("Cannot read device name.\n"); |
373 | printf("Cannot read device name.\n"); |
375 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
374 | ipc_answer_0(iid, EREFUSED); |
376 | return; |
375 | return; |
377 | } |
376 | } |
378 | 377 | ||
379 | if (size > DEVMAP_NAME_MAXLEN) { |
378 | if (size > DEVMAP_NAME_MAXLEN) { |
380 | printf("Too long device name: %u.\n", size); |
379 | printf("Too long device name: %u.\n", size); |
381 | free(device); |
380 | free(device); |
382 | ipc_answer_fast(callid, EINVAL, 0, 0); |
381 | ipc_answer_0(callid, EINVAL); |
383 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
382 | ipc_answer_0(iid, EREFUSED); |
384 | return; |
383 | return; |
385 | } |
384 | } |
386 | 385 | ||
387 | /* +1 for terminating \0 */ |
386 | /* +1 for terminating \0 */ |
388 | device->name = (char *)malloc(size + 1); |
387 | device->name = (char *)malloc(size + 1); |
389 | 388 | ||
390 | if (NULL == device->name) { |
389 | if (NULL == device->name) { |
391 | printf("Cannot read device name.\n"); |
390 | printf("Cannot read device name.\n"); |
392 | free(device); |
391 | free(device); |
393 | ipc_answer_fast(callid, ENOMEM, 0, 0); |
392 | ipc_answer_0(callid, ENOMEM); |
394 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
393 | ipc_answer_0(iid, EREFUSED); |
395 | return; |
394 | return; |
396 | } |
395 | } |
397 | 396 | ||
398 | ipc_data_deliver(callid, &call, device->name, size); |
397 | ipc_data_deliver(callid, device->name, size); |
399 | device->name[size] = 0; |
398 | device->name[size] = 0; |
400 | 399 | ||
401 | list_initialize(&(device->devices)); |
400 | list_initialize(&(device->devices)); |
402 | list_initialize(&(device->driver_devices)); |
401 | list_initialize(&(device->driver_devices)); |
403 | 402 | ||
Line 407... | Line 406... | ||
407 | if (NULL != devmap_device_find_name(device->name)) { |
406 | if (NULL != devmap_device_find_name(device->name)) { |
408 | printf("Device '%s' already registered.\n", device->name); |
407 | printf("Device '%s' already registered.\n", device->name); |
409 | futex_up(&devices_list_futex); |
408 | futex_up(&devices_list_futex); |
410 | free(device->name); |
409 | free(device->name); |
411 | free(device); |
410 | free(device); |
412 | ipc_answer_fast(iid, EEXISTS, 0, 0); |
411 | ipc_answer_0(iid, EEXISTS); |
413 | return; |
412 | return; |
414 | } |
413 | } |
415 | 414 | ||
416 | /* Get unique device handle */ |
415 | /* Get unique device handle */ |
417 | device->handle = devmap_create_handle(); |
416 | device->handle = devmap_create_handle(); |
418 | 417 | ||
419 | device->driver = driver; |
418 | device->driver = driver; |
420 | 419 | ||
421 | /* Insert device into list of all devices */ |
420 | /* Insert device into list of all devices */ |
422 | list_append(&(device->devices), &devices_list); |
421 | list_append(&device->devices, &devices_list); |
423 | 422 | ||
424 | /* Insert device into list of devices that belog to one driver */ |
423 | /* Insert device into list of devices that belog to one driver */ |
425 | futex_down(&(device->driver->devices_futex)); |
424 | futex_down(&device->driver->devices_futex); |
426 | 425 | ||
427 | list_append(&(device->driver_devices), &(device->driver->devices)); |
426 | list_append(&device->driver_devices, &device->driver->devices); |
428 | 427 | ||
429 | futex_up(&(device->driver->devices_futex)); |
428 | futex_up(&device->driver->devices_futex); |
430 | futex_up(&devices_list_futex); |
429 | futex_up(&devices_list_futex); |
431 | 430 | ||
432 | printf("Device '%s' registered.\n", device->name); |
431 | printf("Device '%s' registered.\n", device->name); |
433 | ipc_answer_fast(iid, EOK, device->handle, 0); |
432 | ipc_answer_1(iid, EOK, device->handle); |
434 | 433 | ||
435 | return; |
434 | return; |
436 | } |
435 | } |
437 | 436 | ||
438 | /** |
437 | /** |
439 | * |
438 | * |
440 | */ |
439 | */ |
441 | static int devmap_device_unregister(ipc_callid_t iid, ipc_call_t *icall, |
440 | static int devmap_device_unregister(ipc_callid_t iid, ipc_call_t *icall, |
442 | devmap_driver_t *driver) |
441 | devmap_driver_t *driver) |
443 | { |
442 | { |
444 | /* TODO */ |
443 | /* TODO */ |
445 | 444 | ||
446 | return EOK; |
445 | return EOK; |
447 | } |
446 | } |
Line 462... | Line 461... | ||
462 | */ |
461 | */ |
463 | handle = IPC_GET_ARG1(*call); |
462 | handle = IPC_GET_ARG1(*call); |
464 | dev = devmap_device_find_handle(handle); |
463 | dev = devmap_device_find_handle(handle); |
465 | 464 | ||
466 | if (NULL == dev) { |
465 | if (NULL == dev) { |
467 | printf("DevMap: No registered device with handle %d.\n", |
466 | printf("DEVMAP: No registered device with handle %d.\n", |
468 | handle); |
467 | handle); |
469 | ipc_answer_fast(callid, ENOENT, 0, 0); |
468 | ipc_answer_0(callid, ENOENT); |
470 | return; |
469 | return; |
471 | } |
470 | } |
472 | 471 | ||
473 | /* FIXME: is this correct method how to pass argument on forwarding ?*/ |
472 | /* FIXME: is this correct method how to pass argument on forwarding ?*/ |
474 | ipc_forward_fast(callid, dev->driver->phone, (ipcarg_t)(dev->handle), |
473 | ipc_forward_fast(callid, dev->driver->phone, (ipcarg_t)(dev->handle), |
Line 484... | Line 483... | ||
484 | { |
483 | { |
485 | char *name = NULL; |
484 | char *name = NULL; |
486 | size_t name_size; |
485 | size_t name_size; |
487 | const devmap_device_t *dev; |
486 | const devmap_device_t *dev; |
488 | ipc_callid_t callid; |
487 | ipc_callid_t callid; |
489 | ipc_call_t call; |
- | |
490 | ipcarg_t retval; |
488 | ipcarg_t retval; |
491 | 489 | ||
492 | 490 | ||
493 | /* |
491 | /* |
494 | * Wait for incoming message with device name (but do not |
492 | * Wait for incoming message with device name (but do not |
495 | * read the name itself until the buffer is allocated). |
493 | * read the name itself until the buffer is allocated). |
496 | */ |
494 | */ |
497 | if (!ipc_data_receive(&callid, &call, NULL, &name_size)) { |
495 | if (!ipc_data_receive(&callid, NULL, &name_size)) { |
498 | ipc_answer_fast(callid, EREFUSED, 0, 0); |
496 | ipc_answer_0(callid, EREFUSED); |
499 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
497 | ipc_answer_0(iid, EREFUSED); |
500 | return; |
498 | return; |
501 | } |
499 | } |
502 | 500 | ||
503 | if (name_size > DEVMAP_NAME_MAXLEN) { |
501 | if (name_size > DEVMAP_NAME_MAXLEN) { |
504 | ipc_answer_fast(callid, EINVAL, 0, 0); |
502 | ipc_answer_0(callid, EINVAL); |
505 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
503 | ipc_answer_0(iid, EREFUSED); |
506 | return; |
504 | return; |
507 | } |
505 | } |
508 | 506 | ||
509 | /* |
507 | /* |
510 | * Allocate buffer for device name. |
508 | * Allocate buffer for device name. |
511 | */ |
509 | */ |
512 | if (NULL == (name = (char *)malloc(name_size))) { |
510 | if (NULL == (name = (char *)malloc(name_size))) { |
513 | ipc_answer_fast(callid, ENOMEM, 0, 0); |
511 | ipc_answer_0(callid, ENOMEM); |
514 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
512 | ipc_answer_0(iid, EREFUSED); |
515 | return; |
513 | return; |
516 | } |
514 | } |
517 | 515 | ||
518 | /* |
516 | /* |
519 | * Send confirmation to sender and get data into buffer. |
517 | * Send confirmation to sender and get data into buffer. |
520 | */ |
518 | */ |
521 | if (EOK != (retval = ipc_data_deliver(callid, &call, name, |
519 | if (EOK != (retval = ipc_data_deliver(callid, name, name_size))) { |
522 | name_size))) { |
- | |
523 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
520 | ipc_answer_0(iid, EREFUSED); |
524 | return; |
521 | return; |
525 | } |
522 | } |
526 | 523 | ||
527 | /* |
524 | /* |
528 | * Find device name in linked list of known devices. |
525 | * Find device name in linked list of known devices. |
Line 531... | Line 528... | ||
531 | 528 | ||
532 | /* |
529 | /* |
533 | * Device was not found. |
530 | * Device was not found. |
534 | */ |
531 | */ |
535 | if (NULL == dev) { |
532 | if (NULL == dev) { |
536 | printf("DevMap: device %s has not been registered.\n", name); |
533 | printf("DEVMAP: device %s has not been registered.\n", name); |
537 | ipc_answer_fast(iid, ENOENT, 0, 0); |
534 | ipc_answer_0(iid, ENOENT); |
538 | return; |
535 | return; |
539 | } |
536 | } |
540 | 537 | ||
541 | printf("DevMap: device %s has handler %d.\n", name, dev->handle); |
538 | printf("DEVMAP: device %s has handler %d.\n", name, dev->handle); |
542 | 539 | ||
543 | ipc_answer_fast(iid, EOK, dev->handle, 0); |
540 | ipc_answer_1(iid, EOK, dev->handle); |
544 | 541 | ||
545 | return; |
542 | return; |
546 | } |
543 | } |
547 | 544 | ||
548 | /** Find name of device identified by id and send it to caller. |
545 | /** Find name of device identified by id and send it to caller. |
Line 557... | Line 554... | ||
557 | 554 | ||
558 | /* |
555 | /* |
559 | * Device not found. |
556 | * Device not found. |
560 | */ |
557 | */ |
561 | if (NULL == device) { |
558 | if (NULL == device) { |
562 | ipc_answer_fast(iid, ENOENT, 0, 0); |
559 | ipc_answer_0(iid, ENOENT); |
563 | return; |
560 | return; |
564 | } |
561 | } |
565 | 562 | ||
566 | ipc_answer_fast(iid, EOK, 0, 0); |
563 | ipc_answer_0(iid, EOK); |
567 | 564 | ||
568 | name_size = strlen(device->name); |
565 | name_size = strlen(device->name); |
569 | 566 | ||
570 | 567 | ||
571 | /* FIXME: |
568 | /* FIXME: |
572 | we have no channel from DevMap to client -> |
569 | we have no channel from DEVMAP to client -> |
573 | sending must be initiated by client |
570 | sending must be initiated by client |
574 | 571 | ||
575 | int rc = ipc_data_send(phone, device->name, name_size); |
572 | int rc = ipc_data_send(phone, device->name, name_size); |
576 | if (rc != EOK) { |
573 | if (rc != EOK) { |
577 | async_wait_for(req, NULL); |
574 | async_wait_for(req, NULL); |
Line 592... | Line 589... | ||
592 | ipc_callid_t callid; |
589 | ipc_callid_t callid; |
593 | ipc_call_t call; |
590 | ipc_call_t call; |
594 | bool cont = true; |
591 | bool cont = true; |
595 | devmap_driver_t *driver = NULL; |
592 | devmap_driver_t *driver = NULL; |
596 | 593 | ||
597 | ipc_answer_fast(iid, EOK, 0, 0); |
594 | ipc_answer_0(iid, EOK); |
598 | 595 | ||
599 | devmap_driver_register(&driver); |
596 | devmap_driver_register(&driver); |
600 | 597 | ||
601 | if (NULL == driver) { |
598 | if (NULL == driver) { |
602 | printf("DevMap: driver registration failed.\n"); |
599 | printf("DEVMAP: driver registration failed.\n"); |
603 | return; |
600 | return; |
604 | } |
601 | } |
605 | 602 | ||
606 | while (cont) { |
603 | while (cont) { |
607 | callid = async_get_call(&call); |
604 | callid = async_get_call(&call); |
608 | 605 | ||
609 | switch (IPC_GET_METHOD(call)) { |
606 | switch (IPC_GET_METHOD(call)) { |
610 | case IPC_M_PHONE_HUNGUP: |
607 | case IPC_M_PHONE_HUNGUP: |
611 | printf("DevMap: connection hung up.\n"); |
608 | printf("DEVMAP: connection hung up.\n"); |
612 | cont = false; |
609 | cont = false; |
613 | continue; /* Exit thread */ |
610 | continue; /* Exit thread */ |
614 | case DEVMAP_DRIVER_UNREGISTER: |
611 | case DEVMAP_DRIVER_UNREGISTER: |
615 | printf("DevMap: unregister driver.\n"); |
612 | printf("DEVMAP: unregister driver.\n"); |
616 | if (NULL == driver) { |
613 | if (NULL == driver) { |
617 | printf("DevMap: driver was not registered!\n"); |
614 | printf("DEVMAP: driver was not registered!\n"); |
618 | ipc_answer_fast(callid, ENOENT, 0, 0); |
615 | ipc_answer_0(callid, ENOENT); |
619 | } else { |
616 | } else { |
620 | ipc_answer_fast(callid, EOK, 0, 0); |
617 | ipc_answer_0(callid, EOK); |
621 | } |
618 | } |
622 | break; |
619 | break; |
623 | case DEVMAP_DEVICE_REGISTER: |
620 | case DEVMAP_DEVICE_REGISTER: |
624 | /* Register one instance of device */ |
621 | /* Register one instance of device */ |
625 | devmap_device_register(callid, &call, driver); |
622 | devmap_device_register(callid, &call, driver); |
Line 634... | Line 631... | ||
634 | case DEVMAP_DEVICE_GET_NAME: |
631 | case DEVMAP_DEVICE_GET_NAME: |
635 | devmap_get_handle(callid, &call); |
632 | devmap_get_handle(callid, &call); |
636 | break; |
633 | break; |
637 | default: |
634 | default: |
638 | if (!(callid & IPC_CALLID_NOTIFICATION)) { |
635 | if (!(callid & IPC_CALLID_NOTIFICATION)) { |
639 | ipc_answer_fast(callid, ENOENT, 0, 0); |
636 | ipc_answer_0(callid, ENOENT); |
640 | } |
637 | } |
641 | } |
638 | } |
642 | } |
639 | } |
643 | 640 | ||
644 | if (NULL != driver) { |
641 | if (NULL != driver) { |
645 | /* |
642 | /* |
646 | * Unregister the device driver and all its devices. |
643 | * Unregister the device driver and all its devices. |
647 | */ |
644 | */ |
648 | devmap_driver_unregister(driver); |
645 | devmap_driver_unregister(driver); |
649 | driver = NULL; |
646 | driver = NULL; |
650 | } |
647 | } |
651 | 648 | ||
652 | } |
649 | } |
Line 659... | Line 656... | ||
659 | { |
656 | { |
660 | ipc_callid_t callid; |
657 | ipc_callid_t callid; |
661 | ipc_call_t call; |
658 | ipc_call_t call; |
662 | bool cont = true; |
659 | bool cont = true; |
663 | 660 | ||
664 | ipc_answer_fast(iid, EOK, 0, 0); /* Accept connection */ |
661 | ipc_answer_0(iid, EOK); /* Accept connection */ |
665 | 662 | ||
666 | while (cont) { |
663 | while (cont) { |
667 | callid = async_get_call(&call); |
664 | callid = async_get_call(&call); |
668 | 665 | ||
669 | switch (IPC_GET_METHOD(call)) { |
666 | switch (IPC_GET_METHOD(call)) { |
670 | case IPC_M_PHONE_HUNGUP: |
667 | case IPC_M_PHONE_HUNGUP: |
671 | printf("DevMap: connection hung up.\n"); |
668 | printf("DEVMAP: connection hung up.\n"); |
672 | cont = false; |
669 | cont = false; |
673 | continue; /* Exit thread */ |
670 | continue; /* Exit thread */ |
674 | 671 | ||
675 | case DEVMAP_DEVICE_CONNECT_ME_TO: |
672 | case DEVMAP_DEVICE_CONNECT_ME_TO: |
676 | /* Connect client to selected device */ |
673 | /* Connect client to selected device */ |
677 | printf("DevMap: connect to device %d.\n", |
674 | printf("DEVMAP: connect to device %d.\n", |
678 | IPC_GET_ARG1(call)); |
675 | IPC_GET_ARG1(call)); |
679 | devmap_forward(callid, &call); |
676 | devmap_forward(callid, &call); |
680 | break; |
677 | break; |
681 | 678 | ||
682 | case DEVMAP_DEVICE_GET_HANDLE: |
679 | case DEVMAP_DEVICE_GET_HANDLE: |
Line 687... | Line 684... | ||
687 | /* TODO */ |
684 | /* TODO */ |
688 | devmap_get_name(callid, &call); |
685 | devmap_get_name(callid, &call); |
689 | break; |
686 | break; |
690 | default: |
687 | default: |
691 | if (!(callid & IPC_CALLID_NOTIFICATION)) { |
688 | if (!(callid & IPC_CALLID_NOTIFICATION)) { |
692 | ipc_answer_fast(callid, ENOENT, 0, 0); |
689 | ipc_answer_0(callid, ENOENT); |
693 | } |
690 | } |
694 | } |
691 | } |
695 | } |
692 | } |
696 | } |
693 | } |
697 | 694 | ||
Line 700... | Line 697... | ||
700 | */ |
697 | */ |
701 | static void |
698 | static void |
702 | devmap_connection(ipc_callid_t iid, ipc_call_t *icall) |
699 | devmap_connection(ipc_callid_t iid, ipc_call_t *icall) |
703 | { |
700 | { |
704 | 701 | ||
705 | printf("DevMap: new connection.\n"); |
702 | printf("DEVMAP: new connection.\n"); |
706 | 703 | ||
707 | /* Select interface */ |
704 | /* Select interface */ |
708 | switch ((ipcarg_t)(IPC_GET_ARG1(*icall))) { |
705 | switch ((ipcarg_t)(IPC_GET_ARG1(*icall))) { |
709 | case DEVMAP_DRIVER: |
706 | case DEVMAP_DRIVER: |
710 | devmap_connection_driver(iid, icall); |
707 | devmap_connection_driver(iid, icall); |
711 | break; |
708 | break; |
712 | case DEVMAP_CLIENT: |
709 | case DEVMAP_CLIENT: |
713 | devmap_connection_client(iid, icall); |
710 | devmap_connection_client(iid, icall); |
714 | break; |
711 | break; |
715 | default: |
712 | default: |
716 | ipc_answer_fast(iid, ENOENT, 0, 0); /* No such interface */ |
713 | ipc_answer_0(iid, ENOENT); /* No such interface */ |
717 | printf("DevMap: Unknown interface %u.\n", |
714 | printf("DEVMAP: Unknown interface %u.\n", |
718 | (ipcarg_t)(IPC_GET_ARG1(*icall))); |
715 | (ipcarg_t)(IPC_GET_ARG1(*icall))); |
719 | } |
716 | } |
720 | 717 | ||
721 | /* Cleanup */ |
718 | /* Cleanup */ |
722 | 719 | ||
723 | printf("DevMap: connection closed.\n"); |
720 | printf("DEVMAP: connection closed.\n"); |
724 | return; |
721 | return; |
725 | } |
722 | } |
726 | 723 | ||
727 | /** |
724 | /** |
728 | * |
725 | * |
729 | */ |
726 | */ |
730 | int main(int argc, char *argv[]) |
727 | int main(int argc, char *argv[]) |
731 | { |
728 | { |
732 | ipcarg_t phonead; |
729 | ipcarg_t phonead; |
733 | 730 | ||
734 | printf("DevMap: HelenOS device mapper.\n"); |
731 | printf("DEVMAP: HelenOS device mapper.\n"); |
735 | 732 | ||
736 | if (devmap_init() != 0) { |
733 | if (devmap_init() != 0) { |
737 | printf("Error while initializing DevMap service.\n"); |
734 | printf("Error while initializing DEVMAP service.\n"); |
738 | return -1; |
735 | return -1; |
739 | } |
736 | } |
740 | 737 | ||
741 | /* Set a handler of incomming connections */ |
738 | /* Set a handler of incomming connections */ |
742 | async_set_client_connection(devmap_connection); |
739 | async_set_client_connection(devmap_connection); |