server/window.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 EQSERVER_WINDOW_H
00019 #define EQSERVER_WINDOW_H
00020 
00021 #ifdef EQUALIZERSERVERLIBRARY_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 "types.h"
00029 #include "visitorResult.h"  // enum
00030 #include "swapBarrier.h"
00031 #include <eq/client/pixelViewport.h>
00032 #include <eq/client/window.h>
00033 #include <eq/net/barrier.h>
00034 #include <eq/net/object.h>
00035 
00036 #include <iostream>
00037 #include <vector>
00038 
00039 namespace eq
00040 {
00041 namespace server
00042 {
00043     class WindowVisitor;
00044     class ConstWindowVisitor;
00045     struct ChannelPath;
00046     struct WindowPath;
00047 
00051     class Window : public net::Object
00052     {
00053     public:
00054         enum State
00055         {
00056             STATE_STOPPED = 0,  // next: INITIALIZING
00057             STATE_INITIALIZING, // next: INIT_FAILED or INIT_SUCCESS
00058             STATE_INIT_SUCCESS, // next: RUNNING
00059             STATE_INIT_FAILED,  // next: EXITING
00060             STATE_RUNNING,      // next: EXITING
00061             STATE_EXITING,      // next: EXIT_FAILED or EXIT_SUCCESS
00062             STATE_EXIT_SUCCESS, // next: STOPPED
00063             STATE_EXIT_FAILED,  // next: STOPPED
00064         };
00065 
00069         EQSERVER_EXPORT Window();
00070 
00074         Window( const Window& from, Pipe* pipe );
00075 
00085         EQSERVER_EXPORT void addChannel( Channel* channel );
00086 
00093         void insertChannel( const Channel* position, Channel* channel );
00094 
00102         bool removeChannel( Channel* channel );
00103 
00105         const ChannelVector& getChannels() const { return _channels; }
00106 
00107         Pipe*       getPipe()       { return _pipe; }
00108         const Pipe* getPipe() const { return _pipe; }
00109 
00110         Node* getNode();
00111         const Node* getNode() const;
00112 
00113         Config* getConfig();
00114         const Config* getConfig() const;
00115         
00117         WindowPath getPath() const;
00118 
00119         Channel* getChannel( const ChannelPath& path );
00120 
00121         const eq::Window::DrawableConfig& getDrawableConfig() const
00122             { return _drawableConfig; }
00123 
00124         net::CommandQueue* getServerThreadQueue();
00125         net::CommandQueue* getCommandThreadQueue();
00126 
00128         State getState() const { return _state.get(); }
00129 
00136         EQSERVER_EXPORT VisitorResult accept( WindowVisitor& visitor );
00137         EQSERVER_EXPORT VisitorResult accept( ConstWindowVisitor& ) const;
00138 
00140         void activate();
00141 
00143         void deactivate();
00144 
00146         bool isActive() const { return (_active != 0); }
00147 
00152         void addTasks( const uint32_t tasks );
00153 
00154         void setName( const std::string& name ) { _name = name; }
00155         const std::string& getName() const      { return _name; }
00156 
00162         EQSERVER_EXPORT void setPixelViewport( const eq::PixelViewport& pvp );
00163 
00169         const eq::PixelViewport& getPixelViewport() const { return _pvp; }
00170 
00176         void setViewport( const eq::Viewport& vp );
00177 
00183         const eq::Viewport& getViewport() const { return _vp; }
00184 
00190         void notifyViewportChanged();
00191 
00199         net::Barrier* joinSwapBarrier( net::Barrier* barrier );
00200 
00211         net::Barrier* joinNVSwapBarrier( const SwapBarrier* swapBarrier,
00212                                          net::Barrier* netBarrier );
00213 
00215         bool hasNVSwapBarrier() const { return (_nvSwapBarrier != 0); }
00216 
00218         void setLastDrawChannel( const Channel* channel )
00219             { _lastDrawChannel = channel; }
00220         const Channel* getLastDrawChannel() const { return _lastDrawChannel; }
00221 
00223         void setMaxFPS( const float fps ) { _maxFPS = fps; }
00224         float getMaxFPS() const { return _maxFPS; }
00226 
00232         void updateRunning( const uint32_t initID );
00233 
00235         bool syncRunning();
00236 
00244         void updateDraw( const uint32_t frameID, const uint32_t frameNumber );
00245 
00253         void updatePost( const uint32_t frameID, const uint32_t frameNumber );
00255 
00260         void setIAttribute( const eq::Window::IAttribute attr,
00261                             const int32_t value )
00262             { _iAttributes[attr] = value; }
00263         int32_t  getIAttribute( const eq::Window::IAttribute attr ) const
00264             { return _iAttributes[attr]; }
00266 
00270         const std::string& getErrorMessage() const { return _error; }
00272 
00273         void send( net::ObjectPacket& packet );
00274 
00275     protected:
00276         virtual ~Window();
00277 
00279         base::RequestHandler _requestHandler;
00280 
00282         virtual void attachToSession( const uint32_t id, 
00283                                       const uint32_t instanceID, 
00284                                       net::Session* session );
00285     private:
00286         eq::Window::DrawableConfig _drawableConfig;
00287 
00289         std::string _name;
00290 
00292         std::string            _error;
00293 
00295         int32_t _iAttributes[eq::Window::IATTR_ALL];
00296 
00298         ChannelVector _channels;
00299 
00301         uint32_t _active;
00302 
00304         Pipe* _pipe;
00305         friend class Pipe;
00306 
00308         uint32_t _tasks;
00309 
00311         base::Monitor< State > _state;
00312             
00314         eq::PixelViewport _pvp;
00315         
00317         eq::Viewport _vp;
00318         
00320         float _maxFPS;
00321 
00323         bool _swapFinish;
00324 
00329         bool _swap;
00330 
00335         bool _fixedPVP;
00336 
00338         net::BarrierVector _masterSwapBarriers;
00340         net::BarrierVector _swapBarriers;
00341 
00343         const SwapBarrier* _nvSwapBarrier;
00344 
00346         net::Barrier* _nvNetBarrier;
00347 
00349         const Channel* _lastDrawChannel;
00350 
00351         union // placeholder for binary-compatible changes
00352         {
00353             char dummy[64];
00354         };
00355 
00357         void _construct();
00358 
00360         void _resetSwapBarriers();
00361 
00362         void _send( net::ObjectPacket& packet, const std::string& string );
00363 
00364         void _configInit( const uint32_t initID );
00365         bool _syncConfigInit();
00366         void _configExit();
00367         bool _syncConfigExit();
00368 
00369         void _updateSwap( const uint32_t frameNumber );
00370 
00371         virtual void getInstanceData( net::DataOStream& os ) { EQDONTCALL }
00372         virtual void applyInstanceData( net::DataIStream& is ) { EQDONTCALL }
00373 
00374         /* command handler functions. */
00375         net::CommandResult _cmdConfigInitReply( net::Command& command ); 
00376         net::CommandResult _cmdConfigExitReply( net::Command& command ); 
00377         net::CommandResult _cmdSetPixelViewport( net::Command& command );
00378 
00379         // For access to _fixedPVP
00380         friend std::ostream& operator << ( std::ostream&, const Window*);
00381     };
00382 
00383     std::ostream& operator << ( std::ostream& os, const Window* window );
00384 }
00385 }
00386 
00387 #endif // EQSERVER_WINDOW_H
Generated on Mon Aug 10 18:58:41 2009 for Equalizer 0.9 by  doxygen 1.5.8