Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | Friends
ost::ScriptThread Class Referenceabstract

#include <script3.h>

Inheritance diagram for ost::ScriptThread:
Inheritance graph
[legend]
Collaboration diagram for ost::ScriptThread:
Collaboration graph
[legend]

Public Types

enum  Throw { throwNothing, throwObject, throwException }
 How to raise error. More...
 
typedef enum Thread::Throw Throw
 How to raise error. More...
 
enum  Cancel {
  cancelInitial =0, cancelDeferred =1, cancelImmediate, cancelDisabled,
  cancelManual, cancelDefault =cancelDeferred
}
 How work cancellation. More...
 
typedef enum Thread::Cancel Cancel
 How work cancellation. More...
 
enum  Suspend { suspendEnable, suspendDisable }
 How work suspend. More...
 
typedef enum Thread::Suspend Suspend
 How work suspend. More...
 
enum  scrAccess {
  scrPUBLIC, scrPROTECTED, scrPRIVATE, scrFUNCTION,
  scrLOCAL
}
 
typedef enum scrAccess scrAccess
 
enum  symType {
  symNORMAL = 0, symCONST, symDYNAMIC, symFIFO,
  symSEQUENCE, symSTACK, symCOUNTER, symPOINTER,
  symREF, symARRAY, symASSOC, symINITIAL,
  symNUMBER, symLOCK, symPROPERTY, symORIGINAL,
  symMODIFIED, symTIMER, symBOOL
}
 
typedef enum symType symType
 
typedef bool(ScriptInterp::* Method )(void)
 
typedef const char
*(ScriptCommand::* 
Check )(Line *line, ScriptImage *img)
 
typedef bool(* Cond )(ScriptInterp *interp, const char *v)
 
typedef long(* Function )(long *args, unsigned prec)
 
typedef const char *(* Meta )(ScriptInterp *interp, const char *token)
 
typedef const char *(* Parse )(ScriptCompiler *img, const char *token)
 
typedef void(* Init )(void)
 
typedef struct ost::Script::_symbol Symbol
 
typedef struct ost::Script::_array Array
 

Public Member Functions

virtual timeout_t getTimeout (void)
 
size_t getStack (void)
 
 ScriptThread (ScriptInterp *interp, int pri=0, size_t stack=0)
 
 ~ScriptThread ()
 
int start (Semaphore *start=0)
 When a new thread is created, it does not begin immediate execution. More...
 
int detach (Semaphore *start=0)
 Start a new thread as "detached". More...
 
ThreadgetParent (void)
 Gets the pointer to the Thread class which created the current thread object. More...
 
void suspend (void)
 Suspends execution of the selected thread. More...
 
void resume (void)
 Resumes execution of the selected thread. More...
 
Cancel getCancel (void)
 Used to retrieve the cancellation mode in effect for the selected thread. More...
 
bool isRunning (void) const
 Verifies if the thread is still running or has already been terminated but not yet deleted. More...
 
bool isDetached (void) const
 Check if this thread is detached. More...
 
void join (void)
 Blocking call which unlocks when thread terminates. More...
 
bool isThread (void) const
 Tests to see if the current execution context is the same as the specified thread object. More...
 
cctid_t getId (void) const
 Get system thread numeric identifier. More...
 
const char * getName (void) const
 Get the name string for this thread, to use in debug messages. More...
 

Static Public Member Functions

static Threadget (void)
 
static void setStack (size_t size=0)
 Set base stack limit before manual stack sizes have effect. More...
 
static void sleep (timeout_t msec)
 A thread-safe sleep call. More...
 
static void yield (void)
 Yields the current thread's CPU time slice to allow another thread to begin immediate execution. More...
 
static Throw getException (void)
 Get exception mode of the current thread. More...
 
static void setException (Throw mode)
 Set exception mode of the current thread. More...
 
static Cancel enterCancel (void)
 This is used to help build wrapper functions in libraries around system calls that should behave as cancellation points but don't. More...
 
static void exitCancel (Cancel cancel)
 This is used to restore a cancel block. More...
 
