Changeset 7b616e2 in mainline
- Timestamp:
- 2017-09-27T22:40:09Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d076f16
- Parents:
- 8d6bcc8c
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/ns.c
r8d6bcc8c r7b616e2 40 40 #include "private/ns.h" 41 41 42 /* 43 * XXX ns does not know about session_ns, so we create an extra session for 44 * actual communicaton 45 */ 46 static async_sess_t *sess_ns = NULL; 47 42 48 int service_register(service_t service) 43 49 { 44 async_exch_t *exch = async_exchange_begin(session_ns); 50 sysarg_t retval; 51 ipc_call_t answer; 52 53 async_sess_t *sess = ns_session_get(); 54 if (sess == NULL) 55 return EIO; 56 57 async_exch_t *exch = async_exchange_begin(sess); 58 aid_t req = async_send_1(exch, NS_REGISTER, service, &answer); 45 59 int rc = async_connect_to_me(exch, 0, service, 0); 60 46 61 async_exchange_end(exch); 47 62 63 if (rc != EOK) { 64 async_forget(req); 65 return rc; 66 } 67 68 async_wait_for(req, &retval); 48 69 return rc; 49 70 } 50 71 51 52 72 async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3) 53 73 { 54 async_ exch_t *exch = async_exchange_begin(session_ns);55 if ( !exch)74 async_sess_t *sess = ns_session_get(); 75 if (sess == NULL) 56 76 return NULL; 57 77 58 async_sess_t *sess = 78 async_exch_t *exch = async_exchange_begin(sess); 79 if (exch == NULL) 80 return NULL; 81 82 async_sess_t *csess = 59 83 async_connect_me_to_iface(exch, iface, service, arg3); 60 84 async_exchange_end(exch); 61 85 62 if ( !sess)86 if (csess == NULL) 63 87 return NULL; 64 88 … … 68 92 * first argument for non-initial connections. 69 93 */ 70 async_sess_args_set( sess, iface, arg3, 0);94 async_sess_args_set(csess, iface, arg3, 0); 71 95 72 return sess;96 return csess; 73 97 } 74 98 … … 76 100 sysarg_t arg3) 77 101 { 78 async_exch_t *exch = async_exchange_begin(session_ns); 79 async_sess_t *sess = 102 async_sess_t *sess = ns_session_get(); 103 if (sess == NULL) 104 return NULL; 105 106 async_exch_t *exch = async_exchange_begin(sess); 107 async_sess_t *csess = 80 108 async_connect_me_to_blocking_iface(exch, iface, service, arg3); 81 109 async_exchange_end(exch); 82 110 83 if ( !sess)111 if (csess == NULL) 84 112 return NULL; 85 113 … … 89 117 * first argument for non-initial connections. 90 118 */ 91 async_sess_args_set( sess, iface, arg3, 0);119 async_sess_args_set(csess, iface, arg3, 0); 92 120 93 return sess;121 return csess; 94 122 } 95 123 … … 97 125 int ns_ping(void) 98 126 { 99 async_exch_t *exch = async_exchange_begin(session_ns); 127 async_sess_t *sess = ns_session_get(); 128 if (sess == NULL) 129 return EIO; 130 131 async_exch_t *exch = async_exchange_begin(sess); 100 132 int rc = async_req_0_0(exch, NS_PING); 101 133 async_exchange_end(exch); … … 106 138 int ns_intro(task_id_t id) 107 139 { 108 async_exch_t *exch = async_exchange_begin(session_ns); 140 async_exch_t *exch; 141 async_sess_t *sess = ns_session_get(); 142 if (sess == NULL) 143 return EIO; 144 145 exch = async_exchange_begin(sess); 109 146 int rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id)); 110 147 async_exchange_end(exch); … … 113 150 } 114 151 152 async_sess_t *ns_session_get(void) 153 { 154 async_exch_t *exch; 155 156 if (sess_ns == NULL) { 157 exch = async_exchange_begin(session_ns); 158 sess_ns = async_connect_me_to_iface(exch, 0, 0, 0); 159 async_exchange_end(exch); 160 if (sess_ns == NULL) 161 return NULL; 162 } 163 164 return sess_ns; 165 } 166 115 167 /** @} 116 168 */ -
uspace/lib/c/generic/task.c
r8d6bcc8c r7b616e2 44 44 #include <async.h> 45 45 #include <errno.h> 46 #include <ns.h> 46 47 #include <malloc.h> 47 48 #include <libc.h> … … 324 325 int task_setup_wait(task_id_t id, task_wait_t *wait) 325 326 { 326 async_exch_t *exch = async_exchange_begin(session_ns); 327 async_sess_t *sess_ns = ns_session_get(); 328 if (sess_ns == NULL) 329 return EIO; 330 331 async_exch_t *exch = async_exchange_begin(sess_ns); 327 332 wait->aid = async_send_2(exch, NS_TASK_WAIT, LOWER32(id), UPPER32(id), 328 333 &wait->result); … … 401 406 int task_retval(int val) 402 407 { 403 async_exch_t *exch = async_exchange_begin(session_ns); 408 async_sess_t *sess_ns = ns_session_get(); 409 if (sess_ns == NULL) 410 return EIO; 411 412 async_exch_t *exch = async_exchange_begin(sess_ns); 404 413 int rc = (int) async_req_1_0(exch, NS_RETVAL, val); 405 414 async_exchange_end(exch); -
uspace/lib/c/include/ipc/ns.h
r8d6bcc8c r7b616e2 40 40 typedef enum { 41 41 NS_PING = IPC_FIRST_USER_METHOD, 42 NS_REGISTER, 42 43 NS_TASK_WAIT, 43 44 NS_ID_INTRO, -
uspace/lib/c/include/ns.h
r8d6bcc8c r7b616e2 46 46 extern int ns_ping(void); 47 47 extern int ns_intro(task_id_t); 48 extern async_sess_t *ns_session_get(void); 48 49 49 50 #endif -
uspace/lib/drv/generic/driver.c
r8d6bcc8c r7b616e2 943 943 int rc = async_create_port(INTERFACE_DDF_DRIVER, driver_connection_driver, 944 944 NULL, &port); 945 if (rc != EOK) 945 if (rc != EOK) { 946 printf("Error: Failed to create driver port.\n"); 946 947 return rc; 948 } 947 949 948 950 rc = async_create_port(INTERFACE_DDF_DEVMAN, driver_connection_devman, 949 951 NULL, &port); 950 if (rc != EOK) 952 if (rc != EOK) { 953 printf("Error: Failed to create devman port.\n"); 951 954 return rc; 955 } 952 956 953 957 async_set_fallback_port_handler(driver_connection_client, NULL); … … 964 968 /* Return success from the task since server has started. */ 965 969 rc = task_retval(0); 966 if (rc != EOK) 970 if (rc != EOK) { 971 printf("Error: Failed returning task value.\n"); 967 972 return rc; 973 } 968 974 969 975 async_manager(); -
uspace/srv/ns/clonable.c
r8d6bcc8c r7b616e2 31 31 */ 32 32 33 #include < ipc/ipc.h>33 #include <async.h> 34 34 #include <ipc/services.h> 35 35 #include <adt/list.h> … … 81 81 /* There was no pending connection request. */ 82 82 printf("%s: Unexpected clonable server.\n", NAME); 83 ipc_answer_0(callid, EBUSY);83 async_answer_0(callid, EBUSY); 84 84 return; 85 85 } … … 91 91 assert(csr->service == SERVICE_LOADER); 92 92 93 ipc_answer_0(callid, EOK);93 async_answer_0(callid, EOK); 94 94 95 ipc_forward_fast(csr->callid, phone, csr->iface, csr->arg3, 0, 95 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); 96 if (sess == NULL) 97 async_answer_0(callid, EIO); 98 99 async_exch_t *exch = async_exchange_begin(sess); 100 async_forward_fast(csr->callid, exch, csr->iface, csr->arg3, 0, 96 101 IPC_FF_NONE); 102 async_exchange_end(exch); 97 103 98 104 free(csr); 99 ipc_hangup(phone);105 async_hangup(sess); 100 106 } 101 107 … … 117 123 cs_req_t *csr = malloc(sizeof(cs_req_t)); 118 124 if (csr == NULL) { 119 ipc_answer_0(callid, ENOMEM);125 async_answer_0(callid, ENOMEM); 120 126 return; 121 127 } … … 126 132 if (rc < 0) { 127 133 free(csr); 128 ipc_answer_0(callid, rc);134 async_answer_0(callid, rc); 129 135 return; 130 136 } -
uspace/srv/ns/ns.c
r8d6bcc8c r7b616e2 36 36 */ 37 37 38 #include <ipc/ipc.h> 38 #include <abi/ipc/methods.h> 39 #include <async.h> 39 40 #include <ipc/ns.h> 40 41 #include <ipc/services.h> … … 47 48 #include "clonable.h" 48 49 #include "task.h" 50 51 static void ns_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 52 { 53 ipc_call_t call; 54 ipc_callid_t callid; 55 iface_t iface; 56 service_t service; 57 58 iface = IPC_GET_ARG1(*icall); 59 service = IPC_GET_ARG2(*icall); 60 if (service != 0) { 61 /* 62 * Client requests to be connected to a service. 63 */ 64 if (service_clonable(service)) { 65 connect_to_clonable(service, iface, icall, iid); 66 } else { 67 connect_to_service(service, iface, icall, iid); 68 } 69 return; 70 } 71 72 async_answer_0(iid, EOK); 73 74 while (true) { 75 process_pending_conn(); 76 77 callid = async_get_call(&call); 78 if (!IPC_GET_IMETHOD(call)) 79 break; 80 81 task_id_t id; 82 sysarg_t retval; 83 84 service_t service; 85 sysarg_t phone; 86 87 switch (IPC_GET_IMETHOD(call)) { 88 case NS_REGISTER: 89 service = IPC_GET_ARG1(call); 90 phone = IPC_GET_ARG5(call); 91 92 /* 93 * Server requests service registration. 94 */ 95 if (service_clonable(service)) { 96 register_clonable(service, phone, &call, callid); 97 continue; 98 } else { 99 retval = register_service(service, phone, &call); 100 } 101 102 break; 103 case NS_PING: 104 retval = EOK; 105 break; 106 case NS_TASK_WAIT: 107 id = (task_id_t) 108 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 109 wait_for_task(id, &call, callid); 110 continue; 111 case NS_ID_INTRO: 112 retval = ns_task_id_intro(&call); 113 break; 114 case NS_RETVAL: 115 retval = ns_task_retval(&call); 116 break; 117 default: 118 printf("ns: method not supported\n"); 119 retval = ENOTSUP; 120 break; 121 } 122 123 async_answer_0(callid, retval); 124 } 125 126 (void) ns_task_disconnect(&call); 127 } 49 128 50 129 int main(int argc, char **argv) … … 64 143 return rc; 65 144 145 async_set_fallback_port_handler(ns_connection, NULL); 146 66 147 printf("%s: Accepting connections\n", NAME); 67 68 while (true) { 69 process_pending_conn(); 70 71 ipc_call_t call; 72 ipc_callid_t callid = ipc_wait_for_call(&call); 73 74 task_id_t id; 75 sysarg_t retval; 76 77 iface_t iface; 78 service_t service; 79 sysarg_t phone; 80 81 switch (IPC_GET_IMETHOD(call)) { 82 case IPC_M_PHONE_HUNGUP: 83 retval = ns_task_disconnect(&call); 84 break; 85 case IPC_M_CONNECT_TO_ME: 86 service = IPC_GET_ARG2(call); 87 phone = IPC_GET_ARG5(call); 88 89 /* 90 * Server requests service registration. 91 */ 92 if (service_clonable(service)) { 93 register_clonable(service, phone, &call, callid); 94 continue; 95 } else 96 retval = register_service(service, phone, &call); 97 98 break; 99 case IPC_M_CONNECT_ME_TO: 100 iface = IPC_GET_ARG1(call); 101 service = IPC_GET_ARG2(call); 102 103 /* 104 * Client requests to be connected to a service. 105 */ 106 if (service_clonable(service)) { 107 connect_to_clonable(service, iface, &call, callid); 108 continue; 109 } else { 110 connect_to_service(service, iface, &call, callid); 111 continue; 112 } 113 break; 114 case NS_PING: 115 retval = EOK; 116 break; 117 case NS_TASK_WAIT: 118 id = (task_id_t) 119 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 120 wait_for_task(id, &call, callid); 121 continue; 122 case NS_ID_INTRO: 123 retval = ns_task_id_intro(&call); 124 break; 125 case NS_RETVAL: 126 retval = ns_task_retval(&call); 127 break; 128 default: 129 retval = ENOENT; 130 break; 131 } 132 133 if (!(callid & IPC_CALLID_NOTIFICATION)) 134 ipc_answer_0(callid, retval); 135 } 148 async_manager(); 136 149 137 150 /* Not reached */ -
uspace/srv/ns/service.c
r8d6bcc8c r7b616e2 31 31 */ 32 32 33 #include <ipc/ipc.h>34 33 #include <adt/hash_table.h> 35 34 #include <assert.h> 35 #include <async.h> 36 36 #include <errno.h> 37 37 #include <stdio.h> … … 47 47 service_t service; 48 48 49 /** Phone registered with the interface */ 50 sysarg_t phone; 51 52 /** Incoming phone hash */ 53 sysarg_t in_phone_hash; 49 /** Session to the service */ 50 async_sess_t *sess; 54 51 } hashed_service_t; 55 52 … … 121 118 122 119 hashed_service_t *hashed_service = hash_table_get_inst(link, hashed_service_t, link); 123 (void) ipc_forward_fast(pending->callid, hashed_service->phone, 124 pending->iface, pending->arg3, 0, IPC_FF_NONE); 120 async_exch_t *exch = async_exchange_begin(hashed_service->sess); 121 async_forward_fast(pending->callid, exch, pending->iface, 122 pending->arg3, 0, IPC_FF_NONE); 123 async_exchange_end(exch); 125 124 126 125 list_remove(&pending->link); … … 151 150 152 151 hashed_service->service = service; 153 hashed_service->phone = phone; 154 hashed_service->in_phone_hash = call->in_phone_hash; 152 hashed_service->sess = async_callback_receive(EXCHANGE_SERIALIZE); 153 if (hashed_service->sess == NULL) 154 return EIO; 155 155 156 156 hash_table_insert(&service_hash_table, &hashed_service->link); 157 158 157 return EOK; 159 158 } … … 202 201 203 202 hashed_service_t *hashed_service = hash_table_get_inst(link, hashed_service_t, link); 204 (void) ipc_forward_fast(callid, hashed_service->phone, iface, arg3, 205 0, IPC_FF_NONE); 203 async_exch_t *exch = async_exchange_begin(hashed_service->sess); 204 async_forward_fast(callid, exch, iface, arg3, 0, IPC_FF_NONE); 205 async_exchange_end(exch); 206 206 return; 207 207 208 208 out: 209 if (!(callid & IPC_CALLID_NOTIFICATION)) 210 ipc_answer_0(callid, retval); 209 async_answer_0(callid, retval); 211 210 } 212 211 -
uspace/srv/ns/task.c
r8d6bcc8c r7b616e2 32 32 */ 33 33 34 #include <ipc/ipc.h>35 34 #include <adt/hash_table.h> 35 #include <async.h> 36 36 #include <stdbool.h> 37 37 #include <errno.h> … … 182 182 continue; 183 183 184 if (!(pr->callid & IPC_CALLID_NOTIFICATION)) { 185 texit = ht->have_rval ? TASK_EXIT_NORMAL : 186 TASK_EXIT_UNEXPECTED; 187 ipc_answer_2(pr->callid, EOK, texit, 188 ht->retval); 189 } 184 texit = ht->have_rval ? TASK_EXIT_NORMAL : 185 TASK_EXIT_UNEXPECTED; 186 async_answer_2(pr->callid, EOK, texit, ht->retval); 190 187 191 188 list_remove(&pr->link); … … 203 200 if (ht == NULL) { 204 201 /* No such task exists. */ 205 ipc_answer_0(callid, ENOENT);202 async_answer_0(callid, ENOENT); 206 203 return; 207 204 } … … 210 207 task_exit_t texit = ht->have_rval ? TASK_EXIT_NORMAL : 211 208 TASK_EXIT_UNEXPECTED; 212 ipc_answer_2(callid, EOK, texit, ht->retval);209 async_answer_2(callid, EOK, texit, ht->retval); 213 210 return; 214 211 } … … 218 215 (pending_wait_t *) malloc(sizeof(pending_wait_t)); 219 216 if (!pr) { 220 if (!(callid & IPC_CALLID_NOTIFICATION)) 221 ipc_answer_0(callid, ENOMEM); 217 async_answer_0(callid, ENOMEM); 222 218 return; 223 219 } … … 282 278 int ns_task_retval(ipc_call_t *call) 283 279 { 280 task_id_t id = call->in_task_id; 281 282 ht_link_t *link = hash_table_find(&task_hash_table, &id); 283 hashed_task_t *ht = (link != NULL) ? 284 hash_table_get_inst(link, hashed_task_t, link) : NULL; 285 286 if ((ht == NULL) || (ht->finished)) 287 return EINVAL; 288 289 ht->finished = true; 290 ht->have_rval = true; 291 ht->retval = IPC_GET_ARG1(*call); 292 293 process_pending_wait(); 294 295 return EOK; 296 } 297 298 int ns_task_disconnect(ipc_call_t *call) 299 { 284 300 task_id_t id; 285 301 int rc = get_id_by_phone(call->in_phone_hash, &id); … … 287 303 return rc; 288 304 289 ht_link_t *link = hash_table_find(&task_hash_table, &id);290 hashed_task_t *ht = (link != NULL) ?291 hash_table_get_inst(link, hashed_task_t, link) : NULL;292 293 if ((ht == NULL) || (ht->finished))294 return EINVAL;295 296 ht->finished = true;297 ht->have_rval = true;298 ht->retval = IPC_GET_ARG1(*call);299 300 process_pending_wait();301 302 return EOK;303 }304 305 int ns_task_disconnect(ipc_call_t *call)306 {307 task_id_t id;308 int rc = get_id_by_phone(call->in_phone_hash, &id);309 if (rc != EOK)310 return rc;311 312 305 /* Delete from phone-to-id map. */ 313 306 hash_table_remove(&phone_to_id, &call->in_phone_hash);
Note:
See TracChangeset
for help on using the changeset viewer.