Rev 1084 | Rev 1088 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1084 | Rev 1086 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | 35 | ||
36 | /** Maximum active async calls per thread */ |
36 | /** Maximum active async calls per thread */ |
37 | #define IPC_MAX_ASYNC_CALLS 4 |
37 | #define IPC_MAX_ASYNC_CALLS 4 |
38 | 38 | ||
39 | /* Flags for calls */ |
39 | /* Flags for calls */ |
40 | #define IPC_CALL_ANSWERED 0x1 /**< This is answer to a call */ |
40 | #define IPC_CALL_ANSWERED (1<<0) /**< This is answer to a call */ |
41 | #define IPC_CALL_STATIC_ALLOC 0x2 /**< This call will not be freed on error */ |
41 | #define IPC_CALL_STATIC_ALLOC (1<<1) /**< This call will not be freed on error */ |
42 | #define IPC_CALL_DISPATCHED 0x4 /**< Call is in dispatch queue */ |
42 | #define IPC_CALL_DISPATCHED (1<<2) /**< Call is in dispatch queue */ |
- | 43 | #define IPC_CALL_DISCARD_ANSWER (1<<3) /**< Answer will not be passed to |
|
- | 44 | * userspace, will be discarded */ |
|
43 | 45 | ||
44 | /* Flags for ipc_wait_for_call */ |
46 | /* Flags for ipc_wait_for_call */ |
45 | #define IPC_WAIT_NONBLOCKING 1 |
47 | #define IPC_WAIT_NONBLOCKING 1 |
46 | 48 | ||
47 | /* Flags of callid */ |
49 | /* Flags of callid (the addresses are aligned at least to 4, |
- | 50 | * that is why we can use bottom 2 bits of the call address |
|
- | 51 | */ |
|
48 | #define IPC_CALLID_ANSWERED 1 |
52 | #define IPC_CALLID_ANSWERED 1 /**< Type of this msg is 'answer' */ |
- | 53 | #define IPC_CALLID_NOTIFICATION 2 /**< Type of this msg is 'notification' */ |
|
49 | 54 | ||
50 | /* Return values from IPC_ASYNC */ |
55 | /* Return values from IPC_ASYNC */ |
51 | #define IPC_CALLRET_FATAL -1 |
56 | #define IPC_CALLRET_FATAL -1 |
52 | #define IPC_CALLRET_TEMPORARY -2 |
57 | #define IPC_CALLRET_TEMPORARY -2 |
53 | 58 | ||
54 | 59 | ||
55 | /* Macros for manipulating calling data */ |
60 | /* Macros for manipulating calling data */ |
56 | #define IPC_SET_RETVAL(data, retval) ((data)[0] = (retval)) |
61 | #define IPC_SET_RETVAL(data, retval) ((data).args[0] = (retval)) |
57 | #define IPC_SET_METHOD(data, val) ((data)[0] = (val)) |
62 | #define IPC_SET_METHOD(data, val) ((data).args[0] = (val)) |
58 | #define IPC_SET_ARG1(data, val) ((data)[1] = (val)) |
63 | #define IPC_SET_ARG1(data, val) ((data).args[1] = (val)) |
59 | #define IPC_SET_ARG2(data, val) ((data)[2] = (val)) |
64 | #define IPC_SET_ARG2(data, val) ((data).args[2] = (val)) |
60 | #define IPC_SET_ARG3(data, val) ((data)[3] = (val)) |
65 | #define IPC_SET_ARG3(data, val) ((data).args[3] = (val)) |
61 | 66 | ||
62 | #define IPC_GET_METHOD(data) ((data)[0]) |
67 | #define IPC_GET_METHOD(data) ((data).args[0]) |
63 | #define IPC_GET_RETVAL(data) ((data)[0]) |
68 | #define IPC_GET_RETVAL(data) ((data).args[0]) |
64 | 69 | ||
65 | #define IPC_GET_ARG1(data) ((data)[1]) |
70 | #define IPC_GET_ARG1(data) ((data).args[1]) |
66 | #define IPC_GET_ARG2(data) ((data)[2]) |
71 | #define IPC_GET_ARG2(data) ((data).args[2]) |
67 | #define IPC_GET_ARG3(data) ((data)[3]) |
72 | #define IPC_GET_ARG3(data) ((data).args[3]) |
68 | 73 | ||
69 | /* Well known phone descriptors */ |
74 | /* Well known phone descriptors */ |
70 | #define PHONE_NS 0 |
75 | #define PHONE_NS 0 |
71 | 76 | ||
72 | /* System-specific methods - only through special syscalls |
77 | /* System-specific methods - only through special syscalls |
Line 87... | Line 92... | ||
87 | * the call is accepted and the response is sent back. |
92 | * the call is accepted and the response is sent back. |
88 | * - the allocated phoneid is passed to userspace |
93 | * - the allocated phoneid is passed to userspace |
89 | * (on the receiving sid) as ARG3 of the call. |
94 | * (on the receiving sid) as ARG3 of the call. |
90 | * - the caller obtains taskid of the called thread |
95 | * - the caller obtains taskid of the called thread |
91 | */ |
96 | */ |
92 | #define IPC_M_CONNECTTOME 1 |
97 | #define IPC_M_CONNECT_TO_ME 1 |
93 | /** Protocol for CONNECT - ME - TO |
98 | /** Protocol for CONNECT - ME - TO |
94 | * |
99 | * |
95 | * Calling process asks the callee to create for him a new connection. |
100 | * Calling process asks the callee to create for him a new connection. |
96 | * E.g. the caller wants a name server to connect him to print server. |
101 | * E.g. the caller wants a name server to connect him to print server. |
97 | * |
102 | * |
Line 106... | Line 111... | ||
106 | * - otherwise connection refused |
111 | * - otherwise connection refused |
107 | * - recepient may forward message. Forwarding |
112 | * - recepient may forward message. Forwarding |
108 | * system message |
113 | * system message |
109 | * |
114 | * |
110 | */ |
115 | */ |
111 | #define IPC_M_CONNECTMETO 2 |
116 | #define IPC_M_CONNECT_ME_TO 2 |
112 | /* Control messages that the server sends to the processes |
117 | /** This message is sent to answerbox when the phone |
113 | * about their connections. |
118 | * is hung up |
114 | */ |
119 | */ |
- | 120 | #define IPC_M_PHONE_HUNGUP 3 |
|
115 | 121 | ||
116 | 122 | ||
117 | /* Well-known methods */ |
123 | /* Well-known methods */ |
118 | #define IPC_M_LAST_SYSTEM 511 |
124 | #define IPC_M_LAST_SYSTEM 511 |
119 | #define IPC_M_PING 512 |
125 | #define IPC_M_PING 512 |
Line 126... | Line 132... | ||
126 | #include <synch/condvar.h> |
132 | #include <synch/condvar.h> |
127 | #include <adt/list.h> |
133 | #include <adt/list.h> |
128 | 134 | ||
129 | #define IPC_MAX_PHONES 16 |
135 | #define IPC_MAX_PHONES 16 |
130 | 136 | ||
131 | typedef struct answerbox answerbox_t; |
137 | typedef struct answerbox_s answerbox_t; |
132 | typedef __native ipc_data_t[IPC_CALL_LEN]; |
138 | typedef struct phone_s phone_t; |
133 | - | ||
134 | typedef struct { |
139 | typedef struct { |
135 | link_t list; |
- | |
136 | answerbox_t *callerbox; |
140 | __native args[IPC_CALL_LEN]; |
137 | int flags; |
- | |
138 | task_t *sender; |
141 | phone_t *phone; |
139 | ipc_data_t data; |
142 | }ipc_data_t; |
140 | } call_t; |
- | |
141 | 143 | ||
142 | struct answerbox { |
144 | struct answerbox_s { |
143 | SPINLOCK_DECLARE(lock); |
145 | SPINLOCK_DECLARE(lock); |
144 | 146 | ||
145 | task_t *task; |
147 | task_t *task; |
146 | 148 | ||
147 | waitq_t wq; |
149 | waitq_t wq; |
Line 151... | Line 153... | ||
151 | link_t dispatched_calls; /* Should be hash table in the future */ |
153 | link_t dispatched_calls; /* Should be hash table in the future */ |
152 | 154 | ||
153 | link_t answers; /**< Answered calls */ |
155 | link_t answers; /**< Answered calls */ |
154 | }; |
156 | }; |
155 | 157 | ||
156 | typedef struct { |
158 | struct phone_s { |
157 | SPINLOCK_DECLARE(lock); |
159 | SPINLOCK_DECLARE(lock); |
158 | link_t list; |
160 | link_t list; |
159 | answerbox_t *callee; |
161 | answerbox_t *callee; |
160 | int busy; |
162 | int busy; |
- | 163 | atomic_t active_calls; |
|
- | 164 | }; |
|
- | 165 | ||
- | 166 | typedef struct { |
|
- | 167 | link_t list; |
|
- | 168 | ||
- | 169 | int flags; |
|
- | 170 | ||
- | 171 | /* Identification of the caller */ |
|
- | 172 | task_t *sender; |
|
- | 173 | /* The caller box is different from sender->answerbox |
|
- | 174 | * for synchronous calls |
|
- | 175 | */ |
|
- | 176 | answerbox_t *callerbox; |
|
- | 177 | ||
- | 178 | ipc_data_t data; |
|
161 | } phone_t; |
179 | }call_t; |
162 | 180 | ||
163 | extern void ipc_init(void); |
181 | extern void ipc_init(void); |
164 | extern call_t * ipc_wait_for_call(answerbox_t *box, int flags); |
182 | extern call_t * ipc_wait_for_call(answerbox_t *box, int flags); |
165 | extern void ipc_answer(answerbox_t *box, call_t *request); |
183 | extern void ipc_answer(answerbox_t *box, call_t *request); |
166 | extern void ipc_call(phone_t *phone, call_t *request); |
184 | extern void ipc_call(phone_t *phone, call_t *request); |
167 | extern void ipc_call_sync(phone_t *phone, call_t *request); |
185 | extern void ipc_call_sync(phone_t *phone, call_t *request); |
168 | extern void ipc_phone_destroy(phone_t *phone); |
- | |
169 | extern void ipc_phone_init(phone_t *phone); |
186 | extern void ipc_phone_init(phone_t *phone); |
170 | extern void ipc_phone_connect(phone_t *phone, answerbox_t *box); |
187 | extern void ipc_phone_connect(phone_t *phone, answerbox_t *box); |
171 | extern void ipc_call_free(call_t *call); |
188 | extern void ipc_call_free(call_t *call); |
172 | extern call_t * ipc_call_alloc(void); |
189 | extern call_t * ipc_call_alloc(void); |
173 | extern void ipc_answerbox_init(answerbox_t *box); |
190 | extern void ipc_answerbox_init(answerbox_t *box); |
Line 175... | Line 192... | ||
175 | extern void task_print_list(void); |
192 | extern void task_print_list(void); |
176 | extern void ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox); |
193 | extern void ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox); |
177 | 194 | ||
178 | extern answerbox_t *ipc_phone_0; |
195 | extern answerbox_t *ipc_phone_0; |
179 | extern void ipc_cleanup(task_t *task); |
196 | extern void ipc_cleanup(task_t *task); |
- | 197 | extern int ipc_phone_hangup(phone_t *phone); |
|
180 | 198 | ||
181 | #endif |
199 | #endif |
182 | 200 | ||
183 | #endif |
201 | #endif |