server/node.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_NODE_H
00019 #define EQSERVER_NODE_H
00020 
00021 #include "config.h"                // used in inline method
00022 #include "connectionDescription.h" // used in inline method
00023 
00024 #include <eq/client/node.h> // enum eq::Node::IAttribute
00025 
00026 #include <eq/net/barrier.h>
00027 #include <eq/net/bufferConnection.h>
00028 #include <eq/net/node.h>
00029 
00030 #include <vector>
00031 
00032 namespace eq
00033 {
00034 namespace server
00035 {
00036     class ConstNodeVisitor;
00037     class NodeVisitor;
00038     struct ChannelPath;
00039     struct NodePath;
00040 
00044     class Node : 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 Node();
00063 
00067         Node( const Node& from, Config* config );
00068 
00071         Config* getConfig() const { return _config; }
00072         Server* getServer() const
00073             { return _config ? _config->getServer() : 0; }
00074 
00075         net::NodePtr getNode() const { return _node; }
00076         void setNode( net::NodePtr node ) { _node = node; }
00077         bool isApplicationNode() const
00078             { return (this == _config->getApplicationNode( )); }
00079 
00081         NodePath getPath() const;
00082 
00083         Channel* getChannel( const ChannelPath& path );
00084 
00086         State getState()    const { return _state.get(); }
00087 
00088         net::CommandQueue* getServerThreadQueue()
00089             { return _config->getServerThreadQueue(); }
00090         net::CommandQueue* getCommandThreadQueue()
00091             { return _config->getCommandThreadQueue(); }
00092 
00094         uint32_t getFinishedFrame() const { return _finishedFrame; }
00095 
00101         EQSERVER_EXPORT void addPipe( Pipe* pipe );
00102 
00110         bool removePipe( Pipe* pipe );
00111 
00113         const PipeVector& getPipes() const { return _pipes; }
00114 
00121         VisitorResult accept( NodeVisitor& visitor );
00122         VisitorResult accept( ConstNodeVisitor& visitor ) const;
00123 
00125         void activate();
00126 
00128         void deactivate();
00129 
00131         bool isActive() const { return ( _active != 0 ); }
00132 
00134         void addTasks( const uint32_t tasks ) { _tasks |= tasks; }
00135 
00136         void setName( const std::string& name ) { _name = name; }
00137         const std::string& getName() const      { return _name; }
00138 
00140         void setLastDrawPipe( const Pipe* pipe )
00141             { _lastDrawPipe = pipe; }
00142         const Pipe* getLastDrawPipe() const { return _lastDrawPipe;}
00144 
00150         void updateRunning( const uint32_t initID, const uint32_t frameNumber );
00151 
00153         bool syncRunning();
00154 
00162         void update( const uint32_t frameID, const uint32_t frameNumber );
00163 
00169         void flushFrames( const uint32_t frameNumber );
00170 
00172         void finishFrame( const uint32_t frame );
00174 
00175 
00178         void setIAttribute( const eq::Node::IAttribute attr, 
00179                             const int32_t value )
00180             { _iAttributes[attr] = value; }
00181         int32_t  getIAttribute( const eq::Node::IAttribute attr ) const
00182             { return _iAttributes[attr]; }
00184 
00196         net::Barrier* getBarrier();
00197 
00203         void releaseBarrier( net::Barrier* barrier );
00205 
00206         void send( net::SessionPacket& packet ) 
00207             { 
00208                 packet.sessionID = _config->getID(); 
00209                 _bufferedTasks.send( packet );
00210             }
00211         void send( net::SessionPacket& packet, const std::string& string ) 
00212             {
00213                 packet.sessionID = _config->getID(); 
00214                 _bufferedTasks.send( packet, string );
00215             }
00216         template< typename T >
00217         void send( net::SessionPacket &packet, const std::vector<T>& data )
00218             {
00219                 packet.sessionID = _config->getID(); 
00220                 _bufferedTasks.send( packet, data );
00221             }
00222 
00223         void flushSendBuffer();
00224 
00230         void addConnectionDescription( ConnectionDescriptionPtr desc )
00231             { _connectionDescriptions.push_back( desc ); }
00232         
00238         void removeConnectionDescription( const uint32_t index );
00239 
00241         const ConnectionDescriptionVector& getConnectionDescriptions()
00242             const { return _connectionDescriptions; }
00243 
00247         const std::string& getErrorMessage() const { return _error; }
00249 
00250     protected:
00251         virtual ~Node();
00252 
00254         base::RequestHandler _requestHandler;
00255 
00257         virtual void attachToSession( const uint32_t id, 
00258                                       const uint32_t instanceID, 
00259                                       net::Session* session );
00260     private:
00262         std::string _name;
00263 
00265         int32_t _iAttributes[eq::Node::IATTR_ALL];
00266 
00268         Config* _config;
00269         friend class Config;
00270 
00272         PipeVector _pipes;
00273 
00275         std::string _error;
00276 
00278         uint32_t _active;
00279 
00281         net::NodePtr _node;
00282 
00284         ConnectionDescriptionVector _connectionDescriptions;
00285 
00287         std::map< uint32_t, uint32_t > _frameIDs;
00288 
00290         uint32_t _flushedFrame;
00291 
00293         uint32_t _finishedFrame;
00294 
00296         uint32_t _tasks;
00297 
00299         base::Monitor< State > _state;
00300             
00302         std::vector<net::Barrier*> _barriers;
00303 
00305         net::BufferConnection _bufferedTasks;
00306 
00308         const Pipe* _lastDrawPipe;
00309 
00310         union // placeholder for binary-compatible changes
00311         {
00312             char dummy[64];
00313         };
00314 
00316         void _construct();
00317 
00318         void _configInit( const uint32_t initID, const uint32_t frameNumber );
00319         bool _syncConfigInit();
00320         void _configExit();
00321         bool _syncConfigExit();
00322 
00323         uint32_t _getFinishLatency() const;
00324         void _finish( const uint32_t currentFrame );
00325 
00327         void _flushBarriers();
00328 
00329         void _send( net::ObjectPacket& packet ) 
00330             { packet.objectID = getID(); send( packet ); }
00331         void _send( net::ObjectPacket& packet, const std::string& string ) 
00332             { packet.objectID = getID(); send( packet, string ); }
00333 
00335         void _sendFrameFinish( const uint32_t frameNumber );
00336 
00337         virtual void getInstanceData( net::DataOStream& os ) { EQDONTCALL }
00338         virtual void applyInstanceData( net::DataIStream& is ) { EQDONTCALL }
00339 
00340         /* Command handler functions. */
00341         net::CommandResult _cmdConfigInitReply( net::Command& command );
00342         net::CommandResult _cmdConfigExitReply( net::Command& command );
00343         net::CommandResult _cmdFrameFinishReply( net::Command& command );
00344     };
00345 
00346     std::ostream& operator << ( std::ostream& os, const Node* node );
00347 }
00348 }
00349 #endif // EQSERVER_NODE_H
Generated on Mon Aug 10 18:58:40 2009 for Equalizer 0.9 by  doxygen 1.5.8