-- CommunicationControl.mesa  (last edited by: BLyon on: January 16, 1981  3:01 PM)
-- Function: The control module for Pilot's Communication configuration.
-- Edited by Andrew Birrell on May 27, 1983 4:15 pm (comment out NetworkStreamMgr)

DIRECTORY
  CommunicationInternal USING [
    ChecksumsImpl, EchoServerImpl, PacketExchangeImpl, PilotCommUtil, RouterImpl,
    RoutingTableImpl, SocketImpl, --NetworkStreamMgr,-- PacketStreamMgr],
  DriverDefs USING [CommPackageGo, CommPackageOff, Boss],
  Echo USING [CreateServer, DeleteServer],
  GermSwap USING [switches],
  MPCodes USING [communicationInitialized],
  OISCP USING [OiscpPackageReady],
  ProcessorFace USING [SetMP],
  Router USING [OisRouterOff, OisRouterOn],
  SocketInternal USING [SocketOn],
  StatsOps USING [StatsHot];

CommunicationControl: MONITOR
  IMPORTS
    CommunicationInternal, DriverDefs, Echo, GermSwap, OISCP, ProcessorFace, Router, SocketInternal,
    StatsOps
  EXPORTS OISCP =
  BEGIN

  -- monitor data
  useCount: CARDINAL;

  StartupCommunication: PROCEDURE =
    -- module initialization:
    BEGIN
    useCount ← 0;
    START StatsOps.StatsHot;
    START CommunicationInternal.PilotCommUtil;
    -- AdjustSystemBufferParms[];
    START DriverDefs.Boss;
    START CommunicationInternal.ChecksumsImpl;
    START CommunicationInternal.RouterImpl;
    START CommunicationInternal.RoutingTableImpl;
    START CommunicationInternal.SocketImpl;
    START CommunicationInternal.PacketExchangeImpl;
    START CommunicationInternal.EchoServerImpl;
    OiscpPackageMake[];
    START CommunicationInternal.PacketStreamMgr;
    --START CommunicationInternal.NetworkStreamMgr;--
    ProcessorFace.SetMP[MPCodes.communicationInitialized];
    END;

  InitializeCommunication: PUBLIC PROCEDURE =
    -- module initialization:
    BEGIN
    -- the start trap takes care of everything

    END;


  -- The procedure that a normal client calls to start things either before or
  -- after the MakeImage.

  OiscpPackageMake: PUBLIC ENTRY PROCEDURE =
    BEGIN
    IF (useCount ← useCount + 1) > 1 THEN RETURN;
    OISCP.OiscpPackageReady[];
    DriverDefs.CommPackageGo[];
    Router.OisRouterOn[];
    SocketInternal.SocketOn[];
    Echo.CreateServer[];
    END;

  -- The procedure that a normal client calls to stop things

  OiscpPackageDestroy: PUBLIC ENTRY PROCEDURE =
    BEGIN
    IF (useCount = 0) THEN RETURN;
    IF (useCount ← useCount - 1) > 0 THEN RETURN;
    Echo.DeleteServer[];
    Router.OisRouterOff[];
    DriverDefs.CommPackageOff[];
    END;

  -- main line code

  IF NOT GermSwap.switches[c] THEN StartupCommunication[];

  END.  -- CommunicationControl module
LOG
Time: January 20, 1980  11:01 AM	By: Dalal	Action: changed initialization order.
Time: February 5, 1980  8:31 PM	By: Dalal	Action: started of SimpleHeapImpl.
Time: February 5, 1980  9:16 PM	By: Dalal	Action: added Echo Server.
Time: August 18, 1978  11:37 AM	By: Knutsen	Action: Module now STARTed by  InitializeCommunication[].
Time: May 6, 1980  6:35 PM	By: BLyon	Action: Temp removed CommunicationPrograms from EXPORTS; added  mainline  code so that Communications can be build/started seperately from TestPilotKernel ..  tajo.  
Time: August 11, 1980  3:39 PM	By: BLyon	Action: made it so that communication can start on a start trap (added running: BOOLEAN). 
Time: August 20, 1980  10:38 AM	By: BLyon	Action: added START ChecksumsImpl 
Time: October 22, 1980  3:56 PM	By: BLyon	Action: IF (useCount=0) THEN RETURN in OiscpPackageDestroy.