Changeset 07b39338 in mainline for uspace/srv/loc/loc.c
- Timestamp:
- 2011-08-20T18:21:49Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ab014d
- Parents:
- 0cf27ee (diff), f00af83 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loc/loc.c
r0cf27ee r07b39338 67 67 **/ 68 68 69 staticFIBRIL_MUTEX_INITIALIZE(services_list_mutex);69 FIBRIL_MUTEX_INITIALIZE(services_list_mutex); 70 70 static FIBRIL_CONDVAR_INITIALIZE(services_list_cv); 71 71 static FIBRIL_MUTEX_INITIALIZE(servers_list_mutex); … … 84 84 /** Service directory ogranized by categories (yellow pages) */ 85 85 static categ_dir_t cdir; 86 87 static FIBRIL_MUTEX_INITIALIZE(callback_sess_mutex); 88 static async_sess_t *callback_sess = NULL; 86 89 87 90 service_id_t loc_create_id(void) … … 308 311 { 309 312 assert(fibril_mutex_is_locked(&services_list_mutex)); 310 313 assert(fibril_mutex_is_locked(&cdir.mutex)); 314 311 315 loc_namespace_delref(service->namespace); 312 316 list_remove(&(service->services)); 313 317 list_remove(&(service->server_services)); 318 319 /* Remove service from all categories. */ 320 while (!list_empty(&service->cat_memb)) { 321 link_t *link = list_first(&service->cat_memb); 322 svc_categ_t *memb = list_get_instance(link, svc_categ_t, 323 svc_link); 324 fibril_mutex_lock(&memb->cat->mutex); 325 category_remove_service(memb); 326 fibril_mutex_unlock(&memb->cat->mutex); 327 } 314 328 315 329 free(service->name); … … 412 426 fibril_mutex_lock(&services_list_mutex); 413 427 fibril_mutex_lock(&server->services_mutex); 428 fibril_mutex_lock(&cdir.mutex); 414 429 415 430 while (!list_empty(&server->services)) { … … 420 435 } 421 436 437 fibril_mutex_unlock(&cdir.mutex); 422 438 fibril_mutex_unlock(&server->services_mutex); 423 439 fibril_mutex_unlock(&services_list_mutex); … … 489 505 link_initialize(&service->services); 490 506 link_initialize(&service->server_services); 507 list_initialize(&service->cat_memb); 491 508 492 509 /* Check that service is not already registered */ … … 526 543 * 527 544 */ 528 static intloc_service_unregister(ipc_callid_t iid, ipc_call_t *icall,545 static void loc_service_unregister(ipc_callid_t iid, ipc_call_t *icall, 529 546 loc_server_t *server) 530 547 { 531 /* TODO */ 532 return EOK; 548 loc_service_t *svc; 549 550 fibril_mutex_lock(&services_list_mutex); 551 svc = loc_service_find_id(IPC_GET_ARG1(*icall)); 552 if (svc == NULL) { 553 fibril_mutex_unlock(&services_list_mutex); 554 async_answer_0(iid, ENOENT); 555 return; 556 } 557 558 fibril_mutex_lock(&cdir.mutex); 559 loc_service_unregister_core(svc); 560 fibril_mutex_unlock(&cdir.mutex); 561 fibril_mutex_unlock(&services_list_mutex); 562 async_answer_0(iid, EOK); 563 } 564 565 static void loc_category_get_name(ipc_callid_t iid, ipc_call_t *icall) 566 { 567 ipc_callid_t callid; 568 size_t size; 569 size_t act_size; 570 category_t *cat; 571 572 if (!async_data_read_receive(&callid, &size)) { 573 async_answer_0(callid, EREFUSED); 574 async_answer_0(iid, EREFUSED); 575 return; 576 } 577 578 fibril_mutex_lock(&cdir.mutex); 579 580 cat = category_get(&cdir, IPC_GET_ARG1(*icall)); 581 if (cat == NULL) { 582 fibril_mutex_unlock(&cdir.mutex); 583 async_answer_0(callid, ENOENT); 584 async_answer_0(iid, ENOENT); 585 return; 586 } 587 588 act_size = str_size(cat->name); 589 if (act_size > size) { 590 fibril_mutex_unlock(&cdir.mutex); 591 async_answer_0(callid, EOVERFLOW); 592 async_answer_0(iid, EOVERFLOW); 593 return; 594 } 595 596 sysarg_t retval = async_data_read_finalize(callid, cat->name, 597 min(size, act_size)); 598 599 fibril_mutex_unlock(&cdir.mutex); 600 601 async_answer_0(iid, retval); 533 602 } 534 603 … … 571 640 async_answer_0(iid, retval); 572 641 } 573 574 642 575 643 /** Connect client to the service. … … 728 796 * 729 797 */ 798 static void loc_callback_create(ipc_callid_t iid, ipc_call_t *icall) 799 { 800 async_sess_t *cb_sess = async_callback_receive(EXCHANGE_SERIALIZE); 801 if (cb_sess == NULL) { 802 async_answer_0(iid, ENOMEM); 803 return; 804 } 805 806 fibril_mutex_lock(&callback_sess_mutex); 807 if (callback_sess != NULL) { 808 fibril_mutex_unlock(&callback_sess_mutex); 809 async_answer_0(iid, EEXIST); 810 return; 811 } 812 813 callback_sess = cb_sess; 814 fibril_mutex_unlock(&callback_sess_mutex); 815 816 async_answer_0(iid, EOK); 817 } 818 819 void loc_category_change_event(void) 820 { 821 fibril_mutex_lock(&callback_sess_mutex); 822 823 if (callback_sess != NULL) { 824 async_exch_t *exch = async_exchange_begin(callback_sess); 825 async_msg_0(exch, LOC_EVENT_CAT_CHANGE); 826 async_exchange_end(exch); 827 } 828 829 fibril_mutex_unlock(&callback_sess_mutex); 830 } 831 832 /** Find ID for category specified by name. 833 * 834 * On success, answer will contain EOK int retval and service ID in arg1. 835 * On failure, error code will be sent in retval. 836 * 837 */ 730 838 static void loc_category_get_id(ipc_callid_t iid, ipc_call_t *icall) 731 839 { … … 1095 1203 1096 1204 fibril_mutex_lock(&services_list_mutex); 1205 fibril_mutex_lock(&cdir.mutex); 1097 1206 loc_service_unregister_core(null_services[i]); 1207 fibril_mutex_unlock(&cdir.mutex); 1098 1208 fibril_mutex_unlock(&services_list_mutex); 1099 1209 … … 1129 1239 1130 1240 async_answer_0(iid, retval); 1241 1242 loc_category_change_event(); 1131 1243 } 1132 1244 … … 1156 1268 1157 1269 cat = category_new("serial"); 1270 categ_dir_add_cat(&cdir, cat); 1271 1272 cat = category_new("usbhc"); 1273 categ_dir_add_cat(&cdir, cat); 1274 1275 cat = category_new("virtual"); 1158 1276 categ_dir_add_cat(&cdir, cat); 1159 1277 … … 1244 1362 loc_namespace_get_id(callid, &call); 1245 1363 break; 1364 case LOC_CALLBACK_CREATE: 1365 loc_callback_create(callid, &call); 1366 break; 1246 1367 case LOC_CATEGORY_GET_ID: 1247 1368 loc_category_get_id(callid, &call); 1369 break; 1370 case LOC_CATEGORY_GET_NAME: 1371 loc_category_get_name(callid, &call); 1248 1372 break; 1249 1373 case LOC_CATEGORY_GET_SVCS:
Note:
See TracChangeset
for help on using the changeset viewer.