-- Copyright (C) 1986 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on May 19, 1986 10:00:57 am PDT by Lupine of February 22, 1986 5:15:54 pm PST
-- Source interface ThSmarts came from file ThSmarts.bcd, which was created on May 19, 1986 10:00:40 am PDT with version stamp 13#227#21772711510 from source of May 19, 1986 9:59:17 am PDT.

-- The RPC stub modules for ThSmarts are:
--   ThSmartsRpcControl.mesa;
--   ThSmartsRpcClientImpl.mesa;
--   ThSmartsRpcBinderImpl.mesa;
--   ThSmartsRpcServerImpl.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
  Lark,
  LarkPlay,
  Pup,
  RPC,
  Thrush,
  ThSmarts,
  ThSmartsRpcControl USING [InterfaceRecord, InterMdsCallsOnly, LupineProtocolVersion,
      ProcedureIndex, SignalIndex],
  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]--;


ThSmartsRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, RpcPrivateExtras: RPCLupineExtras,
      Lupine: LupineRuntime, Atom, PrincOpsUtils, Rope
  EXPORTS ThSmartsRpcControl
  SHARES  ThSmarts, ThSmartsRpcControl, Rope
  = BEGIN OPEN ThSmarts, RpcControl: ThSmartsRpcControl, RpcPublic:
      RPC;


-- Standard remote binding routines.


  ImportInterface: PUBLIC ENTRY SAFE PROCEDURE [
        interface: RpcControl.InterfaceRecord,
        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]};
        interface↑ ← [clientStubProgress: clientStubProgress];
    interface.myInterface ← RpcPrivateExtras.ImportInterfaceWithHost
        [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "ThSmarts~13#227#21772711510",
        instance: interfaceName.instance,
        version: interfaceName.version ],
      localOnly: RpcControl.InterMdsCallsOnly,
      stubProtocol: RpcControl.LupineProtocolVersion,
      hostHint: hostHint ];
    interface.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 ];
    interface.bound ← TRUE;
    END;



-- Remote public procedure stubs.

  clientStubProgress: PUBLIC SAFE PROCEDURE [interface: RpcControl.InterfaceRecord,
      shh: SHHH, smartsID: Thrush.SmartsHandle, event: ConvEvent, yourParty:
      BOOL, latestEvent: BOOL, informationOnly: BOOL]
    RETURNS [d: Disposition] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Progress, smartsID
        (1): Thrush.SmartsHandle, yourParty (3): BOOL, latestEvent (4):
        BOOL, informationOnly (5): BOOL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        d (0): Disposition];
    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 ← 6;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: interface.myInterface,
          localConversation: shh];
      argPkt↑ ← [smartsID: smartsID, yourParty: yourParty, latestEvent:
          latestEvent, informationOnly: informationOnly];
      BEGIN  -- Marshal event: ConvEvent to pkt.data[pktLength].
        pktLength ← MarshalConvEvent[event, pkt, pktLength];
        END;  -- Marshal event.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 1, signalHandler: ClientDispatcher];
      [d: d] ← resPkt↑;
      Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[d];
      END;  -- UNWIND.
    END;  -- Progress.


-- 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.
MarshalConvEvent: PROC[value: ThSmarts.ConvEvent, 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.ConvEventBody to pkt.data[pktLength].
      pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
          dataAdr: LOOPHOLE[value], dataLength: SIZE[Thrush.ConvEventBody],
          alwaysOnePkt: FALSE];
      BEGIN OPEN record: value↑;
      BEGIN  -- Marshal record.spec: Lark.ConnectionSpec to pkt.data[pktLength].
        pktLength ← MarshalLarkDotConnectionSpec[record.spec, pkt,
            pktLength];
        END;  -- Marshal record.spec.
      BEGIN  -- Marshal record.keyTable: Lark.KeyTable to pkt.data[pktLength].
        pktLength ← MarshalLarkDotKeyTable[record.keyTable, pkt, pktLength];
        END;  -- Marshal record.keyTable.
      BEGIN  -- Marshal record.intervalSpecs: Thrush.IntervalSpecs
          -- to pkt.data[pktLength].
        thisNode3: Thrush.IntervalSpecs;
        listLength: Lupine.ListHeader ← 0;
        FOR thisNode3 ← record.intervalSpecs, thisNode3.rest UNTIL
            thisNode3 = 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 thisNode3 ← record.intervalSpecs, thisNode3.rest UNTIL
            thisNode3 = NIL DO
          BEGIN  -- Marshal thisNode3.first: Thrush.IntervalSpec to
              -- pkt.data[pktLength].
            pktLength ← MarshalThrushDotIntervalSpec[thisNode3.first,
                pkt, pktLength];
            END;  -- Marshal thisNode3.first.
          ENDLOOP;  -- FOR thisNode3.
        END;  -- Marshal record.intervalSpecs.
      BEGIN  -- Marshal record.proseSpecs: Thrush.ProseSpecs to pkt.data[pktLength].
        thisNode3: Thrush.ProseSpecs;
        listLength: Lupine.ListHeader ← 0;
        FOR thisNode3 ← record.proseSpecs, thisNode3.rest UNTIL thisNode3
            = 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 thisNode3 ← record.proseSpecs, thisNode3.rest UNTIL thisNode3
            = NIL DO
          BEGIN  -- Marshal thisNode3.first: Thrush.ProseSpec to pkt.data[pktLength].
            pktLength ← MarshalThrushDotProseSpec[thisNode3.first,
                pkt, pktLength];
            END;  -- Marshal thisNode3.first.
          ENDLOOP;  -- FOR thisNode3.
        END;  -- Marshal record.proseSpecs.
      BEGIN  -- Marshal record.ringTune: LarkPlay.ToneSpec to pkt.data[pktLength].
        pktLength ← MarshalLarkPlayDotToneSpec[record.ringTune, pkt,
            pktLength];
        END;  -- Marshal record.ringTune.
      BEGIN  -- Marshal record.address: Thrush.ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[record.address, pkt, pktLength,
            TRUE];
        END;  -- Marshal record.address.
      BEGIN  -- Marshal record.comment: Rope.ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[record.comment, pkt, pktLength,
            FALSE];
        END;  -- Marshal record.comment.
      END;  -- OPEN record: value↑.
      END;  -- Marshal value↑.
  };END;

