-- Copyright (C) 1986 by Xerox Corporation.  All rights reserved.
-- Stub file  was translated on June 4, 1986 3:04:12 am PDT by Lupine of February 22, 1986 5:15:54 pm PST
-- Source interface ThParty came from file ThParty.bcd, which was created on June 4, 1986 3:04:05 am PDT with version stamp 156#225#530404037 from source of June 3, 1986 11:47:22 pm PDT.

-- The RPC stub modules for ThParty are:
--   ThPartyRpcControl.mesa;
--   ThPartyRpcClientImpl.mesa;
--   ThPartyRpcBinderImpl.mesa;
--   ThPartyRpcServerImpl.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
  BasicTime,
  IV,
  RefID,
  RPC,
  Thrush,
  ThSmartsRpcControl,
  ThParty,
  ThPartyRpcControl 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]--;


ThPartyRpcClientImpl: MONITOR
  IMPORTS RpcPrivate: RPCLupine, RpcPrivateExtras: RPCLupineExtras,
      Lupine: LupineRuntime, Atom, PrincOpsUtils, Rope
  EXPORTS ThParty, ThPartyRpcControl
  SHARES  ThParty, ThPartyRpcControl, Rope
  = BEGIN OPEN ThParty, RpcControl: ThPartyRpcControl, 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,
        hostHint: RpcPrivateExtras.RPCHost←RpcPrivateExtras.noHost
            ] =
    TRUSTED BEGIN ENABLE UNWIND => NULL;
    IsNull: PROCEDURE [string: Rope.ROPE] RETURNS [BOOLEAN] =
      INLINE {RETURN[string.Length[] = 0]};
        myInterface ← RpcPrivateExtras.ImportInterfaceWithHost [
      interface: [
        type: IF ~IsNull[interfaceName.type]
          THEN interfaceName.type ELSE "ThParty~156#225#530404037",
        instance: interfaceName.instance,
        version: interfaceName.version ],
      localOnly: RpcControl.InterMdsCallsOnly,
      stubProtocol: RpcControl.LupineProtocolVersion,
      hostHint: hostHint ];
    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.

  CreateConversation: PUBLIC SAFE PROCEDURE [shhh: SHHH, credentials:
      Credentials, state: Thrush.StateInConv, urgency: Thrush.CallUrgency,
      alertKind: Thrush.AlertKind, reason: Thrush.Reason, comment: ROPE,
      subject: Thrush.ROPE]
    RETURNS [nb: NB, convEvent: Thrush.ConvEvent] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← CreateConversation,
        credentials (1): Credentials, state (9): Thrush.StateInConv];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 10;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shhh];
      argPkt↑ ← [credentials: credentials, state: state];
      BEGIN  -- Marshal urgency: Thrush.CallUrgency to pkt.data[pktLength].
        pktLength ← Lupine.MarshalAtom[urgency, pkt, pktLength];
        END;  -- Marshal urgency.
      BEGIN  -- Marshal alertKind: Thrush.AlertKind to pkt.data[pktLength].
        pktLength ← Lupine.MarshalAtom[alertKind, pkt, pktLength];
        END;  -- Marshal alertKind.
      BEGIN  -- Marshal reason: Thrush.Reason to pkt.data[pktLength].
        pktLength ← Lupine.MarshalAtom[reason, pkt, pktLength];
        END;  -- Marshal reason.
      BEGIN  -- Marshal comment: ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[comment, pkt, pktLength, FALSE];
        END;  -- Marshal comment.
      BEGIN  -- Marshal subject: Thrush.ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[subject, pkt, pktLength, FALSE];
        END;  -- Marshal subject.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      BEGIN  -- Unmarshal convEvent: Thrush.ConvEvent from pkt.data[pktLength].
        [convEvent, pktLength] ← UnmarshalThrushDotConvEvent[pkt, pktLength];
        END;  -- Unmarshal convEvent.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb, convEvent];
      END;  -- UNWIND.
    END;  -- CreateConversation.

  Alert: PUBLIC SAFE PROCEDURE [shhh: SHHH, credentials: Credentials,
      calledPartyID: PartyID, comment: ROPE]
    RETURNS [nb: NB] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Alert, credentials
        (1): Credentials, calledPartyID (9): PartyID];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 11;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shhh];
      argPkt↑ ← [credentials: credentials, calledPartyID: calledPartyID];
      BEGIN  -- Marshal comment: ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[comment, pkt, pktLength, FALSE];
        END;  -- Marshal comment.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb];
      END;  -- UNWIND.
    END;  -- Alert.

  Advance: PUBLIC SAFE PROCEDURE [shhh: SHHH, credentials: Credentials,
      state: Thrush.StateInConv, reportToAll: BOOL, reason: Thrush.Reason,
      comment: ROPE]
    RETURNS [nb: NB, convEvent: Thrush.ConvEvent] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Advance, credentials
        (1): Credentials, state (9): Thrush.StateInConv, reportToAll (10):
        BOOL];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 11;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shhh];
      argPkt↑ ← [credentials: credentials, state: state, reportToAll:
          reportToAll];
      BEGIN  -- Marshal reason: Thrush.Reason to pkt.data[pktLength].
        pktLength ← Lupine.MarshalAtom[reason, pkt, pktLength];
        END;  -- Marshal reason.
      BEGIN  -- Marshal comment: ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[comment, pkt, pktLength, FALSE];
        END;  -- Marshal comment.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      BEGIN  -- Unmarshal convEvent: Thrush.ConvEvent from pkt.data[pktLength].
        [convEvent, pktLength] ← UnmarshalThrushDotConvEvent[pkt, pktLength];
        END;  -- Unmarshal convEvent.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb, convEvent];
      END;  -- UNWIND.
    END;  -- Advance.

  ReportAction: PUBLIC SAFE PROCEDURE [shhh: SHHH, report: Thrush.ActionReport,
      reportToAll: BOOL, selfOnCompletion: BOOL]
    RETURNS [nb: NB, numReportsIssued: NAT] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← ReportAction, reportToAll
        (1): BOOL, selfOnCompletion (2): BOOL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        numReportsIssued (0): NAT];
    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 ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shhh];
      argPkt↑ ← [reportToAll: reportToAll, selfOnCompletion: selfOnCompletion];
      BEGIN  -- Marshal report: Thrush.ActionReport to pkt.data[pktLength].
        pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: @report, dataLength: SIZE[Thrush.ActionReport], alwaysOnePkt:
            FALSE];
        BEGIN OPEN record: report;
        BEGIN  -- Marshal record.actionClass: ActionClass to pkt.data[pktLength].
          pktLength ← Lupine.MarshalAtom[record.actionClass, pkt, pktLength];
          END;  -- Marshal record.actionClass.
        BEGIN  -- Marshal record.actionType: ActionType to pkt.data[pktLength].
          pktLength ← Lupine.MarshalAtom[record.actionType, pkt, pktLength];
          END;  -- Marshal record.actionType.
        BEGIN  -- Marshal record.actionInfo: ROPE to pkt.data[pktLength].
          pktLength ← Lupine.MarshalRope[record.actionInfo, pkt, pktLength,
              FALSE];
          END;  -- Marshal record.actionInfo.
        END;  -- OPEN record: report.
        END;  -- Marshal report.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 1;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [numReportsIssued: numReportsIssued] ← resPkt↑;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[nb, numReportsIssued];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- ReportAction.

  GetConversationInfo: PUBLIC SAFE PROCEDURE [shh: SHHH, convID: ConversationID]
      RETURNS [nb: NB, cInfo: ConversationInfo] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetConversationInfo,
        convID (1): ConversationID];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [convID: convID];
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      BEGIN  -- Unmarshal cInfo: ConversationInfo from pkt.data[pktLength].
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: @cInfo, dataLength: SIZE[ConversationInfo], alwaysOnePkt:
            FALSE];
        -- Restore garbled REFs to NIL following copy.
        BEGIN OPEN record: cInfo;
        LOOPHOLE[record.subject, LONG POINTER] ← NIL;
        LOOPHOLE[record.urgency, LONG POINTER] ← NIL;
        LOOPHOLE[record.alertKind, LONG POINTER] ← NIL;
        END;  -- OPEN record: cInfo.
        BEGIN OPEN record: cInfo;
        BEGIN  -- Unmarshal record.subject: ROPE from pkt.data[pktLength].
          [record.subject, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
              FALSE];
          END;  -- Unmarshal record.subject.
        BEGIN  -- Unmarshal record.urgency: Thrush.CallUrgency from
            -- pkt.data[pktLength].
          [record.urgency, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
          END;  -- Unmarshal record.urgency.
        BEGIN  -- Unmarshal record.alertKind: Thrush.AlertKind from
            -- pkt.data[pktLength].
          [record.alertKind, pktLength] ← Lupine.UnmarshalAtom[pkt,
              pktLength];
          END;  -- Unmarshal record.alertKind.
        END;  -- OPEN record: cInfo.
        END;  -- Unmarshal cInfo.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb, cInfo];
      END;  -- UNWIND.
    END;  -- GetConversationInfo.

  GetPartyInfo: PUBLIC SAFE PROCEDURE [shh: SHHH, credentials: Credentials,
      nameReq: NameReq, allParties: BOOL]
    RETURNS [nb: NB, pInfo: PartyInfo] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetPartyInfo, credentials
        (1): Credentials, allParties (9): BOOL];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 10;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [credentials: credentials, allParties: allParties];
      BEGIN  -- Marshal nameReq: NameReq to pkt.data[pktLength].
        pktLength ← Lupine.MarshalAtom[nameReq, pkt, pktLength];
        END;  -- Marshal nameReq.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      BEGIN  -- Unmarshal pInfo: PartyInfo from pkt.data[pktLength].
        [pInfo, pktLength] ← UnmarshalPartyInfo[pkt, pktLength];
        END;  -- Unmarshal pInfo.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb, pInfo];
      END;  -- UNWIND.
    END;  -- GetPartyInfo.

  DescribeParty: PUBLIC SAFE PROCEDURE [partyID: Thrush.PartyID, nameReq:
      NameReq] RETURNS [nb: NB, description: Thrush.ROPE] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← DescribeParty, partyID
        (1): Thrush.PartyID];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface];
      argPkt↑ ← [partyID: partyID];
      BEGIN  -- Marshal nameReq: NameReq to pkt.data[pktLength].
        pktLength ← Lupine.MarshalAtom[nameReq, pkt, pktLength];
        END;  -- Marshal nameReq.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      BEGIN  -- Unmarshal description: Thrush.ROPE from pkt.data[pktLength].
        [description, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
            FALSE];
        END;  -- Unmarshal description.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb, description];
      END;  -- UNWIND.
    END;  -- DescribeParty.

  RegisterServiceInterface: PUBLIC SAFE PROCEDURE [shhh: SHHH, credentials:
      Credentials, interfaceSpecPattern: Thrush.InterfaceSpec]
    RETURNS [nb: NB, interfaceSpec: Thrush.InterfaceSpec] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← RegisterServiceInterface,
        credentials (1): Credentials];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 9;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shhh];
      argPkt↑ ← [credentials: credentials];
      BEGIN  -- Marshal interfaceSpecPattern: Thrush.InterfaceSpec
          -- to pkt.data[pktLength].
        pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: @interfaceSpecPattern, dataLength: SIZE[Thrush.InterfaceSpec],
            alwaysOnePkt: TRUE];
        BEGIN OPEN record: interfaceSpecPattern;
        BEGIN  -- Marshal record.interfaceName: RPC.InterfaceName to
            -- pkt.data[pktLength].
          BEGIN OPEN record: record.interfaceName;
          BEGIN  -- Marshal record.type: ShortROPE to pkt.data[pktLength].
            pktLength ← Lupine.MarshalRope[record.type, pkt, pktLength,
                TRUE];
            END;  -- Marshal record.type.
          BEGIN  -- Marshal record.instance: ShortROPE to pkt.data[pktLength].
            pktLength ← Lupine.MarshalRope[record.instance, pkt, pktLength,
                TRUE];
            END;  -- Marshal record.instance.
          END;  -- OPEN record: record.interfaceName.
          END;  -- Marshal record.interfaceName.
        END;  -- OPEN record: interfaceSpecPattern.
        END;  -- Marshal interfaceSpecPattern.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      BEGIN  -- Unmarshal interfaceSpec: Thrush.InterfaceSpec from
          -- pkt.data[pktLength].
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: @interfaceSpec, dataLength: SIZE[Thrush.InterfaceSpec],
            alwaysOnePkt: FALSE];
        -- Restore garbled REFs to NIL following copy.
        BEGIN OPEN record: interfaceSpec;
        BEGIN OPEN record: record.interfaceName;
        LOOPHOLE[record.type, LONG POINTER] ← NIL;
        LOOPHOLE[record.instance, LONG POINTER] ← NIL;
        END;  -- OPEN record: record.interfaceName.
        END;  -- OPEN record: interfaceSpec.
        BEGIN OPEN record: interfaceSpec;
        BEGIN  -- Unmarshal record.interfaceName: RPC.InterfaceName
            -- from pkt.data[pktLength].
          BEGIN OPEN record: record.interfaceName;
          BEGIN  -- Unmarshal record.type: ShortROPE from pkt.data[pktLength].
            [record.type, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
                TRUE];
            END;  -- Unmarshal record.type.
          BEGIN  -- Unmarshal record.instance: ShortROPE from pkt.data[pktLength].
            [record.instance, pktLength] ← Lupine.UnmarshalRope[pkt,
                pktLength, TRUE];
            END;  -- Unmarshal record.instance.
          END;  -- OPEN record: record.interfaceName.
          END;  -- Unmarshal record.interfaceName.
        END;  -- OPEN record: interfaceSpec.
        END;  -- Unmarshal interfaceSpec.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb, interfaceSpec];
      END;  -- UNWIND.
    END;  -- RegisterServiceInterface.

  LookupServiceInterface: PUBLIC SAFE PROCEDURE [shhh: SHHH, credentials:
      Credentials, serviceParty: PartyID, type: RPC.ShortROPE]
    RETURNS [nb: NB, interfaceSpec: Thrush.InterfaceSpec] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← LookupServiceInterface,
        credentials (1): Credentials, serviceParty (9): PartyID];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 11;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shhh];
      argPkt↑ ← [credentials: credentials, serviceParty: serviceParty];
      BEGIN  -- Marshal type: RPC.ShortROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[type, pkt, pktLength, TRUE];
        END;  -- Marshal type.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      BEGIN  -- Unmarshal interfaceSpec: Thrush.InterfaceSpec from
          -- pkt.data[pktLength].
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: @interfaceSpec, dataLength: SIZE[Thrush.InterfaceSpec],
            alwaysOnePkt: FALSE];
        -- Restore garbled REFs to NIL following copy.
        BEGIN OPEN record: interfaceSpec;
        BEGIN OPEN record: record.interfaceName;
        LOOPHOLE[record.type, LONG POINTER] ← NIL;
        LOOPHOLE[record.instance, LONG POINTER] ← NIL;
        END;  -- OPEN record: record.interfaceName.
        END;  -- OPEN record: interfaceSpec.
        BEGIN OPEN record: interfaceSpec;
        BEGIN  -- Unmarshal record.interfaceName: RPC.InterfaceName
            -- from pkt.data[pktLength].
          BEGIN OPEN record: record.interfaceName;
          BEGIN  -- Unmarshal record.type: ShortROPE from pkt.data[pktLength].
            [record.type, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
                TRUE];
            END;  -- Unmarshal record.type.
          BEGIN  -- Unmarshal record.instance: ShortROPE from pkt.data[pktLength].
            [record.instance, pktLength] ← Lupine.UnmarshalRope[pkt,
                pktLength, TRUE];
            END;  -- Unmarshal record.instance.
          END;  -- OPEN record: record.interfaceName.
          END;  -- Unmarshal record.interfaceName.
        END;  -- OPEN record: interfaceSpec.
        END;  -- Unmarshal interfaceSpec.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb, interfaceSpec];
      END;  -- UNWIND.
    END;  -- LookupServiceInterface.

  RegisterKey: PUBLIC SAFE PROCEDURE [shh: SHHH, credentials: Credentials,
      key: Thrush.EncryptionKey, reportNewKeys: BOOL]
    RETURNS [nb: NB, keyIndex: [0..15]] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← RegisterKey, credentials
        (1): Credentials, key (9): Thrush.EncryptionKey, reportNewKeys
        (13): BOOL];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        keyIndex (0): [0..15]];
    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 ← 14;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [credentials: credentials, key: key, reportNewKeys:
          reportNewKeys];
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 1;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [keyIndex: keyIndex] ← resPkt↑;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[nb, keyIndex];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- RegisterKey.

  GetKeyTable: PUBLIC SAFE PROCEDURE [shh: SHHH, credentials: Credentials]
      RETURNS [nb: NB, keyTable: Thrush.KeyTable] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetKeyTable, credentials
        (1): Credentials];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 9;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [credentials: credentials];
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      BEGIN  -- Unmarshal keyTable: Thrush.KeyTable from pkt.data[pktLength].
        [keyTable, pktLength] ← UnmarshalThrushDotKeyTable[pkt, pktLength];
        END;  -- Unmarshal keyTable.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb, keyTable];
      END;  -- UNWIND.
    END;  -- GetKeyTable.

  GetParty: PUBLIC SAFE PROCEDURE [shh: SHHH, partyID: PartyID, rName:
      ROPE, type: Thrush.PartyType]
    RETURNS [nb: NB, newPartyID: PartyID] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetParty, partyID
        (1): PartyID];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        newPartyID (0): PartyID];
    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 ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [partyID: partyID];
      BEGIN  -- Marshal rName: ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[rName, pkt, pktLength, FALSE];
        END;  -- Marshal rName.
      BEGIN  -- Marshal type: Thrush.PartyType to pkt.data[pktLength].
        pktLength ← Lupine.MarshalAtom[type, pkt, pktLength];
        END;  -- Marshal type.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 2;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [newPartyID: newPartyID] ← resPkt↑;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[nb, newPartyID];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- GetParty.

  GetPartyFromNumber: PUBLIC SAFE PROCEDURE [shh: SHHH, partyID: PartyID,
      phoneNumber: Thrush.ROPE, description: ROPE]
    RETURNS [nb: NB, newPartyID: PartyID] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetPartyFromNumber,
        partyID (1): PartyID];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        newPartyID (0): PartyID];
    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 ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [partyID: partyID];
      BEGIN  -- Marshal phoneNumber: Thrush.ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[phoneNumber, pkt, pktLength,
            FALSE];
        END;  -- Marshal phoneNumber.
      BEGIN  -- Marshal description: ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[description, pkt, pktLength,
            FALSE];
        END;  -- Marshal description.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 2;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [newPartyID: newPartyID] ← resPkt↑;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[nb, newPartyID];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- GetPartyFromNumber.

  GetPartyFromFeepNum: PUBLIC SAFE PROCEDURE [shh: SHHH, partyID: PartyID,
      feepNum: Thrush.ROPE]
    RETURNS [nb: NB, newPartyID: PartyID] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetPartyFromFeepNum,
        partyID (1): PartyID];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        newPartyID (0): PartyID];
    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 ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [partyID: partyID];
      BEGIN  -- Marshal feepNum: Thrush.ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[feepNum, pkt, pktLength, FALSE];
        END;  -- Marshal feepNum.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 2;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [newPartyID: newPartyID] ← resPkt↑;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[nb, newPartyID];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- GetPartyFromFeepNum.

  GetCurrentParty: PUBLIC SAFE PROCEDURE [shh: SHHH, smartsID: SmartsID]
      RETURNS [nb: NB, partyID: Thrush.PartyID] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetCurrentParty,
        smartsID (1): SmartsID];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        partyID (0): Thrush.PartyID];
    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 ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [smartsID: smartsID];
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 2;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [partyID: partyID] ← resPkt↑;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[nb, partyID];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- GetCurrentParty.

  GetNumbersForRName: PUBLIC SAFE PROCEDURE [shh: SHHH, rName: ROPE]
      RETURNS [fullRName: ROPE, number: ROPE, homeNumber: ROPE] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← GetNumbersForRName];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 1;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt.transferIndex ← GetNumbersForRName;
      BEGIN  -- Marshal rName: ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[rName, pkt, pktLength, FALSE];
        END;  -- Marshal rName.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal fullRName: ROPE from pkt.data[pktLength].
        [fullRName, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
            FALSE];
        END;  -- Unmarshal fullRName.
      BEGIN  -- Unmarshal number: ROPE from pkt.data[pktLength].
        [number, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
            FALSE];
        END;  -- Unmarshal number.
      BEGIN  -- Unmarshal homeNumber: ROPE from pkt.data[pktLength].
        [homeNumber, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
            FALSE];
        END;  -- Unmarshal homeNumber.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[fullRName, number, homeNumber];
      END;  -- UNWIND.
    END;  -- GetNumbersForRName.

  Register: PUBLIC SAFE PROCEDURE [shh: SHHH, rName: ROPE, type: Thrush.PartyType,
      clonePartyID: PartyID, interface: SmartsInterfaceName, properties:
      SmartsProperties]
    RETURNS [nb: NB, credentials: Credentials] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Register, clonePartyID
        (1): PartyID];
    ResultOverlay: TYPE = MACHINE DEPENDENT RECORD [
        credentials (0): Credentials];
    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 ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [clonePartyID: clonePartyID];
      BEGIN  -- Marshal rName: ROPE to pkt.data[pktLength].
        pktLength ← Lupine.MarshalRope[rName, pkt, pktLength, FALSE];
        END;  -- Marshal rName.
      BEGIN  -- Marshal type: Thrush.PartyType to pkt.data[pktLength].
        pktLength ← Lupine.MarshalAtom[type, pkt, pktLength];
        END;  -- Marshal type.
      BEGIN  -- Marshal interface: SmartsInterfaceName to pkt.data[pktLength].
        pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: @interface, dataLength: SIZE[SmartsInterfaceName],
            alwaysOnePkt: FALSE];
        BEGIN OPEN record: interface;
        BEGIN  -- Marshal record.type: RPC.ShortROPE to pkt.data[pktLength].
          pktLength ← Lupine.MarshalRope[record.type, pkt, pktLength,
              TRUE];
          END;  -- Marshal record.type.
        BEGIN  -- Marshal record.instance: RPC.ShortROPE to pkt.data[pktLength].
          pktLength ← Lupine.MarshalRope[record.instance, pkt, pktLength,
              TRUE];
          END;  -- Marshal record.instance.
        END;  -- OPEN record: interface.
        END;  -- Marshal interface.
      BEGIN  -- Marshal properties: SmartsProperties to pkt.data[pktLength].
        pktLength ← Lupine.CopyToPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: @properties, dataLength: SIZE[SmartsProperties], alwaysOnePkt:
            FALSE];
        BEGIN OPEN record: properties;
        BEGIN  -- Marshal record.role: SmartsRole to pkt.data[pktLength].
          pktLength ← Lupine.MarshalAtom[record.role, pkt, pktLength];
          END;  -- Marshal record.role.
        END;  -- OPEN record: properties.
        END;  -- Marshal properties.
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 8;
      BEGIN  -- OnePkt.
        -- Move statics from pkt now.
        [credentials: credentials] ← resPkt↑;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
