Changes in uspace/srv/ns/service.c [8a637a4:4e00f87] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/ns/service.c
r8a637a4 r4e00f87 40 40 #include "ns.h" 41 41 42 42 43 /** Service hash table item. */ 43 44 typedef struct { 44 45 ht_link_t link; 45 46 /** Service ID */ 47 service_t service; 48 49 /** Phone registered with the interface */ 50 sysarg_t phone; 51 52 /** Incoming phone hash */ 53 sysarg_t in_phone_hash; 46 sysarg_t service; /**< Service ID. */ 47 sysarg_t phone; /**< Phone registered with the service. */ 48 sysarg_t in_phone_hash; /**< Incoming phone hash. */ 54 49 } hashed_service_t; 50 55 51 56 52 static size_t service_key_hash(void *key) 57 53 { 58 return *(s ervice_t *)key;54 return *(sysarg_t*)key; 59 55 } 60 56 61 57 static size_t service_hash(const ht_link_t *item) 62 58 { 63 hashed_service_t *service = 64 hash_table_get_inst(item, hashed_service_t, link); 65 66 return service->service; 59 hashed_service_t *hs = hash_table_get_inst(item, hashed_service_t, link); 60 return hs->service; 67 61 } 68 62 69 63 static bool service_key_equal(void *key, const ht_link_t *item) 70 64 { 71 hashed_service_t *service = 72 hash_table_get_inst(item, hashed_service_t, link); 73 74 return service->service == *(service_t *) key; 65 hashed_service_t *hs = hash_table_get_inst(item, hashed_service_t, link); 66 return hs->service == *(sysarg_t*)key; 75 67 } 76 68 … … 90 82 typedef struct { 91 83 link_t link; 92 s ervice_t service; /**< Service ID*/93 i face_t iface; /**< Interface ID*/94 ipc_callid_t callid; /**< Call ID waiting for the connection*/95 sysarg_t arg3; /**< Third argument */84 sysarg_t service; /**< Number of the service. */ 85 ipc_callid_t callid; /**< Call ID waiting for the connection */ 86 sysarg_t arg2; /**< Second argument */ 87 sysarg_t arg3; /**< Third argument */ 96 88 } pending_conn_t; 97 89 … … 100 92 int service_init(void) 101 93 { 102 if (!hash_table_create(&service_hash_table, 0, 0, 103 &service_hash_table_ops)) { 104 printf("%s: No memory available for services\n", NAME); 94 if (!hash_table_create(&service_hash_table, 0, 0, &service_hash_table_ops)) { 95 printf(NAME ": No memory available for services\n"); 105 96 return ENOMEM; 106 97 } … … 115 106 { 116 107 loop: 117 list_foreach(pending_conn, link, pending_conn_t, pending) { 118 ht_link_t *link = hash_table_find(&service_hash_table, &pending->service); 108 list_foreach(pending_conn, cur) { 109 pending_conn_t *pr = list_get_instance(cur, pending_conn_t, link); 110 111 ht_link_t *link = hash_table_find(&service_hash_table, &pr->service); 119 112 if (!link) 120 113 continue; 121 114 122 hashed_service_t *h ashed_service= hash_table_get_inst(link, hashed_service_t, link);123 (void) ipc_forward_fast(p ending->callid, hashed_service->phone,124 p ending->iface, pending->arg3, 0, IPC_FF_NONE);115 hashed_service_t *hs = hash_table_get_inst(link, hashed_service_t, link); 116 (void) ipc_forward_fast(pr->callid, hs->phone, pr->arg2, 117 pr->arg3, 0, IPC_FF_NONE); 125 118 126 list_remove(&pending->link); 127 free(pending); 128 119 list_remove(cur); 120 free(pr); 129 121 goto loop; 130 122 } … … 140 132 * 141 133 */ 142 int register_service(s ervice_t service, sysarg_t phone, ipc_call_t *call)134 int register_service(sysarg_t service, sysarg_t phone, ipc_call_t *call) 143 135 { 144 136 if (hash_table_find(&service_hash_table, &service)) 145 return EEXIST ;137 return EEXISTS; 146 138 147 hashed_service_t *hashed_service = 148 (hashed_service_t *) malloc(sizeof(hashed_service_t)); 149 if (!hashed_service) 139 hashed_service_t *hs = (hashed_service_t *) malloc(sizeof(hashed_service_t)); 140 if (!hs) 150 141 return ENOMEM; 151 142 152 hashed_service->service = service; 153 hashed_service->phone = phone; 154 hashed_service->in_phone_hash = call->in_phone_hash; 155 156 hash_table_insert(&service_hash_table, &hashed_service->link); 143 hs->service = service; 144 hs->phone = phone; 145 hs->in_phone_hash = call->in_phone_hash; 146 hash_table_insert(&service_hash_table, &hs->link); 157 147 158 148 return EOK; … … 162 152 * 163 153 * @param service Service to be connected to. 164 * @param iface Interface to be connected to.165 154 * @param call Pointer to call structure. 166 155 * @param callid Call ID of the request. … … 169 158 * 170 159 */ 171 void connect_to_service(service_t service, iface_t iface, ipc_call_t *call, 172 ipc_callid_t callid) 160 void connect_to_service(sysarg_t service, ipc_call_t *call, ipc_callid_t callid) 173 161 { 174 sysarg_t arg3 = IPC_GET_ARG3(*call);175 sysarg_t flags = IPC_GET_ARG4(*call);176 162 sysarg_t retval; 177 163 178 164 ht_link_t *link = hash_table_find(&service_hash_table, &service); 179 165 if (!link) { 180 if ( flags& IPC_FLAG_BLOCKING) {166 if (IPC_GET_ARG4(*call) & IPC_FLAG_BLOCKING) { 181 167 /* Blocking connection, add to pending list */ 182 pending_conn_t *p ending=168 pending_conn_t *pr = 183 169 (pending_conn_t *) malloc(sizeof(pending_conn_t)); 184 if (!p ending) {170 if (!pr) { 185 171 retval = ENOMEM; 186 172 goto out; 187 173 } 188 174 189 link_initialize(&pending->link); 190 pending->service = service; 191 pending->iface = iface; 192 pending->callid = callid; 193 pending->arg3 = arg3; 194 195 list_append(&pending->link, &pending_conn); 175 link_initialize(&pr->link); 176 pr->service = service; 177 pr->callid = callid; 178 pr->arg2 = IPC_GET_ARG2(*call); 179 pr->arg3 = IPC_GET_ARG3(*call); 180 list_append(&pr->link, &pending_conn); 196 181 return; 197 182 } 198 199 183 retval = ENOENT; 200 184 goto out; 201 185 } 202 186 203 hashed_service_t *h ashed_service= hash_table_get_inst(link, hashed_service_t, link);204 (void) ipc_forward_fast(callid, h ashed_service->phone, iface, arg3,205 0, IPC_FF_NONE);187 hashed_service_t *hs = hash_table_get_inst(link, hashed_service_t, link); 188 (void) ipc_forward_fast(callid, hs->phone, IPC_GET_ARG2(*call), 189 IPC_GET_ARG3(*call), 0, IPC_FF_NONE); 206 190 return; 207 191
Note:
See TracChangeset
for help on using the changeset viewer.