-- Stub file  was translated on January 3, 1984 0:09 am by Lupine of December 20, 1983 1:22 pm
-- Source interface ThSmarts came from file ThSmarts.bcd, which was created on January 3, 1984 0:09 am with version stamp 355B#46B#14036406517B from source of December 19, 1983 2:07 pm.

-- 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 = 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
  Lark,
  RPC,
  Thrush,
  ThSmarts,
  ThSmartsRpcControl USING [InterMdsCallsOnly, LupineProtocolVersion,
      ProcedureIndex, SignalIndex],
  RPCLupine --USING SOME OF [Call, DataLength, Dispatcher, GetStubPkt,
      -- ImportHandle, ImportInterface, maxDataLength, maxPrincipalLength,
      -- maxShortStringLength, pktOverhead, ReceiveExtraPkt, SendPrelimPkt,
      -- StartCall, StartSignal, StubPkt, UnimportInterface]--,
  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]--,
  Atom --USING SOME OF [GetPName, MakeAtom]--,
  Rope --USING SOME OF [InlineFlatten, Length, NewText, Text]--;


ThSmartsRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, Lupine: LupineRuntime, Atom, Rope
  EXPORTS ThSmarts, ThSmartsRpcControl
  SHARES  ThSmarts, ThSmartsRpcControl, Rope
  = BEGIN OPEN ThSmarts, RpcControl: ThSmartsRpcControl, 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 ] =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IsNull: PROCEDURE [string: Rope.ROPE] RETURNS [BOOLEAN] =
      INLINE {RETURN[string.Length[] = 0]};
    IF bound THEN Lupine.BindingError;
    myInterface ← RpcPrivate.ImportInterface [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "ThSmarts~355B#46B#14036406517B",
        instance: interfaceName.instance,
        version: interfaceName.version ],
      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;

  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.

  Progress: PUBLIC SAFE PROCEDURE [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];
    pktBuffer: ARRAY [1..RpcPrivate.pktOverhead+188] OF WORD;
    pkt: RpcPrivate.StubPkt = RpcPrivate.GetStubPkt[space: @pktBuffer];
    argPkt: POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 6;
    lastPkt: BOOLEAN;
    RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
        shh];
    argPkt↑ ← [smartsID: smartsID, yourParty: yourParty, latestEvent:
        latestEvent, informationOnly: informationOnly];
    BEGIN  -- Marshal event: ConvEvent to pkt.data[pktLength].
      pkt.data[pktLength] ← event=NIL;  pktLength ← pktLength+1;
      IF event # NIL THEN
        BEGIN  -- Marshal event↑: Thrush.ConvEventBody to pkt.data[pktLength].
          pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
              dataAdr: LOOPHOLE[event], dataLength: SIZE[Thrush.ConvEventBody],
              alwaysOnePkt: TRUE];
          BEGIN OPEN record: event↑;
          BEGIN  -- Marshal record.spec: Lark.ConnectionSpec to pkt.data[pktLength].
            pkt.data[pktLength] ← record.spec=NIL;  pktLength ← pktLength+1;
            IF record.spec # NIL THEN
              BEGIN  -- Marshal record.spec↑: Lark.ConnectionSpecRec
                  -- to pkt.data[pktLength].
                pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                    dataAdr: LOOPHOLE[record.spec], dataLength: SIZE[Lark.ConnectionSpecRec],
                    alwaysOnePkt: TRUE];
                END;  -- Marshal record.spec↑.
            END;  -- Marshal record.spec.
          BEGIN  -- Marshal record.keyTable: Lark.KeyTable to pkt.data[pktLength].
            BEGIN  -- Marshal record.keyTable↑: Lark.KeyTableBody to
                -- pkt.data[pktLength].
              pkt.data[pktLength] ← record.keyTable=NIL;  pktLength
                  ← pktLength+1;
              IF record.keyTable # NIL THEN BEGIN
                -- Record has a sequence, put its length up front.
                Lupine.StubPktDoubleWord[pkt, pktLength]↑ ← LENGTH[DESCRIPTOR[record.keyTable↑]];
                pktLength ← pktLength + 2;
                pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                    dataAdr: LOOPHOLE[record.keyTable], dataLength: SIZE[Lark.KeyTableBody[LENGTH[DESCRIPTOR[record.keyTable↑]]]],
                    alwaysOnePkt: TRUE];
                END;  -- IF record.keyTable # NIL.
              END;  -- Marshal record.keyTable↑.
            END;  -- Marshal record.keyTable.
          BEGIN  -- Marshal record.intervalSpec: IntervalSpec to pkt.data[pktLength].
            pkt.data[pktLength] ← record.intervalSpec=NIL;  pktLength
                ← pktLength+1;
            IF record.intervalSpec # NIL THEN
              BEGIN  -- Marshal record.intervalSpec↑: IntervalSpecBody
                  -- to pkt.data[pktLength].
                pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                    dataAdr: LOOPHOLE[record.intervalSpec], dataLength:
                    SIZE[IntervalSpecBody], alwaysOnePkt: TRUE];
                END;  -- Marshal record.intervalSpec↑.
            END;  -- Marshal record.intervalSpec.
          BEGIN  -- Marshal record.address: ROPE to pkt.data[pktLength].
            pkt.data[pktLength] ← record.address=NIL;  pktLength ←
                pktLength+1;
            IF record.address # NIL
              THEN BEGIN
                textRope: Rope.Text = Rope.InlineFlatten[r: record.address];
                IF textRope.length > RpcPrivate.maxShortStringLength
                  THEN Lupine.MarshalingError;
                pkt.data[pktLength] ← textRope.length;  pktLength ←
                    pktLength+1;
                pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                    dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength:
                    Lupine.WordsForChars[textRope.length], alwaysOnePkt:
                    TRUE];
                END;  -- IF record.address # NIL.
            END;  -- Marshal record.address.
          BEGIN  -- Marshal record.comment: ROPE to pkt.data[pktLength].
            pkt.data[pktLength] ← record.comment=NIL;  pktLength ←
                pktLength+1;
            IF record.comment # NIL
              THEN BEGIN
                textRope: Rope.Text = Rope.InlineFlatten[r: record.comment];
                IF textRope.length > RpcPrivate.maxShortStringLength
                  THEN Lupine.MarshalingError;
                pkt.data[pktLength] ← textRope.length;  pktLength ←
                    pktLength+1;
                pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
                    dataAdr: BASE[DESCRIPTOR[textRope.text]], dataLength:
                    Lupine.WordsForChars[textRope.length], alwaysOnePkt:
                    TRUE];
                END;  -- IF record.comment # NIL.
            END;  -- Marshal record.comment.
          END;  -- OPEN record: event↑.
          END;  -- Marshal event↑.
      END;  -- Marshal event.
    [returnLength: , lastPkt: lastPkt] ←
      RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
          maxReturnLength: 1, signalHandler: ClientDispatcher];
    Lupine.CheckPktLength[pkt: pkt, pktLength: 1];
    RETURN[resPkt.d];
    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.


-- No module initialization.

END.  -- ThSmartsRpcClientImpl.