RETURN[nb, credentials];
      END;  -- OnePkt.
      END;  -- UNWIND.
    END;  -- Register.

  CheckIn: PUBLIC SAFE PROCEDURE [shh: SHHH, credentials: Credentials]
      RETURNS [nb: NB] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← CheckIn, credentials
        (1): Credentials];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 9;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [credentials: credentials];
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb];
      END;  -- UNWIND.
    END;  -- CheckIn.

  Deregister: PUBLIC SAFE PROCEDURE [shh: SHHH, smartsID: SmartsID]
      RETURNS [nb: NB] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Deregister, smartsID
        (1): SmartsID];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [smartsID: smartsID];
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb];
      END;  -- UNWIND.
    END;  -- Deregister.

  Enable: PUBLIC SAFE PROCEDURE [shh: SHHH, smartsID: SmartsID] RETURNS
      [nb: Thrush.NB] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Enable, smartsID
        (1): SmartsID];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [smartsID: smartsID];
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: Thrush.NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb];
      END;  -- UNWIND.
    END;  -- Enable.

  Disable: PUBLIC SAFE PROCEDURE [shh: SHHH, smartsID: SmartsID] RETURNS
      [nb: Thrush.NB] =
    TRUSTED BEGIN
    ArgumentOverlay: TYPE = MACHINE DEPENDENT RECORD [
        transferIndex (0): RpcControl.ProcedureIndex ← Disable, smartsID
        (1): SmartsID];
    pkt: RpcPrivate.RPCPkt = RpcPrivate.GetPkt[space: RpcPrivate.Alloc[RpcPrivate.pktOverhead+254]];
    argPkt: LONG POINTER TO ArgumentOverlay = @pkt.data[0];
    pktLength: RpcPrivate.DataLength ← 3;
    lastPkt: BOOLEAN;
    BEGIN ENABLE UNWIND => RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RpcPrivate.StartCall[callPkt: pkt, interface: myInterface, localConversation:
          shh];
      argPkt↑ ← [smartsID: smartsID];
      [returnLength: , lastPkt: lastPkt] ←
        RpcPrivate.Call[ pkt: pkt, callLength: pktLength,
            maxReturnLength: 254, signalHandler: ClientDispatcher];
      pktLength ← 0;
      BEGIN  -- Unmarshal nb: Thrush.NB from pkt.data[pktLength].
        [nb, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
        END;  -- Unmarshal nb.
      Lupine.CheckPktLength[pkt: pkt, pktLength: pktLength];
      RpcPrivate.DeAlloc[LOOPHOLE[pkt], RpcPrivate.pktOverhead+254];
      RETURN[nb];
      END;  -- UNWIND.
    END;  -- Disable.


-- 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.
UnmarshalPartyInfo: PROC[pkt: RpcPrivate.RPCPkt, pktLength0: RpcPrivate.DataLength]
  RETURNS[value: ThParty.PartyInfo, pktLength: RpcPrivate.DataLength]
      = BEGIN
  pktLength ← pktLength0; {
  BEGIN  -- Unmarshal value↑: ThParty.PartyInfoSeq from pkt.data[pktLength].
    recordIsNIL: Lupine.NilHeader;
    IF pktLength+3 > RpcPrivate.maxDataLength
      THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength: pktLength];
    recordIsNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
    IF recordIsNIL
      THEN value ← NIL
      ELSE BEGIN
        seqLength: Lupine.SequenceHeader;
        seqLength ← Lupine.RpcPktDoubleWord[pkt, pktLength]↑;
        pktLength ← pktLength + 2;
        value ← (paramZones.gc.NEW[ThParty.PartyInfoSeq[Lupine.SHORT[seqLength]]]);
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: LOOPHOLE[value], dataLength: SIZE[ThParty.PartyInfoSeq[LENGTH[DESCRIPTOR[value↑]]]],
            alwaysOnePkt: FALSE];
        -- Restore garbled REFs to NIL following copy.
        BEGIN OPEN record: value↑;
        FOR element2: NAT IN [FIRST[NAT]..FIRST[NAT]+LENGTH[DESCRIPTOR[record.parties]])
            DO
          BEGIN OPEN record: record.parties[element2];
          LOOPHOLE[record.type, LONG POINTER] ← NIL;
          LOOPHOLE[record.name, LONG POINTER] ← NIL;
          END;  -- OPEN record: record.parties[element2].
          ENDLOOP;  -- FOR element2.
        END;  -- OPEN record: value↑.
        BEGIN OPEN record: value↑;
        BEGIN  -- Unmarshal record.parties: SEQUENCE len: NAT OF ThParty.PartyInfoSpec
            -- from pkt.data[pktLength].
          -- The sequence's length was carried by its record.
          FOR element3: NAT IN [FIRST[NAT]..FIRST[NAT]+LENGTH[DESCRIPTOR[record.parties]])
              DO
            BEGIN  -- Unmarshal record.parties[element3]: ThParty.PartyInfoSpec
                -- from pkt.data[pktLength].
              pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
                  dataAdr: @record.parties[element3], dataLength: SIZE[ThParty.PartyInfoSpec],
                  alwaysOnePkt: FALSE];
              -- Restore garbled REFs to NIL following copy.
              BEGIN OPEN record: record.parties[element3];
              LOOPHOLE[record.type, LONG POINTER] ← NIL;
              LOOPHOLE[record.name, LONG POINTER] ← NIL;
              END;  -- OPEN record: record.parties[element3].
              BEGIN OPEN record: record.parties[element3];
              BEGIN  -- Unmarshal record.type: Thrush.PartyType from
                  -- pkt.data[pktLength].
                [record.type, pktLength] ← Lupine.UnmarshalAtom[pkt,
                    pktLength];
                END;  -- Unmarshal record.type.
              BEGIN  -- Unmarshal record.name: Thrush.ROPE from pkt.data[pktLength].
                [record.name, pktLength] ← Lupine.UnmarshalRope[pkt,
                    pktLength, FALSE];
                END;  -- Unmarshal record.name.
              END;  -- OPEN record: record.parties[element3].
              END;  -- Unmarshal record.parties[element3].
            ENDLOOP;  -- FOR element3.
          END;  -- Unmarshal record.parties.
        END;  -- OPEN record: value↑.
        END;  -- IF recordIsNIL.
    END;  -- Unmarshal value↑.
  };END;

