(*
    Title: 	User interface to RPC
    LastEdit:	"Mon Feb  1 14:04:21 1988"
    Author: 	Derek McAuley,Oms1,4663,329629
		Cambridge University Computer Laboratory
*)

DEFINITION MODULE RPC;


IMPORT
  Marshal, PktBufs, RPCBasics, RPCNets;

FROM SYSTEM      IMPORT WORD, ADDRESS;
FROM SystemTypes IMPORT String;


EXPORT QUALIFIED 
  ThisLocality,

  NetworkType, ServiceId, CallEnd, Distance, Instance, BinderInfo, 
  Location, Place, CallSemantics, Interface, Binder, PktBuf, ReceiveProc, 
  RC, MemberRC,
  
  ClientArguments, Call, CallNoDiscard, EndOfResults, 
  ServerProcedure, ServerProcedureVCheck, EndOfArgs, SetReturnCode, EndOfCall,
  Find, Offer, SuggestId, OfferId, ReOffer, Retract,
  SamePlace, SameLocation,

  MarshalPlace, MarshalLocation;


CONST
  ThisLocality    = RPCBasics.ThisLocality;


TYPE
  NetworkType     = RPCBasics.NetworkType;
  ServiceId       = RPCBasics.ServiceId;
  CallEnd         = RPCBasics.CallEnd;
  Distance        = RPCBasics.Distance;
  Instance        = RPCBasics.Instance;
  BinderInfo      = RPCBasics.BinderInfo;
  Location        = RPCBasics.Location;
  LocationPointer = RPCBasics.LocationPointer;
  Place           = RPCBasics.Place;
  CallSemantics   = RPCBasics.CallSemantics;
  Interface       = RPCBasics.Interface;
  Binder          = RPCBasics.Binder;

  PktBuf          = PktBufs.T;
  ReceiveProc     = PktBufs.ReceiveProc;
  
  RC              = RPCBasics.RC;
  MemberRC        = RPCBasics.MemberRC;


(* Client Procedures *)

PROCEDURE ClientArguments(
  target:  Interface; 
  proc, 
  version: CARDINAL;
  protocol:CallSemantics
 ):Marshal.T;

PROCEDURE Call(m:Marshal.T):RC;
  (* Discards argument packets after call *)

PROCEDURE CallNoDiscard(m:Marshal.T):RC;

PROCEDURE EndOfResults(VAR m:Marshal.T (* InOut *)):RC;
  (* Does discard of OS PktBufs too *)


(* Server Procedures *)

PROCEDURE ServerProcedure(
     p:      PktBuf;
 VAR m:      Marshal.T; (* Out *)
 VAR version:CARDINAL   (* Out *)
 ):CARDINAL;
  (* Initialises Marshal.T for unmarshalling *)

PROCEDURE ServerProcedureVCheck(
     p:      PktBuf;
 VAR m:      Marshal.T; (* Out *)
 VAR proc:   CARDINAL;  (* Out *)
     version:CARDINAL
 ):RC;

PROCEDURE EndOfArgs(m:Marshal.T):RC;
  (* Checks args used up exactly, and sets m to marshal results.
     Puts in a good return code, assuming that all will be well. *)

PROCEDURE SetReturnCode(
  rc:RC;
  m: Marshal.T
 );
  (* Works regardless of whether EndOfArgs has already been called. Sets m
     to contain the relevant bad return code. *)

PROCEDURE EndOfCall(m: Marshal.T):PktBuf;
  (* Discards m and gives the result data packets back to the system. *)

(* Binder Procedures *)

PROCEDURE Find(
      name: String;
      d:    Distance; 
  VAR place:Place    (* Out *)
 ):MemberRC;

PROCEDURE Offer(
      name:String;
      d:   Distance;
      p:   ReceiveProc;
      i:   Instance;
  VAR svId:ServiceId
 ):MemberRC;
  (* NIL names will be faulted *)

PROCEDURE SuggestId(): ServiceId;

PROCEDURE OfferId(
  id:ServiceId; 
  p: ReceiveProc;
  i: Instance
 ):BOOLEAN;

PROCEDURE ReOffer(
  id:ServiceId;
  p: ReceiveProc;
  i: Instance
 ):BOOLEAN;

PROCEDURE Retract(service:ServiceId);


(* The next two procedures return pointers to fixed variables, giving
   machine location and name. *)

(* Miscellaneous *)

PROCEDURE SamePlace(place1, place2:Place):BOOLEAN;

PROCEDURE SameLocation(location1, location2:Location):BOOLEAN;


(* Marshaling Procedures *)
PROCEDURE MarshalServiceId(VAR svId:ServiceId; (* InOut *) m:Marshal.T);

PROCEDURE MarshalPlace(VAR place:Place (* InOut *); m:Marshal.T);

PROCEDURE MarshalLocation(VAR loc:Location (* InOut *); m:Marshal.T);

END RPC.