static bool isScript (Name *scr)
 
static bool isSymbol (const char *id)
 
static bool use (const char *name)
 
static unsigned getIndex (const char *id)
 
static Symbolderef (Symbol *sym)
 
static bool commit (Symbol *sym, const char *value)
 
static bool append (Symbol *sym, const char *value)
 
static bool symindex (Symbol *sym, short offset)
 
static const char * extract (Symbol *sym)
 
static unsigned count (Symbol *sym)
 
static unsigned storage (Symbol *sym)
 
static void clear (Symbol *sym)
 
static void addFunction (const char *name, unsigned count, Function i)
 
static void addConditional (const char *name, Cond test)
 
static bool isPrivate (Name *scr)
 
static bool isFunction (Name *scr)
 

Data Fields

class __EXPORT Line
 
class __EXPORT Name
 

Static Public Attributes

static bool fastStart
 
static bool useBigmem
 
static unsigned fastStepping
 
static unsigned autoStepping
 
static size_t pagesize
 
static unsigned symsize
 
static unsigned symlimit
 
static char decimal
 
static bool use_definitions
 
static bool use_macros
 
static bool use_prefix
 
static bool use_merge
 
static bool use_funcs
 
static const char * plugins
 
static const char * altplugins
 
static const char * access_user
 
static const char * access_pass
 
static const char * access_host
 
static bool exec_funcs
 
static const char * exec_extensions
 
static const char * exec_token
 
static const char * exec_prefix
 
static const char * exit_token
 
static const char * apps_extensions
 
static const char * apps_prefix
 
static const char * etc_prefix
 
static const char * var_prefix
 
static const char * log_prefix
 

Protected Member Functions

void exit (const char *errmsg=NULL)
 
void exitEvent (const char *evt, bool inherited=true)
 
bool isExiting (void)
 
bool putSymbol (const char *id, const char *value, unsigned short size=0)
 
bool getSymbol (const char *id, char *buffer, unsigned short max)
 
bool addSymbol (const char *id, char *buffer, unsigned short max)
 
void block (void)
 
void unblock (void)
 
void lock (void)
 
void release (void)
 
void setName (const char *text)
 Set the name of the current thread. More...
 
virtual void run (void)=0
 All threads execute by deriving the Run method of Thread. More...
 
virtual void final (void)
 A thread that is self terminating, either by invoking exit() or leaving it's run(), will have this method called. More...
 
virtual void initial (void)
 The initial method is called by a newly created thread when it starts execution. More...
 
virtual void * getExtended (void)
 Since getParent() and getThread() only refer to an object of the Thread "base" type, this virtual method can be replaced in a derived class with something that returns data specific to the derived class that can still be accessed through the pointer returned by getParent() and getThread(). More...
 
virtual void notify (Thread *)
 When a thread terminates, it now sends a notification message to the parent thread which created it. More...
 
void exit (void)
 Used to properly exit from a Thread derived run() or initial() method. More...
 
void sync (void)
 Used to wait for a join or cancel, in place of explicit exit. More...
 
bool testCancel (void)
 test a cancellation point for deferred thread cancellation. More...
 
void setCancel (Cancel mode)
 Sets thread cancellation mode. More...
 
void setSuspend (Suspend mode)
 Sets the thread's ability to be suspended from execution. More...
 
void terminate (void)
 Used by another thread to terminate the current thread. More...
 
void clrParent (void)
 clear parent thread relationship. More...
 

Protected Attributes

ScriptInterpinterp
 

Static Protected Attributes

static Testtest
 
static Funifun
 

Private Attributes

volatile bool exiting
 
size_t stacksize
 

Friends

class __EXPORT ScriptInterp
 

Detailed Description

Definition at line 1623 of file script3.h.

Member Typedef Documentation

typedef struct ost::Script::_array ost::Script::Array
inherited
typedef enum Thread::Cancel Thread::Cancel
inherited

How work cancellation.

typedef const char*(ScriptCommand::* ost::Script::Check)(Line *line, ScriptImage *img)
inherited

Definition at line 106 of file script3.h.