UnmarshalThrushDotConvEvent: PROC[pkt: RpcPrivate.RPCPkt, pktLength0:
    RpcPrivate.DataLength]
  RETURNS[value: Thrush.ConvEvent, pktLength: RpcPrivate.DataLength]
      = BEGIN
  pktLength ← pktLength0; {
  isNIL: Lupine.NilHeader;
  IF pktLength+1 > RpcPrivate.maxDataLength
    THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength: pktLength];
  isNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
  IF isNIL
    THEN value ← NIL
    ELSE BEGIN
      value ← (paramZones.gc.NEW[Thrush.ConvEventBody]);
      BEGIN  -- Unmarshal value↑: Thrush.ConvEventBody from pkt.data[pktLength].
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: LOOPHOLE[value], dataLength: SIZE[Thrush.ConvEventBody],
            alwaysOnePkt: FALSE];
        -- Restore garbled REFs to NIL following copy.
        BEGIN OPEN record: value↑;
        LOOPHOLE[record.reason, LONG POINTER] ← NIL;
        LOOPHOLE[record.comment, LONG POINTER] ← NIL;
        END;  -- OPEN record: value↑.
        BEGIN OPEN record: value↑;
        BEGIN  -- Unmarshal record.reason: Thrush.Reason from pkt.data[pktLength].
          [record.reason, pktLength] ← Lupine.UnmarshalAtom[pkt, pktLength];
          END;  -- Unmarshal record.reason.
        BEGIN  -- Unmarshal record.comment: Thrush.ROPE from pkt.data[pktLength].
          [record.comment, pktLength] ← Lupine.UnmarshalRope[pkt, pktLength,
              FALSE];
          END;  -- Unmarshal record.comment.
        END;  -- OPEN record: value↑.
        END;  -- Unmarshal value↑.
      END;  -- IF isNIL.
  };END;

