-- Stub file  was translated on February 22, 1984 8:55:09 am PST by Lupine of December 20, 1983 1:22:57 pm PST
-- Source interface PDPrinter came from file PDPrinter.bcd, which was created on February 22, 1984 8:54:40 am PST with version stamp 44#52#35257757166 from source of November 18, 1983 10:11:40 am 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
--   Declare signals = TRUE
--   Warn about short POINTER ("MDS") allocations = 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 [EncryptionKey, InterfaceName, Principal, standardZones,
      Zones],
  MesaRPCLupine --USING SOME OF [Call, DataLength, Dispatcher, ExportHandle,
      -- ExportInterface, GetStubPkt, maxDataLength, maxPrincipalLength,
      -- maxShortStringLength, pktOverhead, ReceiveExtraPkt, SendPrelimPkt,
      -- StartCall, StartSignal, StubPkt, UnexportInterface]--,
  LupineRuntime --USING SOME OF [BindingError, CheckPktLength, CopyFromPkt,
      -- CopyFromMultiplePkts, CopyToPkt, CopyToMultiplePkts, defaultZones,
      -- DispatchingError, FinishThisPkt, ListHeader, MarshalingError,
      -- MarshalingExprError, NilHeader, ProtocolError, RopeHeader, RpcPktDoubleWord,
      -- RuntimeError, SequenceHeader, SHORT, StartNextPkt, StringHeader,
      -- StubPktDoubleWord, TranslationError, UnmarshalingError, UnmarshalingExprError,
      -- WordsForChars]--;


PDPrinterRpcServerImpl: MONITOR
  IMPORTS PDPrinter, RpcPrivate: MesaRPCLupine, Lupine: LupineRuntime
  EXPORTS PDPrinterRpcControl
  SHARES  PDPrinter, PDPrinterRpcControl
  = BEGIN OPEN PDPrinter, RpcControl: PDPrinterRpcControl, RpcPublic:
      MesaRPC;


-- Standard remote binding routines.

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

  ExportInterface: PUBLIC ENTRY PROCEDURE [
        interfaceName: RpcPublic.InterfaceName,
        user: RpcPublic.Principal,
        password: RpcPublic.EncryptionKey,
        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.ExportInterface [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "PDPrinter~44#52#35257757166",
        instance: interfaceName.instance,
        version: interfaceName.version ],
      user: user,  password: password,
      dispatcher: ServerDispatcher,
      localOnly: RpcControl.InterMdsCallsOnly,
      stubProtocol: RpcControl.LupineProtocolVersion ];
    paramZones ← [
      gc: IF parameterStorage.gc # NIL
        THEN parameterStorage.gc ELSE Lupine.defaultZones.gc,
      heap: IF parameterStorage.heap # NIL
        THEN parameterStorage.heap ELSE Lupine.defaultZones.heap,
      mds: IF parameterStorage.mds # NIL
        THEN parameterStorage.mds ELSE Lupine.defaultZones.mds ];
    bound ← TRUE;
    END;

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


-- Public procedure dispatcher and public signal and error catcher.

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

    -- Catch public signals.

      ENABLE BEGIN

      END;  -- Catch public signals.


    -- Call public procedures (still in dispatcher).

    SELECT LOOPHOLE[pkt.data[0], RpcControl.ProcedureIndex] FROM
      TransmitBlock => RETURN[
        TransmitBlockStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ServerDispatcher


-- Public procedure dispatcher stubs.

  TransmitBlockStub: --PROCEDURE [dataBlock: DataBlock] RETURNS [response:
      -- Response]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    dataBlock: DataBlock;
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        response (0): Response];
    resPkt: LONG POINTER TO ResultOverlay;
    pktLength: RpcPrivate.DataLength ← 1;
    BEGIN  -- Unmarshal dataBlock: DataBlock from pkt.data[pktLength].
      pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
          dataAdr: @dataBlock, dataLength: SIZE[DataBlock], alwaysOnePkt:
          FALSE];
      END;  -- Unmarshal dataBlock.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    resPkt ← @pkt.data[0];
    [resPkt.response] ← TransmitBlock[dataBlock];
    pktLength ← 5;
    RETURN[returnLength: pktLength];
    END;  -- TransmitBlockStub.


-- No module initialization.

END.  -- PDPrinterRpcServerImpl.