typedef bool(* ost::Script::Cond)(ScriptInterp *interp, const char *v)
inherited

Definition at line 107 of file script3.h.

typedef long(* ost::Script::Function)(long *args, unsigned prec)
inherited

Definition at line 108 of file script3.h.

typedef void(* ost::Script::Init)(void)
inherited

Definition at line 111 of file script3.h.

typedef const char*(* ost::Script::Meta)(ScriptInterp *interp, const char *token)
inherited

Definition at line 109 of file script3.h.

typedef bool(ScriptInterp::* ost::Script::Method)(void)
inherited

Definition at line 105 of file script3.h.

typedef const char*(* ost::Script::Parse)(ScriptCompiler *img, const char *token)
inherited

Definition at line 110 of file script3.h.

typedef enum scrAccess ost::Script::scrAccess
inherited

Definition at line 121 of file script3.h.

typedef enum Thread::Suspend Thread::Suspend
inherited

How work suspend.

typedef struct ost::Script::_symbol ost::Script::Symbol
inherited
typedef enum symType ost::Script::symType
inherited

Definition at line 145 of file script3.h.

typedef enum Thread::Throw Thread::Throw
inherited

How to raise error.

Member Enumeration Documentation

enum Thread::Cancel
inherited

How work cancellation.

Enumerator
cancelInitial 

used internally, do not use

cancelDeferred 

exit thread on cancellation pointsuch as yield

cancelImmediate 

exit befor cancellation

cancelDisabled 

ignore cancellation

cancelManual 

unimplemented (working in progress)

Todo:
implement
cancelDefault 

default you should use this for compatibility instead of deferred

Definition at line 1108 of file thread.h.

enum ost::Script::scrAccess
inherited
Enumerator
scrPUBLIC 
scrPROTECTED 
scrPRIVATE 
scrFUNCTION 
scrLOCAL 

Definition at line 113 of file script3.h.

enum Thread::Suspend
inherited

How work suspend.

Enumerator
suspendEnable 

suspend enabled

suspendDisable 

suspend disabled, Suspend do nothing

Definition at line 1122 of file thread.h.

enum ost::Script::symType
inherited
Enumerator
symNORMAL 
symCONST 
symDYNAMIC 
symFIFO 
symSEQUENCE 
symSTACK 
symCOUNTER 
symPOINTER 
symREF 
symARRAY 
symASSOC 
symINITIAL 
symNUMBER 
symLOCK 
symPROPERTY 
symORIGINAL 
symMODIFIED 
symTIMER 
symBOOL 

Definition at line 123 of file script3.h.

enum Thread::Throw
inherited

How to raise error.

Enumerator
throwNothing 

continue without throwing error

throwObject 

throw object that cause error (throw this)

throwException 

throw an object relative to error

Definition at line 1099 of file thread.h.

Constructor & Destructor Documentation

ost::ScriptThread::ScriptThread ( ScriptInterp interp,
int  pri = 0,
size_t  stack = 0 
)
ost::ScriptThread::~ScriptThread ( )

Member Function Documentation

static void ost::Script::addConditional ( const char *  name,
Cond  test 
)
staticinherited
static void ost::Script::addFunction ( const char *  name,
unsigned  count,
Function  i 
)
staticinherited
bool ost::ScriptThread::addSymbol ( const char *  id,
char *  buffer,
unsigned short  max 
)
inlineprotected

Definition at line 1647 of file script3.h.

static bool ost::Script::append ( Symbol sym,
const char *  value 
)
staticinherited
void ost::ScriptThread::block ( void  )
protected
static void ost::Script::clear ( Symbol sym)
staticinherited
void Thread::clrParent ( void  )
inlineprotectedinherited

clear parent thread relationship.

Definition at line 1295 of file thread.h.

static bool ost::Script::commit ( Symbol sym,
const char *  value 
)
staticinherited
static unsigned ost::Script::count ( Symbol sym)
staticinherited
static Symbol* ost::Script::deref ( Symbol sym)
staticinherited
int Thread::detach ( Semaphore start = 0)
inherited

