Equalizer  1.3.1-git
include/eq/client/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/client/commandQueue.h>  // member
00023 #include <eq/client/types.h>         // typedefs
00024 
00025 #include <eq/fabric/config.h>        // base class
00026 #include <co/objectHandler.h>        // base class
00027 #include <lunchbox/clock.h>           // member
00028 #include <lunchbox/monitor.h>         // member
00029 #include <lunchbox/spinLock.h>        // member
00030 
00031 namespace eq
00032 {
00055     class Config : public fabric::Config< Server, Config, Observer, Layout,
00056                                           Canvas, Node, ConfigVisitor >,
00057                    public co::ObjectHandler
00058     {
00059     public:
00060         typedef fabric::Config< Server, Config, Observer, Layout, Canvas, Node,
00061                                 ConfigVisitor > Super; 
00062 
00064         EQ_API Config( ServerPtr parent );
00065 
00067         EQ_API virtual ~Config();
00068 
00072         EQ_API ClientPtr getClient();
00073 
00075         EQ_API ConstClientPtr getClient() const;
00076 
00081         co::NodePtr getApplicationNode() { return _appNode; }
00082 
00083         EQ_API co::CommandQueue* getMainThreadQueue(); 
00084         EQ_API co::CommandQueue* getCommandThreadQueue(); 
00085 
00087         uint32_t getCurrentFrame()  const { return _currentFrame; }
00088 
00090         uint32_t getFinishedFrame() const { return _finishedFrame.get(); }
00091 
00093         EQ_API void getStatistics( std::vector< FrameStatistics >& stats );
00094 
00100         bool isRunning() const { return _running; }
00101 
00103         void stopRunning() { _running = false; }
00104 
00116         int64_t getTime() const { return _clock.getTime64(); }
00117 
00119         MessagePump* getMessagePump();
00120 
00122         const Channel* findChannel( const std::string& name ) const
00123             { return find< Channel >( name ); }
00125 
00151         EQ_API virtual bool init( const uint128_t& initID );
00152 
00169         EQ_API virtual bool exit();
00170 
00191         EQ_API bool update();
00192         
00194         EQ_API virtual void setLatency( const uint32_t latency );
00196 
00206         EQ_API virtual bool registerObject( co::Object* object );
00207 
00217         EQ_API virtual void deregisterObject( co::Object* object );
00218 
00226         EQ_API virtual bool mapObject( co::Object* object, const UUID& id, 
00227                                 const uint128_t& version = co::VERSION_OLDEST );
00228 
00229 
00231         EQ_API virtual uint32_t mapObjectNB( co::Object* object, const UUID& id,
00232                                 const uint128_t& version = co::VERSION_OLDEST );
00233 
00238         EQ_API virtual uint32_t mapObjectNB( co::Object* object, const UUID& id,
00239                                  const uint128_t& version, co::NodePtr master );
00240 
00242         EQ_API virtual bool mapObjectSync( const uint32_t requestID );
00243 
00251         EQ_API virtual void unmapObject( co::Object* object );
00252 
00254         EQ_API void releaseObject( co::Object* object );
00256 
00276         EQ_API virtual uint32_t startFrame( const uint128_t& frameID );
00277 
00293         EQ_API virtual uint32_t finishFrame();
00294 
00304         EQ_API virtual uint32_t finishAllFrames();
00305 
00318         void releaseFrameLocal( const uint32_t frameNumber )
00319             { _unlockedFrame = frameNumber; }
00320 
00330         EQ_API void stopFrames();
00331 
00333 
00342         EQ_API void sendEvent( ConfigEvent& event );
00343 
00356         EQ_API const ConfigEvent* nextEvent();
00357 
00369         EQ_API const ConfigEvent* tryNextEvent();
00370 
00372         bool checkEvent() const { return !_eventQueue.isEmpty(); }
00373 
00384         EQ_API virtual void handleEvents();
00385 
00393         EQ_API virtual bool handleEvent( const ConfigEvent* event );
00395         
00401         void setupMessagePump( Pipe* pipe );
00402 
00404         void setupServerConnections( const char* connectionData );
00405 
00406     protected:
00408         EQ_API virtual void attach( const UUID& id,
00409                                     const uint32_t instanceID );
00410 
00411         EQ_API virtual void notifyAttached(); 
00412         EQ_API virtual void notifyDetach(); 
00413 
00414         EQ_API virtual void changeLatency( const uint32_t latency );
00415         EQ_API virtual bool mapViewObjects() const; 
00416 
00417     private:
00419         co::NodePtr _appNode;
00420 
00422         CommandQueue _eventQueue;
00423         
00425         co::Command* _lastEvent;
00426 
00428         co::Connections _connections;
00429 
00431         lunchbox::Lockable< std::deque< FrameStatistics >, lunchbox::SpinLock >
00432             _statistics;
00433         
00435         uint32_t _currentFrame;
00437         uint32_t _unlockedFrame;
00439         lunchbox::Monitor< uint32_t > _finishedFrame;
00440 
00442         lunchbox::Clock _clock;
00443 
00444         std::deque< int64_t > _frameTimes; 
00445 
00447         bool _running;
00448 
00450         class LatencyObject : public co::Object
00451         {
00452         public:
00453             LatencyObject( const ChangeType type, const uint32_t compressor,
00454                            const uint32_t frame )
00455                     : frameNumber( frame ), _changeType( type ),
00456                       _compressor( compressor ) {}
00457 
00458             const uint32_t frameNumber;
00459 
00460         protected:
00461             virtual ChangeType getChangeType() const { return _changeType; }
00462             virtual void getInstanceData( co::DataOStream& os ){ LBDONTCALL }
00463             virtual void applyInstanceData( co::DataIStream& is ){ LBDONTCALL }
00464             virtual uint32_t chooseCompressor() const { return _compressor; }
00465 
00466         private:
00467             const ChangeType _changeType;
00468             const uint32_t _compressor;
00469         };
00470         
00472         typedef std::vector< LatencyObject* > LatencyObjects;
00473 
00475        lunchbox::Lockable< LatencyObjects,lunchbox::SpinLock > _latencyObjects;
00476 
00477         struct Private;
00478         Private* _private; // placeholder for binary-compatible changes
00479 
00480         friend class Node;
00481         void _frameStart();
00482         bool _needsLocalSync() const;
00483 
00488         void _updateStatistics( const uint32_t finishedFrame );
00489 
00492         void _releaseObjects();
00493 
00495         void _exitMessagePump();
00496 
00498         bool _cmdSyncClock( co::Command& command );
00499         bool _cmdCreateNode( co::Command& command );
00500         bool _cmdDestroyNode( co::Command& command );
00501         bool _cmdInitReply( co::Command& command );
00502         bool _cmdExitReply( co::Command& command );
00503         bool _cmdUpdateVersion( co::Command& command );
00504         bool _cmdUpdateReply( co::Command& command );
00505         bool _cmdReleaseFrameLocal( co::Command& command );
00506         bool _cmdFrameFinish( co::Command& command );
00507         bool _cmdSwapObject( co::Command& command );
00508     };
00509 }
00510 
00511 #endif // EQ_CONFIG_H
00512 
Generated on Tue May 1 2012 15:14:25 for Equalizer 1.3.1-git by  doxygen 1.8.0