Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

CapiSuite Class Reference

Main application class, implements ApplicationInterface. More...

#include <capisuite.h>

Inheritance diagram for CapiSuite:

ApplicationInterface List of all members.

Public Member Functions

 CapiSuite (int argc, char **argv)
 Constructor. General initializations.
 ~CapiSuite ()
 Destructor. Kill Python interpreter.
virtual void callWaiting (Connection *conn)
 Callback: enqueue Connection in waiting.
void mainLoop ()
 Main Loop. Event Loop (handling incoming connections).
void finish ()
 Request finish of mainLoop.
void parseConfigFile (ifstream &configfile)
 Parse a given configuration file.
void readConfiguration ()
 Read configuration and set default values for options not found.
void readCommandline (int argc, char **argv)
 Read commandline options.
void help ()
 Print help message.
void reload ()
 restart some aspects if the process gets a SIGHUP
void logMessage (string message, int level)
 print a message to the log
void errorMessage (string message)
 print a message to the error log

Private Member Functions

string prefix ()
 return a prefix containing this pointer and date for log messages
void checkOption (string key, string value)
 Test a configuration variable and set default if undefined.

Private Attributes

queue< Connection * > waiting
 queue for waiting connection instances
IdleScriptidle
 reference to the IdleScript object created
PyThreadState * py_state
 saves the created thread state of the main python interpreter
PycStringIO_CAPI * save_cStringIO
 holds a pointer to the Python cStringIO C API
Capicapi
 reference to Capi object to use, set in constructor
ostream * debug
 debug stream
ostream * error
 stream for error messages
unsigned short debug_level
 verbosity level for debug stream
bool finish_flag
 flag to finish mainLoop()
bool daemonmode
 flag set when we're running as daemon
map< string, string > config
 holds the configuration read from the configfile
string custom_configfile
 holds the name of the custom config file if given

Detailed Description

Main application class, implements ApplicationInterface.

This class realizes the main application and thus implements the ApplicationInterface. It firstly generates the necessary objects from the CAPI abstraction layer (one object of class Capi) and enables call listening.

It contains the mainLoop() and creates handling objects of IncomingScript for all incoming calls and one object of IdleScript which will start the idle script at regular intervals. The scripts are informed about disconnection / program termination but will delete themselves.

main() should create one CapiSuite object and then call mainLoop().

Author:
Gernot Hillier


Constructor & Destructor Documentation

CapiSuite::CapiSuite int  argc,
char **  argv
 

Constructor. General initializations.

Creates a Capi object, enables listening, calls readConfiguration, and initializes the Python interpreter in multithreading mode. It immediately releases the global Python lock after doing initialization.

Also an IdleScript object is created and will regularly call the given script.

Parameters:
argc commandline argument count as given to main()
argv commandline arguments as given to main()

CapiSuite::~CapiSuite  ) 
 

Destructor. Kill Python interpreter.

Request finishing of IdleThread and Python interpreter.


Member Function Documentation

void CapiSuite::callWaiting Connection conn  )  [virtual]
 

Callback: enqueue Connection in waiting.

Implements ApplicationInterface.

void CapiSuite::checkOption string  key,
string  value
[private]
 

Test a configuration variable and set default if undefined.

Parameters:
key name of the config variable
value default value to set if key is not defined in config map

void CapiSuite::errorMessage string  message  ) 
 

print a message to the error log

Prints message to the error log

Parameters:
message the message

void CapiSuite::finish  ) 
 

Request finish of mainLoop.

void CapiSuite::help  ) 
 

Print help message.

void CapiSuite::logMessage string  message,
int  level
 

print a message to the log

Prints message to the log if it's level is high enough.

Parameters:
message the message
level level of the message

void CapiSuite::mainLoop  ) 
 

Main Loop. Event Loop (handling incoming connections).

For each incoming connection, an object of IncomingScript is created which handles this call in an own thread.

This loop will run until the program is finished.

void CapiSuite::parseConfigFile ifstream &  configfile  ) 
 

Parse a given configuration file.

This function reads the given configuration file. It must consist of key=value pairs separated on different lines.

Lines beginning with "#" are treated as comments. Leading and trailing whitespaces and quotation marks (") surrounding the values will be ignored.

string CapiSuite::prefix  )  [private]
 

return a prefix containing this pointer and date for log messages

Returns:
constructed prefix as stringstream

void CapiSuite::readCommandline int  argc,
char **  argv
 

Read commandline options.

void CapiSuite::readConfiguration  ) 
 

Read configuration and set default values for options not found.

The configuration is read from PREFIX/etc/capisuite.conf (should exist), ~/.capisuite.conf (optional) and perhaps a given custom config file (optional), while the latter has higher priority. After that all configuration options are checked and set to default values if not found.

void CapiSuite::reload  ) 
 

restart some aspects if the process gets a SIGHUP

Currently, this only reactivates the idle script if it was deactivated by too much errors in a row.


Member Data Documentation

Capi* CapiSuite::capi [private]
 

reference to Capi object to use, set in constructor

map<string,string> CapiSuite::config [private]
 

holds the configuration read from the configfile

string CapiSuite::custom_configfile [private]
 

holds the name of the custom config file if given

bool CapiSuite::daemonmode [private]
 

flag set when we're running as daemon

ostream* CapiSuite::debug [private]
 

debug stream

unsigned short CapiSuite::debug_level [private]
 

verbosity level for debug stream

ostream * CapiSuite::error [private]
 

stream for error messages

bool CapiSuite::finish_flag [private]
 

flag to finish mainLoop()

IdleScript* CapiSuite::idle [private]
 

reference to the IdleScript object created

PyThreadState* CapiSuite::py_state [private]
 

saves the created thread state of the main python interpreter

PycStringIO_CAPI* CapiSuite::save_cStringIO [private]
 

holds a pointer to the Python cStringIO C API

queue<Connection*> CapiSuite::waiting [private]
 

queue for waiting connection instances


The documentation for this class was generated from the following files:
Generated on Sun Nov 28 14:37:44 2004 for CapiSuite by doxygen 1.3.8