-- RPC is the Cedar interface to the RPC runtime.
-- RPC is exactly parallel to MesaRPC, the Mesa-compatible interface.

-- File [Ivy]<Birrell>RPC>RPC.mesa

-- Andrew Birrell   3-Dec-81 10:14:28
-- BZM		29-Oct-81 11:46:31
-- Taft		6-Oct-81 18:35:28


DIRECTORY
Rope		USING [ROPE],
MesaRPC		USING [AuthenticateFailure, CallFailure, Conversation,
		       ConversationID, ConversationLevel, EncryptionKey,
		       EndConversation, ExportFailure, GetLevel, ImportFailure,
		       GetConversationID, GenerateConversation, matchAllVersions,
		       maxPrincipalLength, maxShortStringLength, SecurityLevel,
		       ShortSTRING, unencrypted, VersionRange];


RPC: DEFINITIONS
  IMPORTS MesaRPC =
  BEGIN


-- Short string/rope/atom types. Used only by Lupine clients.

  maxShortStringLength: CARDINAL = MesaRPC.maxShortStringLength;
  -- maximum length of ShortSTRING/ShortROPE/ShortATOM values --

  ShortSTRING: TYPE = MesaRPC.ShortSTRING;
  ShortROPE: TYPE = Rope.ROPE;
  ShortATOM: TYPE = ATOM;


-- Types for Import and Export calls.

  InterfaceName: TYPE = RECORD [
	type: ShortROPE ← NIL,      -- e.g., "AlpineAccess.Alpine"
	instance: ShortROPE ← NIL,  -- e.g., "MontBlanc.Alpine"
	version: VersionRange ← matchAllVersions ];

  defaultInterfaceName: InterfaceName = [];

  VersionRange: TYPE = MesaRPC.VersionRange;

  matchAllVersions: VersionRange = MesaRPC.matchAllVersions;


-- Parameter storage zones.  Used only by Lupine clients.

  Zones: TYPE = RECORD [
	gc:   ZONE ← NIL,
	heap: UNCOUNTED ZONE ← NIL,
	mds:  MDSZone ← NIL ];

  standardZones: Zones = [];
  
-- Encryption and Authentication facilities.

  maxPrincipalLength: CARDINAL = MesaRPC.maxPrincipalLength;
    -- Limit on length of ropes used for Principal names --

  Principal: TYPE = ShortROPE;

  EncryptionKey: TYPE = MesaRPC.EncryptionKey;

  MakeKey: PROCEDURE [text: Rope.ROPE] RETURNS[EncryptionKey];

  Conversation:	TYPE = MesaRPC.Conversation;
  
  SecurityLevel: TYPE = MesaRPC.SecurityLevel;
  
  ConversationLevel: TYPE = MesaRPC.ConversationLevel;

  unencrypted: Conversation = MesaRPC.unencrypted;

  GenerateConversation: PROC RETURNS[Conversation] = INLINE
    { RETURN[ MesaRPC.GenerateConversation[] ] };

  StartConversation: PROCEDURE[caller: Principal, key: EncryptionKey,
			       callee: Principal,
			       level: ConversationLevel ]
                       RETURNS[conversation: Conversation];

  EndConversation: PROCEDURE [conversation: Conversation] = INLINE
    { MesaRPC.EndConversation[conversation] };
 
  GetCaller: PROCEDURE [conversation: Conversation]
               RETURNS [caller: Principal];
 
  GetLevel: PROCEDURE [conversation: Conversation]
               RETURNS [level: SecurityLevel] = INLINE
    { RETURN[ MesaRPC.GetLevel[conversation] ] };

  ConversationID: TYPE = MesaRPC.ConversationID;

  GetConversationID: PROC[conversation: Conversation]
	     RETURNS[id: ConversationID] = INLINE
    { RETURN[ MesaRPC.GetConversationID[conversation] ] };


-- Public signals:

  AuthenticateFailure: TYPE = MesaRPC.AuthenticateFailure;

  ExportFailure:       TYPE = MesaRPC.ExportFailure;

  ImportFailure:       TYPE = MesaRPC.ImportFailure;

  CallFailure:         TYPE = MesaRPC.CallFailure;

  AuthenticateFailed: ERROR[why: AuthenticateFailure];
    -- Raised by StartConversation --

  ExportFailed: ERROR[why: ExportFailure];
    -- Raised by ExportInterface --

  ImportFailed: ERROR[why: ImportFailure];
    -- Raised by ImportInterface --

  CallFailed: SIGNAL[why: CallFailure];
    -- Raised by any remote call; only why=timeout is resumable --

END.