Subversion Repositories HelenOS-historic

Rev

Rev 1285 | Rev 1335 | 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. irq_cmd_t msim_cmds[1] = {
  9.     { CMD_MEM_READ_1, (void *)0xB0000000, 0 }
  10. };
  11.  
  12. irq_code_t msim_kbd = {
  13.     1,
  14.     msim_cmds
  15. };
  16. */
  17. /*
  18. irq_cmd_t i8042_cmds[1] = {
  19.     { CMD_PORT_READ_1, (void *)0x60, 0 }
  20. };
  21.  
  22. irq_code_t i8042_kbd = {
  23.     1,
  24.     i8042_cmds
  25. };
  26. */
  27.  
  28. static int service;
  29.  
  30. int main(int argc, char **argv)
  31. {
  32.     ipc_call_t call;
  33.     ipc_callid_t callid;
  34.     char *as;
  35.    
  36.     ipcarg_t retval, arg1, arg2;
  37.  
  38.     printf("NS:Name service started.\n");
  39. //  ipc_register_irq(2, &msim_kbd);
  40. //  ipc_register_irq(1, &i8042_kbd);
  41.     while (1) {
  42.         callid = ipc_wait_for_call(&call, 0);
  43.         printf("NS:Call phone=%lX..", call.phoneid);
  44.         switch (IPC_GET_METHOD(call)) {
  45.         case IPC_M_AS_SEND:
  46.             as = (char *)IPC_GET_ARG2(call);
  47.             printf("Received as: %P, size:%d\n", as, IPC_GET_ARG3(call));
  48.             retval = ipc_answer(callid, 0,(sysarg_t)(1024*1024), 0);
  49.             if (!retval) {
  50.                 printf("Reading shared memory...");
  51.                 printf("Text: %s", as);
  52.             } else
  53.                 printf("Failed answer: %d\n", retval);
  54.             continue;
  55.             break;
  56.         case IPC_M_INTERRUPT:
  57.             printf("GOT INTERRUPT: %c\n", IPC_GET_ARG2(call));
  58.             break;
  59.         case IPC_M_PHONE_HUNGUP:
  60.             printf("Phone hung up.\n");
  61.             retval = 0;
  62.             break;
  63.         case IPC_M_CONNECT_TO_ME:
  64.             printf("Somebody connecting phid=%zd.\n", IPC_GET_ARG3(call));
  65.             service = IPC_GET_ARG3(call);
  66.             retval = 0;
  67.             break;
  68.         case IPC_M_CONNECT_ME_TO:
  69.             printf("Connectme(%P)to: %zd\n",
  70.                    IPC_GET_ARG3(call), IPC_GET_ARG1(call));
  71.             retval = 0;
  72.             break;
  73.         case NS_PING:
  74.             printf("Ping...%P %P\n", IPC_GET_ARG1(call),
  75.                    IPC_GET_ARG2(call));
  76.             retval = 0;
  77.             arg1 = 0xdead;
  78.             arg2 = 0xbeef;
  79.             break;
  80.         case NS_HANGUP:
  81.             printf("Closing connection.\n");
  82.             retval = EHANGUP;
  83.             break;
  84.         case NS_PING_SVC:
  85.             printf("NS:Pinging service %d\n", service);
  86.             ipc_call_sync(service, NS_PING, 0xbeef, 0);
  87.             printf("NS:Got pong\n");
  88.             break;
  89.         default:
  90.             printf("Unknown method: %zd\n", IPC_GET_METHOD(call));
  91.             retval = ENOENT;
  92.             break;
  93.         }
  94.         if (! (callid & IPC_CALLID_NOTIFICATION)) {
  95.             printf("Answerinh\n");
  96.             ipc_answer(callid, retval, arg1, arg2);
  97.         }
  98.     }
  99. }
  100.