#include <capisuite.h>
Inheritance diagram for CapiSuite:
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 | |
IdleScript * | idle |
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 | |
Capi * | capi |
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 |
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().
|
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.
|
|
Destructor. Kill Python interpreter. Request finishing of IdleThread and Python interpreter. |
|
Callback: enqueue Connection in waiting.
Implements ApplicationInterface.
|
|
Test a configuration variable and set default if undefined.
|
|
print a message to the error log Prints message to the error log
|
|
Request finish of mainLoop.
|
|
Print help message.
|
|
print a message to the log Prints message to the log if it's level is high enough.
|
|
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. |
|
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. |
|
return a prefix containing this pointer and date for log messages
|
|
Read commandline options.
|
|
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. |
|
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. |
|
reference to Capi object to use, set in constructor
|
|
holds the configuration read from the configfile
|
|
holds the name of the custom config file if given
|
|
flag set when we're running as daemon
|
|
debug stream
|
|
verbosity level for debug stream
|
|
stream for error messages
|
|
flag to finish mainLoop()
|
|
reference to the IdleScript object created
|
|
saves the created thread state of the main python interpreter
|
|
holds a pointer to the Python cStringIO C API
|
|
queue for waiting connection instances
|