Changeset 007e6efa in mainline for uspace/srv


Ignore:
Timestamp:
2011-01-28T15:44:39Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4db1fbf
Parents:
ae0300b5
Message:
  • libc routines for registering services and connecting to services via NS
  • async_connect_to_me()
Location:
uspace/srv
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/clip/clip.c

    rae0300b5 r007e6efa  
    2929#include <stdio.h>
    3030#include <bool.h>
     31#include <async.h>
    3132#include <ipc/ipc.h>
    32 #include <async.h>
     33#include <ipc/ns.h>
    3334#include <ipc/services.h>
    3435#include <ipc/clipboard.h>
     
    183184        async_set_client_connection(clip_connection);
    184185       
    185         if (ipc_connect_to_me(PHONE_NS, SERVICE_CLIPBOARD, 0, 0, NULL, NULL))
     186        if (service_register(SERVICE_CLIPBOARD) != EOK)
    186187                return -1;
    187188       
  • uspace/srv/devman/main.c

    rae0300b5 r007e6efa  
    586586
    587587        /* Register device manager at naming service. */
    588         if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, NULL, NULL) != 0)
     588        if (service_register(SERVICE_DEVMAN) != EOK)
    589589                return -1;
    590590
  • uspace/srv/devmap/devmap.c

    rae0300b5 r007e6efa  
    11501150       
    11511151        /* Register device mapper at naming service */
    1152         if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, NULL, NULL) != 0)
     1152        if (service_register(SERVICE_DEVMAP) != EOK)
    11531153                return -1;
    11541154       
  • uspace/srv/fs/devfs/devfs.c

    rae0300b5 r007e6efa  
    4242#include <ipc/ipc.h>
    4343#include <ipc/services.h>
     44#include <ipc/ns.h>
    4445#include <async.h>
    4546#include <errno.h>
     
    126127        }
    127128       
    128         int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
     129        int vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
    129130        if (vfs_phone < EOK) {
    130131                printf(NAME ": Unable to connect to VFS\n");
  • uspace/srv/fs/fat/fat.c

    rae0300b5 r007e6efa  
    4040#include <ipc/ipc.h>
    4141#include <ipc/services.h>
     42#include <ipc/ns.h>
    4243#include <async.h>
    4344#include <errno.h>
     
    153154                goto err;
    154155
    155         vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
     156        vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
    156157        if (vfs_phone < EOK) {
    157158                printf(NAME ": failed to connect to VFS\n");
  • uspace/srv/fs/tmpfs/tmpfs.c

    rae0300b5 r007e6efa  
    4444#include <ipc/ipc.h>
    4545#include <ipc/services.h>
     46#include <ipc/ns.h>
    4647#include <async.h>
    4748#include <errno.h>
     
    157158        }
    158159
    159         int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
     160        int vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);
    160161        if (vfs_phone < EOK) {
    161162                printf(NAME ": Unable to connect to VFS\n");
  • uspace/srv/hid/console/console.c

    rae0300b5 r007e6efa  
    4040#include <ipc/fb.h>
    4141#include <ipc/services.h>
     42#include <ipc/ns.h>
    4243#include <errno.h>
    4344#include <ipc/console.h>
     
    762763       
    763764        /* Connect to framebuffer driver */
    764         fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
     765        fb_info.phone = service_connect_blocking(SERVICE_VIDEO, 0, 0);
    765766        if (fb_info.phone < 0) {
    766767                printf(NAME ": Failed to connect to video service\n");
     
    838839       
    839840        /* Receive kernel notifications */
     841        async_set_interrupt_received(interrupt_received);
    840842        if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
    841843                printf(NAME ": Error registering kconsole notifications\n");
    842        
    843         async_set_interrupt_received(interrupt_received);
    844844       
    845845        return true;
  • uspace/srv/hid/fb/main.c

    rae0300b5 r007e6efa  
    2929#include <ipc/ipc.h>
    3030#include <ipc/services.h>
     31#include <ipc/ns.h>
    3132#include <sysinfo.h>
    3233#include <async.h>
     
    114115                return -1;
    115116       
    116         if (ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, 0, NULL, NULL) != 0)
     117        if (service_register(SERVICE_VIDEO) != EOK)
    117118                return -1;
    118119       
  • uspace/srv/hid/kbd/generic/kbd.c

    rae0300b5 r007e6efa  
    223223       
    224224        if (cir_service) {
    225                 while (cir_phone < 0) {
    226                         cir_phone = ipc_connect_me_to_blocking(PHONE_NS, cir_service,
    227                             0, 0);
    228                 }
     225                while (cir_phone < 0)
     226                        cir_phone = service_connect_blocking(cir_service, 0, 0);
    229227        }
    230228       
  • uspace/srv/hw/irc/apic/apic.c

    rae0300b5 r007e6efa  
    108108       
    109109        async_set_client_connection(apic_connection);
    110         ipc_connect_to_me(PHONE_NS, SERVICE_APIC, 0, 0, NULL, NULL);
     110        service_register(SERVICE_APIC);
    111111       
    112112        return true;
  • uspace/srv/hw/irc/fhc/fhc.c

    rae0300b5 r007e6efa  
    137137       
    138138        async_set_client_connection(fhc_connection);
    139         ipc_connect_to_me(PHONE_NS, SERVICE_FHC, 0, 0, NULL, NULL);
     139        service_register(SERVICE_FHC);
    140140       
    141141        return true;
  • uspace/srv/hw/irc/i8259/i8259.c

    rae0300b5 r007e6efa  
    150150       
    151151        async_set_client_connection(i8259_connection);
    152         ipc_connect_to_me(PHONE_NS, SERVICE_I8259, 0, 0, NULL, NULL);
     152        service_register(SERVICE_I8259);
    153153       
    154154        return true;
  • uspace/srv/hw/irc/obio/obio.c

    rae0300b5 r007e6efa  
    138138       
    139139        async_set_client_connection(obio_connection);
    140         ipc_connect_to_me(PHONE_NS, SERVICE_OBIO, 0, 0, NULL, NULL);
     140        service_register(SERVICE_OBIO);
    141141       
    142142        return true;
  • uspace/srv/hw/netif/ne2000/ne2000.c

    rae0300b5 r007e6efa  
    4545#include <ipc/ipc.h>
    4646#include <ipc/services.h>
     47#include <ipc/ns.h>
    4748#include <ipc/irc.h>
    4849#include <net/modules.h>
     
    389390       
    390391        if (irc_service) {
    391                 while (irc_phone < 0) {
    392                         irc_phone = ipc_connect_me_to_blocking(PHONE_NS, irc_service,
    393                             0, 0);
    394                 }
     392                while (irc_phone < 0)
     393                        irc_phone = service_connect_blocking(irc_service, 0, 0);
    395394        }
    396395       
  • uspace/srv/loader/main.c

    rae0300b5 r007e6efa  
    9595
    9696/** Used to limit number of connections to one. */
    97 static bool connected;
     97static bool connected = false;
    9898
    9999static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
     
    423423int main(int argc, char *argv[])
    424424{
    425         task_id_t id;
    426         int rc;
    427 
    428         connected = false;
    429 
     425        /* Set a handler of incomming connections. */
     426        async_set_client_connection(ldr_connection);
     427       
    430428        /* Introduce this task to the NS (give it our task ID). */
    431         id = task_get_id();
    432         rc = async_req_2_0(PHONE_NS, NS_ID_INTRO, LOWER32(id), UPPER32(id));
     429        task_id_t id = task_get_id();
     430        int rc = async_req_2_0(PHONE_NS, NS_ID_INTRO, LOWER32(id), UPPER32(id));
    433431        if (rc != EOK)
    434432                return -1;
    435 
    436         /* Set a handler of incomming connections. */
    437         async_set_client_connection(ldr_connection);
    438433       
    439434        /* Register at naming service. */
    440         if (ipc_connect_to_me(PHONE_NS, SERVICE_LOAD, 0, 0, NULL, NULL) != 0)
     435        if (service_register(SERVICE_LOAD) != EOK)
    441436                return -2;
    442 
     437       
    443438        async_manager();
    444439       
  • uspace/srv/ns/clonable.c

    rae0300b5 r007e6efa  
    9292       
    9393        ipc_forward_fast(csr->callid, phone, IPC_GET_ARG2(csr->call),
    94                 IPC_GET_ARG3(csr->call), 0, IPC_FF_NONE);
     94            IPC_GET_ARG3(csr->call), 0, IPC_FF_NONE);
    9595       
    9696        free(csr);
     
    127127        }
    128128       
     129        link_initialize(&csr->link);
    129130        csr->service = service;
    130131        csr->call = *call;
  • uspace/srv/ns/service.c

    rae0300b5 r007e6efa  
    4343typedef struct {
    4444        link_t link;
    45         sysarg_t service;        /**< Number of the service. */
     45        sysarg_t service;        /**< Service ID. */
    4646        sysarg_t phone;          /**< Phone registered with the service. */
    4747        sysarg_t in_phone_hash;  /**< Incoming phone hash. */
     
    5656 *
    5757 */
    58 static hash_index_t service_hash(unsigned long *key)
     58static hash_index_t service_hash(unsigned long key[])
    5959{
    6060        assert(key);
    61         return (*key % SERVICE_HASH_TABLE_CHAINS);
     61        return (key[0] % SERVICE_HASH_TABLE_CHAINS);
    6262}
    6363
     
    8686       
    8787        if (keys == 2)
    88                 return (key[1] == hs->in_phone_hash);
     88                return ((key[0] == hs->service) && (key[1] == hs->in_phone_hash));
    8989        else
    9090                return (key[0] == hs->service);
     
    195195        hash_table_insert(&service_hash_table, keys, &hs->link);
    196196       
    197         return 0;
     197        return EOK;
    198198}
    199199
     
    227227                        }
    228228                       
     229                        link_initialize(&pr->link);
    229230                        pr->service = service;
    230231                        pr->callid = callid;
  • uspace/srv/ns/task.c

    rae0300b5 r007e6efa  
    4343
    4444#define TASK_HASH_TABLE_CHAINS  256
    45 #define P2I_HASH_TABLE_CHAINS  256
    46 
    47 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id);
     45#define P2I_HASH_TABLE_CHAINS   256
    4846
    4947/* TODO:
     
    5755typedef struct {
    5856        link_t link;
    59         task_id_t id;   /**< Task ID. */
    60         bool finished;  /**< Task is done. */
    61         bool have_rval; /**< Task returned a value. */
    62         int retval;     /**< The return value. */
     57       
     58        task_id_t id;    /**< Task ID. */
     59        bool finished;   /**< Task is done. */
     60        bool have_rval;  /**< Task returned a value. */
     61        int retval;      /**< The return value. */
    6362} hashed_task_t;
    6463
     
    7170 *
    7271 */
    73 static hash_index_t task_hash(unsigned long *key)
     72static hash_index_t task_hash(unsigned long key[])
    7473{
    7574        assert(key);
    76         return (LOWER32(*key) % TASK_HASH_TABLE_CHAINS);
     75        return (LOWER32(key[0]) % TASK_HASH_TABLE_CHAINS);
    7776}
    7877
     
    124123typedef struct {
    125124        link_t link;
    126         sysarg_t phash;    /**< Task ID. */
    127         task_id_t id;    /**< Task ID. */
     125        sysarg_t in_phone_hash;  /**< Incoming phone hash. */
     126        task_id_t id;            /**< Task ID. */
    128127} p2i_entry_t;
    129128
     
    131130 *
    132131 * @param key Array of keys.
     132 *
    133133 * @return Hash index corresponding to key[0].
    134134 *
    135135 */
    136 static hash_index_t p2i_hash(unsigned long *key)
     136static hash_index_t p2i_hash(unsigned long key[])
    137137{
    138138        assert(key);
    139         return (*key % TASK_HASH_TABLE_CHAINS);
     139        return (key[0] % TASK_HASH_TABLE_CHAINS);
    140140}
    141141
     
    154154        assert(keys == 1);
    155155        assert(item);
    156 
    157         p2i_entry_t *e = hash_table_get_instance(item, p2i_entry_t, link);
    158 
    159         return (key[0] == e->phash);
     156       
     157        p2i_entry_t *entry = hash_table_get_instance(item, p2i_entry_t, link);
     158       
     159        return (key[0] == entry->in_phone_hash);
    160160}
    161161
     
    197197                return ENOMEM;
    198198        }
    199 
     199       
    200200        if (!hash_table_create(&phone_to_id, P2I_HASH_TABLE_CHAINS,
    201201            1, &p2i_ops)) {
     
    205205       
    206206        list_initialize(&pending_wait);
    207        
    208207        return EOK;
    209208}
     
    238237                            ht->retval);
    239238                }
    240 
     239               
    241240                hash_table_remove(&task_hash_table, keys, 2);
    242241                list_remove(cur);
     
    250249        sysarg_t retval;
    251250        task_exit_t texit;
    252 
     251       
    253252        unsigned long keys[2] = {
    254253                LOWER32(id),
    255254                UPPER32(id)
    256255        };
    257 
     256       
    258257        link_t *link = hash_table_find(&task_hash_table, keys);
    259258        hashed_task_t *ht = (link != NULL) ?
    260259            hash_table_get_instance(link, hashed_task_t, link) : NULL;
    261 
     260       
    262261        if (ht == NULL) {
    263262                /* No such task exists. */
     
    265264                return;
    266265        }
    267 
     266       
    268267        if (!ht->finished) {
    269268                /* Add to pending list */
     
    275274                }
    276275               
     276                link_initialize(&pr->link);
    277277                pr->id = id;
    278278                pr->callid = callid;
     
    293293int ns_task_id_intro(ipc_call_t *call)
    294294{
    295         task_id_t id;
    296295        unsigned long keys[2];
    297         link_t *link;
    298         p2i_entry_t *e;
    299         hashed_task_t *ht;
    300 
    301         id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
    302 
     296       
     297        task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
    303298        keys[0] = call->in_phone_hash;
    304 
    305         link = hash_table_find(&phone_to_id, keys);
     299       
     300        link_t *link = hash_table_find(&phone_to_id, keys);
    306301        if (link != NULL)
    307302                return EEXISTS;
    308 
    309         e = (p2i_entry_t *) malloc(sizeof(p2i_entry_t));
    310         if (e == NULL)
     303       
     304        p2i_entry_t *entry = (p2i_entry_t *) malloc(sizeof(p2i_entry_t));
     305        if (entry == NULL)
    311306                return ENOMEM;
    312 
    313         ht = (hashed_task_t *) malloc(sizeof(hashed_task_t));
     307       
     308        hashed_task_t *ht = (hashed_task_t *) malloc(sizeof(hashed_task_t));
    314309        if (ht == NULL)
    315310                return ENOMEM;
    316 
    317         /* Insert to phone-to-id map. */
    318 
    319         link_initialize(&e->link);
    320         e->phash = call->in_phone_hash;
    321         e->id = id;
    322         hash_table_insert(&phone_to_id, keys, &e->link);
    323 
    324         /* Insert to main table. */
    325 
     311       
     312        /*
     313         * Insert into the phone-to-id map.
     314         */
     315       
     316        link_initialize(&entry->link);
     317        entry->in_phone_hash = call->in_phone_hash;
     318        entry->id = id;
     319        hash_table_insert(&phone_to_id, keys, &entry->link);
     320       
     321        /*
     322         * Insert into the main table.
     323         */
     324       
    326325        keys[0] = LOWER32(id);
    327326        keys[1] = UPPER32(id);
    328 
     327       
    329328        link_initialize(&ht->link);
    330329        ht->id = id;
     
    333332        ht->retval = -1;
    334333        hash_table_insert(&task_hash_table, keys, &ht->link);
    335 
     334       
    336335        return EOK;
    337336}
    338337
     338static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id)
     339{
     340        unsigned long keys[1] = {phone_hash};
     341       
     342        link_t *link = hash_table_find(&phone_to_id, keys);
     343        if (link == NULL)
     344                return ENOENT;
     345       
     346        p2i_entry_t *entry = hash_table_get_instance(link, p2i_entry_t, link);
     347        *id = entry->id;
     348       
     349        return EOK;
     350}
     351
    339352int ns_task_retval(ipc_call_t *call)
    340353{
    341354        task_id_t id;
    342         unsigned long keys[2];
    343         int rc;
    344 
    345         rc = get_id_by_phone(call->in_phone_hash, &id);
     355        int rc = get_id_by_phone(call->in_phone_hash, &id);
    346356        if (rc != EOK)
    347357                return rc;
    348 
    349         keys[0] = LOWER32(id);
    350         keys[1] = UPPER32(id);
     358       
     359        unsigned long keys[2] = {
     360                LOWER32(id),
     361                UPPER32(id)
     362        };
    351363       
    352364        link_t *link = hash_table_find(&task_hash_table, keys);
     
    354366            hash_table_get_instance(link, hashed_task_t, link) : NULL;
    355367       
    356         if ((ht == NULL) || ht->finished)
     368        if ((ht == NULL) || (ht->finished))
    357369                return EINVAL;
    358 
     370       
    359371        ht->finished = true;
    360372        ht->have_rval = true;
    361373        ht->retval = IPC_GET_ARG1(*call);
    362 
     374       
    363375        return EOK;
    364376}
     
    367379{
    368380        unsigned long keys[2];
     381       
    369382        task_id_t id;
    370         int rc;
    371 
    372         rc = get_id_by_phone(call->in_phone_hash, &id);
     383        int rc = get_id_by_phone(call->in_phone_hash, &id);
    373384        if (rc != EOK)
    374385                return rc;
    375 
     386       
    376387        /* Delete from phone-to-id map. */
    377388        keys[0] = call->in_phone_hash;
    378389        hash_table_remove(&phone_to_id, keys, 1);
    379 
     390       
    380391        /* Mark task as finished. */
    381392        keys[0] = LOWER32(id);
    382393        keys[1] = UPPER32(id);
    383 
     394       
    384395        link_t *link = hash_table_find(&task_hash_table, keys);
    385396        hashed_task_t *ht =
     
    387398        if (ht == NULL)
    388399                return EOK;
    389 
     400       
    390401        ht->finished = true;
    391 
    392         return EOK;
    393 }
    394 
    395 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id)
    396 {
    397         unsigned long keys[1];
    398         link_t *link;
    399         p2i_entry_t *e;
    400 
    401         keys[0] = phone_hash;
    402         link = hash_table_find(&phone_to_id, keys);
    403         if (link == NULL)
    404                 return ENOENT;
    405 
    406         e = hash_table_get_instance(link, p2i_entry_t, link);
    407         *id = e->id;
    408 
     402       
    409403        return EOK;
    410404}
  • uspace/srv/ns/task.h

    rae0300b5 r007e6efa  
    3939extern void process_pending_wait(void);
    4040
    41 extern void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid);
     41extern void wait_for_task(task_id_t, ipc_call_t *, ipc_callid_t);
    4242
    43 extern int ns_task_id_intro(ipc_call_t *call);
    44 extern int ns_task_disconnect(ipc_call_t *call);
    45 extern int ns_task_retval(ipc_call_t *call);
     43extern int ns_task_id_intro(ipc_call_t *);
     44extern int ns_task_disconnect(ipc_call_t *);
     45extern int ns_task_retval(ipc_call_t *);
    4646
    4747
  • uspace/srv/vfs/vfs.c

    rae0300b5 r007e6efa  
    3838#include <ipc/ipc.h>
    3939#include <ipc/services.h>
     40#include <ipc/ns.h>
    4041#include <async.h>
    4142#include <errno.h>
     
    4748#include "vfs.h"
    4849
    49 #define NAME "vfs"
     50#define NAME  "vfs"
    5051
    5152static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall)
     
    172173         * Register at the naming service.
    173174         */
    174         ipc_connect_to_me(PHONE_NS, SERVICE_VFS, 0, 0, NULL, NULL);
     175        if (service_register(SERVICE_VFS) != EOK) {
     176                printf("%s: Cannot register VFS service\n", NAME);
     177                return EINVAL;
     178        }
    175179       
    176180        /*
Note: See TracChangeset for help on using the changeset viewer.