server/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 EQSERVER_PIPE_H
00019 #define EQSERVER_PIPE_H
00020 
00021 #include "types.h"
00022 #include "visitorResult.h" // enum
00023 
00024 #include <eq/client/global.h>           // eq::OFF enum
00025 #include <eq/client/pixelViewport.h>    // member
00026 #include <eq/net/object.h>              // base class
00027 #include <eq/base/monitor.h>            // member
00028 
00029 #include <ostream>
00030 #include <vector>
00031 
00032 namespace eq
00033 {
00034 namespace server
00035 {
00036     class PipeVisitor;
00037     class ConstPipeVisitor;
00038     struct ChannelPath;
00039     struct PipePath;
00040 
00044     class Pipe : public net::Object
00045     {
00046     public:
00047         enum State
00048         {
00049             STATE_STOPPED = 0,  // next: INITIALIZING
00050             STATE_INITIALIZING, // next: INIT_FAILED or INIT_SUCCESS
00051             STATE_INIT_SUCCESS, // next: RUNNING
00052             STATE_INIT_FAILED,  // next: EXITING
00053             STATE_RUNNING,      // next: EXITING
00054             STATE_EXITING,      // next: EXIT_FAILED or EXIT_SUCCESS
00055             STATE_EXIT_SUCCESS, // next: STOPPED
00056             STATE_EXIT_FAILED,  // next: STOPPED
00057         };
00058 
00062         EQSERVER_EXPORT Pipe();
00063 
00067         Pipe( const Pipe& from, Node* node );
00068 
00069         Server* getServer();
00070         const Server* getServer() const;
00071 
00072         Node*       getNode()       { return _node; }
00073         const Node* getNode() const { return _node; }
00074 
00075         Config* getConfig();
00076         const Config* getConfig() const;
00077 
00078         net::CommandQueue* getServerThreadQueue();
00079         net::CommandQueue* getCommandThreadQueue();
00080 
00082         PipePath getPath() const;
00083 
00084         Channel* getChannel( const ChannelPath& path );
00085 
00087         State getState()    const { return _state.get(); }
00088 
00094         EQSERVER_EXPORT void addWindow( Window* window );
00095 
00103         bool removeWindow( Window* window );
00104 
00106         const WindowVector& getWindows() const { return _windows; }
00107 
00114         VisitorResult accept( PipeVisitor& visitor );
00115         VisitorResult accept( ConstPipeVisitor& visitor ) const;
00116 
00118         void activate();
00119 
00121         void deactivate();
00122 
00124         bool isActive() const { return (_active != 0); }
00125 
00130         void addTasks( const uint32_t tasks );
00131 
00132         void setName( const std::string& name ) { _name = name; }
00133         const std::string& getName() const      { return _name; }
00134 
00139         void setPort( const uint32_t port )      { _port = port; }
00140         uint32_t getPort() const                 { return _port; }
00141         void setDevice( const uint32_t device )  { _device = device; }
00142         uint32_t getDevice() const               { return _device; }
00143 
00153         void setPixelViewport( const eq::PixelViewport& pvp );
00154 
00156         const eq::PixelViewport& getPixelViewport() const { return _pvp; }
00157 
00159         void setLastDrawWindow( const Window* window )
00160             { _lastDrawWindow = window; }
00161         const Window* getLastDrawWindow() const { return _lastDrawWindow; }
00163 
00169         void updateRunning( const uint32_t initID, const uint32_t frameNumber );
00170 
00172         bool syncRunning();
00173 
00181         void update( const uint32_t frameID, const uint32_t frameNumber );
00183 
00188         // Note: also update string array initialization in pipe.cpp
00189         enum IAttribute
00190         {
00191             IATTR_HINT_THREAD,
00192             IATTR_FILL1,
00193             IATTR_FILL2,
00194             IATTR_ALL
00195         };
00196 
00197         void setIAttribute( const IAttribute attr, const int32_t value )
00198             { _iAttributes[attr] = value; }
00199         int32_t  getIAttribute( const IAttribute attr ) const
00200             { return _iAttributes[attr]; }
00201         static const std::string&  getIAttributeString( const IAttribute attr )
00202             { return _iAttributeStrings[attr]; }
00203 
00204         bool isThreaded() const
00205             { return (getIAttribute( IATTR_HINT_THREAD ) != eq::OFF ); }
00207 
00211         const std::string& getErrorMessage() const { return _error; }
00213 
00214         void send( net::ObjectPacket& packet );
00215 
00216     protected:
00217         virtual ~Pipe();
00218 
00220         base::RequestHandler _requestHandler;
00221 
00223         virtual void attachToSession( const uint32_t id, 
00224                                       const uint32_t instanceID, 
00225                                       net::Session* session );
00226     private:
00228         std::string _name;
00229 
00231         int32_t _iAttributes[IATTR_ALL];
00233         static std::string _iAttributeStrings[IATTR_ALL];
00234 
00236         WindowVector _windows;
00237 
00239         uint32_t _active;
00240 
00242         std::string _error;
00243 
00245         Node* _node;
00246         friend class Node;
00247 
00249         uint32_t _tasks;
00250 
00252         base::Monitor< State > _state;
00253             
00255         uint32_t _port;
00256 
00258         uint32_t _device;
00259 
00260         /* The display (AGL) or output channel (X11?, Win32). */
00261         //uint32_t _monitor;
00262 
00264         eq::PixelViewport _pvp;
00265 
00267         const Window* _lastDrawWindow;
00268 
00269         union // placeholder for binary-compatible changes
00270         {
00271             char dummy[64];
00272         };
00273 
00275         void _construct();
00276 
00277         void _send( net::ObjectPacket& packet, const std::string& string ) ;
00278 
00279         void _configInit( const uint32_t initID, const uint32_t frameNumber );
00280         bool _syncConfigInit();
00281         void _configExit();
00282         bool _syncConfigExit();
00283 
00284         virtual void getInstanceData( net::DataOStream& os ) { EQDONTCALL }
00285         virtual void applyInstanceData( net::DataIStream& is ) { EQDONTCALL }
00286 
00287         /* command handler functions. */
00288         net::CommandResult _cmdConfigInitReply( net::Command& command );
00289         net::CommandResult _cmdConfigExitReply( net::Command& command );
00290     };
00291 
00292     std::ostream& operator << ( std::ostream& os, const Pipe* pipe );
00293 }
00294 }
00295 #endif // EQSERVER_PIPE_H
Generated on Mon Aug 10 18:58:40 2009 for Equalizer 0.9 by  doxygen 1.5.8