ot::Context Class Reference
[Core Classes]

#include <Context.h>

Inheritance diagram for ot::Context:

Inheritance graph
[legend]
Collaboration diagram for ot::Context:

Collaboration graph
[legend]
List of all members.

Detailed Description

This class represents one context. It keeps its own modules and tracker tree. Using a ConfigurationParser it builds the tree from a given configuration file. Any factories and modules need to be added before the parsing happens, otherwise the nodes can not be parsed and the modules will not be initialized with their respective configuration elements.

Finally it implements the main loop driving the tracker. This consists of the following basic algorithm described in pseudo code here :

     start();
     while( !stop())
     {
     pushEvents();
     pullEvents();
     }
     close(); 
The whole loop is implemented in the member function run, which can be used instead of implementing it yourself.

The Context also keeps track of various information. The following items are stored and used by modules :

The Context stores a stack of directories. Any module that needs to load a file can use the stack to find files relative to a number of directories. By default the stack contains the path component of the configuration file, followed by the current directory. See the method findFile for details.

Author:
Gerhard Reitmayr


Public Member Functions

void lock ()
 shortcut to stop the main loop by ackquiring the mutex
void unlock ()
void waitDataSignal ()
 methods for data driven traversal
void dataSignal ()
void dataBroadcast ()
 Context (int init=0)
virtual ~Context ()
void addFactory (NodeFactory &newfactory)
void removeFactory (NodeFactory &factory)
void addModule (const std::string &name, Module &module)
ModulegetModule (const std::string &name)
void removeModule (Module &module)
NodecreateNode (const std::string &name, StringTable &attributes)
NodegetRootNode ()
NodefindNode (const std::string &id)
void parseConfiguration (const std::string &filename)
void parseConfigurationString (const char *xmlstring)
void start ()
void pushEvents ()
void pullEvents ()
int loopOnce ()
void run ()
void runAtRate (double rate)
void runOnDemand ()
int stop ()
void stopLoop ()
void close ()
void addDirectoryFirst (const std::string &dir)
void addDirectoryLast (const std::string &dir)
void removeDirectory (const std::string &dir)
bool findFile (const std::string &filename, std::string &fullname)
const std::string & getRootNamespace ()
const std::string & getConfigFile ()
void newVideoFrame (const unsigned char *image, int width, int height, PIXEL_FORMAT format)
 Called by a video providing instance to pass a new video frame into OpenTracker.
void registerVideoUser (VideoUser *videoUser)
 Called by a module to register itself as a video user.
void unregisterVideoUser (VideoUser *videoUser)
 Called by a module to unregister itself as a video user.
void copyFrom (Context &other)
void addNode (std::string parentid, Node *newnode)
void removeSubtree (std::string nodeid)
void removeNode (std::string nodeid)
void replaceNode (std::string nodeid, Node *newnode)
ModulegetModuleFromNode (const Node *node)
ModulegetModuleFromNodeType (std::string nodename)
bool isConfigured ()

Protected Attributes

ModuleMap modules
 A map of the modules this context works with.
Node::Ptr rootNode
 Pointer to the root node of the local tracker tree.
NodeFactoryContainer factory
 A NodeFactoryContainer used by the ConfigurationParser to create new nodes.
bool cleanUp
 flag to remember whether the Context is responsible for cleaning up the modules.
bool stoploopflag
 flag for stopping the main loop
std::string file
 stores the filename of the current configuration.
std::vector< std::string > directories
 stores a stack of directory names to search for files in
std::string rootNamespace
 stores the namespace string of the root element
VideoUserVector videoUsers
ACE_Thread_Mutex * _mutex
 used for synchronization between the main loop and the reconfiguration scheme
ACE_Thread_Mutex * _havedatamutex
ACE_Condition_Thread_Mutex * _havedatacondition

Friends

class ConfigurationParser


Constructor & Destructor Documentation

ot::Context::Context int  init = 0  ) 
 

a constructor method.