Start a new thread as "detached".

This is an alternative start() method that resolves some issues with later glibc implimentations which incorrectly impliment self-detach.

Returns
error code if execution fails.
Parameters
startoptional starting semaphore to alternately use.
static Cancel Thread::enterCancel ( void  )
staticinherited

This is used to help build wrapper functions in libraries around system calls that should behave as cancellation points but don't.

Returns
saved cancel type.
void Thread::exit ( void  )
protectedinherited

Used to properly exit from a Thread derived run() or initial() method.

Terminates execution of the current thread and calls the derived classes final() method.

void ost::ScriptThread::exit ( const char *  errmsg = NULL)
protected
static void Thread::exitCancel ( Cancel  cancel)
staticinherited

This is used to restore a cancel block.

Parameters
canceltype that was saved.
void ost::ScriptThread::exitEvent ( const char *  evt,
bool  inherited = true 
)
protected
static const char* ost::Script::extract ( Symbol sym)
staticinherited
virtual void Thread::final ( void  )
protectedvirtualinherited

A thread that is self terminating, either by invoking exit() or leaving it's run(), will have this method called.

It can be used to self delete the current object assuming the object was created with new on the heap rather than stack local, hence one may often see final defined as "delete this" in a derived thread class. A final method, while running, cannot be terminated or cancelled by another thread. Final is called for all cancellation type (even immediate).

You can safe delete thread ("delete this") class on final, but you should exit ASAP (or do not try to call CommonC++ methods...)

Note
A thread cannot delete its own context or join itself. To make a thread that is a self running object that self-deletes, one has to detach the thread by using detach() instead of start().
See Also
exit
run

Reimplemented in ThreadQueue.

static Thread* Thread::get ( void  )
staticinherited
Cancel Thread::getCancel ( void  )
inlineinherited

Used to retrieve the cancellation mode in effect for the selected thread.

Returns
cancellation mode constant.

Definition at line 1419 of file thread.h.

static Throw Thread::getException ( void  )
staticinherited

Get exception mode of the current thread.

Returns
exception mode.
virtual void* Thread::getExtended ( void  )
protectedvirtualinherited

Since getParent() and getThread() only refer to an object of the Thread "base" type, this virtual method can be replaced in a derived class with something that returns data specific to the derived class that can still be accessed through the pointer returned by getParent() and getThread().

Returns
pointer to derived class specific data.
cctid_t Thread::getId ( void  ) const
inherited

Get system thread numeric identifier.

Returns
numeric identifier of this thread.
static unsigned ost::Script::getIndex ( const char *  id)
staticinherited
const char* Thread::getName ( void  ) const
inlineinherited

Get the name string for this thread, to use in debug messages.

Returns
debug name.

Definition at line 1463 of file thread.h.

Thread* Thread::getParent ( void  )
inlineinherited

Gets the pointer to the Thread class which created the current thread object.

Returns
a Thread *, or "(Thread *)this" if no parent.

Definition at line 1397 of file thread.h.

size_t ost::ScriptThread::getStack ( void  )
inline

Definition at line 1661 of file script3.h.

bool ost::ScriptThread::getSymbol ( const char *  id,
char *  buffer,
unsigned short  max 
)
inlineprotected

Definition at line 1644 of file script3.h.

virtual timeout_t ost::ScriptThread::getTimeout ( void  )
virtual
virtual void Thread::initial ( void  )
protectedvirtualinherited

The initial method is called by a newly created thread when it starts execution.

This method is ran with deferred cancellation disabled by default. The Initial method is given a separate handler so that it can create temporary objects on it's own stack frame, rather than having objects created on run() that are only needed by startup and yet continue to consume stack space.

See Also
run
final

Reimplemented in TCPSession, and UnixSession.

bool Thread::isDetached ( void  ) const
inherited

Check if this thread is detached.

Returns
true if the thread is detached.
bool ost::ScriptThread::isExiting ( void  )
inlineprotected

Definition at line 1638 of file script3.h.

static bool ost::Script::isFunction ( Name scr)
staticinherited
static bool ost::Script::isPrivate ( Name scr)
staticinherited
bool Thread::isRunning ( void  ) const
inherited

