foobar2000 SDK  2015-08-03
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
win32_event

#include <win-objects.h>

+ Inheritance diagram for win32_event:

Public Member Functions

 win32_event ()
 
 ~win32_event ()
 
void create (bool p_manualreset, bool p_initialstate)
 
HANDLE detach ()
 
HANDLE get () const
 
HANDLE get_handle () const
 
bool is_valid () const
 
void release ()
 
void set (HANDLE p_handle)
 
void set_state (bool p_state)
 
bool wait_for (double p_timeout_seconds)
 

Static Public Member Functions

static DWORD g_calculate_wait_time (double p_seconds)
 
static int g_twoEventWait (win32_event &ev1, win32_event &ev2, double timeout)
 
static int g_twoEventWait (HANDLE ev1, HANDLE ev2, double timeout)
 
static bool g_wait_for (HANDLE p_event, double p_timeout_seconds)
 

Private Member Functions

 win32_event (const win32_event &)
 
const win32_eventoperator= (const win32_event &)
 

Private Attributes

HANDLE m_handle
 

Detailed Description

Definition at line 123 of file win-objects.h.

Constructor & Destructor Documentation

win32_event::win32_event ( )
inline

Definition at line 125 of file win-objects.h.

125 : m_handle(NULL) {}
HANDLE m_handle
Definition: win-objects.h:155
win32_event::~win32_event ( )
inline

Definition at line 126 of file win-objects.h.

126 {release();}
void release()
win32_event::win32_event ( const win32_event )
private

Member Function Documentation

void win32_event::create ( bool  p_manualreset,
bool  p_initialstate 
)

Definition at line 199 of file win-objects.cpp.

199  {
200  release();
201  SetLastError(NO_ERROR);
202  m_handle = CreateEvent(NULL,p_manualreset ? TRUE : FALSE, p_initialstate ? TRUE : FALSE,NULL);
203  if (m_handle == NULL) throw exception_win32(GetLastError());
204 }
void release()
HANDLE m_handle
Definition: win-objects.h:155
HANDLE CreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCTSTR lpName)
Definition: pp-winapi.h:8
HANDLE win32_event::detach ( )
inline

Definition at line 133 of file win-objects.h.

133 {return pfc::replace_t(m_handle,(HANDLE)NULL);}
t_type replace_t(t_type &p_var, const t_newval &p_newval)
Definition: primitives.h:682
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
HANDLE m_handle
Definition: win-objects.h:155
DWORD win32_event::g_calculate_wait_time ( double  p_seconds)
static

Definition at line 212 of file win-objects.cpp.

212  {
213  DWORD time = 0;
214  if (p_seconds> 0) {
215  time = pfc::rint32(p_seconds * 1000.0);
216  if (time == 0) time = 1;
217  } else if (p_seconds < 0) {
218  time = INFINITE;
219  }
220  return time;
221 }
t_int32 rint32(double p_val)
Definition: other.cpp:209
int win32_event::g_twoEventWait ( win32_event ev1,
win32_event ev2,
double  timeout 
)
static

Definition at line 259 of file win-objects.cpp.

259  {
260  return g_twoEventWait( ev1.get_handle(), ev2.get_handle(), timeout );
261 }
HANDLE get_handle() const
Definition: win-objects.h:132
static int g_twoEventWait(win32_event &ev1, win32_event &ev2, double timeout)
int win32_event::g_twoEventWait ( HANDLE  ev1,
HANDLE  ev2,
double  timeout 
)
static

Definition at line 245 of file win-objects.cpp.

245  {
246  HANDLE h[2] = {ev1, ev2};
247  switch(WaitForMultipleObjects(2, h, FALSE, g_calculate_wait_time( timeout ) )) {
248  default:
249  pfc::crash();
250  case WAIT_TIMEOUT:
251  return 0;
252  case WAIT_OBJECT_0:
253  return 1;
254  case WAIT_OBJECT_0 + 1:
255  return 2;
256  }
257 }
DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds)
Definition: pp-winapi.h:20
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
void crash()
Definition: other.cpp:112
static DWORD g_calculate_wait_time(double p_seconds)
bool win32_event::g_wait_for ( HANDLE  p_event,
double  p_timeout_seconds 
)
static

Returns true when signaled, false on timeout.

Definition at line 224 of file win-objects.cpp.

224  {
225  SetLastError(NO_ERROR);
226  DWORD status = WaitForSingleObject(p_event,g_calculate_wait_time(p_timeout_seconds));
227  switch(status) {
228  case WAIT_FAILED:
229  throw exception_win32(GetLastError());
230  default:
231  throw pfc::exception_bug_check();
232  case WAIT_OBJECT_0:
233  return true;
234  case WAIT_TIMEOUT:
235  return false;
236  }
237 }
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
Definition: pp-winapi.h:16
static DWORD g_calculate_wait_time(double p_seconds)
HANDLE win32_event::get ( ) const
inline

Definition at line 131 of file win-objects.h.

131 {return m_handle;}
HANDLE m_handle
Definition: win-objects.h:155
HANDLE win32_event::get_handle ( ) const
inline

Definition at line 132 of file win-objects.h.

132 {return m_handle;}
HANDLE m_handle
Definition: win-objects.h:155
bool win32_event::is_valid ( ) const
inline

Definition at line 134 of file win-objects.h.

134 {return m_handle != NULL;}
HANDLE m_handle
Definition: win-objects.h:155
const win32_event& win32_event::operator= ( const win32_event )
private
void win32_event::release ( )

Definition at line 206 of file win-objects.cpp.

206  {
207  HANDLE temp = detach();
208  if (temp != NULL) CloseHandle(temp);
209 }
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
HANDLE detach()
Definition: win-objects.h:133
void win32_event::set ( HANDLE  p_handle)
inline

Definition at line 130 of file win-objects.h.

130 {release(); m_handle = p_handle;}
void release()
HANDLE m_handle
Definition: win-objects.h:155
void win32_event::set_state ( bool  p_state)

Definition at line 239 of file win-objects.cpp.

239  {
240  PFC_ASSERT(m_handle != NULL);
241  if (p_state) SetEvent(m_handle);
242  else ResetEvent(m_handle);
243 }
HANDLE m_handle
Definition: win-objects.h:155
bool win32_event::wait_for ( double  p_timeout_seconds)
inline

Returns true when signaled, false on timeout.

Definition at line 139 of file win-objects.h.

139 {return g_wait_for(get(),p_timeout_seconds);}
static bool g_wait_for(HANDLE p_event, double p_timeout_seconds)
Returns true when signaled, false on timeout.

Field Documentation

HANDLE win32_event::m_handle
private

Definition at line 155 of file win-objects.h.


The documentation for this class was generated from the following files: