Changeset 7b616e2 in mainline for uspace/srv/ns/ns.c


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 */
Note: See TracChangeset for help on using the changeset viewer.