-- Copyright (C) 1985 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on May 15, 1985 1:02:22 pm PDT by Lupine of March 15, 1985 2:49:13 pm PST
-- Source interface ComputeServer came from file ComputeServer.bcd, which was created on May 15, 1985 1:01:00 pm PDT with version stamp 61#260#30520321217 from source of May 13, 1985 3:42:55 pm PDT.

-- The RPC stub modules for ComputeServer are:
--   ComputeServerRpcControl.mesa;
--   ComputeServerRpcClientImpl.mesa;
--   ComputeServerRpcBinderImpl.mesa;
--   ComputeServerRpcServerImpl.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
  ComputeServerClient,
  PupDefs,
  Rope,
  RPC,
  ComputeServer,
  ComputeServerRpcControl USING [InterfaceRecord, InterMdsCallsOnly,
      LupineProtocolVersion, ProcedureIndex, SignalIndex],
  RPCLupine --USING SOME OF [Alloc, Call, DataLength, DeAlloc, Dispatcher,
      -- GetPkt, GetStubPkt, ImportHandle, ImportInterface, maxDataLength,
      -- maxPrincipalLength, maxShortStringLength, pktOverhead, ReceiveExtraPkt,
      -- SendPrelimPkt, StartCall, StartSignal, StubPkt, UnimportInterface]--,
  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]--,
  PrincOpsUtils --USING SOME OF [Enter, Exit]--,
  VM --USING SOME OF [AddressForPageNumber, PageCount, PageNumber,
      -- PageNumberForAddress, PagesForWords]--;


ComputeServerRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, Lupine: LupineRuntime, Atom, PrincOpsUtils,
      Rope
  EXPORTS ComputeServerRpcControl
  SHARES  ComputeServer, ComputeServerRpcControl, Rope
  = BEGIN OPEN ComputeServer, RpcControl: ComputeServerRpcControl,
      RpcPublic: RPC;


-- Standard remote binding routines.


  ImportInterface: PUBLIC ENTRY SAFE PROCEDURE [
        interface: RpcControl.InterfaceRecord,
        interfaceName: RpcPublic.InterfaceName,
        parameterStorage: RpcPublic.Zones ] =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IsNull: PROCEDURE [string: Rope.ROPE] RETURNS [BOOLEAN] =
      INLINE {RETURN[string.Length[] = 0]};
    IF interface.bound THEN Lupine.BindingError;
    interface↑ ← [clientStubAskForService: clientStubAskForService,
        clientStubDoService: clientStubDoService, clientStubAskForAbort:
        clientStubAskForAbort];
    interface.myInterface ← RpcPrivate.ImportInterface [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "ComputeServer~61#260#30520321217",
        instance: interfaceName.instance,
        version: interfaceName.version ],
      localOnly: RpcControl.InterMdsCallsOnly,
      stubProtocol: RpcControl.LupineProtocolVersion ];
    interface.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 ];
    interface.bound ← TRUE;
    END;



