-- Stub file  was translated on October 25, 1983 12:25 pm by Lupine of October 25, 1983 10:51 am
-- Source interface AlpineVolume came from file AlpineVolume.bcd, which was created on October 25, 1983 12:25 pm with version stamp 145B#136B#15512151262B from source of April 2, 1983 1:53 pm.

-- 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 [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, NilHeader, ProtocolError, RopeHeader, RpcPktDoubleWord,
      -- RuntimeError, SequenceHeader, SHORT, StartNextPkt, StringHeader,
      -- StubPktDoubleWord, TranslationError, UnmarshalingError, UnmarshalingExprError,
      -- WordsForChars]--,
  Atom --USING SOME OF [GetPName, MakeAtom]--,
  Rope --USING SOME OF [InlineFlatten, Length, NewText, Text]--;


AlpineVolumeRpcServerImpl: MONITOR
  IMPORTS AlpineVolume, RpcPrivate: RPCLupine, Lupine: LupineRuntime,
      Atom, Rope
  EXPORTS AlpineVolumeRpcControl
  SHARES  AlpineVolume, AlpineVolumeRpcControl, Rope
  = BEGIN OPEN AlpineVolume, RpcControl: AlpineVolumeRpcControl, 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 "AlpineVolume~145B#136B#15512151262B",
        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

      AccessFailed --ERROR [missingAccess: AlpineEnvironment.NeededAccess]--
          =>
        BEGIN
        ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
            transferIndex (0): RpcControl.SignalIndex ← AccessFailed, missingAccess
            (1): AlpineEnvironment.NeededAccess];
        argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
        pktLength: RpcPrivate.DataLength ← 2;
        lastPkt: BOOLEAN;
        RpcPrivate.StartSignal[signalPkt: pkt];
        argPkt↑ ← [missingAccess: missingAccess];
        [returnLength: , lastPkt: lastPkt] ←
          RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
              maxReturnLength: 0];
        Lupine.RuntimeError;  -- Impossible to RESUME an ERROR.
        END;  -- AccessFailed.

      Unknown --ERROR [what: AlpineEnvironment.UnknownType]-- =>
        BEGIN
        ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
            transferIndex (0): RpcControl.SignalIndex ← Unknown, what (1):
            AlpineEnvironment.UnknownType];
        argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
        pktLength: RpcPrivate.DataLength ← 2;
        lastPkt: BOOLEAN;
        RpcPrivate.StartSignal[signalPkt: pkt];
        argPkt↑ ← [what: what];
        [returnLength: , lastPkt: lastPkt] ←
          RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
              maxReturnLength: 0];
        Lupine.RuntimeError;  -- Impossible to RESUME an ERROR.
        END;  -- Unknown.

      StaticallyInvalid --ERROR-- =>
        BEGIN
        ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
            transferIndex (0): RpcControl.SignalIndex ← StaticallyInvalid];
        argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
        pktLength: RpcPrivate.DataLength ← 1;
        lastPkt: BOOLEAN;
        RpcPrivate.StartSignal[signalPkt: pkt];
        argPkt.transferIndex ← StaticallyInvalid;
        [returnLength: , lastPkt: lastPkt] ←
          RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
              maxReturnLength: 0];
        Lupine.RuntimeError;  -- Impossible to RESUME an ERROR.
        END;  -- StaticallyInvalid.

      END;  -- Catch public signals.


    -- Call public procedures (still in dispatcher).

    SELECT LOOPHOLE[pkt.data[0], RpcControl.ProcedureIndex] FROM
      GetNextGroup => RETURN[
        GetNextGroupStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      GetGroup => RETURN[
        GetGroupStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      GetEnclosingGroup => RETURN[
        GetEnclosingGroupStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ServerDispatcher


-- Public procedure dispatcher stubs.

  GetNextGroupStub: --PROCEDURE [conversation: Conversation, transID:
      -- TransID, previousGroup: VolumeGroupID, lock: LockOption]
    -- RETURNS [volumeGroupID: VolumeGroupID]-- RpcPrivate.Dispatcher
        =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, transID (1): TransID,
        previousGroup (10): VolumeGroupID, lock (15): LockOption];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        volumeGroupID (0): VolumeGroupID];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 16;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [resPkt.volumeGroupID] ← GetNextGroup[localConversation, argPkt.transID,
        argPkt.previousGroup, argPkt.lock];
    pktLength ← 5;
    RETURN[returnLength: pktLength];
    END;  -- GetNextGroupStub.

  GetGroupStub: --PROCEDURE [conversation: Conversation, transID: TransID,
      -- volumeGroupID: VolumeGroupID, lock: LockOption]
    -- RETURNS [volumes: LIST OF VolumeID]-- RpcPrivate.Dispatcher
        =
    BEGIN
    volumes: LIST OF VolumeID;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, transID (1): TransID,
        volumeGroupID (10): VolumeGroupID, lock (15): LockOption];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 16;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [volumes] ← GetGroup[localConversation, argPkt.transID, argPkt.volumeGroupID,
        argPkt.lock];
    pktLength ← 0;
    BEGIN  -- Marshal volumes: LIST OF VolumeID to pkt.data[pktLength].
      thisNode1: LIST OF VolumeID;
      listLength: Lupine.ListHeader ← 0;
      FOR thisNode1 ← volumes, thisNode1.rest UNTIL thisNode1 = NIL
          DO
        listLength ← listLength + 1;  ENDLOOP;
      IF pktLength+2 > RpcPrivate.maxDataLength
        THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength: pktLength];
      Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← listLength;
      pktLength ← pktLength + 2;
      FOR thisNode1 ← volumes, thisNode1.rest UNTIL thisNode1 = NIL
          DO
        BEGIN  -- Marshal thisNode1.first: VolumeID to pkt.data[pktLength].
          pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
              dataAdr: @thisNode1.first, dataLength: SIZE[VolumeID], alwaysOnePkt:
              FALSE];
          END;  -- Marshal thisNode1.first.
        ENDLOOP;  -- FOR thisNode1.
      END;  -- Marshal volumes.
    RETURN[returnLength: pktLength];
    END;  -- GetGroupStub.

  GetEnclosingGroupStub: --PROCEDURE [conversation: Conversation, transID:
      -- TransID, volumeID: VolumeID, lock: LockOption]
    -- RETURNS [volumeGroupID: VolumeGroupID]-- RpcPrivate.Dispatcher
        =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, transID (1): TransID,
        volumeID (10): VolumeID, lock (15): LockOption];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        volumeGroupID (0): VolumeGroupID];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 16;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [resPkt.volumeGroupID] ← GetEnclosingGroup[localConversation, argPkt.transID,
        argPkt.volumeID, argPkt.lock];
    pktLength ← 5;
    RETURN[returnLength: pktLength];
    END;  -- GetEnclosingGroupStub.


-- No module initialization.

END.  -- AlpineVolumeRpcServerImpl.