Changes in uspace/srv/devman/main.c [79ae36dd:3ad7b1c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r79ae36dd r3ad7b1c 39 39 #include <assert.h> 40 40 #include <ipc/services.h> 41 #include < ns.h>41 #include <ipc/ns.h> 42 42 #include <async.h> 43 43 #include <stdio.h> … … 108 108 fibril_mutex_lock(&driver->driver_mutex); 109 109 110 if (driver-> sess) {110 if (driver->phone >= 0) { 111 111 /* We already have a connection to the driver. */ 112 112 log_msg(LVL_ERROR, "Driver '%s' already started.\n", … … 128 128 break; 129 129 case DRIVER_RUNNING: 130 /* Should not happen since we do not have a connected session*/130 /* Should not happen since we do not have a connected phone */ 131 131 assert(false); 132 132 } … … 135 135 log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.", 136 136 driver->name); 137 driver->sess = async_callback_receive(EXCHANGE_SERIALIZE); 138 if (!driver->sess) { 137 ipc_call_t call; 138 ipc_callid_t callid = async_get_call(&call); 139 if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) { 139 140 fibril_mutex_unlock(&driver->driver_mutex); 141 async_answer_0(callid, ENOTSUP); 140 142 async_answer_0(iid, ENOTSUP); 141 143 return NULL; 142 144 } 143 145 146 /* Remember driver's phone. */ 147 driver->phone = IPC_GET_ARG5(call); 148 144 149 fibril_mutex_unlock(&driver->driver_mutex); 145 150 146 log_msg(LVL_NOTE, 151 log_msg(LVL_NOTE, 147 152 "The `%s' driver was successfully registered as running.", 148 153 driver->name); 149 154 155 async_answer_0(callid, EOK); 150 156 async_answer_0(iid, EOK); 151 157 … … 428 434 fibril_add_ready(fid); 429 435 430 while (true) { 431 ipc_call_t call; 432 ipc_callid_t callid = async_get_call(&call); 433 434 if (!IPC_GET_IMETHOD(call)) 435 break; 436 ipc_callid_t callid; 437 ipc_call_t call; 438 bool cont = true; 439 while (cont) { 440 callid = async_get_call(&call); 436 441 437 442 switch (IPC_GET_IMETHOD(call)) { 443 case IPC_M_PHONE_HUNGUP: 444 cont = false; 445 continue; 438 446 case DEVMAN_ADD_FUNCTION: 439 447 devman_add_function(callid, &call); … … 507 515 } 508 516 509 /** Find device path by its handle. */510 static void devman_get_device_path_by_handle(ipc_callid_t iid,511 ipc_call_t *icall)512 {513 devman_handle_t handle = IPC_GET_ARG1(*icall);514 515 fun_node_t *fun = find_fun_node(&device_tree, handle);516 if (fun == NULL) {517 async_answer_0(iid, ENOMEM);518 return;519 }520 521 ipc_callid_t data_callid;522 size_t data_len;523 if (!async_data_read_receive(&data_callid, &data_len)) {524 async_answer_0(iid, EINVAL);525 return;526 }527 528 void *buffer = malloc(data_len);529 if (buffer == NULL) {530 async_answer_0(data_callid, ENOMEM);531 async_answer_0(iid, ENOMEM);532 return;533 }534 535 size_t sent_length = str_size(fun->pathname);536 if (sent_length > data_len) {537 sent_length = data_len;538 }539 540 async_data_read_finalize(data_callid, fun->pathname, sent_length);541 async_answer_0(iid, EOK);542 543 free(buffer);544 }545 546 517 547 518 /** Function for handling connections from a client to the device manager. */ … … 551 522 async_answer_0(iid, EOK); 552 523 553 while (true) { 524 bool cont = true; 525 while (cont) { 554 526 ipc_call_t call; 555 527 ipc_callid_t callid = async_get_call(&call); 556 528 557 if (!IPC_GET_IMETHOD(call))558 break;559 560 529 switch (IPC_GET_IMETHOD(call)) { 530 case IPC_M_PHONE_HUNGUP: 531 cont = false; 532 continue; 561 533 case DEVMAN_DEVICE_GET_HANDLE: 562 534 devman_function_get_handle(callid, &call); … … 564 536 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS: 565 537 devman_function_get_handle_by_class(callid, &call); 566 break;567 case DEVMAN_DEVICE_GET_DEVICE_PATH:568 devman_get_device_path_by_handle(callid, &call);569 538 break; 570 539 default: … … 637 606 method = DRIVER_CLIENT; 638 607 639 if (!driver->sess) { 640 log_msg(LVL_ERROR, 641 "Could not forward to driver `%s'.", driver->name); 608 if (driver->phone < 0) { 609 log_msg(LVL_ERROR, 610 "Could not forward to driver `%s' (phone is %d).", 611 driver->name, (int) driver->phone); 642 612 async_answer_0(iid, EINVAL); 643 613 return; … … 653 623 dev->pfun->pathname, driver->name); 654 624 } 655 656 async_exch_t *exch = async_exchange_begin(driver->sess); 657 async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE); 658 async_exchange_end(exch); 625 626 async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE); 659 627 } 660 628 … … 678 646 dev = fun->dev; 679 647 680 if ( (dev->state != DEVICE_USABLE) || (!dev->drv->sess)) {648 if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) { 681 649 async_answer_0(iid, EINVAL); 682 650 return; 683 651 } 684 652 685 async_exch_t *exch = async_exchange_begin(dev->drv->sess); 686 async_forward_fast(iid, exch, DRIVER_CLIENT, fun->handle, 0, 653 async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0, 687 654 IPC_FF_NONE); 688 async_exchange_end(exch); 689 690 log_msg(LVL_DEBUG, 655 log_msg(LVL_DEBUG, 691 656 "Forwarding devmapper request for `%s' function to driver `%s'.", 692 657 fun->pathname, dev->drv->name); … … 780 745 781 746 printf(NAME ": Accepting connections.\n"); 782 task_retval(0);783 747 async_manager(); 784 748
Note:
See TracChangeset
for help on using the changeset viewer.