MarshalLarkDotKeyTable: PROC[value: Lark.KeyTable, pkt: RpcPrivate.RPCPkt,
    pktLength0: RpcPrivate.DataLength]
  RETURNS[pktLength: RpcPrivate.DataLength] = BEGIN
  pktLength ← pktLength0; {
  BEGIN  -- Marshal value↑: Lark.KeyTableBody to pkt.data[pktLength].
    IF pktLength+3 > RpcPrivate.maxDataLength
      THEN pktLength ← Lupine.StartNextPkt[pkt: pkt, pktLength: pktLength];
    pkt.data[pktLength] ← value=NIL;  pktLength ← pktLength+1;
    IF value # NIL THEN BEGIN
      -- Record has a sequence, put its length up front.
      Lupine.RpcPktDoubleWord[pkt, pktLength]↑ ← LENGTH[DESCRIPTOR[value↑]];
      pktLength ← pktLength + 2;
      pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
          dataAdr: LOOPHOLE[value], dataLength: SIZE[Lark.KeyTableBody[LENGTH[DESCRIPTOR[value↑]]]],
          alwaysOnePkt: FALSE];
      END;  -- IF value # NIL.
    END;  -- Marshal value↑.
  };END;

MarshalThrushDotProseSpec: PROC[value: Thrush.ProseSpec, 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.ProseSpecBody to pkt.data[pktLength].
      pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
          dataAdr: LOOPHOLE[value], dataLength: SIZE[Thrush.ProseSpecBody],
          alwaysOnePkt: FALSE];
      BEGIN OPEN record: value↑;
      BEGIN  -- Marshal record.prose: Rope.ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[record.prose, pkt, pktLength,
            FALSE];
        END;  -- Marshal record.prose.
      END;  -- OPEN record: value↑.
      END;  -- Marshal value↑.
  };END;

MarshalLarkPlayDotToneSpec: PROC[value: LarkPlay.ToneSpec, 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↑: LarkPlay.ToneSpecRec to pkt.data[pktLength].
      pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
          dataAdr: LOOPHOLE[value], dataLength: SIZE[LarkPlay.ToneSpecRec],
          alwaysOnePkt: FALSE];
      BEGIN OPEN record: value↑;
      BEGIN  -- Marshal record.tones: LIST OF LarkPlay.ToneList to
          -- pkt.data[pktLength].
        thisNode5: LIST OF LarkPlay.ToneList;
        listLength: Lupine.ListHeader ← 0;
        FOR thisNode5 ← record.tones, thisNode5.rest UNTIL thisNode5
            = 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 thisNode5 ← record.tones, thisNode5.rest UNTIL thisNode5
            = NIL DO
          BEGIN  -- Marshal thisNode5.first: LarkPlay.ToneList to pkt.data[pktLength].
            thisNode6: LarkPlay.ToneList;
            listLength: Lupine.ListHeader ← 0;
            FOR thisNode6 ← thisNode5.first, thisNode6.rest UNTIL thisNode6
                = 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 thisNode6 ← thisNode5.first, thisNode6.rest UNTIL thisNode6
                = NIL DO
              BEGIN  -- Marshal thisNode6.first: LarkPlay.Tone to pkt.data[pktLength].
                pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                    dataAdr: @thisNode6.first, dataLength: SIZE[LarkPlay.Tone],
                    alwaysOnePkt: FALSE];
                END;  -- Marshal thisNode6.first.
              ENDLOOP;  -- FOR thisNode6.
            END;  -- Marshal thisNode5.first.
          ENDLOOP;  -- FOR thisNode5.
        END;  -- Marshal record.tones.
      END;  -- OPEN record: value↑.
      END;  -- Marshal value↑.
  };END;

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;

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



-- No module initialization.

END.  -- ThSmartsRpcClientImpl.