-- Copyright (C) 1986 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on August 22, 1986 11:51:51 am PDT by Lupine of February 22, 1986 5:15:54 pm PST
-- Source interface BluejayUtils came from file BluejayUtils.bcd, which was created on August 22, 1986 11:51:24 am PDT with version stamp 247#174#751570345 from source of July 30, 1986 2:50:39 pm PDT.

-- The RPC stub modules for BluejayUtils are:
--   BluejayUtilsRpcControl.mesa;
--   BluejayUtilsRpcClientImpl.mesa;
--   BluejayUtilsRpcBinderImpl.mesa;
--   BluejayUtilsRpcServerImpl.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
  Jukebox,
  BluejayUtils,
  BluejayUtilsRpcControl 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]--,
  RPCLupineExtras --USING SOME OF [ImportInterfaceWithHost, noHost,
      -- RPCHost]--,
  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]--;


BluejayUtilsRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, RpcPrivateExtras: RPCLupineExtras,
      Lupine: LupineRuntime, Atom, PrincOpsUtils, Rope
  EXPORTS BluejayUtils, BluejayUtilsRpcControl
  SHARES  BluejayUtils, BluejayUtilsRpcControl, Rope
  = BEGIN OPEN BluejayUtils, RpcControl: BluejayUtilsRpcControl, 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,
        hostHint: RpcPrivateExtras.RPCHost←RpcPrivateExtras.noHost
            ] =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IsNull: PROCEDURE [string: Rope.ROPE] RETURNS [BOOLEAN] =
      INLINE {RETURN[string.Length[] = 0]};
        myInterface ← RpcPrivateExtras.ImportInterfaceWithHost [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "BluejayUtils~247#174#751570345",
        instance: interfaceName.instance,
        version: interfaceName.version ],
      localOnly: RpcControl.InterMdsCallsOnly,
      stubProtocol: RpcControl.LupineProtocolVersion,
      hostHint: hostHint ];
    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.

  DescribeTune: PUBLIC SAFE PROCEDURE [tuneID: TuneID] RETURNS [exists:
      BOOL, size: INT] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← DescribeTune, tuneID
        (1): TuneID];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        exists (0): BOOL, size (1): INT];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+3] 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 ← 3;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
    argPkt↑ ← [tuneID: tuneID];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 3, signalHandler: ClientDispatcher];
    [exists: exists, size: size] ← resPkt↑;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 3];
    RETURN[exists, size];
    END;  -- DescribeTune.

  DescribeInterval: PUBLIC SAFE PROCEDURE [intervalSpec: Jukebox.IntervalSpec,
      minSilence: Jukebox.VoiceTime] RETURNS [exists: BOOL, intervals:
      LIST OF Jukebox.IntervalSpec] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← DescribeInterval,
        minSilence (1): Jukebox.VoiceTime];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        exists (0): BOOL];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
      argPkt↑ ← [minSilence: minSilence];
      BEGIN  -- Marshal intervalSpec: Jukebox.IntervalSpec to pkt.data[pktLength].
        pktLength ← MarshalJukeboxDotIntervalSpec[intervalSpec, pkt,
            pktLength];
        END;  -- Marshal intervalSpec.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 1;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [exists: exists] ← resPkt↑;
      BEGIN  -- Unmarshal intervals: LIST OF Jukebox.IntervalSpec from
          -- pkt.data[pktLength].
        lastNode: LIST OF Jukebox.IntervalSpec ← (intervals ← 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 Jukebox.IntervalSpec = paramZones.gc.CONS[--DefaultValue--,NIL];
          BEGIN  -- Unmarshal thisNode1.first: Jukebox.IntervalSpec
              -- from pkt.data[pktLength].
            [thisNode1.first, pktLength] ← UnmarshalJukeboxDotIntervalSpec[pkt,
                pktLength];
            END;  -- Unmarshal thisNode1.first.
          IF lastNode # NIL
            THEN lastNode ← (lastNode.rest ← thisNode1)
            ELSE lastNode ← (intervals ← thisNode1);
          listLength ← listLength - 1;
          ENDLOOP;  -- WHILE listLength > 0.
        END;  -- Unmarshal intervals.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[exists, intervals];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- DescribeInterval.

  DeleteTune: PUBLIC SAFE PROCEDURE [tuneID: TuneID] RETURNS [existed:
      BOOL] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← DeleteTune, tuneID
        (1): TuneID];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        existed (0): BOOL];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+3] 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 ← 3;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
    argPkt↑ ← [tuneID: tuneID];
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 1, signalHandler: ClientDispatcher];
    [existed: existed] ← resPkt↑;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    RETURN[existed];
    END;  -- DeleteTune.

  NewTune: PUBLIC SAFE PROCEDURE RETURNS [tuneID: TuneID] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← NewTune];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        tuneID (0): TuneID];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+2] 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 ← 1;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
    argPkt.transferIndex ← NewTune;
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 2, signalHandler: ClientDispatcher];
    [tuneID: tuneID] ← resPkt↑;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 2];
    RETURN[tuneID];
    END;  -- NewTune.

  TunesInJukebox: PUBLIC SAFE PROCEDURE RETURNS [nTunes: INT] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← TunesInJukebox];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        nTunes (0): INT];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+2] 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 ← 1;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
    argPkt.transferIndex ← TunesInJukebox;
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 2, signalHandler: ClientDispatcher];
    [nTunes: nTunes] ← resPkt↑;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 2];
    RETURN[nTunes];
    END;  -- TunesInJukebox.

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

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

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


-- Remote public signals and errors.


-- 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
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ClientDispatcher


-- Public signal and error dispatcher stubs.


-- Marshall/Unmarshal procedures.
MarshalJukeboxDotIntervalSpec: PROC[value: Jukebox.IntervalSpec, pkt:
    RpcPrivate.RPCPkt, pktLength0: RpcPrivate.DataLength]
  RETURNS[pktLength: RpcPrivate.DataLength] = BEGIN
  pktLength ← pktLength0; {
  pkt.data[pktLength] ← value=NIL;  pktLength ← pktLength+1;
  IF value # NIL THEN
    BEGIN  -- Marshal value↑: Jukebox.IntervalSpecBody to pkt.data[pktLength].
      pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
          dataAdr: LOOPHOLE[value], dataLength: SIZE[Jukebox.IntervalSpecBody],
          alwaysOnePkt: TRUE];
      END;  -- Marshal value↑.
  };END;

UnmarshalJukeboxDotIntervalSpec: PROC[pkt: RpcPrivate.RPCPkt, pktLength0:
    RpcPrivate.DataLength]
  RETURNS[value: Jukebox.IntervalSpec, pktLength: RpcPrivate.DataLength]
      = BEGIN
  pktLength ← pktLength0; {
  isNIL: Lupine.NilHeader;
  IF pktLength+1 > RpcPrivate.maxDataLength
    THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength: pktLength];
  isNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
  IF isNIL
    THEN value ← NIL
    ELSE BEGIN
      value ← (paramZones.gc.NEW[Jukebox.IntervalSpecBody]);
      BEGIN  -- Unmarshal value↑: Jukebox.IntervalSpecBody from pkt.data[pktLength].
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: LOOPHOLE[value], dataLength: SIZE[Jukebox.IntervalSpecBody],
            alwaysOnePkt: FALSE];
        END;  -- Unmarshal value↑.
      END;  -- IF isNIL.
  };END;



-- No module initialization.

END.  -- BluejayUtilsRpcClientImpl.