Changeset 7b616e2 in mainline


Ignore:
Timestamp:
2017-09-27T22:40:09Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d076f16
Parents:
8d6bcc8c
Message:

Name service should communicate using async.h.

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/ns.c

    r8d6bcc8c r7b616e2  
    4040#include "private/ns.h"
    4141
     42/*
     43 * XXX ns does not know about session_ns, so we create an extra session for
     44 * actual communicaton
     45 */
     46static async_sess_t *sess_ns = NULL;
     47
    4248int service_register(service_t service)
    4349{
    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);
    4559        int rc = async_connect_to_me(exch, 0, service, 0);
     60       
    4661        async_exchange_end(exch);
    4762       
     63        if (rc != EOK) {
     64                async_forget(req);
     65                return rc;
     66        }
     67       
     68        async_wait_for(req, &retval);
    4869        return rc;
    4970}
    5071
    51 
    5272async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3)
    5373{
    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)
    5676                return NULL;
    5777       
    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 =
    5983            async_connect_me_to_iface(exch, iface, service, arg3);
    6084        async_exchange_end(exch);
    6185       
    62         if (!sess)
     86        if (csess == NULL)
    6387                return NULL;
    6488       
     
    6892         * first argument for non-initial connections.
    6993         */
    70         async_sess_args_set(sess, iface, arg3, 0);
     94        async_sess_args_set(csess, iface, arg3, 0);
    7195       
    72         return sess;
     96        return csess;
    7397}
    7498
     
    76100    sysarg_t arg3)
    77101{
    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 =
    80108            async_connect_me_to_blocking_iface(exch, iface, service, arg3);
    81109        async_exchange_end(exch);
    82110       
    83         if (!sess)
     111        if (csess == NULL)
    84112                return NULL;
    85113       
     
    89117         * first argument for non-initial connections.
    90118         */
    91         async_sess_args_set(sess, iface, arg3, 0);
     119        async_sess_args_set(csess, iface, arg3, 0);
    92120       
    93         return sess;
     121        return csess;
    94122}
    95123
     
    97125int ns_ping(void)
    98126{
    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);
    100132        int rc = async_req_0_0(exch, NS_PING);
    101133        async_exchange_end(exch);
     
    106138int ns_intro(task_id_t id)
    107139{
    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);
    109146        int rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
    110147        async_exchange_end(exch);
     
    113150}
    114151
     152async_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
    115167/** @}
    116168 */
  • uspace/lib/c/generic/task.c

    r8d6bcc8c r7b616e2  
    4444#include <async.h>
    4545#include <errno.h>
     46#include <ns.h>
    4647#include <malloc.h>
    4748#include <libc.h>
     
    324325int task_setup_wait(task_id_t id, task_wait_t *wait)
    325326{
    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);
    327332        wait->aid = async_send_2(exch, NS_TASK_WAIT, LOWER32(id), UPPER32(id),
    328333            &wait->result);
     
    401406int task_retval(int val)
    402407{
    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);
    404413        int rc = (int) async_req_1_0(exch, NS_RETVAL, val);
    405414        async_exchange_end(exch);
  • uspace/lib/c/include/ipc/ns.h

    r8d6bcc8c r7b616e2  
    4040typedef enum {
    4141        NS_PING = IPC_FIRST_USER_METHOD,
     42        NS_REGISTER,
    4243        NS_TASK_WAIT,
    4344        NS_ID_INTRO,
  • uspace/lib/c/include/ns.h

    r8d6bcc8c r7b616e2  
    4646extern int ns_ping(void);
    4747extern int ns_intro(task_id_t);
     48extern async_sess_t *ns_session_get(void);
    4849
    4950#endif
  • uspace/lib/drv/generic/driver.c

    r8d6bcc8c r7b616e2  
    943943        int rc = async_create_port(INTERFACE_DDF_DRIVER, driver_connection_driver,
    944944            NULL, &port);
    945         if (rc != EOK)
     945        if (rc != EOK) {
     946                printf("Error: Failed to create driver port.\n");
    946947                return rc;
     948        }
    947949       
    948950        rc = async_create_port(INTERFACE_DDF_DEVMAN, driver_connection_devman,
    949951            NULL, &port);
    950         if (rc != EOK)
     952        if (rc != EOK) {
     953                printf("Error: Failed to create devman port.\n");
    951954                return rc;
     955        }
    952956       
    953957        async_set_fallback_port_handler(driver_connection_client, NULL);
     
    964968        /* Return success from the task since server has started. */
    965969        rc = task_retval(0);
    966         if (rc != EOK)
     970        if (rc != EOK) {
     971                printf("Error: Failed returning task value.\n");
    967972                return rc;
     973        }
    968974       
    969975        async_manager();
  • uspace/srv/ns/clonable.c

    r8d6bcc8c r7b616e2  
    3131 */
    3232
    33 #include <ipc/ipc.h>
     33#include <async.h>
    3434#include <ipc/services.h>
    3535#include <adt/list.h>
     
    8181                /* There was no pending connection request. */
    8282                printf("%s: Unexpected clonable server.\n", NAME);
    83                 ipc_answer_0(callid, EBUSY);
     83                async_answer_0(callid, EBUSY);
    8484                return;
    8585        }
     
    9191        assert(csr->service == SERVICE_LOADER);
    9292       
    93         ipc_answer_0(callid, EOK);
     93        async_answer_0(callid, EOK);
    9494       
    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,
    96101            IPC_FF_NONE);
     102        async_exchange_end(exch);
    97103       
    98104        free(csr);
    99         ipc_hangup(phone);
     105        async_hangup(sess);
    100106}
    101107
     
    117123        cs_req_t *csr = malloc(sizeof(cs_req_t));
    118124        if (csr == NULL) {
    119                 ipc_answer_0(callid, ENOMEM);
     125                async_answer_0(callid, ENOMEM);
    120126                return;
    121127        }
     
    126132        if (rc < 0) {
    127133                free(csr);
    128                 ipc_answer_0(callid, rc);
     134                async_answer_0(callid, rc);
    129135                return;
    130136        }
  • uspace/srv/ns/ns.c

    r8d6bcc8c r7b616e2  
    3636 */
    3737
    38 #include <ipc/ipc.h>
     38#include <abi/ipc/methods.h>
     39#include <async.h>
    3940#include <ipc/ns.h>
    4041#include <ipc/services.h>
     
    4748#include "clonable.h"
    4849#include "task.h"
     50
     51static 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}
    49128
    50129int main(int argc, char **argv)
     
    64143                return rc;
    65144       
     145        async_set_fallback_port_handler(ns_connection, NULL);
     146       
    66147        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();
    136149       
    137150        /* Not reached */
  • uspace/srv/ns/service.c

    r8d6bcc8c r7b616e2  
    3131 */
    3232
    33 #include <ipc/ipc.h>
    3433#include <adt/hash_table.h>
    3534#include <assert.h>
     35#include <async.h>
    3636#include <errno.h>
    3737#include <stdio.h>
     
    4747        service_t service;
    4848       
    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;
    5451} hashed_service_t;
    5552
     
    121118               
    122119                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);
    125124               
    126125                list_remove(&pending->link);
     
    151150       
    152151        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;
    155155       
    156156        hash_table_insert(&service_hash_table, &hashed_service->link);
    157        
    158157        return EOK;
    159158}
     
    202201       
    203202        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);
    206206        return;
    207207       
    208208out:
    209         if (!(callid & IPC_CALLID_NOTIFICATION))
    210                 ipc_answer_0(callid, retval);
     209        async_answer_0(callid, retval);
    211210}
    212211
  • uspace/srv/ns/task.c

    r8d6bcc8c r7b616e2  
    3232 */
    3333
    34 #include <ipc/ipc.h>
    3534#include <adt/hash_table.h>
     35#include <async.h>
    3636#include <stdbool.h>
    3737#include <errno.h>
     
    182182                        continue;
    183183               
    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);
    190187               
    191188                list_remove(&pr->link);
     
    203200        if (ht == NULL) {
    204201                /* No such task exists. */
    205                 ipc_answer_0(callid, ENOENT);
     202                async_answer_0(callid, ENOENT);
    206203                return;
    207204        }
     
    210207                task_exit_t texit = ht->have_rval ? TASK_EXIT_NORMAL :
    211208                    TASK_EXIT_UNEXPECTED;
    212                 ipc_answer_2(callid, EOK, texit, ht->retval);
     209                async_answer_2(callid, EOK, texit, ht->retval);
    213210                return;
    214211        }
     
    218215            (pending_wait_t *) malloc(sizeof(pending_wait_t));
    219216        if (!pr) {
    220                 if (!(callid & IPC_CALLID_NOTIFICATION))
    221                         ipc_answer_0(callid, ENOMEM);
     217                async_answer_0(callid, ENOMEM);
    222218                return;
    223219        }
     
    282278int ns_task_retval(ipc_call_t *call)
    283279{
     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
     298int ns_task_disconnect(ipc_call_t *call)
     299{
    284300        task_id_t id;
    285301        int rc = get_id_by_phone(call->in_phone_hash, &id);
     
    287303                return rc;
    288304       
    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        
    312305        /* Delete from phone-to-id map. */
    313306        hash_table_remove(&phone_to_id, &call->in_phone_hash);
Note: See TracChangeset for help on using the changeset viewer.