Verifies if the thread is still running or has already been terminated but not yet deleted.

Returns
true if the thread is still executing.
static bool ost::Script::isScript ( Name scr)
staticinherited
static bool ost::Script::isSymbol ( const char *  id)
staticinherited
bool Thread::isThread ( void  ) const
inherited

Tests to see if the current execution context is the same as the specified thread object.

Returns
true if the current context is this object.
void Thread::join ( void  )
inherited

Blocking call which unlocks when thread terminates.

void ost::ScriptThread::lock ( void  )
protected
virtual void Thread::notify ( Thread )
protectedvirtualinherited

When a thread terminates, it now sends a notification message to the parent thread which created it.

The actual use of this notification is left to be defined in a derived class.

Parameters
-the thread that has terminated.
bool ost::ScriptThread::putSymbol ( const char *  id,
const char *  value,
unsigned short  size = 0 
)
inlineprotected

Definition at line 1641 of file script3.h.

void ost::ScriptThread::release ( void  )
protected
void Thread::resume ( void  )
inherited

Resumes execution of the selected thread.

virtual void Thread::run ( void  )
protectedpure virtualinherited

All threads execute by deriving the Run method of Thread.

This method is called after Initial to begin normal operation of the thread. If the method terminates, then the thread will also terminate after notifying it's parent and calling it's Final() method.

See Also
Initial

Implemented in SerialService, SingleThreadRTPSession< RTPDataChannel, RTCPChannel, ServiceQueue >, SocketService, ThreadQueue, and SingleRTPSessionPool.

void Thread::setCancel ( Cancel  mode)
protectedinherited

Sets thread cancellation mode.

Threads can either be set immune to termination (cancelDisabled), can be set to terminate when reaching specific "thread cancellation points" (cancelDeferred) or immediately when Terminate is requested (cancelImmediate).

Parameters
modefor cancellation of the current thread.
static void Thread::setException ( Throw  mode)
staticinherited

Set exception mode of the current thread.

Returns
exception mode.
void Thread::setName ( const char *  text)
protectedinherited

Set the name of the current thread.

If the name is passed as NULL, then the default name is set (usually object pointer).

Parameters
textname to use.
static void Thread::setStack ( size_t  size = 0)
inlinestaticinherited

Set base stack limit before manual stack sizes have effect.

Parameters
sizestack size to set, or use 0 to clear autostack.

Definition at line 1347 of file thread.h.

void Thread::setSuspend ( Suspend  mode)
protectedinherited

Sets the thread's ability to be suspended from execution.

The thread may either have suspend enabled (suspendEnable) or disabled (suspendDisable).

Parameters
modefor suspend.
static void Thread::sleep ( timeout_t  msec)
staticinherited

A thread-safe sleep call.

On most Posix systems, "sleep()" is implimented with SIGALRM making it unusable from multipe threads. Pthread libraries often define an alternate "sleep" handler such as usleep(), nanosleep(), or nap(), that is thread safe, and also offers a higher timer resolution.

Parameters
msectimeout in milliseconds.
int Thread::start ( Semaphore start = 0)
inherited

When a new thread is created, it does not begin immediate execution.

This is because the derived class virtual tables are not properly loaded at the time the C++ object is created within the constructor itself, at least in some compiler/system combinations. The thread can either be told to wait for an external semaphore, or it can be started directly after the constructor completes by calling the start() method.

Returns
error code if execution fails.
Parameters
startoptional starting semaphore to alternately use.
static unsigned ost::Script::storage ( Symbol sym)
staticinherited
void Thread::suspend ( void  )
inherited

Suspends execution of the selected thread.

Pthreads do not normally support suspendable threads, so the behavior is simulated with signals. On systems such as Linux that define threads as processes, SIGSTOP and SIGCONT may be used.

static bool ost::Script::symindex ( Symbol sym,
short  offset 
)
staticinherited
void Thread::sync ( void  )
protectedinherited

Used to wait for a join or cancel, in place of explicit exit.

