00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00038 #include <ipc/ipc.h>
00039 #include <ipc/ns.h>
00040 #include <stdio.h>
00041 #include <errno.h>
00042 #include <macros.h>
00043 #include "ns.h"
00044 #include "service.h"
00045 #include "clonable.h"
00046 #include "task.h"
00047
00048 int main(int argc, char **argv)
00049 {
00050 printf(NAME ": HelenOS IPC Naming Service\n");
00051
00052 int rc = service_init();
00053 if (rc != EOK)
00054 return rc;
00055
00056 rc = clonable_init();
00057 if (rc != EOK)
00058 return rc;
00059
00060 rc = task_init();
00061 if (rc != EOK)
00062 return rc;
00063
00064 printf("%s: Accepting connections\n", NAME);
00065
00066 while (true) {
00067 process_pending_conn();
00068 process_pending_wait();
00069
00070 ipc_call_t call;
00071 ipc_callid_t callid = ipc_wait_for_call(&call);
00072
00073 task_id_t id;
00074 sysarg_t retval;
00075
00076 switch (IPC_GET_IMETHOD(call)) {
00077 case IPC_M_PHONE_HUNGUP:
00078 retval = ns_task_disconnect(&call);
00079 break;
00080 case IPC_M_CONNECT_TO_ME:
00081
00082
00083
00084 if (service_clonable(IPC_GET_ARG1(call))) {
00085 register_clonable(IPC_GET_ARG1(call),
00086 IPC_GET_ARG5(call), &call, callid);
00087 continue;
00088 } else {
00089 retval = register_service(IPC_GET_ARG1(call),
00090 IPC_GET_ARG5(call), &call);
00091 }
00092 break;
00093 case IPC_M_CONNECT_ME_TO:
00094
00095
00096
00097 if (service_clonable(IPC_GET_ARG1(call))) {
00098 connect_to_clonable(IPC_GET_ARG1(call),
00099 &call, callid);
00100 continue;
00101 } else {
00102 connect_to_service(IPC_GET_ARG1(call), &call,
00103 callid);
00104 continue;
00105 }
00106 break;
00107 case NS_PING:
00108 retval = EOK;
00109 break;
00110 case NS_TASK_WAIT:
00111 id = (task_id_t)
00112 MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
00113 wait_for_task(id, &call, callid);
00114 continue;
00115 case NS_ID_INTRO:
00116 retval = ns_task_id_intro(&call);
00117 break;
00118 case NS_RETVAL:
00119 retval = ns_task_retval(&call);
00120 break;
00121 default:
00122 retval = ENOENT;
00123 break;
00124 }
00125
00126 if (!(callid & IPC_CALLID_NOTIFICATION))
00127 ipc_answer_0(callid, retval);
00128 }
00129
00130
00131 return 0;
00132 }
00133