-- Stub file PDPrinterRpcClientImpl.mesa was translated on 18-Nov-83
    -- 13:13:32 PST by Lupine of 18-Feb-83 11:25:52 PST.

-- Source interface PDPrinter came from file PDPrinter.bcd, which was
    -- created on 18-Nov-83 13:13:16 PST with version stamp 52#57#3264557214
    -- from source of 18-Nov-83 10:11:40 PST.

-- The RPC stub modules for PDPrinter are:
    -- PDPrinterRpcControl.mesa;
    -- PDPrinterRpcClientImpl.mesa;
    -- PDPrinterRpcBinderImpl.mesa;
    -- PDPrinterRpcServerImpl.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,
  PDPrinter,
  PDPrinterRpcControl 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];


PDPrinterRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, Lupine: LupineRuntime, Heap
  EXPORTS PDPrinter, PDPrinterRpcControl
  SHARES  PDPrinter, PDPrinterRpcControl
  = BEGIN OPEN PDPrinter, RpcControl: PDPrinterRpcControl, 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 "PDPrinter~52#57#3264557214"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.

  TransmitBlock: PUBLIC PROCEDURE [dataBlock: DataBlock] RETURNS [--response:--
      Response] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
	transferIndex (0): RpcControl.ProcedureIndex ← TransmitBlock];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
	response (0): Response];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+254] 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 ← 1;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
    argPkt.transferIndex ← TransmitBlock;
    BEGIN  -- Marshal dataBlock: DataBlock to pkt.data[pktLength].
      pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
	  dataAdr: @dataBlock, dataLength: SIZE[DataBlock], alwaysOnePkt:
	  FALSE];
      END;  -- Marshal dataBlock.
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
	  maxReturnLength: 5, signalHandler: ClientDispatcher];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 5];
    RETURN[resPkt.response];
    END;  -- TransmitBlock.

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