Changeset 7b616e2 in mainline for uspace/lib/c/generic/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/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 */
Note: See TracChangeset for help on using the changeset viewer.