Parameters:
init If init is not equal to 0, it instantiates all known modules and factories, adds them to its local containers and also takes care of removing them again in the destructor.

ot::Context::~Context  )  [virtual]
 

destructor method clears containers and removes any modules instantiated in the default setup, if cleanUp is st.


Member Function Documentation

void ot::Context::addDirectoryFirst const std::string &  dir  ) 
 

add a directory to the front of the directory stack

Parameters:
dir directory to add

void ot::Context::addDirectoryLast const std::string &  dir  ) 
 

add a directory to the end of the directory stack

Parameters:
dir directory to add

void ot::Context::addFactory NodeFactory newfactory  ) 
 

adds a new factory to the NodeFactoryContainer.

Parameters:
newfactory reference to the new factory

void ot::Context::addModule const std::string &  name,
Module module
 

adds a module to the contexts container.

Parameters:
name the element name of the modules configuration element
module reference to the module

void ot::Context::addNode std::string  parentid,
Node newnode
 

void ot::Context::close  ) 
 

calls close on all modules to close any resources.

void ot::Context::copyFrom Context other  ) 
 

Called by the Configurator upon reconfiguration. The other context contains the new configuration that must be copied by the running one.

Node * ot::Context::createNode const std::string &  name,
StringTable attributes
 

This method creates a new node based on a given element name and a table of attributes. It will delegate the construction to the stored NodeFactory list and return a new Node, if one of the factories can create the desired type. Otherwise it returns NULL. It makes sure that the node is associated with this context, therefore this is the only way to create new nodes for the user.

Parameters:
name the name of the element
attributes a StringTable containing the attributes of the element
Returns:
pointer to the new node or NULL

void ot::Context::dataBroadcast  ) 
 

void ot::Context::dataSignal  ) 
 

bool ot::Context::findFile const std::string &  filename,
std::string &  fullname
 

tries to locate a file by prepending the directory names in the stack. If a file at that location is found, the full name is returned in fullname and true will be returned. Otherwise fullname is not changed and false is returned.

Parameters:
filename the partial filename of the file to look for
fullname will contain the full filename upon successful return
Returns:
returns true, if a file could be found, false otherwise.

Node * ot::Context::findNode const std::string &  id  ) 
 

returns the node with the given unique ID tag. If none is found NULL is returned.

Parameters:
id string containing the value of the ID tag
Returns:
pointer to the found node, or NULL.

const std::string & ot::Context::getConfigFile  ) 
 

Module * ot::Context::getModule const std::string &  name  ) 
 

returns the module associated with a certain configuration element

Parameters:
name the element name
Returns:
pointer to the module or NULL, if name does not exist

Module * ot::Context::getModuleFromNode const Node node  ) 
 

Obtain the Module responsible for a certain node, Notice that this may return NULL for nodes like EventUtilityNode, which are part of opentracker

Module * ot::Context::getModuleFromNodeType std::string  nodename  ) 
 

Obtain the Module responsible for a node of type nodename. It might return NULL for nodes like EventUtilityNode which are part of opentracker (but have no Module)

const std::string & ot::Context::getRootNamespace  )  [inline]
 

returns the XML namespace of the root element

Returns:
string reference containing the XML namespace

Node * ot::Context::getRootNode  ) 
 

returns the root node, that contains the tracker tree. This node is an instance of the generic node class and only deal with the children API. It does also contain the configuration element in the first node.

Returns:
pointer to the root node

bool ot::Context::isConfigured  ) 
 

void ot::Context::lock  )  [inline]
 

shortcut to stop the main loop by ackquiring the mutex

int ot::Context::loopOnce  ) 
 

do one atomic cycle of the OpenTracker loop, returns the value of of stop(), to indicate whether the main loop needs to be stopped. Introduced for reconfiguration purposes, it is not safe to call pushEvent(), pullEvent(), and stop() separatelly, since the configuration may change between calls. For safety use loopOnce() and test the return.

