-- Stub file  was translated on January 13, 1985 12:57:33 pm PST by Lupine of July 22, 1984 2:36:32 pm PDT
-- Source interface BluejayUtils came from file BluejayUtils.bcd, which was created on January 13, 1985 12:57:13 pm PST with version stamp 347#56#6164222607 from source of September 19, 1984 9:05:53 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 = 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
  Thrush,
  BluejayUtils,
  BluejayUtilsRpcControl 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]--,
  LupineRuntimeExtras --USING SOME OF [MarshalRope, MarshalAtom, UnmarshalRope,
      -- UnmarshalAtom]--,
  Atom --USING SOME OF [GetPName, MakeAtom]--,
  Rope --USING SOME OF [InlineFlatten, Length, NewText, Text]--;


BluejayUtilsRpcServerImpl: MONITOR
  IMPORTS BluejayUtils, RpcPrivate: RPCLupine, Lupine: LupineRuntime,
      LupineRuntimeExtras: LupineRuntimeExtras, Atom, Rope
  EXPORTS BluejayUtilsRpcControl
  SHARES  BluejayUtils, BluejayUtilsRpcControl, Rope
  = BEGIN OPEN BluejayUtils, RpcControl: BluejayUtilsRpcControl, 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 "BluejayUtils~347#56#6164222607",
        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

      END;  -- Catch public signals.


    -- Call public procedures (still in dispatcher).

    SELECT LOOPHOLE[pkt.data[0], RpcControl.ProcedureIndex] FROM
      DescribeTune => RETURN[
        DescribeTuneStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      DescribeInterval => RETURN[
        DescribeIntervalStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      DeleteTune => RETURN[
        DeleteTuneStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      NewTune => RETURN[
        NewTuneStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      TunesInJukebox => RETURN[
        TunesInJukeboxStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      InitializeJukebox => RETURN[
        InitializeJukeboxStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      Initialize => RETURN[
        InitializeStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      Uninitialize => RETURN[
        UninitializeStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ServerDispatcher


-- Public procedure dispatcher stubs.

  DescribeTuneStub: --PROCEDURE [tune: Tune] RETURNS [exists: BOOL,
      -- size: INT]-- RpcPrivate.Dispatcher =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, tune (1): Tune];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        exists (0): BOOL, size (1): INT];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 3];
    [resPkt.exists, resPkt.size] ←
      DescribeTune[argPkt.tune];
    pktLength ← 3;
    RETURN[returnLength: pktLength];
    END;  -- DescribeTuneStub.

  DescribeIntervalStub: --PROCEDURE [targetTune: Thrush.Tune, targetInterval:
      -- Thrush.VoiceInterval, minSilence: Thrush.VoiceTime]
    -- RETURNS [exists: BOOL, intervals: Thrush.IntervalSpecs]-- RpcPrivate.Dispatcher
        =
    BEGIN
    intervals: Thrush.IntervalSpecs;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, targetTune (1): Thrush.Tune,
        targetInterval (3): Thrush.VoiceInterval, minSilence (7): Thrush.VoiceTime];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        exists (0): BOOL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 9];
    [resPkt.exists, intervals] ←
      DescribeInterval[argPkt.targetTune, argPkt.targetInterval, argPkt.minSilence];
    pktLength ← 1;
    BEGIN  -- Marshal intervals: Thrush.IntervalSpecs to pkt.data[pktLength].
      thisNode1: Thrush.IntervalSpecs;
      listLength: Lupine.ListHeader ← 0;
      FOR thisNode1 ← intervals, 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 ← intervals, thisNode1.rest UNTIL thisNode1 = NIL
          DO
        BEGIN  -- Marshal thisNode1.first: Thrush.IntervalSpec to pkt.data[pktLength].
          pktLength ← MarshalThrushDotIntervalSpec[thisNode1.first,
              pkt, pktLength];
          END;  -- Marshal thisNode1.first.
        ENDLOOP;  -- FOR thisNode1.
      END;  -- Marshal intervals.
    RETURN[returnLength: pktLength];
    END;  -- DescribeIntervalStub.

  DeleteTuneStub: --PROCEDURE [tune: Tune] RETURNS [existed: BOOL]--
      RpcPrivate.Dispatcher =
    BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, tune (1): Tune];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        existed (0): BOOL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 3];
    [resPkt.existed] ← DeleteTune[argPkt.tune];
    pktLength ← 1;
    RETURN[returnLength: pktLength];
    END;  -- DeleteTuneStub.

  NewTuneStub: --PROCEDURE RETURNS [tune: Tune]-- RpcPrivate.Dispatcher
      =
    BEGIN
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        tune (0): Tune];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    [resPkt.tune] ← NewTune[];
    pktLength ← 2;
    RETURN[returnLength: pktLength];
    END;  -- NewTuneStub.

  TunesInJukeboxStub: --PROCEDURE RETURNS [nTunes: INT]-- RpcPrivate.Dispatcher
      =
    BEGIN
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        nTunes (0): INT];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    [resPkt.nTunes] ← TunesInJukebox[];
    pktLength ← 2;
    RETURN[returnLength: pktLength];
    END;  -- TunesInJukeboxStub.

  InitializeJukeboxStub: --PROCEDURE-- RpcPrivate.Dispatcher =
    BEGIN
    pktLength: RpcPrivate.DataLength;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    InitializeJukebox[];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- InitializeJukeboxStub.

  InitializeStub: --PROCEDURE-- RpcPrivate.Dispatcher =
    BEGIN
    pktLength: RpcPrivate.DataLength;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    Initialize[];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- InitializeStub.

  UninitializeStub: --PROCEDURE-- RpcPrivate.Dispatcher =
    BEGIN
    pktLength: RpcPrivate.DataLength;
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    Uninitialize[];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- UninitializeStub.


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



-- No module initialization.

END.  -- BluejayUtilsRpcServerImpl.