Changeset 07e4a3c in mainline
- Timestamp:
- 2007-09-28T23:11:46Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b878df3
- Parents:
- af0ff9b2
- Location:
- uspace/srv/devmap
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
raf0ff9b2 r07e4a3c 41 41 #include <stdio.h> 42 42 #include <errno.h> 43 #include <bool.h> 44 #include <libadt/list.h> 45 #include <futex.h> 43 46 44 47 #include "devmap.h" 45 48 49 LIST_INITIALIZE(device_list); 50 51 atomic_t device_list_futex = FUTEX_INITIALIZER; 52 46 53 /** Initialize device mapper. 47 54 * … … 52 59 /* */ 53 60 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 64 static int devmap_register() 65 { 66 ipc_callid_t callid2; 67 size_t size; 68 char buffer[DEVMAP_NAME_MAXLEN + 1]; 64 69 ipc_callid_t callid; 65 70 ipc_call_t call; 66 71 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 86 static int devmap_unregister() 87 { 88 return EOK; 89 } 90 91 static 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 123 static int devmap_get_handle() 124 { 125 return EOK; 126 } 127 128 /** Function for handling connections to devmap 129 * 130 */ 131 static void 132 devmap_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."); 67 140 68 141 ipc_answer_fast(iid, EOK, 0, 0); /* Accept connection */ 69 142 70 while ( 1) {143 while (cont) { 71 144 callid = async_get_call(&call); 72 145 … … 74 147 case IPC_M_PHONE_HUNGUP: 75 148 /* 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 */ 77 153 78 154 case DEVMAP_REGISTER: 79 /* TODO: */ 155 156 if ((retval = devmap_register()) != EOK) { 157 cont = false; 158 } 159 break; 80 160 case DEVMAP_UNREGISTER: 81 /* TODO: */ 161 /* TODO: remove device (if registred) */ 162 retval = devmap_unregister(); 163 cont = false; 164 break; 82 165 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 85 171 break; 86 172 default: … … 90 176 } 91 177 178 printf("DevMap: connection closed."); 179 return; 92 180 } 93 181 -
uspace/srv/devmap/devmap.h
raf0ff9b2 r07e4a3c 35 35 36 36 #include <ipc/ipc.h> 37 #include <libadt/list.h> 38 39 #define DEVMAP_NAME_MAXLEN 512 37 40 38 41 typedef enum { 39 42 DEVMAP_REGISTER = IPC_FIRST_USER_METHOD, 40 43 DEVMAP_UNREGISTER, 41 DEVMAP_CONNECT_TO_DEVICE 44 DEVMAP_CONNECT_TO_DEVICE, 45 DEVMAP_GET_HANDLE 42 46 } devmap_request_t; 47 48 49 /** Info about registered device 50 * 51 */ 52 typedef struct { 53 link_t list; 54 int handle; 55 char *name; 56 ipcarg_t phone; 57 } devmap_device_t; 43 58 44 59 #endif
Note:
See TracChangeset
for help on using the changeset viewer.