(*
    Title: 	De-multiplex packets
    LastEdit:	"Fri Dec 18 11:33:07 1987"
    Author: 	Derek McAuley,Oms1,4663,329629
		Cambridge University Computer Laboratory
*)

(* There are several situations which will cause a (new) thread to execute
(in all other cases the packet is destined for a particular thread). The REAL
first call packet. If it is the first of a multiple packet call RPCMultiple
will be invoked, which will then pick up the rest of the call packets
explicitly. A call packet or a probe packet during execution of the call in
the server. This results in an AlivePkt to the calling machine. And many many
more ... However for the rest, a short list is maintained for each place,
while the packets await collection. *)


DEFINITION MODULE RPCReceive;


IMPORT 
  PktBufs, RPCStates, SYSTEM, Threads;


FROM RPCBasics IMPORT
  CallEnd, CallId, Place;


EXPORT QUALIFIED 
  relevantProcedure,
  
  Add, Remove, NewCall, NewCallRelease, Init;


VAR
  relevantProcedure:ARRAY CallEnd OF PROCEDURE(PktBufs.T, RPCStates.T);


PROCEDURE Add(type:CallEnd; state:RPCStates.T);

PROCEDURE Remove(state:RPCStates.T);

PROCEDURE NewCall(VAR state:RPCStates.T (* Out *)):PktBufs.T;
  (* Blocks until new call packet arrives, and exits holding NewCall lock.
     If a previous call is active then its state is returned, else NIL. *)

PROCEDURE NewCallRelease();

PROCEDURE Init();

END RPCReceive.

