00001
00002
00003
00004
00005 #ifndef EQ_CONFIG_H
00006 #define EQ_CONFIG_H
00007
00008 #include <eq/client/server.h>
00009 #include <eq/client/commandQueue.h>
00010 #include <eq/client/configVisitor.h>
00011 #include <eq/client/matrix4.h>
00012 #include <eq/client/types.h>
00013 #include <eq/client/view.h>
00014
00015 #include <eq/net/session.h>
00016 #include <eq/base/monitor.h>
00017
00018 namespace eq
00019 {
00020 class Node;
00021 class SceneObject;
00022 struct ConfigEvent;
00023
00028 class EQ_EXPORT Config : public net::Session
00029 {
00030 public:
00034 Config( base::RefPtr< Server > parent );
00035
00037
00038 ClientPtr getClient();
00039 ServerPtr getServer();
00040 const NodeVector& getNodes() const { return _nodes; }
00041 CommandQueue* getNodeThreadQueue()
00042 { return getClient()->getNodeThreadQueue(); }
00043 uint32_t getCurrentFrame() const { return _currentFrame; }
00044 uint32_t getFinishedFrame() const { return _finishedFrame.get(); }
00045
00052 ConfigVisitor::Result accept( ConfigVisitor* visitor );
00053
00055 void getStatistics( std::vector< FrameStatistics >& statistics );
00056
00061 bool isRunning() const { return _running; }
00062
00064 void stopRunning() { _running = false; }
00065
00067 int64_t getTime() const { return _clock.getTime64(); }
00068
00070 const ViewVector& getViews() { return _views; }
00071
00072
00079 virtual bool init( const uint32_t initID )
00080 { return _startInit( initID ) && _finishInit(); }
00081
00094 virtual bool exit();
00095
00099
00107 virtual uint32_t startFrame( const uint32_t frameID );
00108
00115 virtual uint32_t finishFrame();
00116
00122 virtual uint32_t finishAllFrames();
00123
00132 void releaseFrameLocal( const uint32_t frameNumber )
00133 { _unlockedFrame = frameNumber; }
00134
00136 void waitFrameFinished( const uint32_t frameNumber ) const
00137 { _finishedFrame.waitGE( frameNumber ); }
00138
00139
00141
00147 void sendEvent( ConfigEvent& event );
00148
00156 const ConfigEvent* nextEvent();
00157
00165 const ConfigEvent* tryNextEvent();
00166
00168 bool checkEvent() const { return !_eventQueue.empty(); }
00169
00177 virtual void handleEvents();
00178
00186 virtual bool handleEvent( const ConfigEvent* event );
00187
00194 virtual void handleViewResize( const uint32_t viewID,
00195 const vmml::Vector2i& newSize );
00196
00197
00202 void setHeadMatrix( const vmml::Matrix4f& matrix );
00203
00205 const vmml::Matrix4f& getHeadMatrix() const { return _headMatrix; }
00206
00207
00209
00211 const std::string& getErrorMessage() const { return _error; }
00212
00213
00214 #ifdef EQ_TRANSMISSION_API
00215
00216
00223 void broadcastData( const void* data, uint64_t size );
00224
00225 #endif
00226
00228 void freezeLoadBalancing( const bool onOff );
00229
00235 void setWindowSystem( const WindowSystem windowSystem );
00236
00237 protected:
00238 virtual ~Config();
00239
00241 struct BaseView
00242 {
00243 View* view;
00244 View base;
00245 vmml::Vector2i size;
00246 };
00247
00249 net::IDHash< BaseView > _baseViews;
00250
00251 private:
00253 net::NodeID _appNodeID;
00254 friend class Server;
00255
00257 net::NodePtr _appNode;
00258
00259 #ifdef EQ_TRANSMISSION_API
00260
00261 std::vector<net::NodeID> _clientNodeIDs;
00262
00264 net::NodeVector _clientNodes;
00265 #endif
00266
00268 NodeVector _nodes;
00269
00271 Matrix4f _headMatrix;
00272
00274 std::string _error;
00275
00277 CommandQueue _eventQueue;
00278
00280 net::Command* _lastEvent;
00281
00283 std::deque< FrameStatistics > _statistics;
00284 base::SpinLock _statisticsMutex;
00285
00287 uint32_t _latency;
00289 uint32_t _currentFrame;
00291 uint32_t _unlockedFrame;
00293 base::Monitor< uint32_t > _finishedFrame;
00294
00296 base::Clock _clock;
00297
00299 ViewVector _views;
00300
00302 class Distributor : public net::Object
00303 {
00304 public:
00305 Distributor( Config* config ) : _config( config ) {}
00306 virtual ~Distributor() {}
00307
00308 protected:
00309 virtual void getInstanceData( net::DataOStream& os ) { EQDONTCALL; }
00310 virtual void applyInstanceData( net::DataIStream& is );
00311
00312 private:
00313 Config* _config;
00314 };
00315
00316 friend class Distributor;
00317
00319 bool _running;
00320
00321 friend class Node;
00322 void _addNode( Node* node );
00323 void _removeNode( Node* node );
00324 Node* _findNode( const uint32_t id );
00325
00331 virtual bool _startInit( const uint32_t initID );
00332
00338 virtual bool _finishInit();
00339
00344 void _updateStatistics( const uint32_t finishedFrame );
00345
00346 #ifdef EQ_TRANSMISSION_API
00347
00348 bool _connectClientNodes();
00349 #endif
00350
00352 void _initAppNode( const uint32_t distributorID );
00353
00355 void _exitAppNode();
00356
00358 net::CommandResult _cmdStartClock( net::Command& command );
00359 net::CommandResult _cmdCreateNode( net::Command& command );
00360 net::CommandResult _cmdDestroyNode( net::Command& command );
00361 net::CommandResult _cmdStartInitReply( net::Command& command );
00362 net::CommandResult _cmdFinishInitReply( net::Command& command );
00363 net::CommandResult _cmdExitReply( net::Command& command );
00364 net::CommandResult _cmdStartFrameReply( net::Command& command );
00365 net::CommandResult _cmdFrameFinish( net::Command& command );
00366 #ifdef EQ_TRANSMISSION_API
00367 net::CommandResult _cmdData( net::Command& command );
00368 #endif
00369 };
00370 }
00371
00372 #endif // EQ_CONFIG_H
00373