-- Copyright (C) 1987 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on February 4, 1987 10:47:08 pm PST by Lupine of February 22, 1986 5:15:54 pm PST
-- Source interface SynthesizerServer came from file SynthesizerServer.bcd, which was created on February 4, 1987 10:46:05 pm PST with version stamp 130#262#12070567032 from source of October 24, 1986 5:53:45 pm PDT.

-- The RPC stub modules for SynthesizerServer are:
--   SynthesizerServerRpcControl.mesa;
--   SynthesizerServerRpcClientImpl.mesa;
--   SynthesizerServerRpcBinderImpl.mesa;
--   SynthesizerServerRpcServerImpl.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,
  Rope,
  Synthesizer,
  Thrush,
  SynthesizerServer,
  SynthesizerServerRpcControl 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]--;


SynthesizerServerRpcServerImpl: MONITOR
  IMPORTS SynthesizerServer, RpcPrivate: RPCLupine, Lupine: LupineRuntime,
      Atom, Rope
  EXPORTS SynthesizerServerRpcControl
  SHARES  SynthesizerServer, SynthesizerServerRpcControl, Rope
  = BEGIN OPEN SynthesizerServer, RpcControl: SynthesizerServerRpcControl,
      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 "SynthesizerServer~130#262#12070567032",
        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
      TextToSpeech => RETURN[
        TextToSpeechStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      StopSpeech => RETURN[
        StopSpeechStub[pkt: pkt, callLength: callLength, lastPkt: lastPkt,
            localConversation: localConversation]];
      GetSynthesizerSpecifications => RETURN[
        GetSynthesizerSpecificationsStub[pkt: pkt, callLength: callLength,
            lastPkt: lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ServerDispatcher


-- Public procedure dispatcher stubs.

  TextToSpeechStub: --PROCEDURE [shhh: Thrush.SHHH, credentials: Thrush.Credentials,
      -- serviceID: RefID.ID, textToSpeak: Rope.ROPE, actionID: Synthesizer.ActionID,
      -- filter: BOOL, queueIt: BOOL]
    -- RETURNS [nb: Thrush.NB]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    credentials: Thrush.Credentials;
    serviceID: RefID.ID;
    textToSpeak: Rope.ROPE;
    actionID: Synthesizer.ActionID;
    filter: BOOL;
    queueIt: BOOL;
    nb: Thrush.NB;
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, credentials (1):
        Thrush.Credentials, serviceID (9): RefID.ID, actionID (11): Synthesizer.ActionID,
        filter (13): BOOL, queueIt (14): BOOL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 15;
    BEGIN  -- OnePkt.
    onePkt: BOOLEAN = lastPkt;
    IF ~onePkt THEN BEGIN  -- Must move statics from pkt now.
      [credentials: credentials, serviceID: serviceID, actionID: actionID,
          filter: filter, queueIt: queueIt] ← argPkt↑;
      END;
    BEGIN  -- Unmarshal textToSpeak: Rope.ROPE from pkt.data[pktLength].
      [textToSpeak, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
          FALSE];
      END;  -- Unmarshal textToSpeak.
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    IF onePkt
      THEN [nb] ← TextToSpeech[localConversation, argPkt.credentials,
          argPkt.serviceID, textToSpeak, argPkt.actionID, argPkt.filter,
          argPkt.queueIt]
      ELSE [nb] ← TextToSpeech[localConversation, credentials, serviceID,
          textToSpeak, actionID, filter, queueIt];
    END;  -- OnePkt.
    pktLength ← 0;
    BEGIN  -- Marshal nb: Thrush.NB to pkt.data[pktLength].
      pktLength ← Lupine.MarshalAtom[nb, pkt, pktLength];
      END;  -- Marshal nb.
    RETURN[returnLength: pktLength];
    END;  -- TextToSpeechStub.

  StopSpeechStub: --PROCEDURE [shhh: Thrush.SHHH, credentials: Thrush.Credentials,
      -- serviceID: RefID.ID, reset: BOOL]
    -- 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, reset (11): BOOL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 12;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [nb] ← StopSpeech[localConversation, argPkt.credentials, argPkt.serviceID,
        argPkt.reset];
    pktLength ← 0;
    BEGIN  -- Marshal nb: Thrush.NB to pkt.data[pktLength].
      pktLength ← Lupine.MarshalAtom[nb, pkt, pktLength];
      END;  -- Marshal nb.
    RETURN[returnLength: pktLength];
    END;  -- StopSpeechStub.

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


-- Marshall/Unmarshal procedures.


-- No module initialization.

END.  -- SynthesizerServerRpcServerImpl.