Changeset a35b458 in mainline for uspace/srv/locsrv
- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- uspace/srv/locsrv
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/locsrv/category.h
r3061bc1 ra35b458 73 73 /** Link to loc_service_t.cat_memb list */ 74 74 link_t svc_link; 75 75 76 76 /** Category */ 77 77 category_t *cat; -
uspace/srv/locsrv/locsrv.c
r3061bc1 ra35b458 100 100 * and implement some version of LRU algorithm, avoid overflow 101 101 */ 102 102 103 103 fibril_mutex_lock(&create_id_mutex); 104 104 last_id++; 105 105 fibril_mutex_unlock(&create_id_mutex); 106 106 107 107 return last_id; 108 108 } … … 121 121 size_t slash_offset = 0; 122 122 size_t slash_after = 0; 123 123 124 124 size_t offset = 0; 125 125 size_t offset_prev = 0; 126 126 wchar_t c; 127 127 128 128 while ((c = str_decode(fqsn, &offset, STR_NO_LIMIT)) != 0) { 129 129 if (c == '/') { … … 134 134 offset_prev = offset; 135 135 } 136 136 137 137 /* More than one slash */ 138 138 if (cnt > 1) 139 139 return false; 140 140 141 141 /* No slash -> namespace is empty */ 142 142 if (cnt == 0) { … … 144 144 if (*ns_name == NULL) 145 145 return false; 146 146 147 147 *name = str_dup(fqsn); 148 148 if (*name == NULL) { … … 150 150 return false; 151 151 } 152 152 153 153 if (str_cmp(*name, "") == 0) { 154 154 free(*name); … … 156 156 return false; 157 157 } 158 158 159 159 return true; 160 160 } 161 161 162 162 /* Exactly one slash */ 163 163 *ns_name = str_ndup(fqsn, slash_offset); 164 164 if (*ns_name == NULL) 165 165 return false; 166 166 167 167 *name = str_dup(fqsn + slash_after); 168 168 if (*name == NULL) { … … 170 170 return false; 171 171 } 172 172 173 173 if (str_cmp(*name, "") == 0) { 174 174 free(*name); … … 176 176 return false; 177 177 } 178 178 179 179 return true; 180 180 } … … 184 184 { 185 185 assert(fibril_mutex_is_locked(&services_list_mutex)); 186 186 187 187 list_foreach(namespaces_list, namespaces, loc_namespace_t, namespace) { 188 188 if (str_cmp(namespace->name, name) == 0) 189 189 return namespace; 190 190 } 191 191 192 192 return NULL; 193 193 } … … 201 201 { 202 202 assert(fibril_mutex_is_locked(&services_list_mutex)); 203 203 204 204 list_foreach(namespaces_list, namespaces, loc_namespace_t, namespace) { 205 205 if (namespace->id == id) 206 206 return namespace; 207 207 } 208 208 209 209 return NULL; 210 210 } … … 215 215 { 216 216 assert(fibril_mutex_is_locked(&services_list_mutex)); 217 217 218 218 list_foreach(services_list, services, loc_service_t, service) { 219 219 if ((str_cmp(service->namespace->name, ns_name) == 0) … … 221 221 return service; 222 222 } 223 223 224 224 return NULL; 225 225 } … … 233 233 { 234 234 assert(fibril_mutex_is_locked(&services_list_mutex)); 235 235 236 236 list_foreach(services_list, services, loc_service_t, service) { 237 237 if (service->id == id) 238 238 return service; 239 239 } 240 240 241 241 return NULL; 242 242 } … … 246 246 { 247 247 loc_namespace_t *namespace; 248 248 249 249 assert(fibril_mutex_is_locked(&services_list_mutex)); 250 250 251 251 namespace = loc_namespace_find_name(ns_name); 252 252 if (namespace != NULL) 253 253 return namespace; 254 254 255 255 namespace = (loc_namespace_t *) malloc(sizeof(loc_namespace_t)); 256 256 if (namespace == NULL) 257 257 return NULL; 258 258 259 259 namespace->name = str_dup(ns_name); 260 260 if (namespace->name == NULL) { … … 262 262 return NULL; 263 263 } 264 264 265 265 namespace->id = loc_create_id(); 266 266 namespace->refcnt = 0; 267 267 268 268 /* 269 269 * Insert new namespace into list of registered namespaces 270 270 */ 271 271 list_append(&(namespace->namespaces), &namespaces_list); 272 272 273 273 return namespace; 274 274 } … … 281 281 if (namespace->refcnt == 0) { 282 282 list_remove(&(namespace->namespaces)); 283 283 284 284 free(namespace->name); 285 285 free(namespace); … … 311 311 assert(fibril_mutex_is_locked(&services_list_mutex)); 312 312 assert(fibril_mutex_is_locked(&cdir.mutex)); 313 313 314 314 loc_namespace_delref(service->namespace); 315 315 list_remove(&(service->services)); 316 316 list_remove(&(service->server_services)); 317 317 318 318 /* Remove service from all categories. */ 319 319 while (!list_empty(&service->cat_memb)) { … … 322 322 svc_link); 323 323 category_t *cat = memb->cat; 324 324 325 325 fibril_mutex_lock(&cat->mutex); 326 326 category_remove_service(memb); 327 327 fibril_mutex_unlock(&cat->mutex); 328 328 } 329 329 330 330 free(service->name); 331 331 free(service); … … 340 340 ipc_call_t icall; 341 341 ipc_callid_t iid = async_get_call(&icall); 342 342 343 343 if (IPC_GET_IMETHOD(icall) != LOC_SERVER_REGISTER) { 344 344 async_answer_0(iid, EREFUSED); 345 345 return NULL; 346 346 } 347 347 348 348 loc_server_t *server = 349 349 (loc_server_t *) malloc(sizeof(loc_server_t)); … … 352 352 return NULL; 353 353 } 354 354 355 355 /* 356 356 * Get server name … … 363 363 return NULL; 364 364 } 365 365 366 366 /* 367 367 * Create connection to the server … … 374 374 return NULL; 375 375 } 376 376 377 377 /* 378 378 * Initialize mutex for list of services … … 380 380 */ 381 381 fibril_mutex_initialize(&server->services_mutex); 382 382 383 383 /* 384 384 * Initialize list of supplied services … … 386 386 list_initialize(&server->services); 387 387 link_initialize(&server->servers); 388 388 389 389 fibril_mutex_lock(&servers_list_mutex); 390 390 391 391 /* TODO: 392 392 * Check that no server with name equal to 393 393 * server->name is registered 394 394 */ 395 395 396 396 /* 397 397 * Insert new server into list of registered servers … … 399 399 list_append(&(server->servers), &servers_list); 400 400 fibril_mutex_unlock(&servers_list_mutex); 401 401 402 402 async_answer_0(iid, EOK); 403 403 404 404 return server; 405 405 } … … 414 414 if (server == NULL) 415 415 return EEXIST; 416 416 417 417 fibril_mutex_lock(&servers_list_mutex); 418 418 419 419 if (server->sess) 420 420 async_hangup(server->sess); 421 421 422 422 /* Remove it from list of servers */ 423 423 list_remove(&(server->servers)); 424 424 425 425 /* Unregister all its services */ 426 426 fibril_mutex_lock(&services_list_mutex); 427 427 fibril_mutex_lock(&server->services_mutex); 428 428 fibril_mutex_lock(&cdir.mutex); 429 429 430 430 while (!list_empty(&server->services)) { 431 431 loc_service_t *service = list_get_instance( … … 434 434 loc_service_unregister_core(service); 435 435 } 436 436 437 437 fibril_mutex_unlock(&cdir.mutex); 438 438 fibril_mutex_unlock(&server->services_mutex); 439 439 fibril_mutex_unlock(&services_list_mutex); 440 440 fibril_mutex_unlock(&servers_list_mutex); 441 441 442 442 /* Free name and server */ 443 443 if (server->name != NULL) 444 444 free(server->name); 445 445 446 446 free(server); 447 447 448 448 loc_category_change_event(); 449 449 return EOK; … … 460 460 return; 461 461 } 462 462 463 463 /* Create new service entry */ 464 464 loc_service_t *service = … … 468 468 return; 469 469 } 470 470 471 471 /* Get fqsn */ 472 472 char *fqsn; … … 478 478 return; 479 479 } 480 480 481 481 char *ns_name; 482 482 if (!loc_fqsn_split(fqsn, &ns_name, &service->name)) { … … 486 486 return; 487 487 } 488 488 489 489 free(fqsn); 490 490 491 491 fibril_mutex_lock(&services_list_mutex); 492 492 493 493 loc_namespace_t *namespace = loc_namespace_create(ns_name); 494 494 free(ns_name); … … 500 500 return; 501 501 } 502 502 503 503 link_initialize(&service->services); 504 504 link_initialize(&service->server_services); 505 505 list_initialize(&service->cat_memb); 506 506 507 507 /* Check that service is not already registered */ 508 508 if (loc_service_find_name(namespace->name, service->name) != NULL) { … … 516 516 return; 517 517 } 518 518 519 519 /* Get unique service ID */ 520 520 service->id = loc_create_id(); … … 522 522 loc_namespace_addref(namespace, service); 523 523 service->server = server; 524 524 525 525 /* Insert service into list of all services */ 526 526 list_append(&service->services, &services_list); 527 527 528 528 /* Insert service into list of services supplied by one server */ 529 529 fibril_mutex_lock(&service->server->services_mutex); 530 530 531 531 list_append(&service->server_services, &service->server->services); 532 532 533 533 fibril_mutex_unlock(&service->server->services_mutex); 534 534 fibril_condvar_broadcast(&services_list_cv); 535 535 fibril_mutex_unlock(&services_list_mutex); 536 536 537 537 async_answer_1(iid, EOK, service->id); 538 538 } … … 545 545 { 546 546 loc_service_t *svc; 547 547 548 548 fibril_mutex_lock(&services_list_mutex); 549 549 svc = loc_service_find_id(IPC_GET_ARG1(*icall)); … … 553 553 return; 554 554 } 555 555 556 556 fibril_mutex_lock(&cdir.mutex); 557 557 loc_service_unregister_core(svc); … … 574 574 size_t act_size; 575 575 category_t *cat; 576 576 577 577 if (!async_data_read_receive(&callid, &size)) { 578 578 async_answer_0(callid, EREFUSED); … … 580 580 return; 581 581 } 582 582 583 583 fibril_mutex_lock(&cdir.mutex); 584 584 585 585 cat = category_get(&cdir, IPC_GET_ARG1(*icall)); 586 586 if (cat == NULL) { … … 590 590 return; 591 591 } 592 592 593 593 act_size = str_size(cat->name); 594 594 if (act_size > size) { … … 598 598 return; 599 599 } 600 600 601 601 errno_t retval = async_data_read_finalize(callid, cat->name, 602 602 min(size, act_size)); 603 603 604 604 fibril_mutex_unlock(&cdir.mutex); 605 605 606 606 async_answer_0(iid, retval); 607 607 } … … 614 614 loc_service_t *svc; 615 615 char *fqn; 616 616 617 617 if (!async_data_read_receive(&callid, &size)) { 618 618 async_answer_0(callid, EREFUSED); … … 620 620 return; 621 621 } 622 622 623 623 fibril_mutex_lock(&services_list_mutex); 624 624 625 625 svc = loc_service_find_id(IPC_GET_ARG1(*icall)); 626 626 if (svc == NULL) { … … 630 630 return; 631 631 } 632 632 633 633 if (asprintf(&fqn, "%s/%s", svc->namespace->name, svc->name) < 0) { 634 634 fibril_mutex_unlock(&services_list_mutex); … … 637 637 return; 638 638 } 639 639 640 640 act_size = str_size(fqn); 641 641 if (act_size > size) { … … 646 646 return; 647 647 } 648 648 649 649 errno_t retval = async_data_read_finalize(callid, fqn, 650 650 min(size, act_size)); 651 651 free(fqn); 652 652 653 653 fibril_mutex_unlock(&services_list_mutex); 654 654 655 655 async_answer_0(iid, retval); 656 656 } … … 662 662 size_t act_size; 663 663 loc_service_t *svc; 664 664 665 665 if (!async_data_read_receive(&callid, &size)) { 666 666 async_answer_0(callid, EREFUSED); … … 668 668 return; 669 669 } 670 670 671 671 fibril_mutex_lock(&services_list_mutex); 672 672 673 673 svc = loc_service_find_id(IPC_GET_ARG1(*icall)); 674 674 if (svc == NULL) { … … 678 678 return; 679 679 } 680 680 681 681 if (svc->server == NULL) { 682 682 fibril_mutex_unlock(&services_list_mutex); … … 685 685 return; 686 686 } 687 687 688 688 act_size = str_size(svc->server->name); 689 689 if (act_size > size) { … … 693 693 return; 694 694 } 695 695 696 696 errno_t retval = async_data_read_finalize(callid, svc->server->name, 697 697 min(size, act_size)); 698 698 699 699 fibril_mutex_unlock(&services_list_mutex); 700 700 701 701 async_answer_0(iid, retval); 702 702 } … … 711 711 { 712 712 fibril_mutex_lock(&services_list_mutex); 713 713 714 714 /* 715 715 * Get ID from request … … 718 718 service_id_t id = IPC_GET_ARG2(*call); 719 719 loc_service_t *svc = loc_service_find_id(id); 720 720 721 721 if ((svc == NULL) || (svc->server == NULL) || (!svc->server->sess)) { 722 722 fibril_mutex_unlock(&services_list_mutex); … … 724 724 return; 725 725 } 726 726 727 727 async_exch_t *exch = async_exchange_begin(svc->server->sess); 728 728 async_forward_fast(callid, exch, iface, svc->id, 0, IPC_FF_NONE); 729 729 async_exchange_end(exch); 730 730 731 731 fibril_mutex_unlock(&services_list_mutex); 732 732 } … … 741 741 { 742 742 char *fqsn; 743 743 744 744 /* Get fqsn */ 745 745 errno_t rc = async_data_write_accept((void **) &fqsn, true, 0, … … 749 749 return; 750 750 } 751 751 752 752 char *ns_name; 753 753 char *name; … … 757 757 return; 758 758 } 759 759 760 760 free(fqsn); 761 761 762 762 fibril_mutex_lock(&services_list_mutex); 763 763 const loc_service_t *svc; 764 764 765 765 recheck: 766 766 767 767 /* 768 768 * Find service name in the list of known services. 769 769 */ 770 770 svc = loc_service_find_name(ns_name, name); 771 771 772 772 /* 773 773 * Device was not found. … … 780 780 goto recheck; 781 781 } 782 782 783 783 async_answer_0(iid, ENOENT); 784 784 free(ns_name); … … 787 787 return; 788 788 } 789 789 790 790 async_answer_1(iid, EOK, svc->id); 791 791 792 792 fibril_mutex_unlock(&services_list_mutex); 793 793 free(ns_name); … … 804 804 { 805 805 char *name; 806 806 807 807 /* Get service name */ 808 808 errno_t rc = async_data_write_accept((void **) &name, true, 0, … … 812 812 return; 813 813 } 814 814 815 815 fibril_mutex_lock(&services_list_mutex); 816 816 const loc_namespace_t *namespace; 817 817 818 818 recheck: 819 819 820 820 /* 821 821 * Find namespace name in the list of known namespaces. 822 822 */ 823 823 namespace = loc_namespace_find_name(name); 824 824 825 825 /* 826 826 * Namespace was not found. … … 833 833 goto recheck; 834 834 } 835 835 836 836 async_answer_0(iid, ENOENT); 837 837 free(name); … … 839 839 return; 840 840 } 841 841 842 842 async_answer_1(iid, EOK, namespace->id); 843 843 844 844 fibril_mutex_unlock(&services_list_mutex); 845 845 free(name); … … 862 862 return; 863 863 } 864 864 865 865 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); 866 866 if (sess == NULL) { … … 869 869 return; 870 870 } 871 871 872 872 cb_sess->sess = sess; 873 873 link_initialize(&cb_sess->cb_sess_list); 874 874 875 875 fibril_mutex_lock(&callback_sess_mutex); 876 876 list_append(&cb_sess->cb_sess_list, &callback_sess_list); 877 877 fibril_mutex_unlock(&callback_sess_mutex); 878 878 879 879 async_answer_0(iid, EOK); 880 880 } … … 883 883 { 884 884 fibril_mutex_lock(&callback_sess_mutex); 885 885 886 886 list_foreach(callback_sess_list, cb_sess_list, cb_sess_t, cb_sess) { 887 887 async_exch_t *exch = async_exchange_begin(cb_sess->sess); … … 889 889 async_exchange_end(exch); 890 890 } 891 891 892 892 fibril_mutex_unlock(&callback_sess_mutex); 893 893 } … … 903 903 char *name; 904 904 category_t *cat; 905 905 906 906 /* Get service name */ 907 907 errno_t rc = async_data_write_accept((void **) &name, true, 0, … … 911 911 return; 912 912 } 913 913 914 914 fibril_mutex_lock(&cdir.mutex); 915 915 … … 920 920 goto cleanup; 921 921 } 922 922 923 923 async_answer_1(iid, EOK, cat->id); 924 924 cleanup: … … 930 930 { 931 931 fibril_mutex_lock(&services_list_mutex); 932 932 933 933 loc_namespace_t *namespace = 934 934 loc_namespace_find_id(IPC_GET_ARG1(*icall)); … … 942 942 } else 943 943 async_answer_1(iid, EOK, LOC_OBJECT_NAMESPACE); 944 944 945 945 fibril_mutex_unlock(&services_list_mutex); 946 946 } … … 956 956 { 957 957 fibril_mutex_lock(&services_list_mutex); 958 958 959 959 loc_namespace_t *namespace = 960 960 loc_namespace_find_id(IPC_GET_ARG1(*icall)); … … 963 963 else 964 964 async_answer_1(iid, EOK, namespace->refcnt); 965 965 966 966 fibril_mutex_unlock(&services_list_mutex); 967 967 } … … 973 973 size_t act_size; 974 974 errno_t rc; 975 975 976 976 if (!async_data_read_receive(&callid, &size)) { 977 977 async_answer_0(callid, EREFUSED); … … 979 979 return; 980 980 } 981 981 982 982 category_id_t *id_buf = (category_id_t *) malloc(size); 983 983 if (id_buf == NULL) { … … 987 987 return; 988 988 } 989 989 990 990 fibril_mutex_lock(&cdir.mutex); 991 991 992 992 rc = categ_dir_get_categories(&cdir, id_buf, size, &act_size); 993 993 if (rc != EOK) { … … 997 997 return; 998 998 } 999 999 1000 1000 fibril_mutex_unlock(&cdir.mutex); 1001 1001 1002 1002 errno_t retval = async_data_read_finalize(callid, id_buf, size); 1003 1003 free(id_buf); 1004 1004 1005 1005 async_answer_1(iid, retval, act_size); 1006 1006 } … … 1015 1015 return; 1016 1016 } 1017 1017 1018 1018 if ((size % sizeof(loc_sdesc_t)) != 0) { 1019 1019 async_answer_0(callid, EINVAL); … … 1021 1021 return; 1022 1022 } 1023 1023 1024 1024 fibril_mutex_lock(&services_list_mutex); 1025 1025 1026 1026 size_t count = size / sizeof(loc_sdesc_t); 1027 1027 if (count != list_count(&namespaces_list)) { … … 1031 1031 return; 1032 1032 } 1033 1033 1034 1034 loc_sdesc_t *desc = (loc_sdesc_t *) malloc(size); 1035 1035 if (desc == NULL) { … … 1039 1039 return; 1040 1040 } 1041 1041 1042 1042 size_t pos = 0; 1043 1043 list_foreach(namespaces_list, namespaces, loc_namespace_t, namespace) { … … 1046 1046 pos++; 1047 1047 } 1048 1048 1049 1049 errno_t retval = async_data_read_finalize(callid, desc, size); 1050 1050 1051 1051 free(desc); 1052 1052 fibril_mutex_unlock(&services_list_mutex); 1053 1053 1054 1054 async_answer_0(iid, retval); 1055 1055 } … … 1059 1059 /* FIXME: Use faster algorithm which can make better use 1060 1060 of namespaces */ 1061 1061 1062 1062 ipc_callid_t callid; 1063 1063 size_t size; … … 1067 1067 return; 1068 1068 } 1069 1069 1070 1070 if ((size % sizeof(loc_sdesc_t)) != 0) { 1071 1071 async_answer_0(callid, EINVAL); … … 1073 1073 return; 1074 1074 } 1075 1075 1076 1076 fibril_mutex_lock(&services_list_mutex); 1077 1077 1078 1078 loc_namespace_t *namespace = 1079 1079 loc_namespace_find_id(IPC_GET_ARG1(*icall)); … … 1084 1084 return; 1085 1085 } 1086 1086 1087 1087 size_t count = size / sizeof(loc_sdesc_t); 1088 1088 if (count != namespace->refcnt) { … … 1092 1092 return; 1093 1093 } 1094 1094 1095 1095 loc_sdesc_t *desc = (loc_sdesc_t *) malloc(size); 1096 1096 if (desc == NULL) { … … 1100 1100 return; 1101 1101 } 1102 1102 1103 1103 size_t pos = 0; 1104 1104 list_foreach(services_list, services, loc_service_t, service) { … … 1109 1109 } 1110 1110 } 1111 1111 1112 1112 errno_t retval = async_data_read_finalize(callid, desc, size); 1113 1113 1114 1114 free(desc); 1115 1115 fibril_mutex_unlock(&services_list_mutex); 1116 1116 1117 1117 async_answer_0(iid, retval); 1118 1118 } … … 1124 1124 size_t act_size; 1125 1125 errno_t rc; 1126 1126 1127 1127 if (!async_data_read_receive(&callid, &size)) { 1128 1128 async_answer_0(callid, EREFUSED); … … 1130 1130 return; 1131 1131 } 1132 1132 1133 1133 fibril_mutex_lock(&cdir.mutex); 1134 1134 1135 1135 category_t *cat = category_get(&cdir, IPC_GET_ARG1(*icall)); 1136 1136 if (cat == NULL) { … … 1140 1140 return; 1141 1141 } 1142 1142 1143 1143 category_id_t *id_buf = (category_id_t *) malloc(size); 1144 1144 if (id_buf == NULL) { … … 1148 1148 return; 1149 1149 } 1150 1150 1151 1151 fibril_mutex_lock(&cat->mutex); 1152 1152 1153 1153 rc = category_get_services(cat, id_buf, size, &act_size); 1154 1154 if (rc != EOK) { … … 1159 1159 return; 1160 1160 } 1161 1161 1162 1162 fibril_mutex_unlock(&cat->mutex); 1163 1163 fibril_mutex_unlock(&cdir.mutex); 1164 1164 1165 1165 errno_t retval = async_data_read_finalize(callid, id_buf, size); 1166 1166 free(id_buf); 1167 1167 1168 1168 async_answer_1(iid, retval, act_size); 1169 1169 } … … 1173 1173 { 1174 1174 fibril_mutex_lock(&null_services_mutex); 1175 1175 1176 1176 unsigned int i; 1177 1177 bool fnd = false; 1178 1178 1179 1179 for (i = 0; i < NULL_SERVICES; i++) { 1180 1180 if (null_services[i] == NULL) { … … 1183 1183 } 1184 1184 } 1185 1185 1186 1186 if (!fnd) { 1187 1187 fibril_mutex_unlock(&null_services_mutex); … … 1189 1189 return; 1190 1190 } 1191 1191 1192 1192 char null[LOC_NAME_MAXLEN]; 1193 1193 snprintf(null, LOC_NAME_MAXLEN, "%u", i); 1194 1194 1195 1195 char *dev_name = str_dup(null); 1196 1196 if (dev_name == NULL) { … … 1199 1199 return; 1200 1200 } 1201 1201 1202 1202 loc_service_t *service = 1203 1203 (loc_service_t *) malloc(sizeof(loc_service_t)); … … 1207 1207 return; 1208 1208 } 1209 1209 1210 1210 fibril_mutex_lock(&services_list_mutex); 1211 1211 1212 1212 loc_namespace_t *namespace = loc_namespace_create("null"); 1213 1213 if (namespace == NULL) { … … 1217 1217 return; 1218 1218 } 1219 1219 1220 1220 link_initialize(&service->services); 1221 1221 link_initialize(&service->server_services); 1222 1222 list_initialize(&service->cat_memb); 1223 1223 1224 1224 /* Get unique service ID */ 1225 1225 service->id = loc_create_id(); 1226 1226 service->server = NULL; 1227 1227 1228 1228 loc_namespace_addref(namespace, service); 1229 1229 service->name = dev_name; 1230 1230 1231 1231 /* 1232 1232 * Insert service into list of all services and into null services array. … … 1237 1237 list_append(&service->server_services, &dummy_null_services); 1238 1238 null_services[i] = service; 1239 1239 1240 1240 fibril_mutex_unlock(&services_list_mutex); 1241 1241 fibril_mutex_unlock(&null_services_mutex); 1242 1242 1243 1243 async_answer_1(iid, EOK, (sysarg_t) i); 1244 1244 } … … 1251 1251 return; 1252 1252 } 1253 1253 1254 1254 fibril_mutex_lock(&null_services_mutex); 1255 1255 1256 1256 if (null_services[i] == NULL) { 1257 1257 fibril_mutex_unlock(&null_services_mutex); … … 1259 1259 return; 1260 1260 } 1261 1261 1262 1262 fibril_mutex_lock(&services_list_mutex); 1263 1263 fibril_mutex_lock(&cdir.mutex); … … 1265 1265 fibril_mutex_unlock(&cdir.mutex); 1266 1266 fibril_mutex_unlock(&services_list_mutex); 1267 1267 1268 1268 null_services[i] = NULL; 1269 1269 1270 1270 fibril_mutex_unlock(&null_services_mutex); 1271 1271 async_answer_0(iid, EOK); … … 1279 1279 service_id_t svc_id; 1280 1280 errno_t retval; 1281 1281 1282 1282 svc_id = IPC_GET_ARG1(*icall); 1283 1283 cat_id = IPC_GET_ARG2(*icall); 1284 1284 1285 1285 fibril_mutex_lock(&services_list_mutex); 1286 1286 fibril_mutex_lock(&cdir.mutex); 1287 1287 1288 1288 cat = category_get(&cdir, cat_id); 1289 1289 svc = loc_service_find_id(svc_id); 1290 1290 1291 1291 if (cat == NULL || svc == NULL) { 1292 1292 fibril_mutex_unlock(&cdir.mutex); … … 1295 1295 return; 1296 1296 } 1297 1297 1298 1298 fibril_mutex_lock(&cat->mutex); 1299 1299 retval = category_add_service(cat, svc); … … 1324 1324 for (i = 0; i < NULL_SERVICES; i++) 1325 1325 null_services[i] = NULL; 1326 1326 1327 1327 categ_dir_init(&cdir); 1328 1328 … … 1368 1368 cat = category_new("virtual"); 1369 1369 categ_dir_add_cat(&cdir, cat); 1370 1370 1371 1371 cat = category_new("nic"); 1372 1372 categ_dir_add_cat(&cdir, cat); 1373 1373 1374 1374 cat = category_new("ieee80211"); 1375 1375 categ_dir_add_cat(&cdir, cat); … … 1383 1383 cat = category_new("renderer"); 1384 1384 categ_dir_add_cat(&cdir, cat); 1385 1385 1386 1386 cat = category_new("audio-pcm"); 1387 1387 categ_dir_add_cat(&cdir, cat); 1388 1388 1389 1389 return true; 1390 1390 } … … 1397 1397 /* Accept connection */ 1398 1398 async_answer_0(iid, EOK); 1399 1399 1400 1400 loc_server_t *server = loc_server_register(); 1401 1401 if (server == NULL) 1402 1402 return; 1403 1403 1404 1404 while (true) { 1405 1405 ipc_call_t call; 1406 1406 ipc_callid_t callid = async_get_call(&call); 1407 1407 1408 1408 if (!IPC_GET_IMETHOD(call)) 1409 1409 break; 1410 1410 1411 1411 switch (IPC_GET_IMETHOD(call)) { 1412 1412 case LOC_SERVER_UNREGISTER: … … 1438 1438 } 1439 1439 } 1440 1440 1441 1441 if (server != NULL) { 1442 1442 /* … … 1455 1455 /* Accept connection */ 1456 1456 async_answer_0(iid, EOK); 1457 1457 1458 1458 while (true) { 1459 1459 ipc_call_t call; 1460 1460 ipc_callid_t callid = async_get_call(&call); 1461 1461 1462 1462 if (!IPC_GET_IMETHOD(call)) 1463 1463 break; 1464 1464 1465 1465 switch (IPC_GET_IMETHOD(call)) { 1466 1466 case LOC_SERVICE_GET_ID: … … 1524 1524 { 1525 1525 printf("%s: HelenOS Location Service\n", NAME); 1526 1526 1527 1527 if (!loc_init()) { 1528 1528 printf("%s: Error while initializing service\n", NAME); 1529 1529 return -1; 1530 1530 } 1531 1531 1532 1532 port_id_t port; 1533 1533 errno_t rc = async_create_port(INTERFACE_LOC_SUPPLIER, … … 1537 1537 return rc; 1538 1538 } 1539 1539 1540 1540 rc = async_create_port(INTERFACE_LOC_CONSUMER, 1541 1541 loc_connection_consumer, NULL, &port); … … 1544 1544 return rc; 1545 1545 } 1546 1546 1547 1547 /* Set a handler of incomming connections */ 1548 1548 async_set_fallback_port_handler(loc_forward, NULL); 1549 1549 1550 1550 /* Register location service at naming service */ 1551 1551 rc = service_register(SERVICE_LOC); … … 1554 1554 return rc; 1555 1555 } 1556 1556 1557 1557 printf("%s: Accepting connections\n", NAME); 1558 1558 async_manager(); 1559 1559 1560 1560 /* Never reached */ 1561 1561 return 0; -
uspace/srv/locsrv/locsrv.h
r3061bc1 ra35b458 49 49 /** Link to servers_list */ 50 50 link_t servers; 51 51 52 52 /** List of services supplied by this server */ 53 53 list_t services; 54 54 55 55 /** Session asociated with this server */ 56 56 async_sess_t *sess; 57 57 58 58 /** Server name */ 59 59 char *name; 60 60 61 61 /** Fibril mutex for list of services owned by this server */ 62 62 fibril_mutex_t services_mutex; … … 69 69 /** Link to namespaces_list */ 70 70 link_t namespaces; 71 71 72 72 /** Unique namespace identifier */ 73 73 service_id_t id; 74 74 75 75 /** Namespace name */ 76 76 char *name; 77 77 78 78 /** Reference count */ 79 79 size_t refcnt; … … 86 86 /** Link to global list of services (services_list) */ 87 87 link_t services; 88 88 89 89 /** Link to server list of services (loc_server_t.services) */ 90 90 link_t server_services; 91 91 92 92 /** Link to list of services in category (category_t.services) */ 93 93 link_t cat_services; 94 94 95 95 /** List of category memberships (svc_categ_t) */ 96 96 list_t cat_memb; 97 97 98 98 /** Unique service identifier */ 99 99 service_id_t id; 100 100 101 101 /** Service namespace */ 102 102 loc_namespace_t *namespace; 103 103 104 104 /** Service name */ 105 105 char *name; 106 106 107 107 /** Supplier of this service */ 108 108 loc_server_t *server;
Note:
See TracChangeset
for help on using the changeset viewer.