-- Remote public procedure stubs.

  clientStubAskForService: PUBLIC SAFE PROCEDURE [interface: RpcControl.InterfaceRecord,
      service: Rope.ROPE, version: RPC.ShortROPE, clientMachineName: RPC.ShortROPE,
      streamPupAddress: PupDefs.PupAddress, needListener: BOOL]
    RETURNS [found: AskResponce, serverPupAddress: PupDefs.PupAddress,
        errMsg: Rope.ROPE] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← AskForService, streamPupAddress
        (1): PupDefs.PupAddress, needListener (4): BOOL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        found (0): AskResponce, serverPupAddress (1): PupDefs.PupAddress];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.AllocInline[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 5;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface];
      argPkt↑ ← [streamPupAddress: streamPupAddress, needListener:
          needListener];
      BEGIN  -- Marshal service: Rope.ROPE to pkt.data[pktLength].
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← service=NIL;  pktLength ← pktLength+1;
        IF service # NIL
          THEN BEGIN
            textRope: Rope.Text = Rope.InlineFlatten[r: service];
            pkt.data[pktLength] ← textRope.length;  pktLength ← pktLength+1;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength: Lupine.WordsForChars[textRope.length],
                alwaysOnePkt: FALSE];
            END;  -- IF service # NIL.
        END;  -- Marshal service.
      BEGIN  -- Marshal version: RPC.ShortROPE to pkt.data[pktLength].
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← version=NIL;  pktLength ← pktLength+1;
        IF version # NIL
          THEN BEGIN
            textRope: Rope.Text = Rope.InlineFlatten[r: version];
            IF textRope.length > RpcPrivate.maxShortStringLength
              THEN Lupine.MarshalingError;
            pkt.data[pktLength] ← textRope.length;  pktLength ← pktLength+1;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength: Lupine.WordsForChars[textRope.length],
                alwaysOnePkt: FALSE];
            END;  -- IF version # NIL.
        END;  -- Marshal version.
      BEGIN  -- Marshal clientMachineName: RPC.ShortROPE to pkt.data[pktLength].
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← clientMachineName=NIL;  pktLength ← pktLength+1;
        IF clientMachineName # NIL
          THEN BEGIN
            textRope: Rope.Text = Rope.InlineFlatten[r: clientMachineName];
            IF textRope.length > RpcPrivate.maxShortStringLength
              THEN Lupine.MarshalingError;
            pkt.data[pktLength] ← textRope.length;  pktLength ← pktLength+1;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength: Lupine.WordsForChars[textRope.length],
                alwaysOnePkt: FALSE];
            END;  -- IF clientMachineName # NIL.
        END;  -- Marshal clientMachineName.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 4;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [found: found, serverPupAddress: serverPupAddress] ← resPkt↑;
      BEGIN  -- Unmarshal errMsg: 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 errMsg ← NIL
          ELSE BEGIN
            ropeLength: Lupine.RopeHeader;
            textRope: Rope.Text;
            ropeLength ← pkt.data[pktLength];  pktLength ← pktLength+1;
            IF ropeLength > LAST[NAT]
              THEN Lupine.UnmarshalingError;
            errMsg ← 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 errMsg.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAllocInline[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[found, serverPupAddress, errMsg];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- AskForService.

  clientStubDoService: PUBLIC SAFE PROCEDURE [interface: RpcControl.InterfaceRecord,
      serverPupAddress: PupDefs.PupAddress, clientNetAddressRope: RPC.ShortROPE,
      commandLine: Rope.ROPE, WorkingDirectory: Rope.ROPE, needRemoteInStream:
      BOOL, needRemoteOutStream: BOOL]
    RETURNS [success: ComputeServerClient.RemoteSuccess, msg: Rope.ROPE]
        =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← DoService, serverPupAddress
        (1): PupDefs.PupAddress, needRemoteInStream (4): BOOL, needRemoteOutStream
        (5): BOOL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        success (0): ComputeServerClient.RemoteSuccess];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.AllocInline[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 6;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface];
      argPkt↑ ← [serverPupAddress: serverPupAddress, needRemoteInStream:
          needRemoteInStream, needRemoteOutStream: needRemoteOutStream];
      BEGIN  -- Marshal clientNetAddressRope: RPC.ShortROPE to pkt.data[pktLength].
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← clientNetAddressRope=NIL;  pktLength
            ← pktLength+1;
        IF clientNetAddressRope # NIL
          THEN BEGIN
            textRope: Rope.Text = Rope.InlineFlatten[r: clientNetAddressRope];
            IF textRope.length > RpcPrivate.maxShortStringLength
              THEN Lupine.MarshalingError;
            pkt.data[pktLength] ← textRope.length;  pktLength ← pktLength+1;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength: Lupine.WordsForChars[textRope.length],
                alwaysOnePkt: FALSE];
            END;  -- IF clientNetAddressRope # NIL.
        END;  -- Marshal clientNetAddressRope.
      BEGIN  -- Marshal commandLine: Rope.ROPE to pkt.data[pktLength].
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← commandLine=NIL;  pktLength ← pktLength+1;
        IF commandLine # NIL
          THEN BEGIN
            textRope: Rope.Text = Rope.InlineFlatten[r: commandLine];
            pkt.data[pktLength] ← textRope.length;  pktLength ← pktLength+1;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength: Lupine.WordsForChars[textRope.length],
                alwaysOnePkt: FALSE];
            END;  -- IF commandLine # NIL.
        END;  -- Marshal commandLine.
      BEGIN  -- Marshal WorkingDirectory: Rope.ROPE to pkt.data[pktLength].
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← WorkingDirectory=NIL;  pktLength ← pktLength+1;
        IF WorkingDirectory # NIL
          THEN BEGIN
            textRope: Rope.Text = Rope.InlineFlatten[r: WorkingDirectory];
            pkt.data[pktLength] ← textRope.length;  pktLength ← pktLength+1;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength: Lupine.WordsForChars[textRope.length],
                alwaysOnePkt: FALSE];
            END;  -- IF WorkingDirectory # NIL.
        END;  -- Marshal WorkingDirectory.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 1;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [success: success] ← resPkt↑;
      BEGIN  -- Unmarshal msg: 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 msg ← NIL
          ELSE BEGIN
            ropeLength: Lupine.RopeHeader;
            textRope: Rope.Text;
            ropeLength ← pkt.data[pktLength];  pktLength ← pktLength+1;
            IF ropeLength > LAST[NAT]
              THEN Lupine.UnmarshalingError;
            msg ← 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 msg.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAllocInline[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[success, msg];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- DoService.

  clientStubAskForAbort: PUBLIC SAFE PROCEDURE [interface: RpcControl.InterfaceRecord,
      serverPupAddress: PupDefs.PupAddress] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← AskForAbort, serverPupAddress
        (1): PupDefs.PupAddress];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+4] OF WORD;
    pkt: RpcPrivate.StubPkt = RpcPrivate.GetStubPkt[space: @pktBuffer];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 4;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface];
    argPkt↑ ← [serverPupAddress: serverPupAddress];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 0, signalHandler: ClientDispatcher];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 0];
    RETURN[];
    END;  -- AskForAbort.


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