MetriVis | Overview | Download | User Manual | Development |
Reference | Overview | Design Documentation | Reference Backend | Reference Frontend |
#include <HTTPDriver.h>
Public Member Functions | |
HTTPDriver (int port_number=8080) | |
virtual | ~HTTPDriver () |
virtual int | Init () |
Initializes the HTTPDriver class. | |
int | StartListening () |
Starts listening for incoming connections. | |
int | StopListening () |
Stop listening for incoming connections. | |
virtual int | Uninit () |
Uninitializes the HTTPDriver class. | |
void | set_port_number (int port_number) |
Interface function for port_number. | |
int | port_number () const |
Interface function for port_number. | |
void | set_number_parallelism (int number_parallelism) |
Sets the number of requests handeled in parallel. | |
int | number_parallelism () const |
Gets the number of requests handeled in parallel. | |
Protected Member Functions | |
virtual void | Run () |
Listens for incomming connection requests. | |
void | RegisterRequestHandler (const std::string &id, RequestHandlerBase *handler) |
Registers a RequestHandler used to handle HTTP requests. | |
void | RegisterRequestHandlers () |
Contains all HTTPDriver::RegisterRequestHandler calls. | |
void | UnregisterRequestHandlers () |
Removes all registred handlers and shuts them down. | |
Private Member Functions | |
void | AssignRequestToHandler (RequestDescription &request_description) |
Assignes the HTTP request to a registered RequestHandler. | |
Private Attributes | |
int | port_number_ |
TCP port number for the http server. | |
http::Connection | connection_ |
Represents server socket/connection. | |
std::map < std::string, RequestHandlerBase * > | request_handlers_ |
int | number_parallelism_ |
Number of parallel dispatchers. | |
http::ehttp | http_parser_ |
eHTTPd object. |
Incoming connections are handled within this class. To handle and parse http requests a slightly changed version of the easyHTTPD framework is used ( http://sourceforge.net/projects/ehttpd/).
HTTPDriver gets the HTTP requests and identifies the handler by looking at the request URL parameters. The 'mode' parameter will identify which RequestHandler the HTTPDriver will choose for handling this request. RequestHandlers recieve the the HTTP request (that will be parsed to a RequestDescription object). They manage a pool of threads that will handle the requests in parallel if desired. Each request is then handeled by a RequestDispatcher.
HTTPDriver is a singleton class. Only access it over it's singleton typedef ( HTTP::Instance()) which will return a reference to the one and only HTTPDriver instance.
metrivis::HTTPDriver::HTTPDriver | ( | int | port_number = 8080 |
) |
Constructor for HTTPDriver class
metrivis::HTTPDriver::~HTTPDriver | ( | ) | [virtual] |
Deconstructor for HTTPDriver class
Grounds all variables to initial values to minimize lucky post-mortem usage. See header file for overview.
int metrivis::HTTPDriver::Init | ( | ) | [virtual] |
Initializes the HTTPDriver class.
Makes the HTTPDriver ready to handle requests. Must be called before listen() is called.
Initialization of the HTTPDriver. See header file for overview.
Reimplemented from metrivis::Thread.
int metrivis::HTTPDriver::StartListening | ( | ) |
Starts listening for incoming connections.
This function starts the driver to listen for incoming connection by binding itself to a socket. It will kick on the internal listening thread. Function returns imediately. Equivalent to the HTTPDriver::Start() function call
int metrivis::HTTPDriver::StopListening | ( | ) |
Stop listening for incoming connections.
Stops listening for incoming connections and frees the socket. Equivalent to the HTTPDriver::Stop() function call.
See header file for overview.
int metrivis::HTTPDriver::Uninit | ( | ) | [virtual] |
Uninitializes the HTTPDriver class.
After stopping the listening thread the driver may be uninitialized. This frees the socket again.
Uninitialization of the HTTPDriver. See header file for overview.
Reimplemented from metrivis::Thread.
void metrivis::HTTPDriver::set_port_number | ( | int | port_number | ) | [inline] |
Interface function for port_number.
port_number | The number of the TCP port to use. |
int metrivis::HTTPDriver::port_number | ( | ) | const [inline] |
Interface function for port_number.
void metrivis::HTTPDriver::set_number_parallelism | ( | int | number_parallelism | ) | [inline] |
Sets the number of requests handeled in parallel.
number_parallelism,: | The number of parallel requests handled. |
int metrivis::HTTPDriver::number_parallelism | ( | ) | const [inline] |
Gets the number of requests handeled in parallel.
Determines the number of HTTP requests that are handled in parallel, also sets the nuber of threads used internally.
void metrivis::HTTPDriver::Run | ( | ) | [protected, virtual] |
Listens for incomming connection requests.
Function is run by an internal thread that is triggered with the StartListening() function.
Implements metrivis::Thread.
void metrivis::HTTPDriver::RegisterRequestHandler | ( | const std::string & | id, | |
RequestHandlerBase * | handler | |||
) | [protected] |
Registers a RequestHandler used to handle HTTP requests.
id,: | String maps HTTP requests to RequestHandlers. | |
handler,: | Reference to the handler. |
See header file for overview.
void metrivis::HTTPDriver::RegisterRequestHandlers | ( | ) | [protected] |
Contains all HTTPDriver::RegisterRequestHandler calls.
If you want to register your own RequestHandler put it in this function. It will be called on initialization time automatically.
See header file for overview.
void metrivis::HTTPDriver::UnregisterRequestHandlers | ( | ) | [protected] |
Removes all registred handlers and shuts them down.
Each handler will be shut down. This may take a while until all handlers have stopped since the handlers may still perform some work.
See header file for overview.
void metrivis::HTTPDriver::AssignRequestToHandler | ( | RequestDescription & | request_description | ) | [private] |
Assignes the HTTP request to a registered RequestHandler.
request_description,: | RequestDescription object. |
http::Connection metrivis::HTTPDriver::connection_ [private] |
Represents server socket/connection.
maps id to handler