-- Copyright (C) 1985 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on May 2, 1985 4:16:19 pm PDT by Lupine of March 15, 1985 2:49:13 pm PST
-- Source interface ComputeServerDebugger came from file ComputeServerDebugger.bcd, which was created on May 2, 1985 4:16:15 pm PDT with version stamp 37#164#6434657572 from source of October 3, 1984 11:19:36 am PDT.

-- The RPC stub modules for ComputeServerDebugger are:
--   ComputeServerDebuggerRpcControl.mesa;
--   ComputeServerDebuggerRpcClientImpl.mesa;
--   ComputeServerDebuggerRpcBinderImpl.mesa;
--   ComputeServerDebuggerRpcServerImpl.mesa.

-- The parameters for this translation are:
--   Target language = Cedar
--   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
  PupDefs,
  Rope,
  ComputeServerDebugger,
  ComputeServerDebuggerRpcControl USING [InterMdsCallsOnly, LupineProtocolVersion,
      ProcedureIndex, SignalIndex],
  RPC USING [EncryptionKey, InterfaceName, Principal, standardZones,
      Zones],
  RPCLupine --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, MarshalAtom, MarshalRope, NilHeader, ProtocolError,
      -- RopeHeader, RpcPktDoubleWord, RuntimeError, SequenceHeader, SHORT,
      -- StartNextPkt, StringHeader, StubPktDoubleWord, TranslationError,
      -- UnmarshalingError, UnmarshalingExprError, UnmarshalAtom, UnmarshalRope,
      -- WordsForChars]--,
  Atom --USING SOME OF [GetPName, MakeAtom]--;


ComputeServerDebuggerRpcServerImpl: MONITOR
  IMPORTS ComputeServerDebugger, RpcPrivate: RPCLupine, Lupine: LupineRuntime,
      Atom, Rope
  EXPORTS ComputeServerDebuggerRpcControl
  SHARES  ComputeServerDebugger, ComputeServerDebuggerRpcControl, Rope
  = BEGIN OPEN ComputeServerDebugger, RpcControl: ComputeServerDebuggerRpcControl,
      RpcPublic: RPC;


