-- Copyright (C) 1987 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on March 25, 1987 3:05:26 pm PST by Lupine of January 22, 1987 5:37:32 pm PST
-- Source interface AlpineVolume came from file AlpineVolume.bcd, which was created on March 25, 1987 12:09:58 pm PST with version stamp 317#341#13634745654 from source of March 7, 1985 2:24:55 pm PST.

-- The RPC stub modules for AlpineVolume are:
--   AlpineVolumeRpcControl.mesa;
--   AlpineVolumeRpcClientImpl.mesa;
--   AlpineVolumeRpcBinderImpl.mesa;
--   AlpineVolumeRpcServerImpl.mesa.

-- The parameters for this translation are:
--   Target language = Cedar
--   Default parameter passing = VALUE
--   Deallocate server heap arguments = TRUE
--   Inline RpcServerImpl dispatcher stubs = FALSE
--   Declare signals = FALSE
--   Warn about short POINTER ("MDS") allocations = TRUE
--   Maximum number of dynamic heap NEWs = 50, MDS NEWs = 50
--   Acceptable parameter protocols = VersionRange[1..1].


DIRECTORY
  AlpineEnvironment,
  AlpineVolume,
  AlpineVolumeRpcControl 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]--;


AlpineVolumeRpcClientImpl: MONITOR
  IMPORTS AlpineVolume, RpcPrivate: RPCLupine, Lupine: LupineRuntime,
      Atom, PrincOpsUtils, Rope
  EXPORTS AlpineVolumeRpcControl
  SHARES  AlpineVolume, AlpineVolumeRpcControl, Rope
  = BEGIN OPEN AlpineVolume, RpcControl: AlpineVolumeRpcControl, 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↑ ← [clientStubGetNextGroup: clientStubGetNextGroup,
            clientStubGetGroup: clientStubGetGroup, clientStubGetEnclosingGroup:
            clientStubGetEnclosingGroup, AccessFailed: AccessFailed, Unknown:
            Unknown, StaticallyInvalid: StaticallyInvalid];
    interface.myInterface ← RpcPrivate.ImportInterfaceWithHost [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "AlpineVolume~317#341#13634745654",
        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.

  clientStubGetNextGroup: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      conversation: Conversation, transID: TransID, previousGroup: VolumeGroupID,
      lock: LockOption]
    RETURNS [volumeGroupID: VolumeGroupID] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetNextGroup, transID
        (1): TransID, previousGroup (10): VolumeGroupID, lock (15): LockOption];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        volumeGroupID (0): VolumeGroupID];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+16] 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 ← 16;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface,
        localConversation: conversation];
    argPkt↑ ← [transID: transID, previousGroup: previousGroup, lock:
        lock];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 5, signalHandler: ClientDispatcher];
    [volumeGroupID: volumeGroupID] ← resPkt↑;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 5];
    RETURN[volumeGroupID];
    END;  -- GetNextGroup.

  clientStubGetGroup: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      conversation: Conversation, transID: TransID, volumeGroupID: VolumeGroupID,
      lock: LockOption]
    RETURNS [volumes: LIST OF VolumeID] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetGroup, transID
        (1): TransID, volumeGroupID (10): VolumeGroupID, lock (15): LockOption];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.AllocInline[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 16;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface,
          localConversation: conversation];
      argPkt↑ ← [transID: transID, volumeGroupID: volumeGroupID, lock:
          lock];
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal volumes: LIST OF VolumeID from pkt.data[pktLength].
        lastNode: LIST OF VolumeID ← (volumes ← NIL);
        listLength: Lupine.ListHeader;
        IF pktLength+2 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength:
              pktLength];
        listLength ← Lupine.RpcPktDoubleWord[pkt, pktLength]↑;
        pktLength ← pktLength + 2;
        WHILE listLength > 0 DO
          thisNode1: LIST OF VolumeID = interface.paramZones.gc.CONS[--DefaultValue--,NIL];
          BEGIN  -- Unmarshal thisNode1.first: VolumeID from pkt.data[pktLength].
            pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: @thisNode1.first, dataLength: SIZE[VolumeID],
                alwaysOnePkt: FALSE];
            END;  -- Unmarshal thisNode1.first.
          IF lastNode # NIL
            THEN lastNode ← (lastNode.rest ← thisNode1)
            ELSE lastNode ← (volumes ← thisNode1);
          listLength ← listLength - 1;
          ENDLOOP;  -- WHILE listLength > 0.
        END;  -- Unmarshal volumes.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAllocInline[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[volumes];
      END;  -- UNWIND.
    END;  -- GetGroup.

  clientStubGetEnclosingGroup: PUBLIC PROCEDURE [interface: RpcControl.InterfaceRecord,
      conversation: Conversation, transID: TransID, volumeID: VolumeID,
      lock: LockOption]
    RETURNS [volumeGroupID: VolumeGroupID] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetEnclosingGroup,
        transID (1): TransID, volumeID (10): VolumeID, lock (15): LockOption];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        volumeGroupID (0): VolumeGroupID];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+16] 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 ← 16;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface,
        localConversation: conversation];
    argPkt↑ ← [transID: transID, volumeID: volumeID, lock: lock];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 5, signalHandler: ClientDispatcher];
    [volumeGroupID: volumeGroupID] ← resPkt↑;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 5];
    RETURN[volumeGroupID];
    END;  -- GetEnclosingGroup.


--Remote public signals and errors are imported from the interface.


-- 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
      AccessFailed => RETURN[
        AccessFailedStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      Unknown => RETURN[
        UnknownStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      StaticallyInvalid => RETURN[
        StaticallyInvalidStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ClientDispatcher


-- Public signal and error dispatcher stubs.

  AccessFailedStub: --ERROR [missingAccess: AlpineEnvironment.NeededAccess]--
      RpcPrivate.Dispatcher =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.SignalIndex, missingAccess (1): AlpineEnvironment.NeededAccess];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 2];
    ERROR AccessFailed[argPkt.missingAccess];
    END;  -- AccessFailedStub.

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

  StaticallyInvalidStub: --ERROR-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    ERROR StaticallyInvalid[];
    END;  -- StaticallyInvalidStub.


-- No module initialization.

END.  -- AlpineVolumeRpcClientImpl.