/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer * * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. * You have to aquire licenses for all used proprietary modules. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include "dataIO_clusterENet.h" using namespace osgVisual; dataIO_clusterENet::dataIO_clusterENet() { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet constructed" << std::endl; serverToConnect = "unknown"; } dataIO_clusterENet::~dataIO_clusterENet(void) { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet destructed" << std::endl; } void dataIO_clusterENet::init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ ) { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet init();" << std::endl; // Configure the clustermode clusterMode = clusterMode_; // store sendContainer sendContainer = sendContainer_; // create ENet implementation object. enet_impl = new osgVisual::dataIO_clusterENet_implementation(); // initialize ENet implementation if(clusterMode == MASTER) { enet_impl->init(dataIO_clusterENet_implementation::SERVER, port); initialized = true; } if(clusterMode == SLAVE) { // Get the server IP if(!arguments_.read("--server",serverToConnect, port)) { // try server discovery //discoverServer(serverToConnect,port); /* todo : implement a udp server discovery based on ASIO */ } // Init ENet enet_impl->init(dataIO_clusterENet_implementation::CLIENT, port); // Connect to server with 5 retries: bool connected = false; for(int i=0; i<5; i++) { std::cout << "Try to connect to server " << serverToConnect << std::endl; if( enet_impl->connectTo( serverToConnect.c_str(), 5000 ) ) { // Connect successful. initialized = true; connected = true; break; } } // For END if(!connected) { initialized = false; std::cout << "Failed to establish connection to server " << serverToConnect << std::endl; } } // IF SLAVE END } void dataIO_clusterENet::shutdown() { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet shutdown();" << std::endl; } bool dataIO_clusterENet::sendTO_OBJvaluesToSlaves() { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet sendTO_OBJvaluesToSlaves()" << std::endl; return true; } bool dataIO_clusterENet::readTO_OBJvaluesFromMaster() { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet readTO_OBJvaluesFromMaster()" << std::endl; return true; } void dataIO_clusterENet::reportAsReadyToSwap() { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet reportAsReadyToSwap()" << std::endl; } bool dataIO_clusterENet::waitForSwap() { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet waitForSwap()" << std::endl; return true; } bool dataIO_clusterENet::waitForAllReadyToSwap() { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet waitForAllReadyToSwap()" << std::endl; return true; } bool dataIO_clusterENet::sendSwapCommand() { OSG_NOTIFY( osg::ALWAYS ) << "clusterENet sendSwapCommand()" << std::endl; return true; }