foobar2000 SDK  2015-01-14
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 70 of file nix-objects.h.

Constructor & Destructor Documentation

pfc::nix_event::nix_event ( )

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

126  {
127  createPipe( m_fd );
128  setNonBlocking( m_fd[0] );
129  setNonBlocking( m_fd[1] );
130  }
void setNonBlocking(int fd, bool bNonBlocking)
Definition: nix-objects.cpp:19
void createPipe(int fd[2], bool bInheritable)
Definition: nix-objects.cpp:39
pfc::nix_event::~nix_event ( )

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

131  {
132  close( m_fd[0] );
133  close( m_fd[1] );
134  }
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 170 of file nix-objects.cpp.

170  {
171  return g_twoEventWait( ev1.get_handle(), ev2.get_handle(), timeout );
172  }
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 158 of file nix-objects.cpp.

158  {
159  fdSelect sel;
160  sel.Reads += h1;
161  sel.Reads += h2;
162  int state = sel.Select( timeout );
163  if (state < 0) throw exception_nix();
164  if (state == 0) return 0;
165  if (sel.Reads[ h1 ] ) return 1;
166  if (sel.Reads[ h2 ] ) return 2;
167  crash(); // should not get here
168  return 0;
169  }
void crash()
Definition: other.cpp:105
bool pfc::nix_event::g_wait_for ( int  p_event,
double  p_timeout_seconds 
)
static

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

155  {
156  return fdWaitRead( p_event, p_timeout_seconds );
157  }
bool fdWaitRead(int fd, double timeOutSeconds)
int pfc::nix_event::get_handle ( ) const
inline

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

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

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

77 {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 136 of file nix-objects.cpp.

136  {
137  if (state) {
138  // Ensure that there is a byte in the pipe
139  if (!fdCanRead(m_fd[0] ) ) {
140  uint8_t dummy = 0;
141  write( m_fd[1], &dummy, 1);
142  }
143  } else {
144  // Keep reading until clear
145  for(;;) {
146  uint8_t dummy;
147  if (read(m_fd[0], &dummy, 1 ) != 1) break;
148  }
149  }
150  }
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 152 of file nix-objects.cpp.

152  {
153  return fdWaitRead( m_fd[0], p_timeout_seconds );
154  }
bool fdWaitRead(int fd, double timeOutSeconds)

Field Documentation

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

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


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