-- Copyright (C) 1987 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on April 3, 1987 2:30:16 pm PST by Lupine of January 22, 1987 5:37:32 pm PST
-- Source interface Multicast came from file Multicast.bcd, which was created on April 3, 1987 2:29:36 pm PST with version stamp 101#311#476232025 from source of May 21, 1986 3:29:16 pm PDT.

-- The RPC stub modules for Multicast are:
--   MulticastRpcControl.mesa;
--   MulticastRpcClientImpl.mesa;
--   MulticastRpcBinderImpl.mesa;
--   MulticastRpcServerImpl.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
  Pup,
  RPC,
  Multicast,
  MulticastRpcControl USING [InterMdsCallsOnly, LupineProtocolVersion,
      ProcedureIndex, SignalIndex],
  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]--;


MulticastRpcServerImpl: MONITOR
  IMPORTS Multicast, RpcPrivate: RPCLupine, Lupine: LupineRuntime,
      Atom, Rope
  EXPORTS MulticastRpcControl
  SHARES  Multicast, MulticastRpcControl, Rope
  = BEGIN OPEN Multicast, RpcControl: MulticastRpcControl, 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 "Multicast~101#311#476232025",
        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
      TurnOnMulticastForNet => RETURN[
        TurnOnMulticastForNetStub[pkt: pkt, callLength: callLength,
            lastPkt: lastPkt, localConversation: localConversation]];
      TurnOffMulticast => RETURN[
        TurnOffMulticastStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      HandleMulticast => RETURN[
        HandleMulticastStub[pkt: pkt, callLength: callLength, lastPkt:
            lastPkt, localConversation: localConversation]];
      StopHandlingMulticast => RETURN[
        StopHandlingMulticastStub[pkt: pkt, callLength: callLength,
            lastPkt: lastPkt, localConversation: localConversation]];
      ENDCASE => RETURN[Lupine.DispatchingError[]];

    END;  -- ServerDispatcher


-- Public procedure dispatcher stubs.

  TurnOnMulticastForNetStub: --PROCEDURE [shh: RPC.Conversation, net:
      -- Pup.Net] RETURNS [ok: BOOL]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, net (1): Pup.Net];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        ok (0): BOOL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 2;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [resPkt.ok] ← TurnOnMulticastForNet[localConversation, argPkt.net];
    pktLength ← 1;
    RETURN[returnLength: pktLength];
    END;  -- TurnOnMulticastForNetStub.

  TurnOffMulticastStub: --PROCEDURE [shh: RPC.Conversation]-- RpcPrivate.Dispatcher
      =
    INLINE BEGIN
    pktLength: RpcPrivate.DataLength ← 1;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    TurnOffMulticast[localConversation];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- TurnOffMulticastStub.

  HandleMulticastStub: --PROCEDURE [shh: RPC.Conversation, net: Pup.Net,
      -- realHost: Pup.Host, listeningTo: Pup.Host]
    -- RETURNS [ok: BOOL]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, net (1): Pup.Net,
        realHost (2): Pup.Host, listeningTo (3): Pup.Host];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        ok (0): BOOL];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    resPkt: LONG POINTER TO ResultOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 4;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    [resPkt.ok] ← HandleMulticast[localConversation, argPkt.net, argPkt.realHost,
        argPkt.listeningTo];
    pktLength ← 1;
    RETURN[returnLength: pktLength];
    END;  -- HandleMulticastStub.

  StopHandlingMulticastStub: --PROCEDURE [shh: RPC.Conversation, realHost:
      -- Pup.Host]-- RpcPrivate.Dispatcher =
    INLINE BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex, realHost (1): Pup.Host];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 2;
    Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
    StopHandlingMulticast[localConversation, argPkt.realHost];
    pktLength ← 0;
    RETURN[returnLength: pktLength];
    END;  -- StopHandlingMulticastStub.


-- Marshall/Unmarshal procedures.


-- No module initialization.

END.  -- MulticastRpcServerImpl.