server/channel.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_CHANNEL_H
00019 #define EQSERVER_CHANNEL_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 "base.h"
00029 #include "types.h"
00030 #include "visitorResult.h" // nested enum
00031 
00032 #include <eq/client/channel.h>
00033 #include <eq/client/commands.h>
00034 #include <eq/client/pixelViewport.h>
00035 #include <eq/client/viewport.h>
00036 #include <eq/net/object.h>
00037 #include <eq/net/packets.h>
00038 
00039 #include <iostream>
00040 #include <vector>
00041 
00042 namespace eq
00043 {
00044 
00045 namespace server
00046 {
00047     class ChannelListener;
00048     class ChannelVisitor;
00049     class ConstChannelVisitor;
00050     struct ChannelPath;
00051 
00055     class Channel : public net::Object
00056     {
00057     public:
00058         enum State
00059         {
00060             STATE_STOPPED = 0,  // next: INITIALIZING
00061             STATE_INITIALIZING, // next: INIT_FAILED or INIT_SUCCESS
00062             STATE_INIT_SUCCESS, // next: RUNNING
00063             STATE_INIT_FAILED,  // next: EXITING
00064             STATE_RUNNING,      // next: EXITING
00065             STATE_EXITING,      // next: EXIT_FAILED or EXIT_SUCCESS
00066             STATE_EXIT_SUCCESS, // next: STOPPED
00067             STATE_EXIT_FAILED,  // next: STOPPED
00068         };
00069 
00073         EQSERVER_EXPORT Channel();
00074 
00078         Channel( const Channel& from, Window* window );
00079 
00081         virtual ~Channel();
00082 
00086         State getState()    const { return _state.get(); }
00087 
00092         Config* getConfig();
00093         const Config* getConfig() const;
00094 
00095         EQSERVER_EXPORT Node* getNode();
00096         EQSERVER_EXPORT const Node* getNode() const;
00097 
00098         Pipe* getPipe();
00099         const Pipe* getPipe() const;
00100 
00101         Window* getWindow()             { return _window; }
00102         const Window* getWindow() const { return _window; }
00103 
00105         ChannelPath getPath() const;
00106 
00107         const CompoundVector& getCompounds() const;
00108 
00109         net::CommandQueue* getServerThreadQueue();
00110         net::CommandQueue* getCommandThreadQueue();
00111 
00118         EQSERVER_EXPORT VisitorResult accept( ChannelVisitor& visitor );
00119         EQSERVER_EXPORT VisitorResult accept( ConstChannelVisitor& ) const;
00120 
00122         void activate();
00123 
00125         void deactivate();
00126 
00128         bool isActive() const { return (_active != 0); }
00129 
00134         void addTasks( const uint32_t tasks );
00135 
00137         void setOutput( View* view, Segment* segment );
00138 
00140         void unsetOutput();
00141 
00143         const View* getView() const { return _view; }
00144 
00146         const Layout* getLayout() const;
00147 
00149         const Segment* getSegment() const { return _segment; }
00150 
00151         void setName( const std::string& name ) { _name = name; }
00152         const std::string& getName() const      { return _name; }
00153 
00159         void setPixelViewport( const eq::PixelViewport& pvp );
00160 
00166         const eq::PixelViewport& getPixelViewport() const { return _pvp; }
00167 
00173         void notifyViewportChanged();
00174 
00180         void setViewport( const eq::Viewport& vp );
00181 
00187         const eq::Viewport& getViewport() const { return _vp; }
00188 
00195         void getNearFar( float* nearPlane, float* farPlane ) const 
00196             { *nearPlane = _near; *farPlane = _far; }
00197 
00199         void setLastDrawCompound( const Compound* compound )
00200             { _lastDrawCompound = compound; }
00201         const Compound* getLastDrawCompound() const { return _lastDrawCompound;}
00203 
00209         void updateRunning( const uint32_t initID );
00210 
00212         bool syncRunning();
00213 
00217         void startConfigExit();
00218 
00225         bool syncConfigExit();
00226 
00235         bool update( const uint32_t frameID, const uint32_t frameNumber );
00236 
00237         void send( net::ObjectPacket& packet );
00238         void send( net::ObjectPacket& packet, const std::string& string );
00239         template< typename T >
00240         void send( net::ObjectPacket &packet, const std::vector<T>& data );
00242 
00246         void addListener( ChannelListener* listener );
00248         void removeListener( ChannelListener* listener );
00250 
00255         void setIAttribute( const eq::Channel::IAttribute attr,
00256                             const int32_t value )
00257             { _iAttributes[attr] = value; }
00258         int32_t  getIAttribute( const eq::Channel::IAttribute attr ) const
00259             { return _iAttributes[attr]; }
00261 
00265         const std::string& getErrorMessage() const { return _error; }
00267         
00268         /* Set the channel's drawable. */
00269         void setDrawable( const uint32_t drawable );
00270 
00271         /* Get the channel's drawable. */
00272         uint32_t getDrawable() const { return _drawable; }
00273 
00274         void setOverdraw( const Vector4i& overdraw )
00275             { _overdraw = overdraw; }
00276         const Vector4i& getOverdraw() const { return _overdraw; }
00277         const Vector2i& getMaxSize()  const { return _maxSize; }
00278 
00279     protected:
00281         base::RequestHandler _requestHandler;
00282 
00284         virtual void attachToSession( const uint32_t id, 
00285                                       const uint32_t instanceID, 
00286                                       net::Session* session );
00287     private:
00288         //-------------------- Members --------------------
00290         uint32_t _active;
00291 
00293         View* _view;
00294 
00296         Segment* _segment;
00297 
00299         std::string _error;
00300 
00302         Window* _window;
00303         friend class Window;
00304 
00305         std::string _name;
00306 
00308         int32_t _iAttributes[eq::Channel::IATTR_ALL];
00309 
00311         eq::Viewport _vp;
00312 
00314         eq::PixelViewport _pvp;
00315 
00317         uint32_t _drawable;
00318         
00320         bool _fixedPVP;
00321 
00323         float        _near;
00325         float        _far;
00326 
00327         Vector4i    _overdraw;
00328         Vector2i    _maxSize;
00329 
00331         uint32_t _tasks;
00332 
00334         base::Monitor< State > _state;
00335 
00337         const Compound* _lastDrawCompound;
00338 
00339         typedef std::vector< ChannelListener* > ChannelListeners;
00340         ChannelListeners _listeners;
00341 
00342         CHECK_THREAD_DECLARE( _serverThread );
00343 
00344         union // placeholder for binary-compatible changes
00345         {
00346             char dummy[64];
00347         };
00348 
00349         //-------------------- Methods --------------------
00351         void _construct();
00352 
00353         Vector3ub _getUniqueColor() const;
00354 
00355         void _configInit( const uint32_t initID );
00356         bool _syncConfigInit();
00357         void _configExit();
00358         bool _syncConfigExit();
00359 
00360         void _setupRenderContext( const uint32_t frameID,
00361                                   eq::RenderContext& context );
00362 
00363         void _fireLoadData( const uint32_t frameNumber, 
00364                             const uint32_t nStatistics,
00365                             const eq::Statistic* statistics );
00366 
00367         virtual void getInstanceData( net::DataOStream& os ) { EQDONTCALL }
00368         virtual void applyInstanceData( net::DataIStream& is ) { EQDONTCALL }
00369 
00370         /* command handler functions. */
00371         net::CommandResult _cmdConfigInitReply( net::Command& command );
00372         net::CommandResult _cmdConfigExitReply( net::Command& command );
00373         net::CommandResult _cmdSetNearFar( net::Command& command );
00374         net::CommandResult _cmdFrameFinishReply( net::Command& command );
00375 
00376         // For access to _fixedPVP
00377         friend std::ostream& operator << ( std::ostream&, const Channel*);
00378     };
00379 
00380     std::ostream& operator << ( std::ostream& os, const Channel* channel);
00381 }
00382 }
00383 #endif // EQSERVER_CHANNEL_H
Generated on Mon Aug 10 18:58:31 2009 for Equalizer 0.9 by  doxygen 1.5.8