Changeset 9cfbf2f in mainline for uspace/srv/ns/service.c


Ignore:
Timestamp:
2015-08-22T03:53:34Z (9 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
57dea62
Parents:
1a522e5
Message:

improve code readability
coding style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/ns/service.c

    r1a522e5 r9cfbf2f  
    4343typedef struct {
    4444        ht_link_t link;
    45         sysarg_t service;        /**< Service ID. */
    46         sysarg_t phone;          /**< Phone registered with the service. */
    47         sysarg_t in_phone_hash;  /**< Incoming phone hash. */
     45       
     46        /** Service ID */
     47        service_t service;
     48       
     49        /** Phone registered with the interface */
     50        sysarg_t phone;
     51       
     52        /** Incoming phone hash */
     53        sysarg_t in_phone_hash;
    4854} hashed_service_t;
    4955
    50 
    5156static size_t service_key_hash(void *key)
    5257{
    53         return *(sysarg_t*)key;
     58        return *(service_t *) key;
    5459}
    5560
    5661static size_t service_hash(const ht_link_t *item)
    5762{
    58         hashed_service_t *hs = hash_table_get_inst(item, hashed_service_t, link);
    59         return hs->service;
     63        hashed_service_t *service =
     64            hash_table_get_inst(item, hashed_service_t, link);
     65       
     66        return service->service;
    6067}
    6168
    6269static bool service_key_equal(void *key, const ht_link_t *item)
    6370{
    64         hashed_service_t *hs = hash_table_get_inst(item, hashed_service_t, link);
    65         return hs->service == *(sysarg_t*)key;
     71        hashed_service_t *service =
     72            hash_table_get_inst(item, hashed_service_t, link);
     73       
     74        return service->service == *(service_t *) key;
    6675}
    6776
     
    8190typedef struct {
    8291        link_t link;
    83         sysarg_t service;        /**< Number of the service. */
    84         ipc_callid_t callid;     /**< Call ID waiting for the connection */
    85         sysarg_t iface;          /**< Interface argument */
    86         sysarg_t arg3;           /**< Third argument */
     92        service_t service;    /**< Service ID */
     93        iface_t iface;        /**< Interface ID */
     94        ipc_callid_t callid;  /**< Call ID waiting for the connection */
     95        sysarg_t arg3;        /**< Third argument */
    8796} pending_conn_t;
    8897
     
    91100int service_init(void)
    92101{
    93         if (!hash_table_create(&service_hash_table, 0, 0, &service_hash_table_ops)) {
    94                 printf(NAME ": No memory available for services\n");
     102        if (!hash_table_create(&service_hash_table, 0, 0,
     103            &service_hash_table_ops)) {
     104                printf("%s: No memory available for services\n", NAME);
    95105                return ENOMEM;
    96106        }
     
    105115{
    106116loop:
    107         list_foreach(pending_conn, link, pending_conn_t, pr) {
    108                 ht_link_t *link = hash_table_find(&service_hash_table, &pr->service);
     117        list_foreach(pending_conn, link, pending_conn_t, pending) {
     118                ht_link_t *link = hash_table_find(&service_hash_table, &pending->service);
    109119                if (!link)
    110120                        continue;
    111121               
    112                 hashed_service_t *hs = hash_table_get_inst(link, hashed_service_t, link);
    113                 (void) ipc_forward_fast(pr->callid, hs->phone, pr->iface, pr->arg3, 0,
    114                     IPC_FF_NONE);
    115                
    116                 list_remove(&pr->link);
    117                 free(pr);
     122                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);
     125               
     126                list_remove(&pending->link);
     127                free(pending);
     128               
    118129                goto loop;
    119130        }
     
    129140 *
    130141 */
    131 int register_service(sysarg_t service, sysarg_t phone, ipc_call_t *call)
     142int register_service(service_t service, sysarg_t phone, ipc_call_t *call)
    132143{
    133144        if (hash_table_find(&service_hash_table, &service))
    134145                return EEXISTS;
    135146       
    136         hashed_service_t *hs = (hashed_service_t *) malloc(sizeof(hashed_service_t));
    137         if (!hs)
     147        hashed_service_t *hashed_service =
     148            (hashed_service_t *) malloc(sizeof(hashed_service_t));
     149        if (!hashed_service)
    138150                return ENOMEM;
    139151       
    140         hs->service = service;
    141         hs->phone = phone;
    142         hs->in_phone_hash = call->in_phone_hash;
    143         hash_table_insert(&service_hash_table, &hs->link);
     152        hashed_service->service = service;
     153        hashed_service->phone = phone;
     154        hashed_service->in_phone_hash = call->in_phone_hash;
     155       
     156        hash_table_insert(&service_hash_table, &hashed_service->link);
    144157       
    145158        return EOK;
     
    149162 *
    150163 * @param service Service to be connected to.
     164 * @param iface   Interface to be connected to.
    151165 * @param call    Pointer to call structure.
    152166 * @param callid  Call ID of the request.
     
    155169 *
    156170 */
    157 void connect_to_service(sysarg_t service, ipc_call_t *call, ipc_callid_t callid)
    158 {
     171void connect_to_service(service_t service, iface_t iface, ipc_call_t *call,
     172    ipc_callid_t callid)
     173{
     174        sysarg_t arg3 = IPC_GET_ARG3(*call);
     175        sysarg_t flags = IPC_GET_ARG4(*call);
    159176        sysarg_t retval;
    160177       
    161178        ht_link_t *link = hash_table_find(&service_hash_table, &service);
    162179        if (!link) {
    163                 if (IPC_GET_ARG4(*call) & IPC_FLAG_BLOCKING) {
     180                if (flags & IPC_FLAG_BLOCKING) {
    164181                        /* Blocking connection, add to pending list */
    165                         pending_conn_t *pr =
     182                        pending_conn_t *pending =
    166183                            (pending_conn_t *) malloc(sizeof(pending_conn_t));
    167                         if (!pr) {
     184                        if (!pending) {
    168185                                retval = ENOMEM;
    169186                                goto out;
    170187                        }
    171188                       
    172                         link_initialize(&pr->link);
    173                         pr->service = service;
    174                         pr->callid = callid;
    175                         pr->iface = IPC_GET_ARG1(*call);
    176                         pr->arg3 = IPC_GET_ARG3(*call);
    177                         list_append(&pr->link, &pending_conn);
     189                        link_initialize(&pending->link);
     190                        pending->service = service;
     191                        pending->iface = iface;
     192                        pending->callid = callid;
     193                        pending->arg3 = arg3;
     194                       
     195                        list_append(&pending->link, &pending_conn);
    178196                        return;
    179197                }
     
    183201        }
    184202       
    185         hashed_service_t *hs = hash_table_get_inst(link, hashed_service_t, link);
    186         (void) ipc_forward_fast(callid, hs->phone, IPC_GET_ARG1(*call),
    187             IPC_GET_ARG3(*call), 0, IPC_FF_NONE);
     203        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);
    188206        return;
    189207       
Note: See TracChangeset for help on using the changeset viewer.