home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff290.lzh / IPC / IPC_Lib_Sources / LoadIPCPort.c < prev    next >
C/C++ Source or Header  |  1989-12-11  |  2KB  |  62 lines

  1. /********************************************************************
  2.  *                                                                  *
  3.  *                 LoadIPCPort module 89:3:26                       *
  4.  *                                                                  *
  5.  *                  Shared Library version                          *
  6.  *                                                                  *
  7.  ********************************************************************/
  8.  
  9. #include "IPCStruct.h"
  10. #include "IPCAsmCalls.h"
  11.  
  12. #define IPPL MAKE_ID('I','P','P','L')
  13. #define PORT MAKE_ID('P','O','R','T')
  14.  
  15. /*
  16.  *  LoadIPCPort
  17.  *
  18.  *     Gets an IPCPort of the specified name.  If it is not already
  19.  *     being served or had a server being loaded, a message is sent
  20.  *     to PortBrokerPort (if IT exists and has a server) requesting
  21.  *     that a server be supplied.
  22.  *     If, when the message is replied, the port is flagged as served
  23.  *     or being loaded, the port pointer is returned. If no server is
  24.  *     available, it drops the port again and returns NULL.
  25.  */
  26.  
  27. struct IPCPort * __asm LoadIPCPort(register __a0 char *name)
  28. {
  29.     struct IPCPort * port = NULL,
  30.                    * RPort = NULL,
  31.                    * brokerport = NULL;
  32.     struct IPCMessage *mesg = NULL;
  33.     struct IPCItem *item;
  34.  
  35.     port = GetIPCPort(name);
  36.     if (!port) return NULL;
  37.     if (port->ipp_Flags & (IPP_SERVED | IPP_LOADING))
  38.         return port;
  39.     if ((RPort = ServeIPCPort(NULL)) /* only a replyport really
  40.                                     ... saves need for CreatePort */
  41.             && (mesg = CreateIPCMsg(1, 0, (struct MsgPort *)RPort))
  42.             && (brokerport = FindIPCPort("PortBrokerPort"))) {
  43.         mesg->ipc_Id = IPPL;
  44.         item = mesg->ipc_Items;
  45.         item->ii_Id = PORT;
  46.         item->ii_Ptr = (void *)port;
  47.         if (PutIPCMsg(brokerport, mesg)) {
  48.             WaitPort(RPort);
  49.             GetMsg(RPort);
  50.         }
  51.         DropIPCPort(brokerport);
  52.     }
  53.     if (RPort) LeaveIPCPort(RPort); /* No need to shut it first */
  54.     if (mesg) DeleteIPCMsg(mesg);
  55.     if (port->ipp_Flags & (IPP_SERVED | IPP_LOADING))
  56.         return port;
  57.     DropIPCPort(port);
  58.     return NULL;
  59. }
  60.  
  61.  
  62.