Changeset 7b616e2 in mainline for uspace/srv


Ignore:
Timestamp:
2017-09-27T22:40:09Z (8 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/srv/ns
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.