home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 164.lha / IPC / Sources / LoadIPCPort.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-28  |  1.8 KB  |  58 lines

  1. /********************************************************************
  2.  *                                                                  *
  3.  *                 LoadIPCPort module 88:7:22                       *
  4.  *                                                                  *
  5.  ********************************************************************/
  6.  
  7. #include "IPCPorts.h"
  8. #include "IPC.h"
  9.  
  10. #define IPPL MAKE_ID('I','P','P','L')
  11. #define PORT MAKE_ID('P','O','R','T')
  12.  
  13. extern struct IPCBasePort *IPCBasePort;
  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 IPCBasePort (if IT has a server) requesting that a server
  21.  *     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 * LoadIPCPort(name) char *name;
  28. {
  29.     struct IPCPort *port=NULL,
  30.                    *RPort = NULL;
  31.     struct IPCMessage *mesg = NULL;
  32.     struct IPCItem *item;
  33.  
  34.     port = GetIPCPort(name);
  35.     if (!port) return NULL;
  36.     if (port->ipp_Flags & (IPP_SERVED | IPP_LOADING))
  37.         return port;
  38.     if ((RPort = ServeIPCPort(NULL)) /* only a replyport really */
  39.             && (mesg = CreateIPCMsg(1L, 0L, (struct MsgPort *)RPort))) {
  40.         mesg->ipc_Id = IPPL;
  41.         item = mesg->ipc_Items;
  42.         item->ii_Id = PORT;
  43.         item->ii_Ptr = (void *)port;
  44.         if (PutIPCMsg((struct IPCPort *)IPCBasePort, mesg)) {
  45.             WaitPort(RPort);
  46.             GetMsg(RPort);
  47.         }
  48.     }
  49.     if (RPort) LeaveIPCPort(RPort);
  50.     if (mesg) DeleteIPCMsg(mesg);
  51.     if (port->ipp_Flags & (IPP_SERVED | IPP_LOADING))
  52.         return port;
  53.     DropIPCPort(port);
  54.     return NULL;
  55. }
  56.  
  57.  
  58.