125 lines
3.4 KiB
C++
125 lines
3.4 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivBase/EventManagee.h
|
|
*
|
|
* @brief Header file for class managed by EventManager.
|
|
*/
|
|
|
|
#if (!defined ACTIV_BASE_EVENT_MANAGEE_H)
|
|
#define ACTIV_BASE_EVENT_MANAGEE_H
|
|
|
|
#include "ActivMiddleware/ActivBase/External.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
class EpollManager;
|
|
class EventManager;
|
|
class IMutex;
|
|
class PollManager;
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief EventManager managed class.
|
|
*/
|
|
class EventManagee : private Boost::noncopyable
|
|
{
|
|
public:
|
|
typedef uint32_t Events; ///< Event type.
|
|
|
|
static const Events EVENT_NONE = 0x00000000;
|
|
static const Events EVENT_READ = 0x00000001; ///< Data to read.
|
|
static const Events EVENT_WRITE = 0x00000002; ///< OK to write.
|
|
static const Events EVENT_CLOSE = 0x00000004; ///< Close has been requested.
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param eventManager reference to EventManager to attach to.
|
|
* @param pMutex (optional) mutex.
|
|
*/
|
|
ACTIV_BASE_API EventManagee(EventManager &eventManager, IMutex * const pMutex);
|
|
|
|
//! Destructor.
|
|
ACTIV_BASE_API virtual ~EventManagee();
|
|
|
|
/**
|
|
* @brief Add fd to event manager.
|
|
*
|
|
* NB can be called from any thread, but the mutex *must* already be locked.
|
|
*
|
|
* @param events set of events to get notification on initially.
|
|
* @param socket (Windows only) optional socket associated with m_handle.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_ALREADY_EXISTS AddFd() has already been called; nothing has been done.
|
|
* @retval ...
|
|
*/
|
|
#if (defined ACTIV_PLATFORM_WINDOWS)
|
|
ACTIV_BASE_API StatusCode AddFd(const Events events, const SOCKET socket = INVALID_SOCKET);
|
|
#else
|
|
ACTIV_BASE_API StatusCode AddFd(const Events events);
|
|
#endif
|
|
|
|
/**
|
|
* @brief Remove fd from event manager.
|
|
*
|
|
* NB this *must* be called from the context of the event manager's thread, and the mutex *must*
|
|
* already be locked.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_NOT_CREATED RemoveFd() has already been called or AddFd() was not called; nothing has been done.
|
|
* @retval ...
|
|
*/
|
|
ACTIV_BASE_API StatusCode RemoveFd();
|
|
|
|
/**
|
|
* @brief Add events to wait for.
|
|
*
|
|
* NB can be called from any thread, but the mutex *must* already be locked.
|
|
*
|
|
* @param addEvents events to add to the wait set.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_BASE_API StatusCode AddEvents(const Events addEvents);
|
|
|
|
//! Get the EventManager.
|
|
EventManager &GetEventManager();
|
|
|
|
protected:
|
|
/**
|
|
* @brief Event processing.
|
|
*
|
|
* @param events the set of events that have occurred.
|
|
*/
|
|
virtual void OnEvents(const Events events) = 0;
|
|
|
|
EventManager & m_eventManager; ///< Hook back to the event manager.
|
|
IMutex * const m_pMutex;
|
|
|
|
HANDLE m_handle; ///< File descriptor to watch.
|
|
Events m_events; ///< Current set of events.
|
|
bool * m_pIsDeletedFlag;
|
|
|
|
friend class EventManager;
|
|
friend class EpollManager;
|
|
friend class PollManager;
|
|
|
|
private:
|
|
bool m_isManaged; ///< Whether the fd has been added to the EventManager.
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline EventManager &EventManagee::GetEventManager()
|
|
{
|
|
return m_eventManager;
|
|
}
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_BASE_EVENT_MANAGEE_H)
|