plumbing::reactor Class Reference

#include <reactor.h>

Public Member Functions

virtual ~reactor ()
 reactor ()
void process (bool block=false)
void run ()
void for_each_endpoint (endpoint_functor &func)
void add_endpoint (const endpoint::pointer &ep)
void register_at_job (const time_value &when, at_job *jp)
void register_at_job_delta (const time_value &when, at_job *jp)
void unregister_at_job (at_job *jp)
bool still_have_work_to_do () const

Private Types

typedef std::list
< endpoint::pointer

Private Member Functions

void fatal_error (const char *fmt,...) FORMAT_PRINTF(2
void void fatal_error_v (const char *fmt, va_list ap) FORMAT_PRINTF(2
void void void kill_suicidal_endpoints ()
 reactor (const reactor &)
reactoroperator= (const reactor &)

Private Attributes

endpoints_t endpoints
at_service at

Detailed Description

The plumbing::reactor class is used to represent an endpoint manager which dispatches to the appropriate endpoint when some file descriptor activity has been detected for them.

The endpoints are completely abstract. They could be a socket listening for new connections, they could be server processes handling client requests, they could be clients handling asynchronous events, or they could be character devices like serial ports.

In particular, if you want your server to listen for connections on a particular port, derive a new class from plumbing::endpoint_listener and define the get_default_port and endpoint_factory methods. The add this listener to the reactor via the add_endpoint method. Fram that point, new connection handling is automatic.

Definition at line 49 of file reactor.h.

Member Typedef Documentation

typedef std::list<endpoint::pointer> plumbing::reactor::endpoints_t [private]

Definition at line 163 of file reactor.h.

Constructor & Destructor Documentation

plumbing::reactor::~reactor (  )  [virtual]

The destructor.

Definition at line 30 of file

plumbing::reactor::reactor (  ) 

The default constructor.

Definition at line 52 of file

plumbing::reactor::reactor ( const reactor  )  [private]

The copy constructor. Do not use.

Member Function Documentation

void plumbing::reactor::add_endpoint ( const endpoint::pointer ep  ) 

The add_endpoint method is used to add another endpoint to those being managed by this reactor. When an endpoint wants to be destroyed, it shall call its kill_Pme_now method, and the reactor will destroy the pointer (and indirectly the object) at the top of its event loop.

ep The endpoint to be managed by this reactor. It shall be dynamically allocated via operator new, via a class create method. It is recommended that this should be the only pointer to the object once it has been created, otherwise its destructor may not be called for some time, potentially leaking resources such as memory and file descriptors.

Definition at line 249 of file

void plumbing::reactor::fatal_error ( const char *  fmt,
) [private]

The fatal_error method is used to report fatal errors.

fmt The format string describing the rest of the arguments. See printf(3) for more information.

Definition at line 36 of file

void plumbing::reactor::fatal_error_v ( const char *  fmt,
va_list  ap 
) [private]

The fatal_error_v method is used to report fatal errors, but it gets its arguments form the given location

fmt The format string describing the rest of the arguments. See vprintf(3) for more information.
ap pointer to the arguments

Definition at line 46 of file

void plumbing::reactor::for_each_endpoint ( endpoint_functor func  ) 

The for_each_endpoint method is used to apply the given functor to each of the connected clients (as presesented by each endpoint object; they could be servers, or clients, or devices, etc).

func The operatoin to be performed.

Definition at line 256 of file

void plumbing::reactor::kill_suicidal_endpoints (  )  [private]

The kill_suicidal_endpoints method is called by the process method to clean up endpoints that are finished.

Definition at line 67 of file

reactor& plumbing::reactor::operator= ( const reactor  )  [private]

The assignment operator. Do not use.

void plumbing::reactor::process ( bool  block = false  ) 

The process method is used to see if any of the if there are any incoming connections, or if any of the current endpoints have input to process.

block whether or not we should block
This method will only block if a child endpoint blocks.

Definition at line 86 of file

void plumbing::reactor::register_at_job ( const time_value when,
at_job jp 
) [inline]

The register_at_job method is used to add a jobs to the queue of jobs waiting to run.

when The time the job is to be called.
jp The job to be queued.

Definition at line 123 of file reactor.h.

void plumbing::reactor::register_at_job_delta ( const time_value when,
at_job jp 
) [inline]

The The register_at_job_delta method is used to add a jobs to the queue of jobs waiting to run.

when How many seconds into the future the job is to be called.
jp The job to be queued.

Definition at line 138 of file reactor.h.

void plumbing::reactor::run (  )  [inline]

The run method is used to process all file descriptor activity. This method blocks until all connections are closed.

Definition at line 79 of file reactor.h.

bool plumbing::reactor::still_have_work_to_do (  )  const [inline]

The still_have_work_to_do method is used to determine whether or not there are any endpoints left to process.

Definition at line 160 of file reactor.h.

void plumbing::reactor::unregister_at_job ( at_job jp  )  [inline]

The unregister_at_job method is used to remove a job from the queue of jobs waiting to run.

jp The job to be de-queued.

Definition at line 151 of file reactor.h.

Field Documentation

The at instance variable is used to remember and manage all of the time-delayed jobs which need to be executed.

Definition at line 175 of file reactor.h.

The endpoints instance variable is used to remember the currently instantiated endpoints of this reactor.

Definition at line 169 of file reactor.h.

The documentation for this class was generated from the following files:
Generated on Thu Sep 16 14:51:27 2010 for Plumbing by  doxygen 1.6.3