void Thread::terminate ( void  )
protectedinherited

Used by another thread to terminate the current thread.

Termination actually occurs based on the current setCancel() mode. When the current thread does terminate, control is returned to the requesting thread. terminate() should always be called at the start of any destructor of a class derived from Thread to assure the remaining part of the destructor is called without the thread still executing.

bool Thread::testCancel ( void  )
protectedinherited

test a cancellation point for deferred thread cancellation.

void ost::ScriptThread::unblock ( void  )
protected
static bool ost::Script::use ( const char *  name)
staticinherited
static void Thread::yield ( void  )
staticinherited

Yields the current thread's CPU time slice to allow another thread to begin immediate execution.

Friends And Related Function Documentation

friend class __EXPORT ScriptInterp
friend

Definition at line 1630 of file script3.h.

Field Documentation

const char* ost::Script::access_host
staticinherited

Definition at line 285 of file script3.h.

const char* ost::Script::access_pass
staticinherited

Definition at line 284 of file script3.h.

const char* ost::Script::access_user
staticinherited

Definition at line 283 of file script3.h.

const char* ost::Script::altplugins
staticinherited

Definition at line 282 of file script3.h.

const char* ost::Script::apps_extensions
staticinherited

Definition at line 291 of file script3.h.

const char* ost::Script::apps_prefix
staticinherited

Definition at line 292 of file script3.h.

unsigned ost::Script::autoStepping
staticinherited

Definition at line 258 of file script3.h.

char ost::Script::decimal
staticinherited

Definition at line 275 of file script3.h.

const char* ost::Script::etc_prefix
staticinherited

Definition at line 294 of file script3.h.

const char* ost::Script::exec_extensions
staticinherited

Definition at line 287 of file script3.h.

bool ost::Script::exec_funcs
staticinherited

Definition at line 286 of file script3.h.

const char* ost::Script::exec_prefix
staticinherited

Definition at line 289 of file script3.h.

const char* ost::Script::exec_token
staticinherited

Definition at line 288 of file script3.h.

const char* ost::Script::exit_token
staticinherited

Definition at line 290 of file script3.h.

volatile bool ost::ScriptThread::exiting
private

Definition at line 1626 of file script3.h.

bool ost::Script::fastStart
staticinherited

Definition at line 255 of file script3.h.

unsigned ost::Script::fastStepping
staticinherited

Definition at line 257 of file script3.h.

Fun* ost::Script::ifun
staticprotectedinherited

Definition at line 306 of file script3.h.

ScriptInterp* ost::ScriptThread::interp
protected

Definition at line 1632 of file script3.h.

class __EXPORT ost::Script::Line
inherited

Definition at line 102 of file script3.h.

const char* ost::Script::log_prefix
staticinherited

Definition at line 296 of file script3.h.

class __EXPORT ost::Script::Name
inherited

Definition at line 103 of file script3.h.

size_t ost::Script::pagesize
staticinherited

Definition at line 259 of file script3.h.

const char* ost::Script::plugins
staticinherited

Definition at line 281 of file script3.h.

size_t ost::ScriptThread::stacksize
private

Definition at line 1627 of file script3.h.

unsigned ost::Script::symlimit
staticinherited

Definition at line 261 of file script3.h.

unsigned ost::Script::symsize
staticinherited

Definition at line 260 of file script3.h.

Test* ost::Script::test
staticprotectedinherited

Definition at line 305 of file script3.h.

bool ost::Script::use_definitions
staticinherited

Definition at line 276 of file script3.h.

bool ost::Script::use_funcs
staticinherited

Definition at line 280 of file script3.h.

bool ost::Script::use_macros
staticinherited

Definition at line 277 of file script3.h.

bool ost::Script::use_merge
staticinherited

Definition at line 279 of file script3.h.

bool ost::Script::use_prefix
staticinherited

Definition at line 278 of file script3.h.

bool ost::Script::useBigmem
staticinherited

Definition at line 256 of file script3.h.

const char* ost::Script::var_prefix
staticinherited

Definition at line 295 of file script3.h.


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