Fastcgipp::Manager< T > Class Template Reference

General task and protocol management class. More...

#include <manager.hpp>

List of all members.

Classes

class  Requests
 Associative container type for active requests. More...
class  Tasks
 Queue type for pending tasks. More...

Public Member Functions

 Manager (int fd=0)
 Construct from a file descriptor.
 ~Manager ()
void handler ()
 General handling function to be called after construction.
void push (Protocol::FullId id, Message message)
 Passes messages to requests.
void stop ()
 Halter for the handler() function.
void setupSignals ()
 Configure the handlers for POSIX signals.

Private Member Functions

void localHandler (Protocol::FullId id)
 Handles management messages.
void terminate ()
 Terminator for the handler() function.

Static Private Member Functions

static void signalHandler (int signum)
 General function to handler POSIX signals.

Private Attributes

Transceiver transceiver
 Handles low level communication with the other side.
Tasks tasks
 Queue for pending tasks.
Requests requests
 Associative container type for active requests.
std::queue< Messagemessages
 A queue of messages for the manager itself.
bool asleep
 Indicated whether or not the manager is currently in sleep mode.
boost::mutex sleepMutex
 Mutex to make accessing asleep thread safe.
pthread_t threadId
 The pthread id of the thread the handler() function is operating in.
bool stopBool
 Boolean value indicating that handler() should halt.
boost::mutex stopMutex
 Mutex to make stopBool thread safe.
bool terminateBool
 Boolean value indication that handler() should terminate.
boost::mutex terminateMutex
 Mutex to make terminateMutex thread safe.

Static Private Attributes

static Manager< T > * instance = 0
 Pointer to the Manager object.


Detailed Description

template<typename T>
class Fastcgipp::Manager< T >

General task and protocol management class.

Handles all task and protocol management, creation/destruction of requests and passing of messages to requests. The template argument should be a class type derived from the Request class with at least the response() function defined. To operate this class all that needs to be done is creating an object and calling handler() on it.

Template Parameters:
T Class that will handle individual requests. Should be derived from the Request class.

Definition at line 58 of file manager.hpp.


Constructor & Destructor Documentation

template<typename T >
Fastcgipp::Manager< T >::Manager ( int  fd = 0  )  [inline]

Construct from a file descriptor.

The only piece of data required to construct a Manager object is a file descriptor to listen on for incoming connections. By default mod_fastcgi sets up file descriptor 0 to do this so it is the value passed by default to the constructor. The only time it would be another value is if an external FastCGI server was defined.

Parameters:
[in] fd File descriptor to listen on.

Definition at line 71 of file manager.hpp.

References Fastcgipp::Manager< T >::instance, and Fastcgipp::Manager< T >::setupSignals().

template<typename T >
Fastcgipp::Manager< T >::~Manager (  )  [inline]

Definition at line 73 of file manager.hpp.

References Fastcgipp::Manager< T >::instance.


Member Function Documentation

template<class T >
void Fastcgipp::Manager< T >::handler (  )  [inline]

General handling function to be called after construction.

This function will loop continuously manager tasks and FastCGI requests until either the stop() function is called (obviously from another thread) or the appropriate signals are caught.

See also:
setupSignals()

Definition at line 302 of file manager.hpp.

References Fastcgipp::Manager< T >::asleep, Fastcgipp::Transceiver::handler(), Fastcgipp::Manager< T >::localHandler(), Fastcgipp::Manager< T >::requests, Fastcgipp::Transceiver::sleep(), Fastcgipp::Manager< T >::sleepMutex, Fastcgipp::Manager< T >::stopBool, Fastcgipp::Manager< T >::stopMutex, Fastcgipp::Manager< T >::tasks, Fastcgipp::Manager< T >::terminateBool, Fastcgipp::Manager< T >::terminateMutex, Fastcgipp::Manager< T >::threadId, and Fastcgipp::Manager< T >::transceiver.

template<class T >
void Fastcgipp::Manager< T >::localHandler ( Protocol::FullId  id  )  [inline, private]

Handles management messages.

This function is called by handler() in the case that a management message is recieved. Although the request id of a management record is always 0, the Protocol::FullId associated with the message is passed to this function to keep track of it's associated file descriptor.

Parameters:
[in] id FullId associated with the messsage.

Definition at line 376 of file manager.hpp.

References Fastcgipp::Protocol::GET_VALUES, Fastcgipp::Protocol::maxConnsReply, Fastcgipp::Protocol::maxReqsReply, Fastcgipp::Manager< T >::messages, Fastcgipp::Protocol::mpxsConnsReply, Fastcgipp::Protocol::processParamHeader(), Fastcgipp::Transceiver::requestWrite(), Fastcgipp::Transceiver::secureWrite(), Fastcgipp::Manager< T >::transceiver, Fastcgipp::Protocol::UNKNOWN_TYPE, and Fastcgipp::Protocol::version.

Referenced by Fastcgipp::Manager< T >::handler().

template<class T >
void Fastcgipp::Manager< T >::push ( Protocol::FullId  id,
Message  message 
) [inline]

Passes messages to requests.

Whenever a message needs to be passed to a request, it must be done through this function. Requests are associated with their Protocol::FullId value so that and the message itself is all that is needed. Calling this function from another thread is safe. Although this function can be called from outside the fastcgi++ library, the Request class contains a callback function based on this that is more usable. An id with a Protocol::RequestId of 0 means the message is destined for the Manager itself. Should a message by passed with an id that doesn't exist, it will be discarded.

