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

IdleScript Class Reference

Implements calling of python script in regular intervals for user defined activity (e.g. sending faxes). More...

#include <idlescript.h>

Inheritance diagram for IdleScript:

PythonScript List of all members.

Public Member Functions

 IdleScript (ostream &debug, unsigned short debug_level, ostream &error, Capi *capi, string idlescript, int idlescript_interval, PyThreadState *py_state, PycStringIO_CAPI *cStringIO) throw (ApplicationError)
 Constructor. Create Object and start a detached thread.
virtual ~IdleScript ()
 Destructor. Destruct object.
void requestTerminate (void)
 terminate thread
void activate (void)
 reactivate the script execution in the case it was deactivated by too much errors

Private Member Functions

virtual void run (void) throw ()
 Thread body. Calls the python function idle().

Private Attributes

PyThreadState * py_state
 py_state of the main python interpreter used for run().
string idlescript
 name of the python script which is called at regular intervals
int idlescript_interval
 interval between subsequent executions of idle script
Capicapi
 reference to Capi object
bool active
 used to disable IdleScript in case of too much errors
pthread_t thread_handle
 handle for the created pthread thread

Friends

void * idlescript_exec_handler (void *)
 Thread exec handler for IdleScript class.
void idlescript_cleanup_handler (void *)
 Thread clean handler for IdleScript class.

Detailed Description

Implements calling of python script in regular intervals for user defined activity (e.g. sending faxes).

Executes a given idle script at regular intervals thus giving the user the ability to do arbitrary things. The main use is surely initiating outgoing calls, e.g. to send faxes.

It creates one new thread which will execute the idle script over and over...

If the script fails too often, it's deactivated. After fixing the script, it can be reactivated with activate().

Author:
Gernot Hillier


Constructor & Destructor Documentation

IdleScript::IdleScript ostream &  debug,
unsigned short  debug_level,
ostream &  error,
Capi capi,
string  idlescript,
int  idlescript_interval,
PyThreadState *  py_state,
PycStringIO_CAPI *  cStringIO
throw (ApplicationError)
 

Constructor. Create Object and start a detached thread.

Parameters:
debug stream for debugging info
debug_level verbosity level for debug messages
error stream for error messages
capi reference to Capi object
idlescript file name of the python script to use as incoming script
idlescript_interval interval between two subsequent calls to the idle script in seconds
py_state thread state of the main python interpreter which must be initialized an Py_SaveThread()'d before.
cStringIO pointer to the Python cStringIO C API
Exceptions:
ApplicationError Thrown if thread can't be started

IdleScript::~IdleScript  )  [virtual]
 

Destructor. Destruct object.


Member Function Documentation

void IdleScript::activate void   ) 
 

reactivate the script execution in the case it was deactivated by too much errors

void IdleScript::requestTerminate void   ) 
 

terminate thread

void IdleScript::run void   )  throw () [private, virtual]
 

Thread body. Calls the python function idle().

The read Python idle script must provide a function named idle with the following signature:

def idle(capi): # function body

The parameters given to the python function are:

  • capi: reference to the capi providing the interface to the ISDN hardware (meeded for the call_*() function class)

The script is responsible for clearing each call it initiates, even in the exception handlers!

If the call is disconnected by the other party, the Python exception CallGoneError is raised and should be caught by the script (don't forget to call disconnect() there).

If the script produces too much errors in a row, it will be deactivated. Use activate() to re-enable.

The python global lock will be acquired while the function runs.

Reimplemented from PythonScript.


Friends And Related Function Documentation

void idlescript_cleanup_handler void *   )  [friend]
 

Thread clean handler for IdleScript class.

This is a handler which is called by pthreads at cleanup. It will call this->final().

void* idlescript_exec_handler void *   )  [friend]
 

Thread exec handler for IdleScript class.

This is a handler which will call this->run() for the use in pthread_create(). It will also register idlescript_cleanup_handler


Member Data Documentation

bool IdleScript::active [private]
 

used to disable IdleScript in case of too much errors

Capi* IdleScript::capi [private]
 

reference to Capi object

string IdleScript::idlescript [private]
 

name of the python script which is called at regular intervals

int IdleScript::idlescript_interval [private]
 

interval between subsequent executions of idle script

PyThreadState* IdleScript::py_state [private]
 

py_state of the main python interpreter used for run().

pthread_t IdleScript::thread_handle [private]
 

handle for the created pthread thread


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