void ot::Context::newVideoFrame const unsigned char *  image,
int  width,
int  height,
PIXEL_FORMAT  format
 

Called by a video providing instance to pass a new video frame into OpenTracker.

void ot::Context::parseConfiguration const std::string &  filename  ) 
 

This method initialies the context with a tracker tree described by a configuration file. It parses the file and builds the tree.

Parameters:
filename the path and name of the configuration file

void ot::Context::parseConfigurationString const char *  xmlstring  ) 
 

void ot::Context::pullEvents  ) 
 

calls pullSEvent on all modules to get data out again.

void ot::Context::pushEvents  ) 
 

This method calls pushEvent on all moadules to get new data into the shared data tree.

void ot::Context::registerVideoUser VideoUser videoUser  ) 
 

Called by a module to register itself as a video user.

void ot::Context::removeDirectory const std::string &  dir  ) 
 

remove a directory from the directory stack

Parameters:
dir directory to add

void ot::Context::removeFactory NodeFactory factory  ) 
 

removes a factory from the NodeFactoryContainer.

Parameters:
factory reference to the factory to remove

void ot::Context::removeModule Module module  ) 
 

removes a module from the map

Parameters:
reference to the module

void ot::Context::removeNode std::string  nodeid  ) 
 

void ot::Context::removeSubtree std::string  nodeid  ) 
 

void ot::Context::replaceNode std::string  nodeid,
Node newnode
 

void ot::Context::run  ) 
 

This method implements the main loop and runs until it is stopped somehow. Then it calls close() on all modules.

Reimplemented in ot::LiveContext, and ot::ThreadContext.

void ot::Context::runAtRate double  rate  ) 
 

This method implements the main loop in a way that it is run at a specificed rate until it is stopped somehow. Then it calls close() on all modules.

Reimplemented in ot::ThreadContext.

void ot::Context::runOnDemand  ) 
 

This is a data-driven implementation of the main loop

Reimplemented in ot::ThreadContext.

void ot::Context::start  ) 
 

calls start on all modules to do some initialization.

int ot::Context::stop  ) 
 

tests whether the mainloop should stop, by asking all modules whether they need to stop.

void ot::Context::stopLoop  ) 
 

sets a termination flag for the main loop

void ot::Context::unlock  )  [inline]
 

void ot::Context::unregisterVideoUser VideoUser videoUser  ) 
 

Called by a module to unregister itself as a video user.

void ot::Context::waitDataSignal  ) 
 

methods for data driven traversal


Friends And Related Function Documentation

friend class ConfigurationParser [friend]
 

Reimplemented in ot::ThreadContext.


Member Data Documentation

ACE_Condition_Thread_Mutex* ot::Context::_havedatacondition [protected]
 

ACE_Thread_Mutex* ot::Context::_havedatamutex [protected]
 

used for synchronization in data-driven traversal in this case the graph is only traversed if some event-driven enabled event generator node produces new data

ACE_Thread_Mutex* ot::Context::_mutex [protected]
 

used for synchronization between the main loop and the reconfiguration scheme

bool ot::Context::cleanUp [protected]
 

flag to remember whether the Context is responsible for cleaning up the modules.

std::vector<std::string> ot::Context::directories [protected]
 

stores a stack of directory names to search for files in

NodeFactoryContainer ot::Context::factory [protected]
 

A NodeFactoryContainer used by the ConfigurationParser to create new nodes.

std::string ot::Context::file [protected]
 

stores the filename of the current configuration.

ModuleMap ot::Context::modules [protected]
 

A map of the modules this context works with.

std::string ot::Context::rootNamespace [protected]
 

stores the namespace string of the root element

Node::Ptr ot::Context::rootNode [protected]
 

Pointer to the root node of the local tracker tree.

bool ot::Context::stoploopflag [protected]
 

flag for stopping the main loop

VideoUserVector ot::Context::videoUsers [protected]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 28 15:28:59 2007 for NaviTrack by  doxygen 1.4.6