Parameters:
[in] id The id of the request the message should go to
[in] message The message itself
See also:
Request::callback

Definition at line 258 of file manager.hpp.

References Fastcgipp::Manager< T >::asleep, Fastcgipp::Protocol::BEGIN_REQUEST, Fastcgipp::Message::data, Fastcgipp::Manager< T >::messages, Fastcgipp::Manager< T >::requests, Fastcgipp::Manager< T >::sleepMutex, Fastcgipp::Manager< T >::tasks, Fastcgipp::Manager< T >::transceiver, Fastcgipp::Message::type, and Fastcgipp::Transceiver::wake().

template<class T >
void Fastcgipp::Manager< T >::setupSignals (  )  [inline]

Configure the handlers for POSIX signals.

By calling this function appropriate handlers will be set up for SIGPIPE, SIGUSR1 and SIGTERM. It is called by default upon construction of a Manager object. Should the user want to override these handlers, it should be done post-construction.

See also:
signalHandler()

Definition at line 247 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::Manager().

template<class T >
void Fastcgipp::Manager< T >::signalHandler ( int  signum  )  [inline, static, private]

General function to handler POSIX signals.

Definition at line 229 of file manager.hpp.

References Fastcgipp::Manager< T >::instance.

template<class T >
void Fastcgipp::Manager< T >::stop (  )  [inline]

Halter for the handler() function.

This function is intended to be called from a thread separate from the handler() in order to halt it. It should also be called by a signal handler in the case of of a SIGTERM. Once handler() has been halted it may be re-called to pick up exactly where it left off without any data loss.

See also:
setupSignals()

signalHandler()

Definition at line 222 of file manager.hpp.

References Fastcgipp::Manager< T >::stopBool, and Fastcgipp::Manager< T >::stopMutex.

template<class T >
void Fastcgipp::Manager< T >::terminate (  )  [inline, private]

Terminator for the handler() function.

This function is intended to be called from a signal handler in the case of of a SIGUSR1. It is similar to stop() except that handler() will wait until all requests are complete before halting.

See also:
setupSignals()

signalHandler()

Definition at line 215 of file manager.hpp.

References Fastcgipp::Manager< T >::terminateBool, and Fastcgipp::Manager< T >::terminateMutex.


Member Data Documentation

template<typename T >
bool Fastcgipp::Manager< T >::asleep [private]

Indicated whether or not the manager is currently in sleep mode.

Definition at line 169 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler(), and Fastcgipp::Manager< T >::push().

template<typename T >
Fastcgipp::Manager< T > * Fastcgipp::Manager< T >::instance = 0 [inline, static, private]

Pointer to the Manager object.

Definition at line 197 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::Manager(), Fastcgipp::Manager< T >::signalHandler(), and Fastcgipp::Manager< T >::~Manager().

template<typename T >
std::queue<Message> Fastcgipp::Manager< T >::messages [private]

A queue of messages for the manager itself.

Definition at line 155 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::localHandler(), and Fastcgipp::Manager< T >::push().

template<typename T >
Requests Fastcgipp::Manager< T >::requests [private]

Associative container type for active requests.

This container associated the Protocol::FullId of each active request with a pointer to the actual Request object.

Definition at line 152 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler(), and Fastcgipp::Manager< T >::push().

template<typename T >
boost::mutex Fastcgipp::Manager< T >::sleepMutex [private]

Mutex to make accessing asleep thread safe.

Definition at line 171 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler(), and Fastcgipp::Manager< T >::push().

template<typename T >
bool Fastcgipp::Manager< T >::stopBool [private]

Boolean value indicating that handler() should halt.

See also:
stop()

Definition at line 183 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler(), and Fastcgipp::Manager< T >::stop().

template<typename T >
boost::mutex Fastcgipp::Manager< T >::stopMutex [private]

Mutex to make stopBool thread safe.

Definition at line 185 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler(), and Fastcgipp::Manager< T >::stop().

template<typename T >
Tasks Fastcgipp::Manager< T >::tasks [private]

Queue for pending tasks.

This contains a queue of Protocol::FullId that need their handlers called.

Definition at line 139 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler(), and Fastcgipp::Manager< T >::push().

template<typename T >
bool Fastcgipp::Manager< T >::terminateBool [private]

Boolean value indication that handler() should terminate.

See also:
terminate()

Definition at line 190 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler(), and Fastcgipp::Manager< T >::terminate().

template<typename T >
boost::mutex Fastcgipp::Manager< T >::terminateMutex [private]

Mutex to make terminateMutex thread safe.

Definition at line 192 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler(), and Fastcgipp::Manager< T >::terminate().

template<typename T >
pthread_t Fastcgipp::Manager< T >::threadId [private]

The pthread id of the thread the handler() function is operating in.

Although this library is intended to be used with boost::thread and not pthread, the underlying pthread id of the handler() function is needed to call pthread_kill() when sleep is to be interrupted.

Definition at line 177 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler().

template<typename T >
Transceiver Fastcgipp::Manager< T >::transceiver [private]

Handles low level communication with the other side.

Definition at line 127 of file manager.hpp.

Referenced by Fastcgipp::Manager< T >::handler(), Fastcgipp::Manager< T >::localHandler(), and Fastcgipp::Manager< T >::push().


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

Generated on Thu Dec 11 01:47:28 2008 for fastcgi++ by  doxygen 1.5.7.1