Changeset 07e4a3c in mainline


Ignore:
Timestamp:
2007-09-28T23:11:46Z (17 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b878df3
Parents:
af0ff9b2
Message:

Added message forwarding to device mapper.

Location:
uspace/srv/devmap
Files:
2 edited

Legend:

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

    raf0ff9b2 r07e4a3c  
    4141#include <stdio.h>
    4242#include <errno.h>
     43#include <bool.h>
     44#include <libadt/list.h>
     45#include <futex.h>
    4346
    4447#include "devmap.h"
    4548
     49LIST_INITIALIZE(device_list);
     50
     51atomic_t device_list_futex = FUTEX_INITIALIZER;
     52
    4653/** Initialize device mapper.
    4754 *
     
    5259        /* */
    5360
    54         return 0;
    55 }
    56 
    57 
    58 /** Function for handling connections to devmap
    59  *
    60  */
    61 static void
    62 devmap_client_connection(ipc_callid_t iid, ipc_call_t *icall)
    63 {
     61        return EOK;
     62}
     63
     64static int devmap_register()
     65{
     66        ipc_callid_t callid2;
     67        size_t size;
     68        char buffer[DEVMAP_NAME_MAXLEN + 1];
    6469        ipc_callid_t callid;
    6570        ipc_call_t call;
    6671        int retval;
     72       
     73        if (ipc_data_receive(&callid, &call, NULL, &size) != 0) {
     74        //      retval =
     75        }
     76
     77        if (size > DEVMAP_NAME_MAXLEN) {
     78                retval = ELIMIT;
     79        } else {
     80                ipc_data_deliver(callid2, &call, buffer, size);
     81                buffer[DEVMAP_NAME_MAXLEN] = 0;
     82        }
     83        return EOK;
     84}
     85
     86static int devmap_unregister()
     87{
     88        return EOK;
     89}
     90
     91static int devmap_forward(int handle, ipc_call_t *call, ipc_callid_t callid)
     92{
     93        link_t *item;
     94        ipcarg_t phone;
     95        devmap_device_t *dev;
     96
     97        /* FIXME: add futex */
     98        futex_down(&device_list_futex);
     99
     100        item = (&device_list)->next;
     101
     102        while (item != &device_list) {
     103
     104                dev = list_get_instance(item, devmap_device_t, list);
     105                if (dev->handle == handle) {
     106                        break;
     107                }
     108                item = item->next;
     109        }
     110
     111        if (item == &device_list) {
     112                return ENOENT;
     113        }
     114
     115        dev = list_get_instance(item, devmap_device_t, list);
     116        phone = dev->phone;
     117
     118        futex_up(&device_list_futex);
     119       
     120        return ipc_forward_fast(callid, phone, 0, 0);
     121}
     122
     123static int devmap_get_handle()
     124{
     125        return EOK;
     126}
     127
     128/** Function for handling connections to devmap
     129 *
     130 */
     131static void
     132devmap_client_connection(ipc_callid_t iid, ipc_call_t *icall)
     133{
     134        ipc_callid_t callid;
     135        ipc_call_t call;
     136        int retval;
     137        bool cont = true;
     138
     139        printf("DevMap: new connection.");
    67140
    68141        ipc_answer_fast(iid, EOK, 0, 0); /* Accept connection */
    69142
    70         while (1) {
     143        while (cont) {
    71144                callid = async_get_call(&call);
    72145
     
    74147                case IPC_M_PHONE_HUNGUP:
    75148                                /* TODO: if its a device connection, remove it from table */
    76                         return; /* Exit thread */
     149                        devmap_unregister();
     150                        printf("DevMap: connection hung up.");
     151                        cont = false;
     152                        continue; /* Exit thread */
    77153
    78154                case DEVMAP_REGISTER:
    79                         /* TODO: */
     155                       
     156                        if ((retval = devmap_register()) != EOK) {
     157                                cont = false;
     158                        }
     159                        break;
    80160                case DEVMAP_UNREGISTER:
    81                         /* TODO: */
     161                        /* TODO: remove device (if registred) */
     162                        retval = devmap_unregister();
     163                        cont = false;
     164                        break;
    82165                case DEVMAP_CONNECT_TO_DEVICE:
    83                         /* TODO: */
    84                         retval = 0;
     166                        retval = devmap_forward(IPC_GET_ARG1(call), &call, callid);
     167                        cont = false;
     168                        break;
     169                case DEVMAP_GET_HANDLE:
     170                       
    85171                        break;
    86172                default:
     
    90176        }
    91177               
     178        printf("DevMap: connection closed.");
     179        return;
    92180}
    93181
  • uspace/srv/devmap/devmap.h

    raf0ff9b2 r07e4a3c  
    3535
    3636#include <ipc/ipc.h>
     37#include <libadt/list.h>
     38
     39#define DEVMAP_NAME_MAXLEN 512
    3740
    3841typedef enum {
    3942        DEVMAP_REGISTER = IPC_FIRST_USER_METHOD,
    4043        DEVMAP_UNREGISTER,
    41         DEVMAP_CONNECT_TO_DEVICE
     44        DEVMAP_CONNECT_TO_DEVICE,
     45        DEVMAP_GET_HANDLE
    4246} devmap_request_t;
     47
     48
     49/** Info about registered device
     50 *
     51 */
     52typedef struct {
     53        link_t list;
     54        int handle;
     55        char *name;
     56        ipcarg_t phone;
     57} devmap_device_t;
    4358
    4459#endif
Note: See TracChangeset for help on using the changeset viewer.