- Timestamp:
- Jun 8, 2010, 9:39:17 AM (14 years ago)
- Location:
- osgVisual
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
osgVisual/include/cluster/dataIO_clusterAsioTcpIostream.h
r59 r62 18 18 #include "dataIO_cluster.h" 19 19 20 #include <osg/notify> 21 #include <osg/ArgumentParser> 22 23 #include <iostream> 24 #include <string> 25 #include <vector> 26 #include <boost/asio.hpp> 27 #include <boost/date_time/posix_time/posix_time.hpp> 28 29 20 30 namespace osgVisual 21 31 { 22 32 23 class dataIO_clusterAsioTcpIostream : public dataIO_cluster 33 /** 34 * \brief This is a Boost ASIO iostream implementation of dataIO_cluster.. 35 * 36 * This class uses Boost ASIO and it iostream privider to fullfil the functions of dataIO_cluster. 37 * It sends the clusterdata into the network to any connected client. 38 * 39 * 40 * \todo Add getHorizonColor to transport it to slave for consistent fog. 41 * @author Torben Dannhauer 42 * @date May 2010 43 */ 44 class dataIO_clusterAsioTcpIostream : public dataIO_cluster 24 45 { 46 25 47 public: 48 26 49 dataIO_clusterAsioTcpIostream(); 27 virtual ~dataIO_clusterAsioTcpIostream( void);50 virtual ~dataIO_clusterAsioTcpIostream(); 28 51 29 virtual void init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ ); 30 virtual void shutdown(); 31 virtual bool sendTO_OBJvaluesToSlaves() ; 32 virtual bool readTO_OBJvaluesFromMaster(); 33 virtual void reportAsReadyToSwap(); 34 virtual bool waitForSwap(); 35 virtual bool waitForAllReadyToSwap(); 36 virtual bool sendSwapCommand(); 52 void init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ ); 53 void shutdown(); 54 bool sendTO_OBJvaluesToSlaves(); 55 bool readTO_OBJvaluesFromMaster(); 56 void reportAsReadyToSwap(); 57 bool waitForSwap(); 58 bool waitForAllReadyToSwap(); 59 bool sendSwapCommand(); 60 61 private: 62 osgVisual::dataIO_cluster::clustermode clusterMode; 63 bool initialized; 64 int port; // Defaults to 5678 65 66 /** 67 * This list contains the connections to communicate with in each frame. 68 * 69 * As slave, contains only one entry: connection to master. 70 * As Master,contains the connection to all slaves which use this connection. 71 */ 72 std::vector<boost::asio::ip::tcp::iostream> clientlists; 73 74 boost::asio::io_service io_service; 37 75 }; 38 76 39 } // END N amespace77 } // END NAMESPACE -
osgVisual/src/cluster/dataIO_clusterAsioTcpIostream.cpp
r59 r62 15 15 */ 16 16 17 #include " ..\..\include\cluster\dataIO_clusterAsioTcpIostream.h"17 #include "dataIO_clusterAsioTcpIostream.h" 18 18 19 19 using namespace osgVisual; 20 20 21 dataIO_clusterAsioTcpIostream::dataIO_clusterAsioTcpIostream() 21 using boost::asio::ip::tcp; 22 23 dataIO_clusterAsioTcpIostream::dataIO_clusterAsioTcpIostream() 22 24 { 23 OSG_NOTIFY( osg::ALWAYS ) << "clusterAsioTcpIostream constructed" << std::endl; 25 OSG_NOTIFY(osg::ALWAYS) << "dataIO_clusterAsioTcpIostream constructed" << std::endl; 26 27 port = 5678; 28 initialized = false; 24 29 } 25 30 26 dataIO_clusterAsioTcpIostream::~dataIO_clusterAsioTcpIostream( void)31 dataIO_clusterAsioTcpIostream::~dataIO_clusterAsioTcpIostream() 27 32 { 28 OSG_NOTIFY( osg::ALWAYS ) << "clusterAsioTcpIostream destructed" << std::endl;33 OSG_NOTIFY(osg::ALWAYS) << "dataIO_clusterAsioTcpIostream destructed" << std::endl; 29 34 } 30 35 31 36 void dataIO_clusterAsioTcpIostream::init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ ) 32 37 { 33 OSG_NOTIFY( osg::ALWAYS ) << "clusterAsioTcpIostream init()" << std::endl; 38 OSG_NOTIFY(osg::ALWAYS) << "dataIO_clusterAsioTcpIostream initialized" << std::endl; 39 40 clusterMode = clusterMode_; 41 42 if(clusterMode == osgVisual::dataIO_cluster::MASTER) 43 { 44 45 46 tcp::endpoint endpoint(tcp::v4(), port); 47 tcp::acceptor acceptor(io_service, endpoint); 48 49 tcp::iostream stream; 50 51 acceptor.accept(*stream.rdbuf()); 52 tcp::no_delay option(true); 53 boost::system::error_code ec; 54 stream.rdbuf()->set_option(option, ec); 55 if (ec) 56 { 57 OSG_NOTIFY(osg::WARN) << "Error: Unable to set TCP_NODELAY option" << ec << std::endl; 58 // An error occurred. 59 } 60 } 61 62 if(clusterMode == osgVisual::dataIO_cluster::SLAVE) 63 { 64 65 } 66 67 initialized = true; 34 68 } 35 69 36 70 void dataIO_clusterAsioTcpIostream::shutdown() 37 71 { 38 OSG_NOTIFY( osg::ALWAYS ) << "clusterAsioTcpIostream shutdown()" << std::endl; 72 OSG_NOTIFY(osg::ALWAYS) << "dataIO_clusterAsioTcpIostream shut down" << std::endl; 73 74 if(initialized) 75 { 76 77 } 39 78 } 40 79 41 80 bool dataIO_clusterAsioTcpIostream::sendTO_OBJvaluesToSlaves() 42 81 { 43 OSG_NOTIFY( osg::INFO ) << "clusterAsioTcpIostream sendTO_OBJvaluesToSlaves()" << std::endl; 82 OSG_NOTIFY(osg::INFO) << "dataIO_clusterAsioTcpIostream::sendTO_OBJvaluesToSlaves()" << std::endl; 83 44 84 return true; 45 85 } … … 47 87 bool dataIO_clusterAsioTcpIostream::readTO_OBJvaluesFromMaster() 48 88 { 49 OSG_NOTIFY( osg::INFO ) << "clusterAsioTcpIostreamreadTO_OBJvaluesFromMaster()" << std::endl;89 OSG_NOTIFY(osg::INFO) << "dataIO_clusterAsioTcpIostream::readTO_OBJvaluesFromMaster()" << std::endl; 50 90 51 91 return true; … … 54 94 void dataIO_clusterAsioTcpIostream::reportAsReadyToSwap() 55 95 { 56 OSG_NOTIFY( osg::INFO ) << "clusterAsioTcpIostreamreportAsReadyToSwap()" << std::endl;96 OSG_NOTIFY(osg::INFO) << "dataIO_clusterAsioTcpIostream::reportAsReadyToSwap()" << std::endl; 57 97 } 58 98 59 99 bool dataIO_clusterAsioTcpIostream::waitForSwap() 60 100 { 61 OSG_NOTIFY( osg::INFO ) << "clusterAsioTcpIostream waitForSwap()" << std::endl; 101 OSG_NOTIFY(osg::INFO) << "dataIO_clusterAsioTcpIostream::waitForAllReadyToSwap()" << std::endl; 102 62 103 return true; 63 104 } … … 65 106 bool dataIO_clusterAsioTcpIostream::waitForAllReadyToSwap() 66 107 { 67 OSG_NOTIFY( osg::INFO ) << "clusterAsioTcpIostream waitForAllReadyToSwap()" << std::endl; 108 OSG_NOTIFY(osg::INFO) << "dataIO_clusterAsioTcpIostream::waitForAllReadyToSwap()" << std::endl; 109 68 110 return true; 69 111 } … … 71 113 bool dataIO_clusterAsioTcpIostream::sendSwapCommand() 72 114 { 73 OSG_NOTIFY( osg::INFO ) << "clusterAsioTcpIostream sendSwapCommand()" << std::endl; 115 OSG_NOTIFY(osg::INFO) << "dataIO_clusterAsioTcpIostream::sendSwapCommand()" << std::endl; 116 74 117 return true; 75 118 }
Note: See TracChangeset
for help on using the changeset viewer.