home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 332.lha / IPC_nov89 / Sources / Broker_skel.c < prev    next >
C/C++ Source or Header  |  1990-01-09  |  3KB  |  123 lines

  1. /* Primitive test program for LoadIPCPort facility */
  2. /* ...simply displays a request for a port in its console window */
  3. /* Shared Library version 89:3:26 */
  4.  
  5. #include "IPCPorts.h"
  6. #include "IPC_proto.h"
  7. #include "IPC.h"
  8.  
  9. #include "exec/memory.h"
  10. #include "exec/tasks.h"
  11. #include "libraries/DOS.h"
  12.  
  13. #define  SOL(s)  ((LONG)sizeof(s))
  14.  
  15. #define IPPL MAKE_ID('I','P','P','L')
  16. #define PORT MAKE_ID('P','O','R','T')
  17.  
  18. ULONG IPCBase = NULL;
  19.  
  20. struct IPCPort *brokerport;
  21. struct IPCMessage *imsg=NULL;
  22.  
  23. void baditem(struct IPCItem *, ULONG);
  24. void outputstr(char *);
  25.  
  26. struct Task * FindTask(char *);
  27.  
  28. void Cleanup();
  29.  
  30.  
  31. ULONG bportsig = 0;  /* signal masks for port */
  32.  
  33. int active = TRUE;
  34.  
  35.  
  36. void _main()
  37. {
  38.     ULONG sigset;
  39.  
  40.     IPCBase = OpenLibrary("ppipc.library",0);
  41.     if (!IPCBase) {
  42.         outputstr("couldn't find IPC Library -- TTFN...\n");
  43.         _exit(20);
  44.     }
  45.  
  46.     brokerport = ServeIPCPort("PortBrokerPort");
  47.     if (!brokerport) {Cleanup(); _exit(11);}
  48.     bportsig = 1<<brokerport->ipp_Port.mp_SigBit;
  49.     outputstr("Opened 'PortBrokerPort'\n");
  50.  
  51.  
  52.     do {
  53.         while ( procimsg() ) ;    /* loop */
  54.         if (active) {
  55.             sigset = Wait(bportsig | SIGBREAKF_CTRL_C);
  56.             if (sigset & SIGBREAKF_CTRL_C) {
  57.                 active = FALSE;
  58.                 ShutIPCPort(brokerport);
  59.                 continue; /* so we clear out any messages that sneak in */
  60.             }
  61.         }
  62.     } while (active);
  63.     outputstr("Broker terminating...\n");
  64.  
  65.     Cleanup();
  66. }
  67.  
  68.  
  69. void Cleanup()
  70. {
  71.     if (brokerport) LeaveIPCPort(brokerport);
  72.     CloseLibrary(IPCBase);
  73. }
  74.  
  75.  
  76. procimsg()
  77. {
  78.     struct IPCItem *item;
  79.     if (!(imsg = (struct IPCMessage *) GetMsg(brokerport))) return FALSE;
  80.     outputstr("got message\n");
  81.     item = imsg->ipc_Items;
  82.     if (imsg->ipc_Id == IPPL && item->ii_Id == PORT
  83.         && loadport(item->ii_Ptr)) /* everything OK */;
  84.     else imsg->ipc_Flags |= IPC_NOTKNOWN;
  85.     ReplyMsg(imsg);
  86.     return TRUE;
  87. }
  88.  
  89.  
  90. void baditem(item, extraflags)
  91.     struct IPCItem *item;
  92.     ULONG extraflags;
  93. {
  94.     imsg->ipc_Flags |= IPC_CHECKITEM;
  95.     item->ii_Flags |= IPC_NOTKNOWN | extraflags;
  96. }
  97.  
  98. void outputstr(str) char *str;
  99. {
  100.     Write(Output(), str, strlen(str));
  101. }
  102.  
  103.  
  104. /*
  105.  *  loadport(portptr)
  106.  *
  107.  *  -- actually initiates the loading procedure (here just a skeleton).
  108.  *      returns TRUE if successful, otherwise FALSE.
  109.  */
  110.  
  111. loadport(port) struct IPCPort *port;
  112. {
  113.     outputstr("Please load server for port '");
  114.     outputstr(port->ipp_Name);
  115.     outputstr("' -- Thanks\n");
  116.     return TRUE; /* -- doesn't know how to fail yet... */
  117. }
  118.  
  119.  
  120. /****************************************************************/
  121.  
  122.  
  123.