(*
    Title: 	Basics types etc for RPC
    LastEdit:	"Thu Feb 25 18:03:06 1988"
    Author: 	Derek McAuley,Oms101,4652
		Cambridge University Computer Laboratory
*)

DEFINITION MODULE RPCBasics;

EXPORT QUALIFIED
  NetworkType, ServiceId, Instance, ThreadHand, CallSemantics, 
  LocationPointer, Location, Place, Distance,
  Interface, Binder, CallId, ConverseId, ProtocolType, PacketRate,
  SequenceNumber, PacketType, BinderInfo, ThisLocality, 
  CallEnd, RC, MemberRC;


TYPE
  NetworkType     = (UdpIpNet, UdlNet);
  ServiceId       = CARDINAL;
  Instance        = CARDINAL;
  ThreadHand      = CARDINAL;
  CallSemantics   = (ExactlyOnce, AtLeastOnce, AtMostOnce);

  Views           = (ViewBytes, ViewWords, ViewUdpIp, ViewUdl);
  LocationPointer = POINTER TO Location;
  Location =
    RECORD (* a net/machine address *)
      CASE Views OF
        ViewBytes:
          byte:ARRAY [0..11] OF CHAR
      | ViewWords:
          word:ARRAY [0..2] OF CARDINAL
      | ViewUdpIp:
          udpType:NetworkType; (* byte  0 *)
          udpPort,             (* short 0 *)
          machineId:CARDINAL   (* long    *)
      | ViewUdl:
          tom, dick, harry:CARDINAL
      END;
    END; (* record *)
  Place = 
    RECORD
      location:Location;
      service: ServiceId
    END;
  Distance =
    (WithinDomain,
     WithinMachine,
     SameDomain,
     SameMachine,
     SameGroup,
     SameNet,
     SameDivision,
     SameOrganisation,
     SameUniverse,
     DifferentUniverse
    );
(*
  WithinMachine does not allow any external callers
  SameMachine allows external callers,
  but does not allow offering to remote binders
*)

  Interface    = Place;
  Binder       = Interface;
  CallId       = CARDINAL;
  ConverseId   = CARDINAL;
  ProtocolType = CallSemantics;

  PacketRate     = [0..0FFh];
  SequenceNumber = [0..0FFh];
  
  PacketType = 
    (CallPkt,
     CNackPkt,
     ReplyPkt,
     RNackPkt,
     TermPkt,
     AlivePkt,
     AliveAckPkt,
     DeadPkt);

  BinderInfo = 
    RECORD
      id: ServiceId;
      i: Instance;
      d: Distance;
    END;

  CallEnd = (ClientEnd, ServerEnd);
  
  RC =
    (OK,
     UnknownService,   (* Service id unknown (server crash?) *)
     ProcError,        (* Unknown procedure at server *)
     VersionError,     (* Bad version number at server *)
     ArgError,         (* Unmarshalling error at server *)
     ResultError,      (* Unmarshalling error at client *)
     Congested,        (* Server executing too many RPCs *)
     NoReply,          (* AMO *)
     CallTooBig,       (* Multiple packet call not allowed *)
     ReplyTooBig,      (* Multiple packet reply not allowed *)
     NoSuchCall,       (* Server denies call executing *)
     DomainUnknown,    (* Domain has crashed (or say TASK in TRIPOS) *)
     MachineAdUnknown, (* Unable to send to that machine address *)
     ServerCrash,      (* Server has crashed *)
     UnknownError,     (* No further information *)
     UserException     (* A user exception was caught (m2+) *)
    );

  MemberRC =
    (BindOK,
     NotFound,       (* Service not found *)
     NoBinder,       (* No binder available *)
     NetBinderError, (* Some internal binder error *)
     NetBinderFull,  (* Net binder full! *)
     Exists          (* Service exists *)
    );
  


CONST
  ThisLocality = SameDomain;


END RPCBasics.
