Rev 2550 | Rev 2594 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2550 | Rev 2555 | ||
---|---|---|---|
Line 38... | Line 38... | ||
38 | #include <ipc/services.h> |
38 | #include <ipc/services.h> |
39 | #include <ipc/ns.h> |
39 | #include <ipc/ns.h> |
40 | #include <async.h> |
40 | #include <async.h> |
41 | #include <stdio.h> |
41 | #include <stdio.h> |
42 | #include <errno.h> |
42 | #include <errno.h> |
- | 43 | #include <bool.h> |
|
- | 44 | #include <libadt/list.h> |
|
- | 45 | #include <futex.h> |
|
43 | 46 | ||
44 | #include "devmap.h" |
47 | #include "devmap.h" |
45 | 48 | ||
- | 49 | LIST_INITIALIZE(device_list); |
|
- | 50 | ||
- | 51 | atomic_t device_list_futex = FUTEX_INITIALIZER; |
|
- | 52 | ||
46 | /** Initialize device mapper. |
53 | /** Initialize device mapper. |
47 | * |
54 | * |
48 | * |
55 | * |
49 | */ |
56 | */ |
50 | static int devmap_init() |
57 | static int devmap_init() |
51 | { |
58 | { |
52 | /* */ |
59 | /* */ |
53 | 60 | ||
54 | return 0; |
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]; |
|
- | 69 | ipc_callid_t callid; |
|
- | 70 | ipc_call_t call; |
|
- | 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); |
|
55 | } |
121 | } |
56 | 122 | ||
- | 123 | static int devmap_get_handle() |
|
- | 124 | { |
|
- | 125 | return EOK; |
|
- | 126 | } |
|
57 | 127 | ||
58 | /** Function for handling connections to devmap |
128 | /** Function for handling connections to devmap |
59 | * |
129 | * |
60 | */ |
130 | */ |
61 | static void |
131 | static void |
62 | devmap_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
132 | devmap_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
63 | { |
133 | { |
64 | ipc_callid_t callid; |
134 | ipc_callid_t callid; |
65 | ipc_call_t call; |
135 | ipc_call_t call; |
66 | int retval; |
136 | int retval; |
- | 137 | bool cont = true; |
|
- | 138 | ||
- | 139 | printf("DevMap: new connection."); |
|
67 | 140 | ||
68 | ipc_answer_fast(iid, EOK, 0, 0); /* Accept connection */ |
141 | ipc_answer_fast(iid, EOK, 0, 0); /* Accept connection */ |
69 | 142 | ||
70 | while (1) { |
143 | while (cont) { |
71 | callid = async_get_call(&call); |
144 | callid = async_get_call(&call); |
72 | 145 | ||
73 | switch (IPC_GET_METHOD(call)) { |
146 | switch (IPC_GET_METHOD(call)) { |
74 | case IPC_M_PHONE_HUNGUP: |
147 | case IPC_M_PHONE_HUNGUP: |
75 | /* TODO: if its a device connection, remove it from table */ |
148 | /* TODO: if its a device connection, remove it from table */ |
- | 149 | devmap_unregister(); |
|
- | 150 | printf("DevMap: connection hung up."); |
|
- | 151 | cont = false; |
|
76 | return; /* Exit thread */ |
152 | continue; /* Exit thread */ |
77 | 153 | ||
78 | case DEVMAP_REGISTER: |
154 | case DEVMAP_REGISTER: |
- | 155 | ||
- | 156 | if ((retval = devmap_register()) != EOK) { |
|
79 | /* TODO: */ |
157 | cont = false; |
- | 158 | } |
|
- | 159 | break; |
|
80 | case DEVMAP_UNREGISTER: |
160 | case DEVMAP_UNREGISTER: |
- | 161 | /* TODO: remove device (if registred) */ |
|
- | 162 | retval = devmap_unregister(); |
|
81 | /* TODO: */ |
163 | cont = false; |
- | 164 | break; |
|
82 | case DEVMAP_CONNECT_TO_DEVICE: |
165 | case DEVMAP_CONNECT_TO_DEVICE: |
- | 166 | retval = devmap_forward(IPC_GET_ARG1(call), &call, callid); |
|
83 | /* TODO: */ |
167 | cont = false; |
84 | retval = 0; |
168 | break; |
- | 169 | case DEVMAP_GET_HANDLE: |
|
- | 170 | ||
85 | break; |
171 | break; |
86 | default: |
172 | default: |
87 | retval = ENOENT; |
173 | retval = ENOENT; |
88 | } |
174 | } |
89 | ipc_answer_fast(callid, retval, 0, 0); |
175 | ipc_answer_fast(callid, retval, 0, 0); |
90 | } |
176 | } |
91 | 177 | ||
- | 178 | printf("DevMap: connection closed."); |
|
- | 179 | return; |
|
92 | } |
180 | } |
93 | 181 | ||
94 | 182 | ||
95 | int main(int argc, char *argv[]) |
183 | int main(int argc, char *argv[]) |
96 | { |
184 | { |