#ifndef EVENTOBJECT_H
#define EVENTOBJECT_H

#include "ossync.h"
#include "types.h"

/*------------------------------------------------------------
CLASS 
	EventObject 

DESCRIPTION
	EventObject encapsulates a binary semaphore and the basic operations
	performed on a binary semaphore. It also contains a a single, 
	static event signalling semaphore intended to be used with the 
	MicroEventHandler class. On setting the EventObject, both the contained
	semaphore and the signalling semaphore are triggered. It should be used
	where both a module-level asynchronous mechanism is needed as well as 
	a system-level asynchronous mechanism is needed.

AUTHOR 
	Danelle Cline. Copyright 1998 MBARI.											
	
LOG
	Modifier 	Date    		Change
	--------   	----    		--------
	D. Cline	5/14/97			Alpha prototype
	D. Cline	9/14/99			Charlie prototype
	D. Cline	02/14/00		Added event id
------------------------------------------------------------*/
class EventObject
{
  public:	    

	  // Initialize event as 	
	  // SEM_EMPTY,			/* 0: semaphore not available */
	  // SEM_FULL			/* 1: semaphore available */
	  EventObject(SEM_B_STATE initialstate = SEM_EMPTY, const char *name = NULL);
	  
	  virtual ~EventObject(void);

	  // Set event. Sets a flag, and gives the encapsulated sempahore and
	  // signal semaphore.
	  void set(void);

	  // Clear event. Sets a flag, and resets the encapsulated sempahore.
	  // and signal semaphore
	  void clear(void);

	  // Wait for semaphore to release up to msectimeout
	  Int32 wait(Int32 msectimeout = WAIT_FOREVER);
	  
      // Returns TRUE if the semaphore was released.
	  MBool isSet();

	  // Wait for semaphore to release up to msectimeout
	  // Returns -1 if timed out before signal was released
	  static Int32 waitForSignal(Int32 msectimeout = WAIT_FOREVER);

  protected:
	  // Gives the static BinarySemaphore _signalSem. This is used with
	  // the EventHandler to signal a semaphore release. To test for
	  // a particular semaphore's signalled state use isSet()
	  static void signalEventHandler();

  private:
  
	  MBool _set;
	  BinarySemaphore _event;	  
	  Int32	_id;
	  static BinarySemaphore _signalSem;	
};
#endif // !defined(EVENTOBJECT_H)
