foobar2000 SDK  2015-08-03
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
pfc::nix_event

#include <nix-objects.h>

Public Member Functions

 nix_event ()
 
 ~nix_event ()
 
int get_handle () const
 
bool is_set ()
 
void set_state (bool state)
 
bool wait_for (double p_timeout_seconds)
 

Static Public Member Functions

static int g_twoEventWait (nix_event &ev1, nix_event &ev2, double timeout)
 
static int g_twoEventWait (int h1, int h2, double timeOut)
 
static bool g_wait_for (int p_event, double p_timeout_seconds)
 

Private Member Functions

 nix_event (nix_event const &)
 
void operator= (nix_event const &)
 

Private Attributes

int m_fd [2]
 

Detailed Description

Definition at line 71 of file nix-objects.h.

Constructor & Destructor Documentation

pfc::nix_event::nix_event ( )

Definition at line 158 of file nix-objects.cpp.

158  {
159  createPipe( m_fd );
160  setNonBlocking( m_fd[0] );
161  setNonBlocking( m_fd[1] );
162  }
void setNonBlocking(int fd, bool bNonBlocking)
Definition: nix-objects.cpp:21
void createPipe(int fd[2], bool bInheritable)
Definition: nix-objects.cpp:41
pfc::nix_event::~nix_event ( )

Definition at line 163 of file nix-objects.cpp.

163  {
164  close( m_fd[0] );
165  close( m_fd[1] );
166  }
pfc::nix_event::nix_event ( nix_event const &  )
private

Member Function Documentation

int pfc::nix_event::g_twoEventWait ( nix_event ev1,
nix_event ev2,
double  timeout 
)
static

Definition at line 202 of file nix-objects.cpp.

202  {
203  return g_twoEventWait( ev1.get_handle(), ev2.get_handle(), timeout );
204  }
static int g_twoEventWait(nix_event &ev1, nix_event &ev2, double timeout)
int pfc::nix_event::g_twoEventWait ( int  h1,
int  h2,
double  timeOut 
)
static

Definition at line 190 of file nix-objects.cpp.

190  {
191  fdSelect sel;
192  sel.Reads += h1;
193  sel.Reads += h2;
194  int state = sel.Select( timeout );
195  if (state < 0) throw exception_nix();
196  if (state == 0) return 0;
197  if (sel.Reads[ h1 ] ) return 1;
198  if (sel.Reads[ h2 ] ) return 2;
199  crash(); // should not get here
200  return 0;
201  }
void crash()
Definition: other.cpp:112
bool pfc::nix_event::g_wait_for ( int  p_event,
double  p_timeout_seconds 
)
static

Definition at line 187 of file nix-objects.cpp.

187  {
188  return fdWaitRead( p_event, p_timeout_seconds );
189  }
bool fdWaitRead(int fd, double timeOutSeconds)
int pfc::nix_event::get_handle ( ) const
inline

Definition at line 84 of file nix-objects.h.

84 {return m_fd[0]; }
bool pfc::nix_event::is_set ( )
inline

Definition at line 78 of file nix-objects.h.

78 {return wait_for(0); }
bool wait_for(double p_timeout_seconds)
void pfc::nix_event::operator= ( nix_event const &  )
private
void pfc::nix_event::set_state ( bool  state)

Definition at line 168 of file nix-objects.cpp.

168  {
169  if (state) {
170  // Ensure that there is a byte in the pipe
171  if (!fdCanRead(m_fd[0] ) ) {
172  uint8_t dummy = 0;
173  write( m_fd[1], &dummy, 1);
174  }
175  } else {
176  // Keep reading until clear
177  for(;;) {
178  uint8_t dummy;
179  if (read(m_fd[0], &dummy, 1 ) != 1) break;
180  }
181  }
182  }
void read(const service_ptr_t< file > &p_file, abort_callback &p_abort, pfc::string_base &p_out, bool &is_utf8)
bool fdCanRead(int fd)
void write(const service_ptr_t< file > &p_file, abort_callback &p_abort, const char *p_string, bool is_utf8)
bool pfc::nix_event::wait_for ( double  p_timeout_seconds)

Definition at line 184 of file nix-objects.cpp.

184  {
185  return fdWaitRead( m_fd[0], p_timeout_seconds );
186  }
bool fdWaitRead(int fd, double timeOutSeconds)

Field Documentation

int pfc::nix_event::m_fd[2]
private

Definition at line 93 of file nix-objects.h.


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