-- Copyright (C) 1985 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on May 24, 1985 11:17:57 am PDT by Lupine of May 22, 1985 8:12:39 am PDT
-- Source interface MazeWarPlayer came from file MazeWarPlayer.bcd, which was created on May 9, 1985 4:33:24 pm PDT with version stamp 356#202#31457543646 from source of May 9, 1985 4:31:39 pm PDT.

-- The RPC stub modules for MazeWarPlayer are:
--   MazeWarPlayerRpcControl.mesa;
--   MazeWarPlayerRpcClientImpl.mesa;
--   MazeWarPlayerRpcBinderImpl.mesa;
--   MazeWarPlayerRpcServerImpl.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
  MazeWarFinder,
  Rope,
  MazeWarPlayer,
  MazeWarPlayerRpcControl USING [InterfaceRecord, InterMdsCallsOnly,
      LupineProtocolVersion, ProcedureIndex, SignalIndex],
  RPC --USING SOME OF [InterfaceName, standardZones, Zones]--,
  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]--;


MazeWarPlayerRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, Lupine: LupineRuntime, Atom, PrincOpsUtils,
      Rope
  EXPORTS MazeWarPlayerRpcControl
  SHARES  MazeWarPlayer, MazeWarPlayerRpcControl, Rope
  = BEGIN OPEN MazeWarPlayer, RpcControl: MazeWarPlayerRpcControl,
      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↑ ← [clientStubKnowPlayer: clientStubKnowPlayer, clientStubGetState:
        clientStubGetState, clientStubRemovePlayer: clientStubRemovePlayer,
        clientStubTakeStatus: clientStubTakeStatus, clientStubShoot: clientStubShoot,
        StupidFuckingWarnings: StupidFuckingWarnings];
    interface.myInterface ← RpcPrivate.ImportInterface [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "MazeWarPlayer~356#202#31457543646",
        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.

  clientStubKnowPlayer: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      bp: BasicPlayer] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← KnowPlayer];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.AllocInline[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 1;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface];
      argPkt.transferIndex ← KnowPlayer;
      BEGIN  -- Marshal bp: BasicPlayer to pkt.data[pktLength].
        pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: @bp, dataLength: SIZE[BasicPlayer], alwaysOnePkt:
            FALSE];
        BEGIN OPEN record: bp;
        BEGIN  -- Marshal record.instance: Rope.ROPE to pkt.data[pktLength].
          IF pktLength+2 > RpcPrivate.maxDataLength
            THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
                pktLength];
          pkt.data[pktLength] ← record.instance=NIL;  pktLength ← pktLength+1;
          IF record.instance # NIL
            THEN BEGIN
              textRope: Rope.Text = Rope.InlineFlatten[r: record.instance];
              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 record.instance # NIL.
          END;  -- Marshal record.instance.
        END;  -- OPEN record: bp.
        END;  -- Marshal bp.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 0, signalHandler: ClientDispatcher];
      Lupine.CheckPktLength[pkt: pkt, pktLength: 0];
      RpcPrivate.DeAllocInline[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[];
      END;  -- UNWIND.
    END;  -- KnowPlayer.

  clientStubGetState: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord]RETURNS
      [id: PlayerId, name: ROPE, pics: ROPE, maze: ROPE, row: INTEGER,
      col: INTEGER, score: INTEGER, angle: Angle] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetState];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        id (0): PlayerId, row (1): INTEGER, col (2): INTEGER, score (3):
        INTEGER, angle (4): Angle];
    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 ← 1;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface];
      argPkt.transferIndex ← GetState;
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 5;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [id: id, row: row, col: col, score: score, angle: angle] ←
            resPkt↑;
      BEGIN  -- Unmarshal name: 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 pics: 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 pics ← NIL
          ELSE BEGIN
            ropeLength: Lupine.RopeHeader;
            textRope: Rope.Text;
            ropeLength ← pkt.data[pktLength];  pktLength ← pktLength+1;
            IF ropeLength > LAST[NAT]
              THEN Lupine.UnmarshalingError;
            pics ← 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 pics.
      BEGIN  -- Unmarshal maze: 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 maze ← NIL
          ELSE BEGIN
            ropeLength: Lupine.RopeHeader;
            textRope: Rope.Text;
            ropeLength ← pkt.data[pktLength];  pktLength ← pktLength+1;
            IF ropeLength > LAST[NAT]
              THEN Lupine.UnmarshalingError;
            maze ← 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 maze.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAllocInline[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[id, name, pics, maze, row, col, score, angle];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- GetState.

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

  clientStubTakeStatus: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      id: PlayerId, row: INTEGER, col: INTEGER, score: INTEGER, angle:
      Angle, shot: BOOLEAN] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← TakeStatus, id (1):
        PlayerId, row (2): INTEGER, col (3): INTEGER, score (4): INTEGER,
        angle (5): Angle, shot (6): BOOLEAN];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+7] OF WORD;
    pkt: RpcPrivate.StubPkt = RpcPrivate.GetStubPkt[space: @pktBuffer];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 7;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface];
    argPkt↑ ← [id: id, row: row, col: col, score: score, angle: angle,
        shot: shot];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 0, signalHandler: ClientDispatcher];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 0];
    RETURN[];
    END;  -- TakeStatus.

  clientStubShoot: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      shooterId: PlayerId, row: INTEGER, col: INTEGER, drow: INTEGER, dcol:
      INTEGER]
    RETURNS [shot: BOOLEAN] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Shoot, shooterId
        (1): PlayerId, row (2): INTEGER, col (3): INTEGER, drow (4): INTEGER,
        dcol (5): INTEGER];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        shot (0): BOOLEAN];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+6] OF WORD;
    pkt: RpcPrivate.StubPkt = RpcPrivate.GetStubPkt[space: @pktBuffer];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 6;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface];
    argPkt↑ ← [shooterId: shooterId, row: row, col: col, drow: drow,
        dcol: dcol];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 1, signalHandler: ClientDispatcher];
    [shot: shot] ← resPkt↑;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    RETURN[shot];
    END;  -- Shoot.


-- Remote public signals and errors.

  StupidFuckingWarnings: PUBLIC SIGNAL [atom: ATOM] = CODE;


-- 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
      StupidFuckingWarnings => RETURN[
        StupidFuckingWarningsStub[pkt: pkt, callLength: callLength,
            lastPkt: lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ClientDispatcher


-- Public signal and error dispatcher stubs.

  StupidFuckingWarningsStub: --SIGNAL [atom: ATOM]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    atom: ATOM;
    pktLength: RpcPrivate.DataLength ← 1;
    BEGIN  -- Unmarshal atom: ATOM from pkt.data[pktLength].
      pNameOfAtom: Rope.ROPE;
      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 pNameOfAtom ← NIL
        ELSE BEGIN
          ropeLength: Lupine.RopeHeader;
          textRope: Rope.Text;
          ropeLength ← pkt.data[pktLength];  pktLength ← pktLength+1;
          IF ropeLength > LAST[NAT]
            THEN Lupine.UnmarshalingError;
          pNameOfAtom ← 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.
      atom ← Atom.MakeAtom[--pName:-- pNameOfAtom];
      END;  -- Unmarshal atom.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    SIGNAL StupidFuckingWarnings[atom];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- StupidFuckingWarningsStub.


-- No module initialization.

END.  -- MazeWarPlayerRpcClientImpl.