next up previous
Next: semaphore Up: simioprocess Previous: processmanager

IOProcess


     NAME
	  ioprocess - superclass of user-defined processes

     DESCRIPTION
	  Specialized in user subclasses to processes taking care of
	  external The user will define	subclasses of IOProcess	where
	  the body will	be used	to specify the activity	of the
	  process. Each	such class will	thus look like a main program.
	  If it	does not communicate with other	processes in the same
	  program it can be written with no knowledge of the rest of
	  the processes.

     EXAMPLES
	  See the users	manual in simioprocess.ps

     AUTHOR
	  Boris	Magnusson, Lund	Institute of Technology.

     DETAILED INTERFACE
	     BasicProcess class	IOProcess;
	  There	will typically be a one-to-one correspondence  between
	  an  interesting  file	 and  a	process	to receive I/O events.
	  This process knows how to initialize the  file  and  how  to
	  read	from the file.	Other processes	might ask for periodic
	  events to work as a clock. It	is good	practice to  keep  the
	  processes  small  handling  one external file	or one kind of
	  periodic events each.

	  An IOProcess object is created by another IOProcess (or  the
	  main	 program),   initialized   and	 registered   by   the
	  ProcessManager, and the Started.

	  It can be Stop either	by itself (calling Terminate  or  pass
	  out  through its final end), or it can be stopped by another
	  process (calling its 'Stop').

	  Of the many events, there are	typically just a few relevenat
	  for a	single class of	IOProcesses.

	  Supers: BasicProcess,	EventQ,	Simset
	  Kind:	Abstract
	  Init:	The body of the	subclass will be  executed  as	a  c
