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

-- Source interface PDTransfer came from file PDTransfer.bcd, which
    -- was created on 17-Nov-83 16:29:48 PST with version stamp 52#64#3245523734
    -- from source of 16-Nov-83 16:06:10 PST.

-- The RPC stub modules for PDTransfer are:
    -- PDTransferRpcControl.mesa;
    -- PDTransferRpcClientImpl.mesa;
    -- PDTransferRpcBinderImpl.mesa;
    -- PDTransferRpcServerImpl.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
  PDInterpBasic,
  PDTransfer,
  PDTransferRpcControl 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];


PDTransferRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, Lupine: LupineRuntime, Heap
  EXPORTS PDTransfer, PDTransferRpcControl
  SHARES  PDTransfer, PDTransferRpcControl
  = BEGIN OPEN PDTransfer, RpcControl: PDTransferRpcControl, 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 "PDTransfer~52#64#3245523734"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.

  GetBlock: PUBLIC PROCEDURE [sourceIndex: INT, words: INT] RETURNS
      [anonP1id2457549: DataBlock] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
	transferIndex (0): RpcControl.ProcedureIndex ← GetBlock, sourceIndex
	(1): INT, words (3): INT];
    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 ← 5;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
    argPkt↑ ← [sourceIndex: sourceIndex, words: words];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
	  maxReturnLength: 254, signalHandler: ClientDispatcher];
    pktLength ← 0;
    BEGIN  -- Unmarshal anonP1id2457549: DataBlock from pkt.data[pktLength].
      pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
	  dataAdr: @anonP1id2457549, dataLength: SIZE[DataBlock], alwaysOnePkt:
	  FALSE];
      END;  -- Unmarshal anonP1id2457549.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    RETURN[anonP1id2457549];
    END;  -- GetBlock.

  ReportStatus: PUBLIC PROCEDURE [status: PDInterpBasic.Status, queueSize:
      NAT, queuePosition: NAT, page: INT, pass: INT, sourceIndex: INT]
    RETURNS [--abort:-- BOOLEAN] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
	transferIndex (0): RpcControl.ProcedureIndex ← ReportStatus, status
	(1): PDInterpBasic.Status, queueSize (2): NAT, queuePosition (3):
	NAT, page (4): INT, pass (6): INT, sourceIndex (8): INT];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
	abort (0): BOOLEAN];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+10] OF WORD;
    pkt: RpcPrivate.StubPkt = RpcPrivate.GetStubPkt[space: @pktBuffer];
    argPkt: POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 10;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
    argPkt↑ ← [status: status, queueSize: queueSize, queuePosition:
	queuePosition, page: page, pass: pass, sourceIndex: sourceIndex];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
	  maxReturnLength: 1, signalHandler: ClientDispatcher];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    RETURN[resPkt.abort];
    END;  -- ReportStatus.


-- 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.  -- PDTransferRpcClientImpl.