lib/client/pipe.h

00001 
00002 /* Copyright (c) 2005-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef EQ_PIPE_H
00019 #define EQ_PIPE_H
00020 
00021 #ifdef EQUALIZER_EXPORTS
00022    // We need to instantiate a Monitor< State > when compiling the library,
00023    // but we don't want to have <pthread.h> for a normal build, hence this hack
00024 #  include <pthread.h>
00025 #endif
00026 #include <eq/base/monitor.h>
00027 
00028 #include <eq/client/eye.h>            // Eye enum
00029 #include <eq/client/pixelViewport.h>  // member
00030 #include <eq/client/types.h>
00031 #include <eq/client/visitorResult.h>  // enum
00032 #include <eq/client/windowSystem.h>   // WGLEWContext
00033 
00034 #include <eq/net/object.h>
00035 #include <eq/net/objectVersion.h>
00036 
00037 #include <eq/base/refPtr.h>
00038 #include <eq/base/lock.h>
00039 #include <eq/base/thread.h>
00040 
00041 namespace eq
00042 {
00043     class CommandQueue;
00044     class OSPipe;
00045     class PipeVisitor;
00046 
00055     class Pipe : public net::Object
00056     {
00057     public:
00059         EQ_EXPORT Pipe( Node* parent );
00060 
00062         EQ_EXPORT virtual ~Pipe();
00063 
00066         EQ_EXPORT net::CommandQueue* getPipeThreadQueue();
00067         Node*       getNode()       { return _node; }
00068         const Node* getNode() const { return _node; }
00069 
00070         EQ_EXPORT Config* getConfig();
00071         EQ_EXPORT const Config* getConfig() const;
00072 
00073         EQ_EXPORT ClientPtr getClient();
00074         EQ_EXPORT ServerPtr getServer();
00075 
00076         const WindowVector& getWindows() const { return _windows; }
00077 
00078         const std::string& getName() const { return _name; }
00079 
00090         uint32_t getTasks() const { return _tasks; }
00091 
00092         bool isThreaded() const { return ( _thread != 0 ); }
00093         uint32_t getCurrentFrame()  const { return _currentFrame; }
00094         EQ_EXPORT uint32_t getFinishedFrame() const;
00095 
00102         EQ_EXPORT VisitorResult accept( PipeVisitor& visitor );
00103 
00111          void setPixelViewport( const eq::PixelViewport& pvp ){ _pvp = pvp; }
00112 
00116         const PixelViewport& getPixelViewport() const { return _pvp; }
00117 
00127         uint32_t getPort() const { return _port; }
00128 
00140         uint32_t getDevice() const { return _device; }
00141 
00151         WindowSystem getWindowSystem() const { return _windowSystem; }
00152 
00154         EQ_EXPORT int64_t getFrameTime() const;
00155 
00157         EQ_EXPORT WGLEWContext* wglewGetContext();
00159 
00172         Frame* getFrame( const net::ObjectVersion& frameVersion, 
00173                          const Eye eye );
00174 
00176         void flushFrames();
00177 
00179         bool isCurrent( const Window* window ) const;
00180 
00182         void setCurrent( const Window* window ) const;
00183 
00185         View* getView( const net::ObjectVersion& viewVersion );
00187 
00189         EQ_EXPORT void waitExited() const;
00190         EQ_EXPORT bool isRunning() const;
00191         
00198         EQ_EXPORT void waitFrameFinished( const uint32_t frameNumber ) const;
00199 
00206         EQ_EXPORT void waitFrameLocal( const uint32_t frameNumber ) const;
00207 
00209         void startThread();
00210 
00212         void joinThread();
00213 
00225         void setOSPipe( OSPipe* pipe )  { _osPipe = pipe; }
00226 
00227         const OSPipe* getOSPipe() const { return _osPipe; }
00228               OSPipe* getOSPipe()       { return _osPipe; }
00229 
00231 
00242         void setErrorMessage( const std::string& message ) { _error = message; }
00244 
00245     protected:
00246         friend class Node;
00247 
00255         EQ_EXPORT void startFrame( const uint32_t frameNumber );
00256 
00262         EQ_EXPORT void releaseFrame( const uint32_t frameNumber );
00263 
00275         EQ_EXPORT void releaseFrameLocal( const uint32_t frameNumber );
00277 
00293         EQ_EXPORT virtual bool supportsWindowSystem( const WindowSystem system )
00294                                    const;
00295 
00304         EQ_EXPORT virtual WindowSystem selectWindowSystem() const;
00305 
00311         EQ_EXPORT virtual bool configInit( const uint32_t initID );
00312 
00316         EQ_EXPORT virtual bool configExit();
00317 
00334         EQ_EXPORT virtual void frameStart( const uint32_t frameID, 
00335                                            const uint32_t frameNumber );
00336 
00350         EQ_EXPORT virtual void frameFinish( const uint32_t frameID, 
00351                                             const uint32_t frameNumber );
00352 
00362         EQ_EXPORT virtual void frameDrawFinish( const uint32_t frameID, 
00363                                                 const uint32_t frameNumber );
00364 
00375         virtual bool useMessagePump() { return true; }
00377 
00379         EQ_EXPORT virtual void attachToSession( const uint32_t id, 
00380                                                 const uint32_t instanceID, 
00381                                                 net::Session* session );
00382 
00383     private:
00384         //-------------------- Members --------------------
00386         std::string _error;
00387 
00389         OSPipe *_osPipe;
00390 
00392         Node* const    _node;
00393 
00395         std::string    _name;
00396 
00398         WindowVector   _windows;
00399 
00401         WindowSystem _windowSystem;
00402 
00404         PixelViewport _pvp;
00405 
00407         uint32_t _tasks;
00408 
00410         uint32_t _port;
00411 
00413         uint32_t _device;
00414 
00415         enum State
00416         {
00417             STATE_STOPPED,
00418             STATE_INITIALIZING,
00419             STATE_RUNNING
00420         };
00422         base::Monitor< State > _state;
00423 
00425         uint32_t _currentFrame;
00426 
00428         base::Monitor< uint32_t > _finishedFrame;
00429 
00431         base::Monitor<uint32_t> _unlockedFrame;
00432 
00434         std::deque< int64_t > _frameTimes;
00435         base::Lock            _frameTimeMutex;
00436 
00438         int64_t _frameTime;
00439 
00441         int64_t _waitTime;
00442 
00443         typedef stde::hash_map< uint32_t, Frame* > FrameHash;
00445         FrameHash _frames;
00446 
00447         typedef stde::hash_map< uint32_t, View* > ViewHash;
00449         ViewHash _views;
00450 
00452         class PipeThread : public base::Thread
00453         {
00454         public:
00455             PipeThread( Pipe* pipe ) 
00456                     : _pipe( pipe )
00457                 {}
00458             
00459             virtual void* run(){ return _pipe->_runThread(); }
00460 
00461         private:
00462             Pipe* _pipe;
00463         };
00464         PipeThread* _thread;
00465 
00467         eq::CommandQueue*   _pipeThreadQueue;
00468 
00470         const mutable Window* _currentWindow;
00471 
00472         union // placeholder for binary-compatible changes
00473         {
00474             char dummy[64];
00475         };
00476 
00477         //-------------------- Methods --------------------
00478         void* _runThread();
00479         void _setupCommandQueue();
00480 
00481         friend class Window;
00482         void _addWindow( Window* window );
00483         void _removeWindow( Window* window );
00484         Window* _findWindow( const uint32_t id );
00485 
00486         virtual void getInstanceData( net::DataOStream& os ) { EQDONTCALL }
00487         virtual void applyInstanceData( net::DataIStream& is ) { EQDONTCALL }
00488 
00490         void _releaseViews();
00491 
00493         void _flushViews();
00494 
00495         /* The command functions. */
00496         net::CommandResult _cmdCreateWindow( net::Command& command );
00497         net::CommandResult _cmdDestroyWindow( net::Command& command );
00498         net::CommandResult _cmdConfigInit( net::Command& command );
00499         net::CommandResult _cmdConfigExit( net::Command& command );
00500         net::CommandResult _cmdFrameStartClock( net::Command& command );
00501         net::CommandResult _cmdFrameStart( net::Command& command );
00502         net::CommandResult _cmdFrameFinish( net::Command& command );
00503         net::CommandResult _cmdFrameDrawFinish( net::Command& command );
00504 
00505         CHECK_THREAD_DECLARE( _pipeThread );
00506     };
00507 }
00508 
00509 #endif // EQ_PIPE_H
00510 
Generated on Mon Aug 10 18:58:40 2009 for Equalizer 0.9 by  doxygen 1.5.8