o-
	  routine/process
	  Sequencing:	new   <sync   init>   PMG.RegisterProcess(this
	  IOProcess) Start
	   :	(A* Stop Start)* Kill/Terminate/end-of-class
	   : A=	Pause /	Nice / WaitEvent / AskEvent / PutEvent /
	   :	EnablePeriodicEvents  /	DisablePeriodicEvents /
	   :	EnableCancelEvents    /	DisableCancelEvents /
	   :	EnableUpdateEvents    /	DisableUpdateEvents /
	     :	     EnableInputEvents	      /	   StartIOTimeout    /
	  DisableInputEvents /
	   :	EnableOutputEvents    /	DisableOutputEvents /
	     :	    EnableInputEventsUNIX   /	StartIOTimeoutUNIX   /
	  DisableInputEventsUNIX /
	   :	EnableOutputEventsUNIX/	DisableOutputEventsUNIX	/

     EXTERNAL OPERATIONS ONLY
     Start
	     procedure Start;
	  Put the process into the  Read/Running  state.  The  process
	  will	be  given  chance  to execute in due time according to
	  priorities  and  scheduling  policies.  This	operations  is
	  intend to be invoced from outside the	IOProcess object only,
	  typically by the  creator,  after  some  initializations  (a
	  process can not start	itself).

     Kill
	     procedure Kill;
	  This operation causes	the process to become  terminated.  It
	  is thus analogous to the operation Terminate but Kill	can be
	  called from another process and the killed process can be in
	  any state of execution.

     INTERNAL (PROTECTED) OPERATIONS
     Stop
	     procedure Stop;
	  Move the process into	the Suspended state. This  means  that
	  the  process	will  nou  execute  until it has been Start:ed
	  again. Stop can be called (direct or indirect) only when the
	  process itself is executing.

     Nice
	     procedure Nice(N);	integer	N;
	  Lower	the priority of	this  IOProcess.  Initially  processes
	  have	the same, high,	priority. Nice is called by background
	  processes not	 to  disrupt  response-critical	 processes  to
	  much.	 They  should  have  Pause-calles  sprinkled over time
	  consuming parts.  Notice that	 Nice  can  NOT	 be  used  for
	  solving  synchronization  problems.	There  is no guarantee
	  that a nicer process is not executed	when  other  processes
	  are ready, it	is just	a bit less likely.

     Terminate
	     procedure Terminate;
	  Stop execution of this IOProcess and deregister it.

     WaitEvent
	     ref(BasicProcessEvent) procedure WaitEvent;
	  Wait for next	event to arrive, then return with  the	Event.
	  If  no  event	 is  queued  the IOProcess is blocked until an
	  Event	has been sent to this process with a call to PutEvent.

     AskEvent
	     Boolean procedure AskEvent;
	  This function	returns	 True  if  any	event  pending,	 False
	  otherwise.

     PutEvent
	     procedure PutEvent(E);
	     ref(BasicProcessEvent) E;
	  Queue	the ProcessEvent,  E,  for  this  process.  This  will
	  trigger the IOProcess	to be moved to the Ready/Running state
	  if it	has called the operation WaitEvent and	no  event  was
	  pending.

     Pause
	     procedure Pause;
	  Simulation of	interrupt used to trigger rescheduling.	Insert
	  this	into  code  where the execution	tends to take a	lot of
	  time.	Note: Beware of	concurrency problems and ensure	mutual
	  exclusion!

     EVENT CONTROL
     EnableCancelEvents
	     procedure EnableCancelEvents;
	  Enable CancelEvent to	be received as broadcasted by  a  call
	  to CancelAll of the PMG.

     DisableCancelEvents
	     procedure DisableCancelEvents;
	  Called to not	get any	future CancelEvents.

     EnablePeriodicEvents
	     procedure EnablePeriodicEvents(Seconds); long real
	     Seconds;
	  Order	PeriodicEvents	to  appear  with  a  distance  of  Sec
	  seconds  on  the  average  starting  Sec  seconds  from now.
	  Earlier enables are replaced by a new	request. Note  periods
	  longer  than	24  hours are not allowed.  If for some	reason
	  the event can	not be generated at the	propper	time  one  (or
	  several)  will  be  generated	as soon	as possible to make up
	  for the passing time.

     DisablePeriodicEvents
	     procedure DisablePeriodicEvents;
	  Cancels any ordered PeriodicEvent.

     EnableUpdateEvents
	     procedure EnableUpdateEvents;
	  Order	UpdateEvent. They are generated	when the Scheduler has
	  nothing  more	 to do and is about to go idle.	Can be used to
	  trigged clean	up activities such as emptying output  buffers
	  etc  before  the  system  goes  to  sleep,  wating  for some
	  external (Periodic, Input, IOTimeout or Output -) Event.

     DisableUpdateEvents
	     procedure DisableUpdateEvents;
	  Cancels generating UpdateEvents to this IOProcess.

     EnableInputEvents
	     procedure EnableInputEvents(F);
	     ref(File) F; ! Simula In(byte)file	or Direct(byte)file;
	  Enable events	related	to the Simula (input or	 directaccess)
	  File	F.   F	must  have  been  opened  before the call. The
	  IOProcess will receive an InputEvent when an	'Inimage'  (or
	  Intext) can be performed.

     StartIOTimeout
	     procedure StartIOTimeout(F,Sec);
	     ref(File) F; ! Simula In(byte)file	or Direct(byte)file;
	     Real Sec; ! Maximum time to wait for next input.;
	  Start	a timer	on the file F with duration  Sec  Seconds.  (F
	  must	  previously	been	enabled	  with	 a   call   to
	  EnableInputEvents).  The effect of  the  timer  is  that  an
	  IOTimeoutEvent  will	appear	after  the  time Sec if	not an
	  InputEvent has been generated	before.	One and	 only  one  of
	  these	two possible events will appear.  The timer is started
	  at the time of the call of this operation and	it  have  only
	  effect once.

     DisableInputEvents
	     procedure DisableInputEvents(F);
	     ref(file) F; ! Simula In(byte)file	or Direct(byte)file;
	  Forget about the Simula file F. This operation is  typically
	  called before	the file is closed.

     EnableOutputEvents
	     procedure EnableOutputEvents(F);
	     ref(File) F; ! Simula Out(byte)file or Direct(byte)file;
	  Enable events	related	to the Simula (output or directaccess)
	  File	F.   F	must  have  been  opened  before the call. The
	  IOProcess will receive an OutputEvent	when an	'Outimage' (or
	  'Outtext') can be performed.

     DisableOutputEvents
	     procedure DisableOutputEvents(F);
	     ref(file) F; ! Simula Out(byte)file or Direct(byte)file;
	  Forget about the Simula file F. This operation is  typically
	  called before	the file is closed.

     UNIX RELATED OPERATIONS
	  These	 Five  operations  have	 the  same   effect   as   the
	  corresponding	 operations  above but relate to standard UNIX
	  files. N is a	Unix file system number	as returned by open.

     EnableInputEventsUNIX
	     procedure EnableInputEventsUNIX(N);
	     integer N;	! Unix file number (0,1,2..) as	returned by
	     open.;

     StartIOTimeoutUNIX
	     procedure StartIOTimeoutUNIX(N,Sec);
	     integer N;	! Unix file number (0,1,2..) as	returned by
	     open.;
	     Real Sec; ! Maximum time to wit for next input operation.
	     ;

     DisableInputEventsUNIX
	     procedure DisableInputEventsUNIX(N);
	     integer N;	! Unix file number (0,1,2..) as	returned by
	     open.;

     EnableOutputEventsUNIX
	     procedure EnableOutputEventsUNIX(N);
	     integer N;	! Unix file number (0,1,2..) as	returned by
	     open.;

     DisableOutputEventsUNIX
	     procedure DisableOutputEventsUNIX(N);
	     integer N;	! Unix file number (0,1,2..) as	returned by
	     open.;