ot::Context Class Reference
[Core Classes]
This class represents one context.
More...
#include <Context.h>
Collaboration diagram for ot::Context:

Public Member Functions | |
| Context (int init=0) | |
| virtual | ~Context () |
| void | addFactory (NodeFactory &newfactory) |
| void | removeFactory (NodeFactory &factory) |
| void | addModule (const std::string &name, Module &module) |
| Module * | getModule (const std::string &name) |
| void | removeModule (Module &module) |
| Node * | createNode (const std::string &name, StringTable &attributes) |
| Node * | getRootNode () |
| Node * | findNode (const std::string &id) |
| void | parseConfiguration (const std::string &filename) |
| void | start () |
| void | pushEvents () |
| void | pullEvents () |
| void | run () |
| void | runAtRate (double rate) |
| int | stop () |
| 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 () |
| void | newVideoFrame (const unsigned char *image, int width, int height, PIXEL_FORMAT format) |
| void | registerVideoUser (VideoUser *videoUser) |
| void | unregisterVideoUser (VideoUser *videoUser) |
Protected Attributes | |
| ModuleMap | modules |
| Node * | rootNode |
| NodeFactoryContainer | factory |
| bool | cleanUp |
| std::string | file |
| std::vector< std::string > | directories |
| std::string | rootNamespace |
| VideoUserVector | videoUsers |
Friends | |
| class | ConfigurationParser |
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 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
Definition at line 92 of file Context.h.
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.
Definition at line 77 of file Context.cxx.
References cleanUp, directories, and ot::initializeContext().
| ot::Context::~Context | ( | ) | [virtual] |
destructor method clears containers and removes any modules instantiated in the default setup, if cleanUp is st.
Definition at line 94 of file Context.cxx.
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
Definition at line 398 of file Context.cxx.
References directories.
Referenced by ot::ARToolKitPlusModule::createNode(), ot::ARToolKitPlusModule::init(), and parseConfiguration().
| void ot::Context::addDirectoryLast | ( | const std::string & | dir | ) |
add a directory to the end of the directory stack
- Parameters:
-
dir directory to add
Definition at line 408 of file Context.cxx.
References directories.
Referenced by ot::OpenTrackerResolver::resolveEntity().
| void ot::Context::addFactory | ( | NodeFactory & | newfactory | ) |
adds a new factory to the NodeFactoryContainer.
- Parameters:
-
newfactory reference to the new factory
Definition at line 111 of file Context.cxx.
References ot::NodeFactoryContainer::addFactory(), and factory.
Referenced by ot::OTQt::init(), and ot::initializeContext().
| 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
Definition at line 125 of file Context.cxx.
References ot::Module::context, and modules.
Referenced by ot::OTQt::init(), and ot::initializeContext().
| void ot::Context::close | ( | ) |
calls close on all modules to close any resources.
Definition at line 166 of file Context.cxx.
References modules, and ot::OSUtils::sleep().
Referenced by ot::OTQt::driveOT(), run(), and runAtRate().
| 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
Definition at line 288 of file Context.cxx.
References ot::NodeFactoryContainer::createNode(), factory, ot::StringTable::get(), ot::KeyIterator::hasMoreKeys(), ot::KeyIterator::nextElement(), ot::Node::parent, ot::Node::put(), rootNamespace, rootNode, and ot::Node::setParent().
Referenced by ot::Node::addPort().
| 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.
Definition at line 429 of file Context.cxx.
References directories.
Referenced by ot::FileModule::createNode(), ot::ARToolKitPlusModule::createNode(), ot::ARToolKitPlusModule::init(), and ot::OpenTrackerResolver::resolveEntity().
| 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.
Definition at line 376 of file Context.cxx.
References ot::findElementRecursive(), ot::Node::parent, rootNode, and ot::ud_node.
| 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
Definition at line 133 of file Context.cxx.
References modules.
Referenced by main(), and ot::ConfigurationParser::parseConfigurationFile().
| const std::string & ot::Context::getRootNamespace | ( | ) | [inline] |
returns the XML namespace of the root element
- Returns:
- string reference containing the XML namespace
Definition at line 247 of file Context.h.
References rootNamespace.
Referenced by ot::Node::addPort(), ot::Node::get(), ot::Node::getPort(), ot::Node::put(), and ot::Node::remove().
| 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
Definition at line 371 of file Context.cxx.
References rootNode.
Referenced by ot::XMLWriter::write().
| 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.
Definition at line 455 of file Context.cxx.
References videoUsers.
Referenced by ot::VideoSinkSubscriber::update().
| 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
Definition at line 178 of file Context.cxx.
References addDirectoryFirst(), file, ot::Node::parent, rootNamespace, rootNode, and ot::ud_node.
Referenced by ot::OTQt::init(), and main().
| void ot::Context::pullEvents | ( | ) |
calls pullSEvent on all modules to get data out again.
Definition at line 218 of file Context.cxx.
References modules.
Referenced by ot::OTQt::driveOT(), run(), and runAtRate().
| void ot::Context::pushEvents | ( | ) |
This method calls pushEvent on all moadules to get new data into the shared data tree.
Definition at line 228 of file Context.cxx.
References modules.
Referenced by ot::OTQt::driveOT(), run(), and runAtRate().
| void ot::Context::registerVideoUser | ( | VideoUser * | videoUser | ) |
Called by a module to register itself as a video user.
Definition at line 461 of file Context.cxx.
References videoUsers.
Referenced by ot::initializeContext().
| void ot::Context::removeDirectory | ( | const std::string & | dir | ) |
remove a directory from the directory stack
- Parameters:
-
dir directory to add
Definition at line 418 of file Context.cxx.
References directories.
Referenced by ot::ARToolKitPlusModule::createNode(), ot::ARToolKitPlusModule::init(), and ot::OpenTrackerResolver::resolveEntity().
| void ot::Context::removeFactory | ( | NodeFactory & | factory | ) |
removes a factory from the NodeFactoryContainer.
- Parameters:
-
factory reference to the factory to remove
Definition at line 118 of file Context.cxx.
References factory, and ot::NodeFactoryContainer::removeFactory().
| void ot::Context::removeModule | ( | Module & | module | ) |
removes a module from the map
- Parameters:
-
reference to the module
Definition at line 143 of file Context.cxx.
References modules.
| void ot::Context::run | ( | ) |
This method implements the main loop and runs until it is stopped somehow.
Then it calls close() on all modules.
Definition at line 238 of file Context.cxx.
References close(), pullEvents(), pushEvents(), start(), and stop().
Referenced by main().
| void ot::Context::runAtRate | ( | double | rate | ) |
Definition at line 255 of file Context.cxx.
References close(), ot::OSUtils::currentTime(), pullEvents(), pushEvents(), ot::OSUtils::sleep(), start(), and stop().
| void ot::Context::start | ( | ) |
calls start on all modules to do some initialization.
Definition at line 156 of file Context.cxx.
References modules.
Referenced by ot::OTQt::init(), run(), and runAtRate().
| int ot::Context::stop | ( | ) |
tests whether the mainloop should stop, by asking all modules whether they need to stop.
Definition at line 276 of file Context.cxx.
References modules.
Referenced by ot::OTQt::driveOT(), run(), and runAtRate().
| void ot::Context::unregisterVideoUser | ( | VideoUser * | videoUser | ) |
Called by a module to unregister itself as a video user.
Definition at line 471 of file Context.cxx.
References videoUsers.
Friends And Related Function Documentation
friend class ConfigurationParser [friend] |
Member Data Documentation
bool ot::Context::cleanUp [protected] |
flag to remember whether the Context is responsible for cleaning up the modules.
Definition at line 103 of file Context.h.
Referenced by Context(), and ~Context().
std::vector<std::string> ot::Context::directories [protected] |
stores a stack of directory names to search for files in
Definition at line 107 of file Context.h.
Referenced by addDirectoryFirst(), addDirectoryLast(), Context(), findFile(), and removeDirectory().
NodeFactoryContainer ot::Context::factory [protected] |
A NodeFactoryContainer used by the ConfigurationParser to create new nodes.
Definition at line 101 of file Context.h.
Referenced by addFactory(), ot::ConfigurationParser::buildTree(), createNode(), and removeFactory().
std::string ot::Context::file [protected] |
stores the filename of the current configuration.
Definition at line 105 of file Context.h.
Referenced by parseConfiguration().
ModuleMap ot::Context::modules [protected] |
A map of the modules this context works with.
Definition at line 97 of file Context.h.
Referenced by addModule(), close(), getModule(), pullEvents(), pushEvents(), removeModule(), start(), stop(), and ~Context().
std::string ot::Context::rootNamespace [protected] |
stores the namespace string of the root element
Definition at line 109 of file Context.h.
Referenced by createNode(), getRootNamespace(), and parseConfiguration().
Node* ot::Context::rootNode [protected] |
Pointer to the root node of the local tracker tree.
Definition at line 99 of file Context.h.
Referenced by createNode(), findNode(), getRootNode(), parseConfiguration(), and ~Context().
VideoUserVector ot::Context::videoUsers [protected] |
Definition at line 111 of file Context.h.
Referenced by newVideoFrame(), registerVideoUser(), and unregisterVideoUser().
The documentation for this class was generated from the following files: