Rev 3438 | Rev 3444 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3438 | Rev 3443 | ||
---|---|---|---|
Line 61... | Line 61... | ||
61 | int have_conn[MAX_PHONE]; |
61 | int have_conn[MAX_PHONE]; |
62 | 62 | ||
63 | #define PCALL_TABLE_CHAINS 32 |
63 | #define PCALL_TABLE_CHAINS 32 |
64 | hash_table_t pending_calls; |
64 | hash_table_t pending_calls; |
65 | 65 | ||
- | 66 | /* |
|
- | 67 | * Pseudo-protocols |
|
- | 68 | */ |
|
- | 69 | proto_t *proto_system; /**< Protocol describing system IPC methods. */ |
|
- | 70 | proto_t *proto_unknown; /**< Protocol with no known methods. */ |
|
- | 71 | ||
66 | static hash_index_t pending_call_hash(unsigned long key[]); |
72 | static hash_index_t pending_call_hash(unsigned long key[]); |
67 | static int pending_call_compare(unsigned long key[], hash_count_t keys, |
73 | static int pending_call_compare(unsigned long key[], hash_count_t keys, |
68 | link_t *item); |
74 | link_t *item); |
69 | static void pending_call_remove_callback(link_t *item); |
75 | static void pending_call_remove_callback(link_t *item); |
70 | 76 | ||
Line 113... | Line 119... | ||
113 | connections[phone].proto = NULL; |
119 | connections[phone].proto = NULL; |
114 | } |
120 | } |
115 | 121 | ||
116 | static void ipc_m_print(proto_t *proto, ipcarg_t method) |
122 | static void ipc_m_print(proto_t *proto, ipcarg_t method) |
117 | { |
123 | { |
118 | ipc_m_desc_t *desc; |
- | |
119 | oper_t *oper; |
124 | oper_t *oper; |
120 | 125 | ||
121 | /* FIXME: too slow */ |
126 | /* Try system methods first */ |
122 | desc = ipc_methods; |
- | |
123 | while (desc->number != 0) { |
- | |
124 | if (desc->number == method) { |
- | |
125 | printf("%s (%d)", desc->name, method); |
127 | oper = proto_get_oper(proto_system, method); |
126 | return; |
- | |
127 | } |
- | |
128 | 128 | ||
- | 129 | if (oper == NULL && proto != NULL) { |
|
- | 130 | /* Not a system method, try the user protocol. */ |
|
129 | ++desc; |
131 | oper = proto_get_oper(proto, method); |
130 | } |
132 | } |
131 | 133 | ||
132 | if (proto != NULL) { |
- | |
133 | oper = proto_get_oper(proto, method); |
- | |
134 | if (oper != NULL) { |
134 | if (oper != NULL) { |
135 | printf("%s (%d)", oper->name, method); |
135 | printf("%s (%d)", oper->name, method); |
136 | return; |
136 | return; |
137 | } |
- | |
138 | } |
137 | } |
139 | 138 | ||
140 | printf("%d", method); |
139 | printf("%d", method); |
141 | } |
140 | } |
142 | 141 | ||
143 | void ipcp_init(void) |
142 | void ipcp_init(void) |
144 | { |
143 | { |
- | 144 | ipc_m_desc_t *desc; |
|
- | 145 | oper_t *oper; |
|
- | 146 | ||
- | 147 | /* |
|
- | 148 | * Create a pseudo-protocol 'unknown' that has no known methods. |
|
- | 149 | */ |
|
- | 150 | proto_unknown = proto_new("unknown"); |
|
- | 151 | ||
- | 152 | /* |
|
- | 153 | * Create a pseudo-protocol 'system' defining names of system IPC |
|
- | 154 | * methods. |
|
- | 155 | */ |
|
- | 156 | proto_system = proto_new("system"); |
|
- | 157 | ||
- | 158 | desc = ipc_methods; |
|
- | 159 | while (desc->number != 0) { |
|
- | 160 | oper = oper_new(desc->name); |
|
- | 161 | proto_add_oper(proto_system, desc->number, oper); |
|
- | 162 | ||
- | 163 | ++desc; |
|
- | 164 | } |
|
- | 165 | ||
145 | hash_table_create(&pending_calls, PCALL_TABLE_CHAINS, 1, &pending_call_ops); |
166 | hash_table_create(&pending_calls, PCALL_TABLE_CHAINS, 1, &pending_call_ops); |
146 | } |
167 | } |
147 | 168 | ||
148 | void ipcp_cleanup(void) |
169 | void ipcp_cleanup(void) |
149 | { |
170 | { |
- | 171 | proto_delete(proto_system); |
|
150 | hash_table_destroy(&pending_calls); |
172 | hash_table_destroy(&pending_calls); |
151 | } |
173 | } |
152 | 174 | ||
153 | void ipcp_call_out(int phone, ipc_call_t *call, ipc_callid_t hash) |
175 | void ipcp_call_out(int phone, ipc_call_t *call, ipc_callid_t hash) |
154 | { |
176 | { |
Line 187... | Line 209... | ||
187 | { |
209 | { |
188 | int phone; |
210 | int phone; |
189 | ipcarg_t method; |
211 | ipcarg_t method; |
190 | ipcarg_t service; |
212 | ipcarg_t service; |
191 | int retval; |
213 | int retval; |
192 | static proto_t proto_unknown = { .name = "unknown" }; |
- | |
193 | proto_t *proto; |
214 | proto_t *proto; |
194 | int cphone; |
215 | int cphone; |
195 | 216 | ||
196 | // printf("parse_answer\n"); |
217 | // printf("parse_answer\n"); |
197 | 218 | ||
Line 203... | Line 224... | ||
203 | 224 | ||
204 | if (phone == 0 && method == IPC_M_CONNECT_ME_TO && retval == 0) { |
225 | if (phone == 0 && method == IPC_M_CONNECT_ME_TO && retval == 0) { |
205 | /* Connected to a service (through NS) */ |
226 | /* Connected to a service (through NS) */ |
206 | service = IPC_GET_ARG1(pcall->question); |
227 | service = IPC_GET_ARG1(pcall->question); |
207 | proto = proto_get_by_srv(service); |
228 | proto = proto_get_by_srv(service); |
208 | if (proto == NULL) proto = &proto_unknown; |
229 | if (proto == NULL) proto = proto_unknown; |
209 | 230 | ||
210 | cphone = IPC_GET_ARG5(*answer); |
231 | cphone = IPC_GET_ARG5(*answer); |
211 | printf("registering connection (phone %d, protocol: %s)\n", cphone, |
232 | printf("registering connection (phone %d, protocol: %s)\n", cphone, |
212 | proto->name); |
233 | proto->name); |
213 | ipcp_connection_set(cphone, 0, proto); |
234 | ipcp_connection_set(cphone, 0, proto); |