Changeset cc574511 in mainline for uspace/srv/loc
- Timestamp:
- 2011-08-16T12:37:58Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 16dc887
- Parents:
- 86ffa27f
- Location:
- uspace/srv/loc
- Files:
-
- 3 added
- 2 edited
-
Makefile (modified) (1 diff)
-
category.c (added)
-
category.h (added)
-
loc.c (modified) (8 diffs)
-
loc.h (added)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loc/Makefile
r86ffa27f rcc574511 33 33 34 34 SOURCES = \ 35 category.c \ 35 36 loc.c 36 37 -
uspace/srv/loc/loc.c
r86ffa27f rcc574511 49 49 #include <assert.h> 50 50 51 #include "category.h" 52 #include "loc.h" 53 51 54 #define NAME "loc" 52 55 #define NULL_SERVICES 256 53 54 /** Representation of server (supplier).55 *56 * Each server supplies a set of services.57 *58 */59 typedef struct {60 /** Link to servers_list */61 link_t servers;62 63 /** List of services supplied by this server */64 list_t services;65 66 /** Session asociated with this server */67 async_sess_t *sess;68 69 /** Server name */70 char *name;71 72 /** Fibril mutex for list of services owned by this server */73 fibril_mutex_t services_mutex;74 } loc_server_t;75 76 /** Info about registered namespaces77 *78 */79 typedef struct {80 /** Link to namespaces_list */81 link_t namespaces;82 83 /** Unique namespace identifier */84 service_id_t id;85 86 /** Namespace name */87 char *name;88 89 /** Reference count */90 size_t refcnt;91 } loc_namespace_t;92 93 /** Info about registered service94 *95 */96 typedef struct {97 /** Link to global list of services (services_list) */98 link_t services;99 /** Link to server list of services (loc_server_t.services) */100 link_t server_services;101 /** Unique service identifier */102 service_id_t id;103 /** Service namespace */104 loc_namespace_t *namespace;105 /** Service name */106 char *name;107 /** Supplier of this service */108 loc_server_t *server;109 /** Use this interface when forwarding to server. */110 sysarg_t forward_interface;111 } loc_service_t;112 56 113 57 LIST_INITIALIZE(services_list); … … 137 81 static LIST_INITIALIZE(dummy_null_services); 138 82 139 static service_id_t loc_create_id(void) 83 /** Service directory ogranized by categories (yellow pages) */ 84 static categ_dir_t cdir; 85 86 service_id_t loc_create_id(void) 140 87 { 141 88 /* TODO: allow reusing old ids after their unregistration … … 734 681 } 735 682 683 /** Find ID for category specified by name. 684 * 685 * On success, answer will contain EOK int retval and service ID in arg1. 686 * On failure, error code will be sent in retval. 687 * 688 */ 689 static void loc_category_get_id(ipc_callid_t iid, ipc_call_t *icall) 690 { 691 char *name; 692 category_t *cat; 693 694 /* Get service name */ 695 int rc = async_data_write_accept((void **) &name, true, 0, 696 LOC_NAME_MAXLEN, 0, NULL); 697 if (rc != EOK) { 698 async_answer_0(iid, rc); 699 return; 700 } 701 702 fibril_mutex_lock(&cdir.mutex); 703 704 cat = category_find_by_name(&cdir, name); 705 if (cat == NULL) { 706 /* Category not found */ 707 async_answer_0(iid, ENOENT); 708 goto cleanup; 709 } 710 711 async_answer_1(iid, EOK, cat->id); 712 cleanup: 713 fibril_mutex_unlock(&cdir.mutex); 714 free(name); 715 } 716 736 717 static void loc_id_probe(ipc_callid_t iid, ipc_call_t *icall) 737 718 { … … 892 873 } 893 874 875 static void loc_category_get_svcs(ipc_callid_t iid, ipc_call_t *icall) 876 { 877 ipc_callid_t callid; 878 size_t size; 879 size_t act_size; 880 int rc; 881 882 if (!async_data_read_receive(&callid, &size)) { 883 async_answer_0(callid, EREFUSED); 884 async_answer_0(iid, EREFUSED); 885 return; 886 } 887 888 fibril_mutex_lock(&cdir.mutex); 889 890 category_t *cat = category_get(&cdir, IPC_GET_ARG1(*icall)); 891 if (cat == NULL) { 892 fibril_mutex_unlock(&cdir.mutex); 893 async_answer_0(callid, ENOENT); 894 async_answer_0(iid, ENOENT); 895 return; 896 } 897 898 category_id_t *id_buf = (category_id_t *) malloc(size); 899 if (id_buf == NULL) { 900 fibril_mutex_unlock(&cdir.mutex); 901 async_answer_0(callid, ENOMEM); 902 async_answer_0(iid, ENOMEM); 903 return; 904 } 905 906 fibril_mutex_lock(&cat->mutex); 907 908 rc = category_get_services(cat, id_buf, size, &act_size); 909 if (rc != EOK) { 910 fibril_mutex_unlock(&cat->mutex); 911 fibril_mutex_unlock(&cdir.mutex); 912 async_answer_0(callid, rc); 913 async_answer_0(iid, rc); 914 return; 915 } 916 917 fibril_mutex_unlock(&cat->mutex); 918 fibril_mutex_unlock(&cdir.mutex); 919 920 sysarg_t retval = async_data_read_finalize(callid, id_buf, size); 921 free(id_buf); 922 923 async_answer_1(iid, retval, act_size); 924 } 925 926 894 927 static void loc_null_create(ipc_callid_t iid, ipc_call_t *icall) 895 928 { … … 991 1024 } 992 1025 1026 static void loc_service_add_to_cat(ipc_callid_t iid, ipc_call_t *icall) 1027 { 1028 category_t *cat; 1029 loc_service_t *svc; 1030 catid_t cat_id; 1031 service_id_t svc_id; 1032 sysarg_t retval; 1033 1034 svc_id = IPC_GET_ARG1(*icall); 1035 cat_id = IPC_GET_ARG2(*icall); 1036 1037 fibril_mutex_lock(&services_list_mutex); 1038 fibril_mutex_lock(&cdir.mutex); 1039 1040 cat = category_get(&cdir, cat_id); 1041 svc = loc_service_find_id(svc_id); 1042 1043 fibril_mutex_lock(&cat->mutex); 1044 retval = category_add_service(cat, svc); 1045 1046 fibril_mutex_unlock(&cat->mutex); 1047 fibril_mutex_unlock(&cdir.mutex); 1048 fibril_mutex_unlock(&services_list_mutex); 1049 1050 async_answer_0(iid, retval); 1051 } 1052 1053 993 1054 /** Initialize location service. 994 1055 * … … 997 1058 static bool loc_init(void) 998 1059 { 999 fibril_mutex_lock(&null_services_mutex);1000 1001 1060 unsigned int i; 1061 category_t *cat; 1062 1002 1063 for (i = 0; i < NULL_SERVICES; i++) 1003 1064 null_services[i] = NULL; 1004 1065 1005 fibril_mutex_unlock(&null_services_mutex); 1006 1066 categ_dir_init(&cdir); 1067 1068 cat = category_new("bd"); 1069 categ_dir_add_cat(&cdir, cat); 1070 1071 cat = category_new("keyboard"); 1072 categ_dir_add_cat(&cdir, cat); 1073 1074 cat = category_new("mouse"); 1075 categ_dir_add_cat(&cdir, cat); 1076 1077 cat = category_new("serial"); 1078 categ_dir_add_cat(&cdir, cat); 1079 1007 1080 return true; 1008 1081 } … … 1034 1107 async_answer_0(callid, EOK); 1035 1108 break; 1109 case LOC_SERVICE_ADD_TO_CAT: 1110 /* Add service to category */ 1111 loc_service_add_to_cat(callid, &call); 1112 break; 1036 1113 case LOC_SERVICE_REGISTER: 1037 1114 /* Register one service */ … … 1083 1160 case LOC_NAMESPACE_GET_ID: 1084 1161 loc_namespace_get_id(callid, &call); 1162 break; 1163 case LOC_CATEGORY_GET_ID: 1164 loc_category_get_id(callid, &call); 1165 break; 1166 case LOC_CATEGORY_GET_SVCS: 1167 loc_category_get_svcs(callid, &call); 1085 1168 break; 1086 1169 case LOC_ID_PROBE:
Note:
See TracChangeset
for help on using the changeset viewer.
