Equalizer 1.0

include/eq/config.h

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/commandQueue.h>  // member
00023 #include <eq/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 void freezeLoadBalancing( const bool onOff );
00193 
00195         EQ_API virtual void setLatency( const uint32_t latency );
00197 
00207         EQ_API virtual bool registerObject( co::Object* object );
00208 
00218         EQ_API virtual void deregisterObject( co::Object* object );
00219 
00227         EQ_API virtual bool mapObject( co::Object* object, const UUID& id, 
00228                                 const uint128_t& version = co::VERSION_OLDEST );
00229 
00230 
00232         EQ_API virtual uint32_t mapObjectNB( co::Object* object, const UUID& id,
00233                                 const uint128_t& version = co::VERSION_OLDEST );
00234 
00239         EQ_API virtual uint32_t mapObjectNB( co::Object* object, const UUID& id, 
00240                                  const uint128_t& version, co::NodePtr master );
00241 
00243         EQ_API virtual bool mapObjectSync( const uint32_t requestID );
00244 
00252         EQ_API virtual void unmapObject( co::Object* object );
00253 
00255         EQ_API void releaseObject( co::Object* object );
00257 
00277         EQ_API virtual uint32_t startFrame( const uint128_t& frameID );
00278 
00294         EQ_API virtual uint32_t finishFrame();
00295 
00305         EQ_API virtual uint32_t finishAllFrames();
00306 
00319         void releaseFrameLocal( const uint32_t frameNumber )
00320             { _unlockedFrame = frameNumber; }
00321 
00331         EQ_API void stopFrames();
00332 
00334 
00343         EQ_API void sendEvent( ConfigEvent& event );
00344 
00357         EQ_API const ConfigEvent* nextEvent();
00358 
00370         EQ_API const ConfigEvent* tryNextEvent();
00371 
00373         bool checkEvent() const { return !_eventQueue.isEmpty(); }
00374 
00385         EQ_API virtual void handleEvents();
00386 
00394         EQ_API virtual bool handleEvent( const ConfigEvent* event );
00396         
00402         void setupMessagePump( Pipe* pipe );
00403 
00405         void setupServerConnections( const char* connectionData );
00406 
00407     protected:
00409         EQ_API virtual void attach( const co::base::UUID& id,
00410                                     const uint32_t instanceID );
00411 
00412         EQ_API virtual void notifyAttached(); 
00413         EQ_API virtual void notifyDetach(); 
00414 
00415         EQ_API virtual void changeLatency( const uint32_t latency );
00416         EQ_API virtual bool mapViewObjects() const; 
00417 
00418     private:
00420         co::NodePtr _appNode;
00421 
00423         CommandQueue _eventQueue;
00424         
00426         co::Command* _lastEvent;
00427 
00429         co::Connections _connections;
00430 
00432         co::base::Lockable< std::deque< FrameStatistics >, co::base::SpinLock >
00433             _statistics;
00434         
00436         uint32_t _currentFrame;
00438         uint32_t _unlockedFrame;
00440         co::base::Monitor< uint32_t > _finishedFrame;
00441 
00443         co::base::Clock _clock;
00444 
00445         std::deque< int64_t > _frameTimes; 
00446 
00448         bool _running;
00449 
00451         class LatencyObject : public co::Object
00452         {
00453         public:
00454             LatencyObject( const ChangeType type, const uint32_t compressor,
00455                            const uint32_t frame )
00456                     : frameNumber( frame ), _changeType( type ),
00457                       _compressor( compressor ) {}
00458 
00459             const uint32_t frameNumber;
00460 
00461         protected:
00462             virtual ChangeType getChangeType() const { return _changeType; }
00463             virtual void getInstanceData( co::DataOStream& os ){ EQDONTCALL }
00464             virtual void applyInstanceData( co::DataIStream& is ){ EQDONTCALL }
00465             virtual uint32_t chooseCompressor() const { return _compressor; }
00466 
00467         private:
00468             const ChangeType _changeType;
00469             const uint32_t _compressor;
00470         };
00471         
00473         typedef std::vector< LatencyObject* > LatencyObjects;
00474 
00476        co::base::Lockable< LatencyObjects,co::base::SpinLock > _latencyObjects;
00477 
00478         struct Private;
00479         Private* _private; // placeholder for binary-compatible changes
00480 
00481         friend class Node;
00482         void _frameStart();
00483         bool _needsLocalSync() const;
00484 
00489         void _updateStatistics( const uint32_t finishedFrame );
00490 
00493         void _releaseObjects();
00494 
00496         void _exitMessagePump();
00497 
00499         bool _cmdSyncClock( co::Command& command );
00500         bool _cmdCreateNode( co::Command& command );
00501         bool _cmdDestroyNode( co::Command& command );
00502         bool _cmdInitReply( co::Command& command );
00503         bool _cmdExitReply( co::Command& command );
00504         bool _cmdUpdateVersion( co::Command& command );
00505         bool _cmdUpdateReply( co::Command& command );
00506         bool _cmdReleaseFrameLocal( co::Command& command );
00507         bool _cmdFrameFinish( co::Command& command );
00508         bool _cmdSwapObject( co::Command& command );
00509     };
00510 }
00511 
00512 #endif // EQ_CONFIG_H
00513 
Generated on Sun May 8 2011 19:11:05 for Equalizer 1.0 by  doxygen 1.7.3