UnmarshalThrushDotKeyTable: PROC[pkt: RpcPrivate.RPCPkt, pktLength0:
    RpcPrivate.DataLength]
  RETURNS[value: Thrush.KeyTable, pktLength: RpcPrivate.DataLength]
      = BEGIN
  pktLength ← pktLength0; {
  BEGIN  -- Unmarshal value↑: IV.KeyTableBody from pkt.data[pktLength].
    recordIsNIL: Lupine.NilHeader;
    IF pktLength+3 > RpcPrivate.maxDataLength
      THEN pktLength ← Lupine.FinishThisPkt[pkt: pkt, pktLength: pktLength];
    recordIsNIL ← pkt.data[pktLength];  pktLength ← pktLength+1;
    IF recordIsNIL
      THEN value ← NIL
      ELSE BEGIN
        seqLength: Lupine.SequenceHeader;
        seqLength ← Lupine.RpcPktDoubleWord[pkt, pktLength]↑;
        pktLength ← pktLength + 2;
        value ← (paramZones.gc.NEW[IV.KeyTableBody[Lupine.SHORT[seqLength]]]);
        pktLength ← Lupine.CopyFromPkt[pkt: pkt, pktLength: pktLength,
            dataAdr: LOOPHOLE[value], dataLength: SIZE[IV.KeyTableBody[LENGTH[DESCRIPTOR[value↑]]]],
            alwaysOnePkt: FALSE];
        END;  -- IF recordIsNIL.
    END;  -- Unmarshal value↑.
  };END;



-- No module initialization.

END.  -- ThPartyRpcClientImpl.