-- Copyright (C) 1987 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on March 26, 1987 5:07:05 pm PST by Lupine of January 22, 1987 5:37:32 pm PST
-- Source interface OldAlpineTransaction came from file OldAlpineTransaction.bcd, which was created on March 26, 1987 5:06:58 pm PST with version stamp 301#256#27357460457 from source of January 6, 1987 2:16:32 pm PST.

-- The RPC stub modules for OldAlpineTransaction are:
--   OldAlpineTransactionRpcControl.mesa;
--   OldAlpineTransactionRpcClientImpl.mesa;
--   OldAlpineTransactionRpcBinderImpl.mesa;
--   OldAlpineTransactionRpcServerImpl.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
  OldAlpineEnvironment,
  OldAlpineTransaction,
  OldAlpineTransactionRpcControl 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, ImportInterfaceWithHost,
      -- maxDataLength, maxPrincipalLength, maxShortStringLength, noHost,
      -- pktOverhead, ReceiveExtraPkt, RPCHost, 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]--,
  Rope --USING SOME OF [InlineFlatten, Length, NewText, Text]--,
  VM --USING SOME OF [AddressForPageNumber, PageCount, PageNumber,
      -- PageNumberForAddress, PagesForWords]--;


OldAlpineTransactionRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, Lupine: LupineRuntime, Atom, PrincOpsUtils,
      Rope
  EXPORTS OldAlpineTransactionRpcControl
  SHARES  OldAlpineTransaction, OldAlpineTransactionRpcControl, Rope
  = BEGIN OPEN OldAlpineTransaction, RpcControl: OldAlpineTransactionRpcControl,
      RpcPublic: RPC;


-- Standard remote binding routines.


  ImportInterface: PUBLIC ENTRY SAFE PROCEDURE [
        interface: RpcControl.InterfaceRecord,
        interfaceName: RpcPublic.InterfaceName,
        parameterStorage: RpcPublic.Zones,
        hostHint: RpcPrivate.RPCHost←RpcPrivate.noHost ] =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IsNull: PROCEDURE [string: Rope.ROPE] RETURNS [BOOLEAN] =
      INLINE {RETURN[string.Length[] = 0]};
        interface↑ ← [clientStubCreate: clientStubCreate, clientStubCreateWorker:
            clientStubCreateWorker, clientStubAssertAlpineWheel: clientStubAssertAlpineWheel,
            clientStubFinish: clientStubFinish, Unknown: Unknown, OperationFailed:
            OperationFailed];
    interface.myInterface ← RpcPrivate.ImportInterfaceWithHost [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "OldAlpineTransaction~301#256#27357460457",
        instance: interfaceName.instance,
        version: interfaceName.version ],
      localOnly: RpcControl.InterMdsCallsOnly,
      stubProtocol: RpcControl.LupineProtocolVersion,
      hostHint: hostHint ];
    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.

  clientStubCreate: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      conversation: Conversation, createLocalWorker: BOOL] RETURNS [transID:
      TransID] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Create, createLocalWorker
        (1): BOOL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transID (0): TransID];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+9] 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 ← 2;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface,
        localConversation: conversation];
    argPkt↑ ← [createLocalWorker: createLocalWorker];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 9, signalHandler: ClientDispatcher];
    [transID: transID] ← resPkt↑;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 9];
    RETURN[transID];
    END;  -- Create.

  clientStubCreateWorker: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      conversation: Conversation, transID: TransID, coordinator: FileStore]
      =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← CreateWorker, transID
        (1): TransID];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.AllocInline[RpcPrivate.pktOverhead+44]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 10;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+44];
      RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface,
          localConversation: conversation];
      argPkt↑ ← [transID: transID];
      BEGIN  -- Marshal coordinator: FileStore to pkt.data[pktLength].
        pkt.data[pktLength] ← coordinator=NIL;  pktLength ← pktLength+1;
        IF coordinator # NIL
          THEN BEGIN
            textRope: Rope.Text = Rope.InlineFlatten[r: coordinator];
            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: TRUE];
            END;  -- IF coordinator # NIL.
        END;  -- Marshal coordinator.
      [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+44];
      RETURN[];
      END;  -- UNWIND.
    END;  -- CreateWorker.

  clientStubAssertAlpineWheel: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      conversation: Conversation, transID: TransID, enable: BOOL] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← AssertAlpineWheel,
        transID (1): TransID, enable (10): BOOL];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+11] OF WORD;
    pkt: RpcPrivate.StubPkt = RpcPrivate.GetStubPkt[space: @pktBuffer];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 11;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface,
        localConversation: conversation];
    argPkt↑ ← [transID: transID, enable: enable];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 0, signalHandler: ClientDispatcher];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 0];
    RETURN[];
    END;  -- AssertAlpineWheel.

  clientStubFinish: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      conversation: Conversation, transID: TransID, requestedOutcome: RequestedOutcome,
      continue: BOOL]
    RETURNS [outcome: Outcome, newTrans: TransID] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Finish, transID
        (1): TransID, requestedOutcome (10): RequestedOutcome, continue
        (11): BOOL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        outcome (0): Outcome, newTrans (1): TransID];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+12] 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 ← 12;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface,
        localConversation: conversation];
    argPkt↑ ← [transID: transID, requestedOutcome: requestedOutcome,
        continue: continue];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 10, signalHandler: ClientDispatcher];
    [outcome: outcome, newTrans: newTrans] ← resPkt↑;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 10];
    RETURN[outcome, newTrans];
    END;  -- Finish.


-- Remote public signals and errors.

  Unknown: PUBLIC ERROR [what: OldAlpineEnvironment.UnknownType] =
      CODE;

  OperationFailed: PUBLIC ERROR [why: OldAlpineEnvironment.OperationFailure]
      = 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
      Unknown => RETURN[
        UnknownStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      OperationFailed => RETURN[
        OperationFailedStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ClientDispatcher


-- Public signal and error dispatcher stubs.

  UnknownStub: --ERROR [what: OldAlpineEnvironment.UnknownType]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.SignalIndex, what (1): OldAlpineEnvironment.UnknownType];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 2];
    ERROR Unknown[argPkt.what];
    END;  -- UnknownStub.

  OperationFailedStub: --ERROR [why: OldAlpineEnvironment.OperationFailure]--
      RpcPrivate.Dispatcher =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.SignalIndex, why (1): OldAlpineEnvironment.OperationFailure];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 2];
    ERROR OperationFailed[argPkt.why];
    END;  -- OperationFailedStub.


-- No module initialization.

END.  -- OldAlpineTransactionRpcClientImpl.