Context.h

Go to the documentation of this file.
00001 /* ========================================================================
00002  * Copyright (c) 2006,
00003  * Institute for Computer Graphics and Vision
00004  * Graz University of Technology
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  *
00011  * Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the following disclaimer.
00013  *
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the distribution.
00017  *
00018  * Neither the name of the Graz University of Technology nor the names of
00019  * its contributors may be used to endorse or promote products derived from
00020  * this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00023  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00024  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00026  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  * ========================================================================
00034  * PROJECT: OpenTracker
00035  * ======================================================================== */
00042 /* ======================================================================= */
00043 
00044 #ifndef _CONTEXT_H
00045 #define _CONTEXT_H
00046 
00047 #include "../dllinclude.h"
00048 
00049 #include "Node.h"
00050 #include "Module.h"
00051 #include "NodeFactoryContainer.h"
00052 #include "VideoUser.h"
00053 
00054 class ACE_Thread_Mutex;
00055 class ACE_Condition_Thread_Mutex;
00056 
00057 
00058 
00059 namespace ot {
00060 
00062     typedef std::map<std::string, Module *> ModuleMap;
00063 
00096     class OPENTRACKER_API Context
00097     {
00098 
00099     protected:
00101         ModuleMap modules;
00103         Node::Ptr rootNode;
00105         NodeFactoryContainer factory;
00107         bool cleanUp;
00109         bool stoploopflag;
00111         std::string file;
00113         std::vector<std::string> directories;
00115         std::string rootNamespace;
00116 
00117         VideoUserVector videoUsers;
00118 
00120         ACE_Thread_Mutex* _mutex;
00124         ACE_Thread_Mutex* _havedatamutex;
00125         ACE_Condition_Thread_Mutex* _havedatacondition;
00126     public:
00128         void lock();
00129         void unlock();
00131         void waitDataSignal();
00132         void dataSignal();
00133         void dataBroadcast();
00134         // Methods
00135     public:
00136 
00141         Context( int init = 0 );
00144         virtual ~Context();
00145 
00148         void addFactory(NodeFactory& newfactory);
00151         void removeFactory(NodeFactory & factory);
00152 
00156         void addModule(const std::string & name, Module & module);
00157 
00161         Module * getModule(const std::string & name);
00162 
00165         void removeModule(Module & module);
00166 
00177         Node * createNode(const std::string & name, StringTable & attributes);
00178 
00183         Node * getRootNode();
00184 
00190         Node * findNode(const std::string & id);
00191 
00195         void parseConfiguration(const std::string& filename);
00196         void parseConfigurationString(const char* xmlstring);
00197 
00199         void start();
00200 
00203         void pushEvents();
00204 
00206         void pullEvents();
00207 
00213                 int loopOnce();
00214 
00217         void run();
00218 
00222         void runAtRate(double rate);
00223 
00225         void runOnDemand();
00226 
00229         int stop();
00230 
00232         void stopLoop();
00233 
00235         void close();
00236 
00240         void addDirectoryFirst( const std::string & dir );
00241 
00245         void addDirectoryLast( const std::string & dir );
00246 
00250         void removeDirectory( const std::string & dir );
00251 
00260         bool findFile( const std::string & filename, std::string & fullname );
00261 
00266         const std::string & getRootNamespace();
00267 
00268                 const std::string& getConfigFile();
00270         void newVideoFrame(const unsigned char* image, int width, int height, PIXEL_FORMAT format);
00271 
00272 
00274         void registerVideoUser(VideoUser* videoUser);
00275 
00276 
00278         void unregisterVideoUser(VideoUser* videoUser);
00279 
00282         void copyFrom( Context & other);
00283         void addNode(std::string parentid, Node * newnode);
00284         void removeSubtree(std::string nodeid);
00285         void removeNode(std::string nodeid);
00286         void replaceNode(std::string nodeid, Node * newnode);
00287 
00290         Module * getModuleFromNode(const Node * node);
00293         Module * getModuleFromNodeType(std::string nodename);
00294         
00295         bool isConfigured();
00296 
00297     friend class ConfigurationParser;
00298     };
00299 
00300     // returns the namespace of the root node
00301     inline const std::string & Context::getRootNamespace()
00302     {
00303         return rootNamespace;
00304     }
00305 
00306 
00307 
00308 } // namespace ot
00309 
00310 #endif
00311 
00312 /*
00313  * ------------------------------------------------------------
00314  *   End of Context.cxx
00315  * ------------------------------------------------------------
00316  *   Automatic Emacs configuration follows.
00317  *   Local Variables:
00318  *   mode:c++
00319  *   c-basic-offset: 4
00320  *   eval: (c-set-offset 'substatement-open 0)
00321  *   eval: (c-set-offset 'case-label '+)
00322  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00323  *   eval: (setq indent-tabs-mode nil)
00324  *   End:
00325  * ------------------------------------------------------------
00326  */

Generated on Wed Feb 28 15:18:48 2007 for NaviTrack by  doxygen 1.4.6