00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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
00301 inline const std::string & Context::getRootNamespace()
00302 {
00303 return rootNamespace;
00304 }
00305
00306
00307
00308 }
00309
00310 #endif
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326