Equalizer
1.2.1
|
00001 00002 /* Copyright (c) 2005-2011, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 2010, Cedric Stalder <cedric Stalder@gmail.com> 00004 * 00005 * This library is free software; you can redistribute it and/or modify it under 00006 * the terms of the GNU Lesser General Public License version 2.1 as published 00007 * by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this library; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00017 */ 00018 00019 #ifndef EQ_CONFIG_H 00020 #define EQ_CONFIG_H 00021 00022 #include <eq/client/commandQueue.h> // member 00023 #include <eq/client/types.h> // typedefs 00024 00025 #include <eq/fabric/config.h> // base class 00026 #include <co/base/clock.h> // member 00027 #include <co/base/monitor.h> // member 00028 #include <co/base/spinLock.h> // member 00029 00030 namespace eq 00031 { 00054 class Config : public fabric::Config< Server, Config, Observer, Layout, 00055 Canvas, Node, ConfigVisitor > 00056 { 00057 public: 00058 typedef fabric::Config< Server, Config, Observer, Layout, Canvas, Node, 00059 ConfigVisitor > Super; 00060 00062 EQ_API Config( ServerPtr parent ); 00063 00065 EQ_API virtual ~Config(); 00066 00070 EQ_API ClientPtr getClient(); 00071 00073 EQ_API ConstClientPtr getClient() const; 00074 00079 co::NodePtr getApplicationNode() { return _appNode; } 00080 00081 EQ_API co::CommandQueue* getMainThreadQueue(); 00082 EQ_API co::CommandQueue* getCommandThreadQueue(); 00083 00085 uint32_t getCurrentFrame() const { return _currentFrame; } 00086 00088 uint32_t getFinishedFrame() const { return _finishedFrame.get(); } 00089 00091 EQ_API void getStatistics( std::vector< FrameStatistics >& stats ); 00092 00098 bool isRunning() const { return _running; } 00099 00101 void stopRunning() { _running = false; } 00102 00114 int64_t getTime() const { return _clock.getTime64(); } 00115 00117 MessagePump* getMessagePump(); 00118 00120 const Channel* findChannel( const std::string& name ) const 00121 { return find< Channel >( name ); } 00123 00149 EQ_API virtual bool init( const uint128_t& initID ); 00150 00167 EQ_API virtual bool exit(); 00168 00189 EQ_API bool update(); 00190 00192 EQ_API virtual void setLatency( const uint32_t latency ); 00194 00204 EQ_API virtual bool registerObject( co::Object* object ); 00205 00215 EQ_API virtual void deregisterObject( co::Object* object ); 00216 00224 EQ_API virtual bool mapObject( co::Object* object, const UUID& id, 00225 const uint128_t& version = co::VERSION_OLDEST ); 00226 00227 00229 EQ_API virtual uint32_t mapObjectNB( co::Object* object, const UUID& id, 00230 const uint128_t& version = co::VERSION_OLDEST ); 00231 00236 EQ_API virtual uint32_t mapObjectNB( co::Object* object, const UUID& id, 00237 const uint128_t& version, co::NodePtr master ); 00238 00240 EQ_API virtual bool mapObjectSync( const uint32_t requestID ); 00241 00249 EQ_API virtual void unmapObject( co::Object* object ); 00250 00252 EQ_API void releaseObject( co::Object* object ); 00254 00274 EQ_API virtual uint32_t startFrame( const uint128_t& frameID ); 00275 00291 EQ_API virtual uint32_t finishFrame(); 00292 00302 EQ_API virtual uint32_t finishAllFrames(); 00303 00316 void releaseFrameLocal( const uint32_t frameNumber ) 00317 { _unlockedFrame = frameNumber; } 00318 00328 EQ_API void stopFrames(); 00329 00331 00340 EQ_API void sendEvent( ConfigEvent& event ); 00341 00354 EQ_API const ConfigEvent* nextEvent(); 00355 00367 EQ_API const ConfigEvent* tryNextEvent(); 00368 00370 bool checkEvent() const { return !_eventQueue.isEmpty(); } 00371 00382 EQ_API virtual void handleEvents(); 00383 00391 EQ_API virtual bool handleEvent( const ConfigEvent* event ); 00393 00399 void setupMessagePump( Pipe* pipe ); 00400 00402 void setupServerConnections( const char* connectionData ); 00403 00404 protected: 00406 EQ_API virtual void attach( const co::base::UUID& id, 00407 const uint32_t instanceID ); 00408 00409 EQ_API virtual void notifyAttached(); 00410 EQ_API virtual void notifyDetach(); 00411 00412 EQ_API virtual void changeLatency( const uint32_t latency ); 00413 EQ_API virtual bool mapViewObjects() const; 00414 00415 private: 00417 co::NodePtr _appNode; 00418 00420 CommandQueue _eventQueue; 00421 00423 co::Command* _lastEvent; 00424 00426 co::Connections _connections; 00427 00429 co::base::Lockable< std::deque< FrameStatistics >, co::base::SpinLock > 00430 _statistics; 00431 00433 uint32_t _currentFrame; 00435 uint32_t _unlockedFrame; 00437 co::base::Monitor< uint32_t > _finishedFrame; 00438 00440 co::base::Clock _clock; 00441 00442 std::deque< int64_t > _frameTimes; 00443 00445 bool _running; 00446 00448 class LatencyObject : public co::Object 00449 { 00450 public: 00451 LatencyObject( const ChangeType type, const uint32_t compressor, 00452 const uint32_t frame ) 00453 : frameNumber( frame ), _changeType( type ), 00454 _compressor( compressor ) {} 00455 00456 const uint32_t frameNumber; 00457 00458 protected: 00459 virtual ChangeType getChangeType() const { return _changeType; } 00460 virtual void getInstanceData( co::DataOStream& os ){ EQDONTCALL } 00461 virtual void applyInstanceData( co::DataIStream& is ){ EQDONTCALL } 00462 virtual uint32_t chooseCompressor() const { return _compressor; } 00463 00464 private: 00465 const ChangeType _changeType; 00466 const uint32_t _compressor; 00467 }; 00468 00470 typedef std::vector< LatencyObject* > LatencyObjects; 00471 00473 co::base::Lockable< LatencyObjects,co::base::SpinLock > _latencyObjects; 00474 00475 struct Private; 00476 Private* _private; // placeholder for binary-compatible changes 00477 00478 friend class Node; 00479 void _frameStart(); 00480 bool _needsLocalSync() const; 00481 00486 void _updateStatistics( const uint32_t finishedFrame ); 00487 00490 void _releaseObjects(); 00491 00493 void _exitMessagePump(); 00494 00496 bool _cmdSyncClock( co::Command& command ); 00497 bool _cmdCreateNode( co::Command& command ); 00498 bool _cmdDestroyNode( co::Command& command ); 00499 bool _cmdInitReply( co::Command& command ); 00500 bool _cmdExitReply( co::Command& command ); 00501 bool _cmdUpdateVersion( co::Command& command ); 00502 bool _cmdUpdateReply( co::Command& command ); 00503 bool _cmdReleaseFrameLocal( co::Command& command ); 00504 bool _cmdFrameFinish( co::Command& command ); 00505 bool _cmdSwapObject( co::Command& command ); 00506 }; 00507 } 00508 00509 #endif // EQ_CONFIG_H 00510