-- Standard remote binding routines.

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

  ExportInterface: PUBLIC ENTRY SAFE PROCEDURE [
        interfaceName: RpcPublic.InterfaceName,
        user: RpcPublic.Principal,
        password: RpcPublic.EncryptionKey,
        parameterStorage: RpcPublic.Zones ] =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IsNull: PROCEDURE [string: Rope.ROPE] RETURNS [BOOLEAN] =
      INLINE {RETURN[string.Length[] = 0]};
    IF bound THEN Lupine.BindingError;
    myInterface ← RpcPrivate.ExportInterface [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "ComputeServerDebugger~37#164#6434657572",
        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 SAFE PROCEDURE =
    TRUSTED 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
      OpenDebugStream => RETURN[
        OpenDebugStreamStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      OpenSourceViewer => RETURN[
        OpenSourceViewerStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ServerDispatcher


-- Public procedure dispatcher stubs.

  OpenDebugStreamStub: --PROCEDURE [listenerPupAddress: PupDefs.PupAddress,
      -- newListenerPupAddress: PupDefs.PupAddress, name: Rope.ROPE, serverMachine:
      -- Rope.ROPE]
    -- RETURNS [byteStreamOK: BOOL]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    listenerPupAddress: PupDefs.PupAddress;
    newListenerPupAddress: PupDefs.PupAddress;
    name: Rope.ROPE;
    serverMachine: Rope.ROPE;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, listenerPupAddress
        (1): PupDefs.PupAddress, newListenerPupAddress (4): PupDefs.PupAddress];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        byteStreamOK (0): BOOL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay;
    pktLength: RpcPrivate.DataLength ← 7;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [listenerPupAddress: listenerPupAddress, newListenerPupAddress:
          newListenerPupAddress] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal name: Rope.ROPE from pkt.data[pktLength].
      ropeIsNIL: Lupine.NilHeader;
      IF pktLength+2 > RpcPrivate.maxDataLength
        THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength:
            pktLength];
      ropeIsNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
      IF ropeIsNIL
        THEN name ← NIL
        ELSE BEGIN
          ropeLength: Lupine.RopeHeader;
          textRope: Rope.Text;
          ropeLength ← pkt.data[pktLength];  pktLength ← pktLength+1;
          IF ropeLength > LAST[NAT]
            THEN Lupine.UnmarshalingError;
          name ← textRope ← Rope.NewText[size: ropeLength];
          pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
              dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength: Lupine.WordsForChars[ropeLength],
              alwaysOnePkt: FALSE];
          END;  -- IF ropeIsNIL.
      END;  -- Unmarshal name.
    BEGIN  -- Unmarshal serverMachine: Rope.ROPE from pkt.data[pktLength].
      ropeIsNIL: Lupine.NilHeader;
      IF pktLength+2 > RpcPrivate.maxDataLength
        THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength:
            pktLength];
      ropeIsNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
      IF ropeIsNIL
        THEN serverMachine ← NIL
        ELSE BEGIN
          ropeLength: Lupine.RopeHeader;
          textRope: Rope.Text;
          ropeLength ← pkt.data[pktLength];  pktLength ← pktLength+1;
          IF ropeLength > LAST[NAT]
            THEN Lupine.UnmarshalingError;
          serverMachine ← textRope ← Rope.NewText[size: ropeLength];
          pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
              dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength: Lupine.WordsForChars[ropeLength],
              alwaysOnePkt: FALSE];
          END;  -- IF ropeIsNIL.
      END;  -- Unmarshal serverMachine.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    resPkt ← @pkt.data[0];
    IF onePkt
      THEN [resPkt.byteStreamOK] ← OpenDebugStream[argPkt.listenerPupAddress,
          argPkt.newListenerPupAddress, name, serverMachine]
      ELSE [resPkt.byteStreamOK] ← OpenDebugStream[listenerPupAddress,
          newListenerPupAddress, name, serverMachine];
    END;  -- OnePkt.
    pktLength ← 1;
    RETURN[returnLength: pktLength];
    END;  -- OpenDebugStreamStub.

  OpenSourceViewerStub: --PROCEDURE [listenerPupAddress: PupDefs.PupAddress,
      -- name: Rope.ROPE, index: INT]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    listenerPupAddress: PupDefs.PupAddress;
    name: Rope.ROPE;
    index: INT;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, listenerPupAddress
        (1): PupDefs.PupAddress, index (4): INT];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 6;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [listenerPupAddress: listenerPupAddress, index: index] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal name: Rope.ROPE from pkt.data[pktLength].
      ropeIsNIL: Lupine.NilHeader;
      IF pktLength+2 > RpcPrivate.maxDataLength
        THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength:
            pktLength];
      ropeIsNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
      IF ropeIsNIL
        THEN name ← NIL
        ELSE BEGIN
          ropeLength: Lupine.RopeHeader;
          textRope: Rope.Text;
          ropeLength ← pkt.data[pktLength];  pktLength ← pktLength+1;
          IF ropeLength > LAST[NAT]
            THEN Lupine.UnmarshalingError;
          name ← textRope ← Rope.NewText[size: ropeLength];
          pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
              dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength: Lupine.WordsForChars[ropeLength],
              alwaysOnePkt: FALSE];
          END;  -- IF ropeIsNIL.
      END;  -- Unmarshal name.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    IF onePkt
      THEN OpenSourceViewer[argPkt.listenerPupAddress, name, argPkt.index]
      ELSE OpenSourceViewer[listenerPupAddress, name, index];
    END;  -- OnePkt.
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- OpenSourceViewerStub.


-- No module initialization.

END.  -- ComputeServerDebuggerRpcServerImpl.