(*
    Title: 	Various random utility procedures
    LastEdit:	"Tue Jan  5 10:31:01 1988"
    Author: 	Derek McAuley,Oms1,4663,329629
		Cambridge University Computer Laboratory
*)

DEFINITION MODULE RPCStates;


IMPORT
  PktBufs, Threads;

FROM RPCBasics IMPORT
  CallId, CallEnd, RC, Location, PacketType, ProtocolType,
  ServiceId, ThreadHand;


EXPORT QUALIFIED
  Status, T, RPCStateR,
  
  CopyInToPkt, CopyOutOfPkt,
  New, Dispose, DisposeAndNew, SendTerminator, ReplyWithTerminator,
  SendAliveOne, SendADeadOne, ReplyWithADeadOne, SignalPacket, Init;
  

TYPE
  Status =
    (ClientMultipleCall, ClientWaitReply, ClientMultipleReply,
     ServerMultipleCall, ServerExecute, ServerMultipleReply, ServerTerminate);

  T = POINTER TO RPCStateR; 
  RPCStateR =
    RECORD
      sNext:     T;
      sStatus:   Status;
      sProtocol: ProtocolType;
      
      sLocation: ARRAY CallEnd OF Location;
      sServiceId:ServiceId;
      sThreadId: ThreadHand;
      sCallId:   CallId;
      
      sArguments:PktBufs.T;
      sResults:  PktBufs.T;
      sAlive:    BOOLEAN;
      sUnknown:  PktBufs.T;
      sCondition:Threads.Condition;
      sLock:     Threads.Mutex
    END;


  (* Packet formats: overlay these on data area of PktBufs.T.

     CallPkt and Replypkt are user datar ...

     ProkePkt, TermPkt, and AlivePkt contain no information, it's all in the
     header...  *)


PROCEDURE CopyInToPkt(state:T; p:PktBufs.T);

PROCEDURE CopyOutOfPkt(p:PktBufs.T; state:T);


PROCEDURE New():T;

PROCEDURE Dispose(state:T);

PROCEDURE DisposeAndNew(state:T);

PROCEDURE SendTerminator(state:T);

PROCEDURE ReplyWithTerminator(p:PktBufs.T);

PROCEDURE SendAliveOne(end:CallEnd; state:T);

PROCEDURE SendADeadOne(
  state: T;
  reason:RC
 );

PROCEDURE ReplyWithADeadOne(
  p:  PktBufs.T;
  err:RC
 );

PROCEDURE SignalPacket(
  state:T;
  pkt:  PktBufs.T
 );

PROCEDURE Init();

END RPCStates.
