-- Copyright (C) 1986 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on June 25, 1986 10:04:37 am PDT by Lupine of February 22, 1986 5:15:54 pm PST
-- Source interface VoiceTemp came from file VoiceTemp.bcd, which was created on June 25, 1986 10:04:23 am PDT with version stamp 332#245#31477705223 from source of June 25, 1986 10:03:13 am PDT.

-- The RPC stub modules for VoiceTemp are:
--   VoiceTempRpcControl.mesa;
--   VoiceTempRpcClientImpl.mesa;
--   VoiceTempRpcBinderImpl.mesa;
--   VoiceTempRpcServerImpl.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
  RefID,
  Thrush,
  VoiceTemp,
  VoiceTempRpcControl 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, MarshalAtom, MarshalRope, NilHeader, ProtocolError,
      -- RopeHeader, RpcPktDoubleWord, RuntimeError, SequenceHeader, SHORT,
      -- StartNextPkt, StringHeader, StubPktDoubleWord, TranslationError,
      -- UnmarshalingError, UnmarshalingExprError, UnmarshalAtom, UnmarshalRope,
      -- WordsForChars]--,
  Atom --USING SOME OF [GetPName, MakeAtom]--,
  Rope --USING SOME OF [InlineFlatten, Length, NewText, Text]--;


VoiceTempRpcServerImpl: MONITOR
  IMPORTS VoiceTemp, RpcPrivate: RPCLupine, Lupine: LupineRuntime,
      Atom, Rope
  EXPORTS VoiceTempRpcControl
  SHARES  VoiceTemp, VoiceTempRpcControl, Rope
  = BEGIN OPEN VoiceTemp, RpcControl: VoiceTempRpcControl, 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 "VoiceTemp~332#245#31477705223",
        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
      Play => RETURN[
        PlayStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      Record => RETURN[
        RecordStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      Stop => RETURN[
        StopStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      DescribeInterval => RETURN[
        DescribeIntervalStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ServerDispatcher


-- Public procedure dispatcher stubs.

  PlayStub: --PROCEDURE [shhh: Thrush.SHHH, credentials: Thrush.Credentials,
      -- serviceID: RefID.ID, intervalSpec: IntervalSpec, queueIt: BOOL]
    -- RETURNS [nb: Thrush.NB]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    intervalSpec: IntervalSpec;
    nb: Thrush.NB;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, credentials (1):
        Thrush.Credentials, serviceID (9): RefID.ID, queueIt (11): BOOL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 12;
    BEGIN  -- Unmarshal intervalSpec: IntervalSpec from pkt.data[pktLength].
      [intervalSpec, pktLength] ← UnmarshalIntervalSpec[pkt, pktLength];
      END;  -- Unmarshal intervalSpec.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [nb] ← Play[localConversation, argPkt.credentials, argPkt.serviceID,
        intervalSpec, argPkt.queueIt];
    pktLength ← 0;
    BEGIN  -- Marshal nb: Thrush.NB to pkt.data[pktLength].
      pktLength ← Lupine.MarshalAtom[nb, pkt, pktLength];
      END;  -- Marshal nb.
    RETURN[returnLength: pktLength];
    END;  -- PlayStub.

  RecordStub: --PROCEDURE [shhh: Thrush.SHHH, credentials: Thrush.Credentials,
      -- serviceID: RefID.ID, intervalSpec: IntervalSpec, queueIt: BOOL]
    -- RETURNS [nb: Thrush.NB, tuneID: TuneID]-- RpcPrivate.Dispatcher
        =
    INLINE BEGIN
    intervalSpec: IntervalSpec;
    nb: Thrush.NB;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, credentials (1):
        Thrush.Credentials, serviceID (9): RefID.ID, queueIt (11): BOOL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        tuneID (0): TuneID];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 12;
    BEGIN  -- Unmarshal intervalSpec: IntervalSpec from pkt.data[pktLength].
      [intervalSpec, pktLength] ← UnmarshalIntervalSpec[pkt, pktLength];
      END;  -- Unmarshal intervalSpec.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [nb, resPkt.tuneID] ←
      Record[localConversation, argPkt.credentials, argPkt.serviceID,
          intervalSpec, argPkt.queueIt];
    pktLength ← 2;
    BEGIN  -- Marshal nb: Thrush.NB to pkt.data[pktLength].
      pktLength ← Lupine.MarshalAtom[nb, pkt, pktLength];
      END;  -- Marshal nb.
    RETURN[returnLength: pktLength];
    END;  -- RecordStub.

  StopStub: --PROCEDURE [shhh: Thrush.SHHH, credentials: Thrush.Credentials,
      -- serviceID: RefID.ID]
    -- RETURNS [nb: Thrush.NB]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    nb: Thrush.NB;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, credentials (1):
        Thrush.Credentials, serviceID (9): RefID.ID];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 11;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [nb] ← Stop[localConversation, argPkt.credentials, argPkt.serviceID];
    pktLength ← 0;
    BEGIN  -- Marshal nb: Thrush.NB to pkt.data[pktLength].
      pktLength ← Lupine.MarshalAtom[nb, pkt, pktLength];
      END;  -- Marshal nb.
    RETURN[returnLength: pktLength];
    END;  -- StopStub.

  DescribeIntervalStub: --PROCEDURE [shhh: Thrush.SHHH, credentials:
      -- Thrush.Credentials, serviceID: RefID.ID, targetInterval: IntervalSpec,
      -- minSilence: VoiceTime]
    -- RETURNS [nb: Thrush.NB, length: INT, intervals: IntervalSpecs]--
        RpcPrivate.Dispatcher =
    INLINE BEGIN
    targetInterval: IntervalSpec;
    nb: Thrush.NB;
    intervals: IntervalSpecs;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, credentials (1):
        Thrush.Credentials, serviceID (9): RefID.ID, minSilence (11): VoiceTime];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        length (0): INT];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 13;
    BEGIN  -- Unmarshal targetInterval: IntervalSpec from pkt.data[pktLength].
      [targetInterval, pktLength] ← UnmarshalIntervalSpec[pkt, pktLength];
      END;  -- Unmarshal targetInterval.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [nb, resPkt.length, intervals] ←
      DescribeInterval[localConversation, argPkt.credentials, argPkt.serviceID,
          targetInterval, argPkt.minSilence];
    pktLength ← 2;
    BEGIN  -- Marshal nb: Thrush.NB to pkt.data[pktLength].
      pktLength ← Lupine.MarshalAtom[nb, pkt, pktLength];
      END;  -- Marshal nb.
    BEGIN  -- Marshal intervals: IntervalSpecs to pkt.data[pktLength].
      thisNode1: 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: IntervalSpec to pkt.data[pktLength].
          pktLength ← MarshalIntervalSpec[thisNode1.first, pkt, pktLength];
          END;  -- Marshal thisNode1.first.
        ENDLOOP;  -- FOR thisNode1.
      END;  -- Marshal intervals.
    RETURN[returnLength: pktLength];
    END;  -- DescribeIntervalStub.


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

MarshalIntervalSpec: PROC[value: VoiceTemp.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↑: VoiceTemp.IntervalSpecBody to pkt.data[pktLength].
      pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
          dataAdr: LOOPHOLE[value], dataLength: SIZE[VoiceTemp.IntervalSpecBody],
          alwaysOnePkt: FALSE];
      END;  -- Marshal value↑.
  };END;



-- No module initialization.

END.  -- VoiceTempRpcServerImpl.