ARPDAS_QNX6 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
Selector Class Reference

#include <Selector.h>

Collaboration diagram for Selector:

List of all members.

Public Member Functions

 Selector ()
 ~Selector ()
void add_child (Selectee *P)
void delete_child (int fd_in)
int update_flags (int fd_in, int flag)
void set_gflag (unsigned gflag_index)
void event_loop ()

Static Public Member Functions

static int gflag (unsigned gflag_index)

Static Public Attributes

static const int Sel_Read = 1
static const int Sel_Write = 2
static const int Sel_Except = 4
static const int Sel_Timeout = 8

Private Member Functions

virtual int ProcessTimeout ()
virtual TimeoutGetTimeout ()

Private Attributes

SelecteeMap S
bool children_changed
int gflags

Detailed Description

Definition at line 31 of file Selector.h.


Constructor & Destructor Documentation

Selector::Selector ( )

Definition at line 7 of file Selector.cc.

References children_changed, and gflags.

Selector::~Selector ( )

Actually does nothing.

Definition at line 15 of file Selector.cc.


Member Function Documentation

void Selector::add_child ( Selectee P)

Adds the Selectee as a child of the Selector. This adds the Selectee's fd to the list of fds in the Selector's select() call, depending on the Selectee's flags.

Definition at line 23 of file Selector.cc.

References children_changed, Selectee::fd, nl_error, S, and Selectee::Stor.

void Selector::delete_child ( int  fd_in)

Removes Selectee from the Selector and deletes the Selectee. Note that this is for use in a special case where the fd is being closed and the child needs to be deleted, but the caller does not know the mapping from the fd to the Selectee. In the usual case, the Selectee is deleted by its owner after the event_loop has exited, and it is unnecessary to explicitly remove the Selectees as children of the Selector.

Definition at line 41 of file Selector.cc.

References children_changed, Selectee::fd, nl_assert, nl_error, and S.

void Selector::event_loop ( )

Loops waiting on select(), using the fds and flags of each Selectee registered via add_child(). When select() indicates that an fd is ready, the corresponding Selectee's ProcessData() method is invoked with the flag value indicating what action is ready.

Definition at line 93 of file Selector.cc.

References children_changed, Selectee::fd, Selectee::flags, Selectee::GetTimeout(), GetTimeout(), gflags, nl_error, Selectee::ProcessData(), ProcessTimeout(), S, Sel_Except, Sel_Read, Sel_Timeout, Sel_Write, TimeoutAccumulator::Set_Min(), and TimeoutAccumulator::timeout_val().

Here is the call graph for this function:

Timeout * Selector::GetTimeout ( ) [private, virtual]

Virtual method to allow Selector to bid on the select() timeout along with the Selectee children. The minimum timeout value is used.

Returns:
a Timeout * indicating the requested timeout value or NULL.

Definition at line 167 of file Selector.cc.

Referenced by event_loop().

Here is the caller graph for this function:

static int Selector::gflag ( unsigned  gflag_index) [inline, static]

Method to map a global flag number to a bit mask to be set in a Selectee's flags word.

Parameters:
gflag_indexglobal flag bit number
Returns:
bit mask selecting the specified global flag.

Definition at line 49 of file Selector.h.

Referenced by set_gflag().

Here is the caller graph for this function:

int Selector::ProcessTimeout ( ) [private, virtual]

Virtual method called whenever select() returns 0. The default does nothing, but it can be overridden.

Returns:
non-zero if the event loop should terminate.

Definition at line 160 of file Selector.cc.

Referenced by event_loop().

Here is the caller graph for this function:

void Selector::set_gflag ( unsigned  gflag_index)

Sets a bit in the global flags word. Selectees can set a corresponding bit in their flags word to request notification when the bit gets set. The function Selector::gflag(gflag_index) returns the bit that corresponds to set_gflag(gflag_index). gflag_index can take on values from 0 to 8*sizeof(int)-4.

Definition at line 81 of file Selector.cc.

References gflag(), gflags, and nl_assert.

Referenced by TM_Selectee::ProcessData().

Here is the call graph for this function:

Here is the caller graph for this function:

int Selector::update_flags ( int  fd_in,
int  flag 
)

Useful when we know the fd but not the Selectee.

Returns:
0 on success, 1 if fd_in is not found.

Definition at line 60 of file Selector.cc.

References children_changed, Selectee::flags, and S.


Member Data Documentation

Definition at line 55 of file Selector.h.

Referenced by add_child(), delete_child(), event_loop(), Selector(), and update_flags().

int Selector::gflags [private]

Definition at line 56 of file Selector.h.

Referenced by event_loop(), Selector(), and set_gflag().

Definition at line 54 of file Selector.h.

Referenced by add_child(), delete_child(), event_loop(), and update_flags().

const int Selector::Sel_Except = 4 [static]

Definition at line 35 of file Selector.h.

Referenced by event_loop().

const int Selector::Sel_Read = 1 [static]

Definition at line 33 of file Selector.h.

Referenced by event_loop(), and Ser_Sel::init().

const int Selector::Sel_Timeout = 8 [static]

Definition at line 36 of file Selector.h.

Referenced by event_loop().

const int Selector::Sel_Write = 2 [static]

Definition at line 34 of file Selector.h.

Referenced by event_loop(), and TM_Selectee::init().


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines