-- Stub file PDInterpControlRpcClientImpl.mesa was translated on 17-Nov-83
    -- 16:30:29 PST by Lupine of 18-Feb-83 11:25:52 PST.

-- Source interface PDInterpControl came from file PDInterpControl.bcd,
    -- which was created on 17-Nov-83 16:29:50 PST with version stamp 143#147#26343705132
    -- from source of 16-Nov-83 14:49:41 PST.

-- The RPC stub modules for PDInterpControl are:
    -- PDInterpControlRpcControl.mesa;
    -- PDInterpControlRpcClientImpl.mesa;
    -- PDInterpControlRpcBinderImpl.mesa;
    -- PDInterpControlRpcServerImpl.mesa.

-- The parameters for this translation are:
    -- Target language = Mesa;
    -- Default parameter passing = VALUE;
    -- Deallocate server heap arguments = TRUE;
    -- Inline RpcServerImpl dispatcher stubs = TRUE;
    -- Maximum number of dynamic heap NEWs = 50, MDS NEWs = 50;
    -- Acceptable parameter protocols = VersionRange[1,1].


DIRECTORY
  PDInterpControl,
  PDInterpControlRpcControl USING [InterMdsCallsOnly, LupineProtocolVersion,
      ProcedureIndex, SignalIndex],
  MesaRPC USING [InterfaceName, standardZones, Zones],
  RPCLupine --USING SOME OF [Call, DataLength, Dispatcher, GetStubPkt,
      -- ImportHandle, ImportInterface, maxDataLength, maxPrincipalLength,
      -- maxShortStringLength, pktOverhead, ReceiveExtraPkt, SendPrelimPkt,
      -- StartCall, StartSignal, StubPkt, UnimportInterface]--,
  LupineRuntime --USING SOME OF [BindingError, CheckPktLength, CopyFromPkt,
      -- CopyFromMultiplePkts, CopyToPkt, CopyToMultiplePkts, DispatchingError,
      -- FinishThisPkt, ListHeader, MarshalingError, MarshalingExprError,
      -- NilHeader, ProtocolError, RopeHeader, RpcPktDoubleWord, RuntimeError,
      -- SequenceHeader, SHORT, StartNextPkt, StringHeader, StubPktDoubleWord,
      -- TranslationError, UnmarshalingError, UnmarshalingExprError, WordsForChars]--,
  Heap USING [systemZone, systemMDSZone];


PDInterpControlRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, Lupine: LupineRuntime, Heap
  EXPORTS PDInterpControl, PDInterpControlRpcControl
  SHARES  PDInterpControl, PDInterpControlRpcControl
  = BEGIN OPEN PDInterpControl, RpcControl: PDInterpControlRpcControl,
      RpcPublic: MesaRPC;


-- Standard remote binding routines.

  bound: BOOLEAN ← FALSE;
  myInterface: RpcPrivate.ImportHandle ← NULL;
  paramZones: RpcPublic.Zones ← RpcPublic.standardZones;

  ImportInterface: PUBLIC ENTRY PROCEDURE [
        interfaceName: RpcPublic.InterfaceName,
        parameterStorage: RpcPublic.Zones ] =
    BEGIN ENABLE UNWIND => NULL;
    IsNull: PROCEDURE [string: LONG STRING] RETURNS [BOOLEAN] =
      INLINE {RETURN[ string=NIL OR string.length=0 ]};
    IF bound THEN Lupine.BindingError;
    myInterface ← RpcPrivate.ImportInterface [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "PDInterpControl~143#147#26343705132"L,
        instance: interfaceName.instance,
        version: interfaceName.version ],
      localOnly: RpcControl.InterMdsCallsOnly,
      stubProtocol: RpcControl.LupineProtocolVersion ];
    paramZones ← [
      heap: IF parameterStorage.heap # NIL
        THEN parameterStorage.heap ELSE Heap.systemZone,
      mds: IF parameterStorage.mds # NIL
        THEN parameterStorage.mds ELSE Heap.systemMDSZone ];
    bound ← TRUE;
    END;

  UnimportInterface: PUBLIC ENTRY PROCEDURE =
    BEGIN ENABLE UNWIND => NULL;
    IF ~bound THEN Lupine.BindingError;
    myInterface ← RpcPrivate.UnimportInterface[myInterface];
    paramZones ← RpcPublic.standardZones;
    bound ← FALSE;
    END;


-- Remote public procedure stubs.

  RequestService: PUBLIC PROCEDURE [requestorName: LONG STRING, pageSpec:
      PageSpec] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
	transferIndex (0): RpcControl.ProcedureIndex ← RequestService,
	pageSpec (1): PageSpec];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+254] OF WORD;
    pkt: RpcPrivate.StubPkt = RpcPrivate.GetStubPkt[space: @pktBuffer];
    argPkt: POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 61;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
    argPkt↑ ← [pageSpec: pageSpec];
    BEGIN  -- Marshal requestorName: LONG STRING to pkt.data[pktLength].
      IF pktLength+3 > RpcPrivate.maxDataLength
	THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength: pktLength];
      pkt.data[pktLength] ← requestorName=NIL;  pktLength ← pktLength+1;
      IF requestorName # NIL
	THEN BEGIN
	  stringHeader: Lupine.StringHeader = [
	    Lengths[length: requestorName.length, maxLength: requestorName.maxlength]];
	  Lupine.StubPktDoubleWord[pkt, pktLength]↑ ← stringHeader.all;
	  pktLength ← pktLength + 2;
	  pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
	      dataAdr: BASE[requestorName.text], dataLength: Lupine.WordsForChars[stringHeader.length],
	      alwaysOnePkt: FALSE];
	  END;  -- IF requestorName # NIL.
      END;  -- Marshal requestorName.
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
	  maxReturnLength: 0, signalHandler: ClientDispatcher];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 0];
    RETURN[];
    END;  -- RequestService.


-- Remote public signals and errors.


-- Public signal and error dispatcher.

  ClientDispatcher: --PROCEDURE [pkt: RPCPkt, callLength: DataLength,
      -- lastPkt: BOOLEAN, localConversation: Conversation] RETURNS [returnLength:
      -- DataLength]-- RpcPrivate.Dispatcher =
    BEGIN

    SELECT LOOPHOLE[pkt.data[0], RpcControl.SignalIndex] FROM
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ClientDispatcher


-- Public signal and error dispatcher stubs.


-- No module initialization.

  END.  -- PDInterpControlRpcClientImpl.