Rev 1360 | Rev 1365 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1360 | Rev 1363 | ||
---|---|---|---|
Line 43... | Line 43... | ||
43 | 43 | ||
44 | #define NAME "NS" |
44 | #define NAME "NS" |
45 | 45 | ||
46 | #define NS_HASH_TABLE_CHAINS 20 |
46 | #define NS_HASH_TABLE_CHAINS 20 |
47 | 47 | ||
- | 48 | extern int __DONT_OPEN_STDIO__=1; |
|
- | 49 | ||
48 | static int register_service(ipcarg_t service, ipcarg_t phone, ipc_call_t *call); |
50 | static int register_service(ipcarg_t service, ipcarg_t phone, ipc_call_t *call); |
49 | static int connect_to_service(ipcarg_t service, ipc_call_t *call, ipc_callid_t callid); |
51 | static int connect_to_service(ipcarg_t service, ipc_call_t *call, ipc_callid_t callid); |
50 | 52 | ||
51 | /* Static functions implementing NS hash table operations. */ |
53 | /* Static functions implementing NS hash table operations. */ |
52 | static hash_index_t ns_hash(unsigned long *key); |
54 | static hash_index_t ns_hash(unsigned long *key); |
Line 79... | Line 81... | ||
79 | ipc_callid_t callid; |
81 | ipc_callid_t callid; |
80 | char *as_area; |
82 | char *as_area; |
81 | 83 | ||
82 | ipcarg_t retval, arg1, arg2; |
84 | ipcarg_t retval, arg1, arg2; |
83 | 85 | ||
84 | printf("%s: Naming service started.\n", NAME); |
86 | // printf("%s: Naming service started.\n", NAME); |
85 | 87 | ||
86 | if (!hash_table_create(&ns_hash_table, NS_HASH_TABLE_CHAINS, 3, &ns_hash_table_ops)) { |
88 | if (!hash_table_create(&ns_hash_table, NS_HASH_TABLE_CHAINS, 3, &ns_hash_table_ops)) { |
87 | printf("%s: cannot create hash table\n", NAME); |
89 | // printf("%s: cannot create hash table\n", NAME); |
88 | return ENOMEM; |
90 | return ENOMEM; |
89 | } |
91 | } |
90 | 92 | ||
91 | while (1) { |
93 | while (1) { |
92 | callid = ipc_wait_for_call(&call, 0); |
94 | callid = ipc_wait_for_call(&call, 0); |
93 | // printf("NS: Call in_phone_hash=%lX...", call.in_phone_hash); |
95 | // printf("NS: Call in_phone_hash=%lX...", call.in_phone_hash); |
94 | switch (IPC_GET_METHOD(call)) { |
96 | switch (IPC_GET_METHOD(call)) { |
95 | case IPC_M_AS_AREA_SEND: |
97 | case IPC_M_AS_AREA_SEND: |
96 | as_area = (char *)IPC_GET_ARG2(call); |
98 | as_area = (char *)IPC_GET_ARG2(call); |
97 | printf("Received as_area: %P, size:%d\n", as_area, IPC_GET_ARG3(call)); |
99 | // printf("Received as_area: %P, size:%d\n", as_area, IPC_GET_ARG3(call)); |
98 | retval = ipc_answer_fast(callid, 0,(sysarg_t)(1024*1024), 0); |
100 | retval = ipc_answer_fast(callid, 0,(sysarg_t)(1024*1024), 0); |
99 | if (!retval) { |
101 | if (!retval) { |
100 | printf("Reading shared memory..."); |
102 | // printf("Reading shared memory..."); |
101 | printf("Text: %s", as_area); |
103 | // printf("Text: %s", as_area); |
102 | } else |
104 | } else |
103 | printf("Failed answer: %d\n", retval); |
105 | // printf("Failed answer: %d\n", retval); |
104 | continue; |
106 | continue; |
105 | break; |
107 | break; |
106 | case IPC_M_INTERRUPT: |
108 | case IPC_M_INTERRUPT: |
107 | printf("GOT INTERRUPT: %c\n", IPC_GET_ARG2(call)); |
109 | // printf("GOT INTERRUPT: %c\n", IPC_GET_ARG2(call)); |
108 | break; |
110 | break; |
109 | case IPC_M_PHONE_HUNGUP: |
111 | case IPC_M_PHONE_HUNGUP: |
110 | printf("Phone hung up.\n"); |
112 | // printf("Phone hung up.\n"); |
111 | retval = 0; |
113 | retval = 0; |
112 | break; |
114 | break; |
113 | case IPC_M_CONNECT_TO_ME: |
115 | case IPC_M_CONNECT_TO_ME: |
114 | /* |
116 | /* |
115 | * Server requests service registration. |
117 | * Server requests service registration. |
Line 122... | Line 124... | ||
122 | * Client requests to be connected to a service. |
124 | * Client requests to be connected to a service. |
123 | */ |
125 | */ |
124 | retval = connect_to_service(IPC_GET_ARG1(call), &call, callid); |
126 | retval = connect_to_service(IPC_GET_ARG1(call), &call, callid); |
125 | break; |
127 | break; |
126 | case NS_HANGUP: |
128 | case NS_HANGUP: |
127 | printf("Closing connection.\n"); |
129 | // printf("Closing connection.\n"); |
128 | retval = EHANGUP; |
130 | retval = EHANGUP; |
129 | break; |
131 | break; |
130 | case NS_PING: |
132 | case NS_PING: |
131 | printf("Ping...%P %P\n", IPC_GET_ARG1(call), |
133 | // printf("Ping...%P %P\n", IPC_GET_ARG1(call), |
132 | IPC_GET_ARG2(call)); |
134 | // IPC_GET_ARG2(call)); |
133 | retval = 0; |
135 | retval = 0; |
134 | arg1 = 0xdead; |
136 | arg1 = 0xdead; |
135 | arg2 = 0xbeef; |
137 | arg2 = 0xbeef; |
136 | break; |
138 | break; |
137 | case NS_PING_SVC: |
139 | case NS_PING_SVC: |
138 | printf("NS:Pinging service %d\n", ping_phone); |
140 | // printf("NS:Pinging service %d\n", ping_phone); |
139 | ipc_call_sync(ping_phone, NS_PING, 0xbeef, 0); |
141 | ipc_call_sync(ping_phone, NS_PING, 0xbeef, 0); |
140 | printf("NS:Got pong\n"); |
142 | // printf("NS:Got pong\n"); |
141 | break; |
143 | break; |
142 | default: |
144 | default: |
143 | printf("Unknown method: %zd\n", IPC_GET_METHOD(call)); |
145 | // printf("Unknown method: %zd\n", IPC_GET_METHOD(call)); |
144 | retval = ENOENT; |
146 | retval = ENOENT; |
145 | break; |
147 | break; |
146 | } |
148 | } |
147 | if (! (callid & IPC_CALLID_NOTIFICATION)) { |
149 | if (! (callid & IPC_CALLID_NOTIFICATION)) { |
148 | // printf("Answering.\n"); |
150 | // printf("Answering.\n"); |
Line 162... | Line 164... | ||
162 | int register_service(ipcarg_t service, ipcarg_t phone, ipc_call_t *call) |
164 | int register_service(ipcarg_t service, ipcarg_t phone, ipc_call_t *call) |
163 | { |
165 | { |
164 | unsigned long keys[3] = { service, call->in_phone_hash, 0 }; |
166 | unsigned long keys[3] = { service, call->in_phone_hash, 0 }; |
165 | hashed_service_t *hs; |
167 | hashed_service_t *hs; |
166 | 168 | ||
167 | printf("Registering service %d on phone %d...", service, phone); |
169 | // printf("Registering service %d on phone %d...", service, phone); |
168 | 170 | ||
169 | if (hash_table_find(&ns_hash_table, keys)) { |
171 | if (hash_table_find(&ns_hash_table, keys)) { |
170 | printf("Service %d already registered.\n", service); |
172 | // printf("Service %d already registered.\n", service); |
171 | return EEXISTS; |
173 | return EEXISTS; |
172 | } |
174 | } |
173 | 175 | ||
174 | hs = (hashed_service_t *) malloc(sizeof(hashed_service_t)); |
176 | hs = (hashed_service_t *) malloc(sizeof(hashed_service_t)); |
175 | if (!hs) { |
177 | if (!hs) { |
176 | printf("Failed to register service %d.\n", service); |
178 | // printf("Failed to register service %d.\n", service); |
177 | return ENOMEM; |
179 | return ENOMEM; |
178 | } |
180 | } |
179 | 181 | ||
180 | link_initialize(&hs->link); |
182 | link_initialize(&hs->link); |
181 | hs->service = service; |
183 | hs->service = service; |
Line 204... | Line 206... | ||
204 | if (!hlp) { |
206 | if (!hlp) { |
205 | // printf("Service %d not registered.\n", service); |
207 | // printf("Service %d not registered.\n", service); |
206 | return ENOENT; |
208 | return ENOENT; |
207 | } |
209 | } |
208 | hs = hash_table_get_instance(hlp, hashed_service_t, link); |
210 | hs = hash_table_get_instance(hlp, hashed_service_t, link); |
209 | printf("Connecting in_phone_hash=%lX to service at phone %d...", call->in_phone_hash, hs->phone); |
211 | // printf("Connecting in_phone_hash=%lX to service at phone %d...", call->in_phone_hash, hs->phone); |
210 | return ipc_forward_fast(callid, hs->phone, 0, 0); |
212 | return ipc_forward_fast(callid, hs->phone, 0, 0); |
211 | } |
213 | } |
212 | 214 | ||
213 | /** Compute hash index into NS hash table. |
215 | /** Compute hash index into NS hash table. |
214 | * |
216 | * |