Changeset 043dcc27 in mainline


Ignore:
Timestamp:
2006-05-15T13:45:12Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
108602e
Parents:
babe786
Message:

Implement simple connect_me_to in NS.
Disambigue the term phoneid by creating new term in_phone_hash,
which in fact represents kernel address of the phone sending the
message.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libadt/generic/hash_table.c

    rbabe786 r043dcc27  
    107107        assert(chain < h->entries);
    108108       
    109         /*
    110          * The hash table is not redundant.
    111          * Check if the keys are not in place already.
    112          */
    113109        for (cur = h->entry[chain].next; cur != &h->entry[chain]; cur = cur->next) {
    114110                if (h->op->compare(key, h->max_keys, cur)) {
  • libipc/generic/ipc.c

    rbabe786 r043dcc27  
    273273}
    274274
     275int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
     276{
     277        return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
     278}
     279
    275280/*
    276281int ipc_open_dgrconn(int pohoneid, size_t max_dgram)
  • libipc/include/ipc.h

    rbabe786 r043dcc27  
    3838typedef struct {
    3939        ipcarg_t args[IPC_CALL_LEN];
    40         ipcarg_t phoneid;
     40        ipcarg_t in_phone_hash;
    4141} ipc_call_t ;
    4242typedef sysarg_t ipc_callid_t;
     
    5959
    6060#define ipc_call_async(phoneid,method,arg1,private, callback) (ipc_call_async_2(phoneid, method, arg1, 0, private, callback))
    61 void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
     61extern void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
    6262                      ipcarg_t arg2, void *private,
    6363                      ipc_async_callback_t callback);
    64 int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone);
    65 int ipc_connect_me_to(int phoneid, int arg1, int arg2);
    66 int ipc_hangup(int phoneid);
    67 int ipc_register_irq(int irq, irq_code_t *code);
    68 int ipc_unregister_irq(int irq);
     64extern int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone);
     65extern int ipc_connect_me_to(int phoneid, int arg1, int arg2);
     66extern int ipc_hangup(int phoneid);
     67extern int ipc_register_irq(int irq, irq_code_t *code);
     68extern int ipc_unregister_irq(int irq);
     69extern int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1);
    6970
    7071#endif
  • ns/ns.c

    rbabe786 r043dcc27  
    4646#define NS_HASH_TABLE_CHAINS    20
    4747
     48static int register_service(ipcarg_t service, ipcarg_t phone, ipc_call_t *call);
     49static int connect_to_service(ipcarg_t service, ipc_call_t *call, ipc_callid_t callid);
     50
    4851/* Static functions implementing NS hash table operations. */
    4952static hash_index_t ns_hash(unsigned long *key);
    5053static int ns_compare(unsigned long *key, hash_count_t keys, link_t *item);
     54static void ns_remove(link_t *item);
    5155
    5256/** Operations for NS hash table. */
     
    5458        .hash = ns_hash,
    5559        .compare = ns_compare,
    56         .remove_callback = NULL
     60        .remove_callback = ns_remove
    5761};
    5862
     
    6569        ipcarg_t service;               /**< Number of the service. */
    6670        ipcarg_t phone;                 /**< Phone registered with the service. */
     71        ipcarg_t in_phone_hash;         /**< Incoming phone hash. */
    6772} hashed_service_t;
    6873
     
    101106        printf("%s: Name service started.\n", NAME);
    102107       
    103         if (!hash_table_create(&ns_hash_table, NS_HASH_TABLE_CHAINS, 1, &ns_hash_table_ops)) {
     108        if (!hash_table_create(&ns_hash_table, NS_HASH_TABLE_CHAINS, 3, &ns_hash_table_ops)) {
    104109                printf("%s: cannot create hash table\n", NAME);
    105110                return ENOMEM;
     
    111116        while (1) {
    112117                callid = ipc_wait_for_call(&call, 0);
    113                 printf("NS: Call phone=%lX...", call.phoneid);
     118                printf("NS: Call in_phone_hash=%lX...", call.in_phone_hash);
    114119                switch (IPC_GET_METHOD(call)) {
    115120                case IPC_M_AS_SEND:
     
    131136                        retval = 0;
    132137                        break;
    133                 case IPC_M_CONNECT_TO_ME:;
     138                case IPC_M_CONNECT_TO_ME:
    134139                        /*
    135                          * Request for registration of a service.
     140                         * Server requests service registration.
    136141                         */
    137                         ipcarg_t service;
    138                         ipcarg_t phone;
    139                         hashed_service_t *hs;
    140                        
    141                         service = IPC_GET_ARG1(call);
    142                         phone = IPC_GET_ARG3(call);
    143                         printf("Registering service %d on phone %d...", service, phone);
    144                        
    145                         hs = (hashed_service_t *) malloc(sizeof(hashed_service_t));
    146                         if (!hs) {
    147                                 printf("Failed to register service %d.\n", service);
    148                         }
    149                        
    150                         link_initialize(&hs->link);
    151                         hs->service = service;
    152                         hs->phone = phone;
    153                         hash_table_insert(&ns_hash_table, (unsigned long *) &service, &hs->link);
    154                        
    155                         ping_phone = phone;
    156                         retval = 0;
     142                        retval = register_service(IPC_GET_ARG1(call), IPC_GET_ARG3(call), &call);
     143                        ping_phone = IPC_GET_ARG3(call);
    157144                        break;
    158145                case IPC_M_CONNECT_ME_TO:
    159                         printf("Connectme(%P)to: %zd\n",
    160                                IPC_GET_ARG3(call), IPC_GET_ARG1(call));
    161                         retval = 0;
     146                        /*
     147                         * Client requests to be connected to a service.
     148                         */
     149                        retval = connect_to_service(IPC_GET_ARG1(call), &call, callid);
    162150                        break;
    163151                case NS_PING:
     
    189177}
    190178
     179/** Register server.
     180 *
     181 * @param service Service to be registered.
     182 * @param phone phone Phone to be used for connections to the service.
     183 * @param call Pointer to call structure.
     184 *
     185 * @return Zero on success or a value from @ref errno.h.
     186 */
     187int register_service(ipcarg_t service, ipcarg_t phone, ipc_call_t *call)
     188{
     189        unsigned long keys[3] = { service, call->in_phone_hash, 0 };
     190        hashed_service_t *hs;
     191                       
     192        printf("Registering service %d on phone %d...", service, phone);
     193
     194        if (hash_table_find(&ns_hash_table, keys)) {
     195                printf("Service %d already registered.\n", service);
     196                return EEXISTS;
     197        }
     198                       
     199        hs = (hashed_service_t *) malloc(sizeof(hashed_service_t));
     200        if (!hs) {
     201                printf("Failed to register service %d.\n", service);
     202                return ENOMEM;
     203        }
     204                       
     205        link_initialize(&hs->link);
     206        hs->service = service;
     207        hs->phone = phone;
     208        hs->in_phone_hash = call->in_phone_hash;
     209        hash_table_insert(&ns_hash_table, keys, &hs->link);
     210                       
     211        return 0;
     212}
     213
     214/** Connect client to service.
     215 *
     216 * @param service Service to be connected to.
     217 * @param call Pointer to call structure.
     218 * @param callid Call ID of the request.
     219 *
     220 * @return Zero on success or a value from @ref errno.h.
     221 */
     222int connect_to_service(ipcarg_t service, ipc_call_t *call, ipc_callid_t callid)
     223{
     224        unsigned long keys[3] = { service, 0, 0 };
     225        link_t *hlp;
     226        hashed_service_t *hs;
     227                       
     228        hlp = hash_table_find(&ns_hash_table, keys);
     229        if (!hlp) {
     230                printf("Service %d noty registered.\n", service);
     231                return ENOENT;
     232        }
     233        hs = hash_table_get_instance(hlp, hashed_service_t, link);
     234        printf("Connecting in_phone_hash=%lX to service at phone %d...", call->in_phone_hash, hs->phone);
     235        return ipc_forward_fast(callid, hs->phone, 0, 0);
     236}
     237
    191238/** Compute hash index into NS hash table.
    192239 *
    193  * @param key Pointer to single key (i.e. service number).
    194  * @return Hash index corresponding to *key.
     240 * @param key Pointer keys. However, only the first key (i.e. service number)
     241 *            is used to compute the hash index.
     242 * @return Hash index corresponding to key[0].
    195243 */
    196244hash_index_t ns_hash(unsigned long *key)
     
    202250/** Compare a key with hashed item.
    203251 *
    204  * @param key Single key pointer.
    205  * @param keys Must be 1.
     252 * This compare function always ignores the third key.
     253 * It exists only to make it possible to remove records
     254 * originating from connection with key[1] in_phone_hash
     255 * value. Note that this is close to being classified
     256 * as a nasty hack.
     257 *
     258 * @param key Array of keys.
     259 * @param keys Must be lesser or equal to 3.
    206260 * @param item Pointer to a hash table item.
    207261 * @return Non-zero if the key matches the item, zero otherwise.
    208262 */
    209 int ns_compare(unsigned long *key, hash_count_t keys, link_t *item)
     263int ns_compare(unsigned long key[], hash_count_t keys, link_t *item)
    210264{
    211265        hashed_service_t *hs;
    212266
    213267        assert(key);
    214         assert(keys == 1);
     268        assert(keys <= 3);
    215269        assert(item);
    216270       
    217271        hs = hash_table_get_instance(item, hashed_service_t, link);
    218272       
    219         return *key == hs->service;
    220 }
     273        if (keys == 2)
     274                return key[1] == hs->in_phone_hash;
     275        else
     276                return key[0] == hs->service;
     277}
     278
     279/** Perform actions after removal of item from the hash table.
     280 *
     281 * @param item Item that was removed from the hash table.
     282 */
     283void ns_remove(link_t *item)
     284{
     285        assert(item);
     286        free(hash_table_get_instance(item, hashed_service_t, link));
     287}
  • pci/pci.c

    rbabe786 r043dcc27  
    3232
    3333        int ipc_res;
    34         ipcarg_t ns_phone_addr;
     34        ipcarg_t ns_in_phone_hash;
    3535
    3636        printf("%s: HelenOS PCI driver\n", NAME);
     
    5656
    5757        printf("%s: registering at naming service.\n", NAME);
    58         if (ipc_connect_to_me(PHONE_NS, 40, 70, &ns_phone_addr) != 0) {
     58        if (ipc_connect_to_me(PHONE_NS, 40, 70, &ns_in_phone_hash) != 0) {
    5959                printf("Failed to register %s at naming service.\n", NAME);
    6060                return -1;
Note: See TracChangeset for help on using the changeset viewer.