-- Copyright (C) 1985 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on August 28, 1985 10:55:51 pm PDT by Lupine of May 23, 1985 8:38:08 am PDT
-- Source interface NSFiler came from file NSFiler.bcd, which was created on August 28, 1985 10:54:07 pm PDT with version stamp 14#17#26135214577 from source of August 28, 1985 10:53:20 pm PDT.

-- The RPC stub modules for NSFiler are:
--   NSFilerRpcControl.mesa;
--   NSFilerRpcClientImpl.mesa;
--   NSFilerRpcBinderImpl.mesa;
--   NSFilerRpcServerImpl.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 = 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
  NSFiler,
  NSFilerRpcControl 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]--,
  Rope --USING SOME OF [InlineFlatten, Length, NewText, Text]--,
  VM --USING SOME OF [AddressForPageNumber, PageCount, PageNumber,
      -- PageNumberForAddress, PagesForWords]--;


NSFilerRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, Lupine: LupineRuntime, Atom, PrincOpsUtils,
      Rope
  EXPORTS NSFiler, NSFilerRpcControl
  SHARES  NSFiler, NSFilerRpcControl, Rope
  = BEGIN OPEN NSFiler, RpcControl: NSFilerRpcControl, RpcPublic: RPC;


-- Standard remote binding routines.

  bound: BOOLEAN ← FALSE;
  myInterface: RpcPrivate.ImportHandle;
  paramZones: RpcPublic.Zones ← RpcPublic.standardZones;

  ImportInterface: PUBLIC ENTRY SAFE PROCEDURE [
        interfaceName: RpcPublic.InterfaceName,
        parameterStorage: RpcPublic.Zones ] =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IsNull: PROCEDURE [string: Rope.ROPE] RETURNS [BOOLEAN] =
      INLINE {RETURN[string.Length[] = 0]};
        myInterface ← RpcPrivate.ImportInterface [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "NSFiler~14#17#26135214577",
        instance: interfaceName.instance,
        version: interfaceName.version ],
      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;

  UnimportInterface: PUBLIC ENTRY SAFE PROCEDURE =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IF ~bound THEN Lupine.BindingError;
    myInterface ← RpcPrivate.UnimportInterface[myInterface];
    paramZones ← RpcPublic.standardZones;
    bound ← FALSE;
    END;



-- Remote public procedure stubs.

  Copy: PUBLIC PROCEDURE [from: String, to: String, gvname: String,
      gvpasswd: String, chname: String, chpasswd: String] =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Copy];
    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: myInterface];
      argPkt.transferIndex ← Copy;
      BEGIN  -- Marshal from: String to pkt.data[pktLength].
        IF pktLength+3 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← from=NIL;  pktLength ← pktLength+1;
        IF from # NIL
          THEN BEGIN
            stringHeader: Lupine.StringHeader = [
              Lengths[length: from.length, maxLength: from.maxlength]];
            Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← stringHeader.all;
            pktLength ← pktLength + 2;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[from.text], dataLength: Lupine.WordsForChars[stringHeader.length],
                alwaysOnePkt: FALSE];
            END;  -- IF from # NIL.
        END;  -- Marshal from.
      BEGIN  -- Marshal to: String to pkt.data[pktLength].
        IF pktLength+3 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← to=NIL;  pktLength ← pktLength+1;
        IF to # NIL
          THEN BEGIN
            stringHeader: Lupine.StringHeader = [
              Lengths[length: to.length, maxLength: to.maxlength]];
            Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← stringHeader.all;
            pktLength ← pktLength + 2;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[to.text], dataLength: Lupine.WordsForChars[stringHeader.length],
                alwaysOnePkt: FALSE];
            END;  -- IF to # NIL.
        END;  -- Marshal to.
      BEGIN  -- Marshal gvname: String to pkt.data[pktLength].
        IF pktLength+3 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← gvname=NIL;  pktLength ← pktLength+1;
        IF gvname # NIL
          THEN BEGIN
            stringHeader: Lupine.StringHeader = [
              Lengths[length: gvname.length, maxLength: gvname.maxlength]];
            Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← stringHeader.all;
            pktLength ← pktLength + 2;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[gvname.text], dataLength: Lupine.WordsForChars[stringHeader.length],
                alwaysOnePkt: FALSE];
            END;  -- IF gvname # NIL.
        END;  -- Marshal gvname.
      BEGIN  -- Marshal gvpasswd: String to pkt.data[pktLength].
        IF pktLength+3 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← gvpasswd=NIL;  pktLength ← pktLength+1;
        IF gvpasswd # NIL
          THEN BEGIN
            stringHeader: Lupine.StringHeader = [
              Lengths[length: gvpasswd.length, maxLength: gvpasswd.maxlength]];
            Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← stringHeader.all;
            pktLength ← pktLength + 2;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[gvpasswd.text], dataLength: Lupine.WordsForChars[stringHeader.length],
                alwaysOnePkt: FALSE];
            END;  -- IF gvpasswd # NIL.
        END;  -- Marshal gvpasswd.
      BEGIN  -- Marshal chname: String to pkt.data[pktLength].
        IF pktLength+3 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← chname=NIL;  pktLength ← pktLength+1;
        IF chname # NIL
          THEN BEGIN
            stringHeader: Lupine.StringHeader = [
              Lengths[length: chname.length, maxLength: chname.maxlength]];
            Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← stringHeader.all;
            pktLength ← pktLength + 2;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[chname.text], dataLength: Lupine.WordsForChars[stringHeader.length],
                alwaysOnePkt: FALSE];
            END;  -- IF chname # NIL.
        END;  -- Marshal chname.
      BEGIN  -- Marshal chpasswd: String to pkt.data[pktLength].
        IF pktLength+3 > RpcPrivate.maxDataLength
          THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength:
              pktLength];
        pkt.data[pktLength] ← chpasswd=NIL;  pktLength ← pktLength+1;
        IF chpasswd # NIL
          THEN BEGIN
            stringHeader: Lupine.StringHeader = [
              Lengths[length: chpasswd.length, maxLength: chpasswd.maxlength]];
            Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← stringHeader.all;
            pktLength ← pktLength + 2;
            pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                dataAdr: BASE[chpasswd.text], dataLength: Lupine.WordsForChars[stringHeader.length],
                alwaysOnePkt: FALSE];
            END;  -- IF chpasswd # NIL.
        END;  -- Marshal chpasswd.
      [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;  -- Copy.


-- Remote public signals and errors.

  Error: PUBLIC SIGNAL [reason: Huh] = 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
      Error => RETURN[
        ErrorStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ClientDispatcher


-- Public signal and error dispatcher stubs.

  ErrorStub: --SIGNAL [reason: Huh]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.SignalIndex, reason (1): Huh];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 2];
    SIGNAL Error[argPkt.reason];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- ErrorStub.


-- Marshall/Unmarshal procedures.


-- No module initialization.

END.  -- NSFilerRpcClientImpl.