Click here to Skip to main content
15,896,557 members
Articles / Desktop Programming / MFC

STL WebServer

Rate me:
Please Sign up or sign in to vote.
4.89/5 (5 votes)
8 May 2000 90.3K   2.5K   47  
A set of classes written in STL that implement a web server
#if !defined(SysEvent_H)
#define SysEvent_H






#include <string>
using namespace std;



////////////////////////////////////////////////////////////////////////
// SysEvent 

class SysEvent
{
	string		m_name;				// name of event
	HANDLE		m_hEvent;			// handle to user event
	bool		m_attached;			// shows if just attached to event

public:
	SysEvent () :
		m_name (),
		m_hEvent (NULL),
		m_attached(false)
	{}

	SysEvent ( SysEvent & event ) :
		m_name (),
		m_hEvent (NULL),
		m_attached(false)
	{ *this = event; }

	virtual ~SysEvent ()
	{ release(); }

	// create/release
	bool create ()
	{
		// release if needed
		release();

		// init name
		m_name = "";

		// create event
		m_attached = false;
		m_hEvent = ::CreateEvent( NULL, TRUE, FALSE, NULL );	

		if ( m_hEvent == NULL )
			return false;
		else
			return true;
	}

	bool create ( LPTSTR name )
	{
		if ( !name )
			return false;

		// release if needed
		release();

		// create named event
		m_attached = false;
		m_hEvent = ::CreateEvent( NULL, TRUE, FALSE, (LPCTSTR) name );	

		if ( m_hEvent == NULL )
			return false;
		else
			return true;
	}

	void release ()
	{
		// if only attached just detach
		// else destroy event and name
		if ( m_attached )
			detach();
		else
		{
			if ( m_hEvent )
			{
				::CloseHandle(m_hEvent);
				m_hEvent = NULL;
			}

			if ( !m_name.empty() )
				m_name.erase();
		}
	}


	// attach/detach from event
	bool attached ()
	{ return m_attached; }

	bool attach	( HANDLE hEvent )
	{
		if ( !hEvent )
			return false;

		// get handle show attached
		m_hEvent = hEvent;
		m_attached = true;
		
		return true;
	}

	void detach		()
	{
		// if not attached stop
		if ( !m_attached )
			return;

		m_hEvent = NULL;
		if ( !m_name.empty() )
			m_name.erase();
		m_attached = false;
	}

	// set/reset event
	void set ()
	{
		::SetEvent( m_hEvent );
	}

	void reset ()
	{
		::ResetEvent( m_hEvent );
	}

	// get event handle
	HANDLE	getEvent ()
	{ return m_hEvent; }


	// ref operators
	HANDLE operator & ()		
	{ return m_hEvent; }

	operator HANDLE () 
	{ 
		return m_hEvent; 
	}

	// sort operators
	bool operator < ( SysEvent & event )
	{
		if ( m_hEvent < event.m_hEvent )
			return true;
		else
			return false;
	}

	bool operator == ( SysEvent & event )
	{
		if ( m_hEvent == event.m_hEvent )
			return true;
		else
			return false;
	}

	bool operator = ( SysEvent & event )
	{
		m_name = event.m_name;
		m_hEvent = event.m_hEvent;
		m_attached = event.m_attached;
	}

};


#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions