Subversion Repositories HelenOS-historic

Rev

Rev 1089 | Rev 1282 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <ipc.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <ns.h>
  6. #include <errno.h>
  7.  
  8. static int service;
  9.  
  10. int main(int argc, char **argv)
  11. {
  12.     ipc_call_t call;
  13.     ipc_callid_t callid;
  14.    
  15.     ipcarg_t retval, arg1, arg2;
  16.  
  17.     printf("NS:Name service started.\n");
  18.     while (1) {
  19.         callid = ipc_wait_for_call(&call, 0);
  20.         printf("NS:Call phone=%lX..", call.phoneid);
  21.         switch (IPC_GET_METHOD(call)) {
  22.         case IPC_M_PHONE_HUNGUP:
  23.             printf("Phone hung up.\n");
  24.             retval = 0;
  25.             break;
  26.         case IPC_M_CONNECT_TO_ME:
  27.             printf("Somebody connecting phid=%zd.\n", IPC_GET_ARG3(call));
  28.             service = IPC_GET_ARG3(call);
  29.             retval = 0;
  30.             break;
  31.         case IPC_M_CONNECT_ME_TO:
  32.             printf("Connectme(%P)to: %zd\n",
  33.                    IPC_GET_ARG3(call), IPC_GET_ARG1(call));
  34.             retval = 0;
  35.             break;
  36.         case NS_PING:
  37.             printf("Ping...%P %P\n", IPC_GET_ARG1(call),
  38.                    IPC_GET_ARG2(call));
  39.             retval = 0;
  40.             arg1 = 0xdead;
  41.             arg2 = 0xbeef;
  42.             break;
  43.         case NS_HANGUP:
  44.             printf("Closing connection.\n");
  45.             retval = EHANGUP;
  46.             break;
  47.         case NS_PING_SVC:
  48.             printf("NS:Pinging service %d\n", service);
  49.             ipc_call_sync(service, NS_PING, 0xbeef, 0);
  50.             printf("NS:Got pong\n");
  51.             break;
  52.         default:
  53.             printf("Unknown method: %zd\n", IPC_GET_METHOD(call));
  54.             retval = ENOENT;
  55.             break;
  56.         }
  57.         ipc_answer(callid, retval, arg1, arg2);
  58.     }
  59. }
  60.