Changes in uspace/srv/devman/main.c [1dc4a5e:cc574511] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/main.c
r1dc4a5e rcc574511 64 64 static driver_list_t drivers_list; 65 65 static dev_tree_t device_tree; 66 static class_list_t class_list; 66 67 67 68 /** Register running driver. */ … … 332 333 } 333 334 334 static void devman_add_function_to_cat(ipc_callid_t callid, ipc_call_t *call) 335 static void loc_register_class_dev(dev_class_info_t *cli) 336 { 337 /* Create loc path and name for the service. */ 338 char *loc_pathname = NULL; 339 340 asprintf(&loc_pathname, "%s/%s%c%s", LOC_CLASS_NAMESPACE, 341 cli->dev_class->name, LOC_SEPARATOR, cli->dev_name); 342 if (loc_pathname == NULL) 343 return; 344 345 /* 346 * Register the device with location service and remember its 347 * service ID. 348 */ 349 loc_service_register_with_iface(loc_pathname, 350 &cli->service_id, DEVMAN_CONNECT_FROM_LOC); 351 352 /* 353 * Add device to the hash map of class devices registered with 354 * location service. 355 */ 356 class_add_loc_function(&class_list, cli); 357 358 free(loc_pathname); 359 } 360 361 static void devman_add_function_to_class(ipc_callid_t callid, ipc_call_t *call) 335 362 { 336 363 devman_handle_t handle = IPC_GET_ARG1(*call); … … 338 365 int rc; 339 366 340 /* Get c ategoryname. */341 char *c at_name;342 rc = async_data_write_accept((void **) &c at_name, true,367 /* Get class name. */ 368 char *class_name; 369 rc = async_data_write_accept((void **) &class_name, true, 343 370 0, 0, 0, 0); 344 371 if (rc != EOK) { … … 353 380 } 354 381 355 rc = loc_category_get_id(cat_name, &cat_id, IPC_FLAG_BLOCKING); 382 dev_class_t *cl = get_dev_class(&class_list, class_name); 383 dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL); 384 385 /* Register the device's class alias with location service. */ 386 loc_register_class_dev(class_info); 387 388 rc = loc_category_get_id(class_name, &cat_id, IPC_FLAG_BLOCKING); 356 389 if (rc == EOK) { 357 390 loc_service_add_to_cat(fun->service_id, cat_id); 358 391 } else { 359 392 log_msg(LVL_ERROR, "Failed adding function `%s' to category " 360 "`%s'.", fun->pathname, c at_name);361 } 362 363 log_msg(LVL_NOTE, "Function `%s' added to c ategory`%s'.",364 fun->pathname, c at_name);393 "`%s'.", fun->pathname, class_name); 394 } 395 396 log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.", 397 fun->pathname, class_name, class_info->dev_name); 365 398 366 399 async_answer_0(callid, EOK); … … 416 449 devman_add_function(callid, &call); 417 450 break; 418 case DEVMAN_ADD_DEVICE_TO_C ATEGORY:419 devman_add_function_to_c at(callid, &call);451 case DEVMAN_ADD_DEVICE_TO_CLASS: 452 devman_add_function_to_class(callid, &call); 420 453 break; 421 454 default: … … 450 483 } 451 484 485 /** Find handle for the device instance identified by device class name. */ 486 static void devman_function_get_handle_by_class(ipc_callid_t iid, 487 ipc_call_t *icall) 488 { 489 char *classname; 490 char *devname; 491 492 int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0); 493 if (rc != EOK) { 494 async_answer_0(iid, rc); 495 return; 496 } 497 rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0); 498 if (rc != EOK) { 499 free(classname); 500 async_answer_0(iid, rc); 501 return; 502 } 503 504 505 fun_node_t *fun = find_fun_node_by_class(&class_list, 506 classname, devname); 507 508 free(classname); 509 free(devname); 510 511 if (fun == NULL) { 512 async_answer_0(iid, ENOENT); 513 return; 514 } 515 516 async_answer_1(iid, EOK, fun->handle); 517 } 518 452 519 /** Find device path by its handle. */ 453 520 static void devman_get_device_path_by_handle(ipc_callid_t iid, … … 487 554 } 488 555 489 /** Find handle for the function instance identified by its service ID. */490 static void devman_fun_sid_to_handle(ipc_callid_t iid, ipc_call_t *icall)491 {492 fun_node_t *fun;493 494 fun = find_loc_tree_function(&device_tree, IPC_GET_ARG1(*icall));495 496 if (fun == NULL) {497 async_answer_0(iid, ENOENT);498 return;499 }500 501 async_answer_1(iid, EOK, fun->handle);502 }503 556 504 557 /** Function for handling connections from a client to the device manager. */ … … 519 572 devman_function_get_handle(callid, &call); 520 573 break; 574 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS: 575 devman_function_get_handle_by_class(callid, &call); 576 break; 521 577 case DEVMAN_DEVICE_GET_DEVICE_PATH: 522 578 devman_get_device_path_by_handle(callid, &call); 523 break;524 case DEVMAN_FUN_SID_TO_HANDLE:525 devman_fun_sid_to_handle(callid, &call);526 579 break; 527 580 default: … … 625 678 626 679 fun = find_loc_tree_function(&device_tree, service_id); 680 if (fun == NULL) 681 fun = find_loc_class_function(&class_list, service_id); 627 682 628 683 if (fun == NULL || fun->dev->drv == NULL) { 629 log_msg(LVL_WARN, "devman_connection_loc(): function "630 "not found.\n");631 684 async_answer_0(iid, ENOENT); 632 685 return; … … 634 687 635 688 dev = fun->dev; 689 690 if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) { 691 async_answer_0(iid, EINVAL); 692 return; 693 } 636 694 637 695 async_exch_t *exch = async_exchange_begin(dev->drv->sess); … … 695 753 } 696 754 755 init_class_list(&class_list); 756 697 757 /* 698 758 * !!! devman_connection ... as the device manager is not a real loc
Note:
See TracChangeset
for help on using the changeset viewer.