source: osgVisual/src/cluster/dataIO_clusterENet.cpp @ 67

Last change on this file since 67 was 67, checked in by Torben Dannhauer, 14 years ago
File size: 3.7 KB
RevLine 
[65]1/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer
2 *
3 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
9 * You have to aquire licenses for all used proprietary modules.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * OpenSceneGraph Public License for more details.
15*/
16
17#include "dataIO_clusterENet.h"
18
19using namespace osgVisual;
20
21dataIO_clusterENet::dataIO_clusterENet()
22{
23        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet constructed" << std::endl;
[67]24        serverToConnect = "unknown";
[65]25}
26
[67]27
[65]28dataIO_clusterENet::~dataIO_clusterENet(void)
29{
30        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet destructed" << std::endl;
31}
32
[67]33
[65]34void dataIO_clusterENet::init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ )
35{
[66]36        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet init();" << std::endl;
37       
[67]38        // Configure the clustermode
39        clusterMode = clusterMode_;
40
41        // store sendContainer
[65]42        sendContainer = sendContainer_;
[66]43       
44        // create ENet implementation object.
45        enet_impl = new osgVisual::dataIO_clusterENet_implementation();
[67]46
47        // initialize ENet implementation
48        if(clusterMode == MASTER)
49        {
50                enet_impl->init(dataIO_clusterENet_implementation::SERVER, port);
51
52                initialized = true;
53        }
54        if(clusterMode == SLAVE)
55        {
56                // Get the server IP
57                if(!arguments_.read("--server",serverToConnect, port))
58                {
59                        // try server discovery
60                        //discoverServer(serverToConnect,port);
61                        /* todo : implement a udp server discovery based on ASIO */
62                }
63
64                // Init ENet
65                enet_impl->init(dataIO_clusterENet_implementation::CLIENT, port);
66
67                // Connect to server with 5 retries:
68                bool connected = false;
69                for(int i=0; i<5; i++)
70                {
71                        std::cout << "Try to connect to server " << serverToConnect << std::endl;
72                        if( enet_impl->connectTo( serverToConnect.c_str(), 5000 ) )
73                        {
74                                // Connect successful.
75                                initialized = true;
76                                connected = true;
77                                break;
78                        }
79                }       // For END
80                if(!connected)
81                {
82                        initialized = false;
83                        std::cout << "Failed to establish connection to server " << serverToConnect << std::endl;
84                }
85        }       // IF SLAVE END
[65]86}
87
[67]88
[65]89void dataIO_clusterENet::shutdown()
90{
91        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet shutdown();" << std::endl;
92}
93
[67]94
[65]95bool dataIO_clusterENet::sendTO_OBJvaluesToSlaves()
96{
97        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet sendTO_OBJvaluesToSlaves()" << std::endl;
98
99        return true;
100}
101
[67]102
[65]103bool dataIO_clusterENet::readTO_OBJvaluesFromMaster()
104{
105        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet readTO_OBJvaluesFromMaster()" << std::endl;
106
107        return true;
108}
109
[67]110
[65]111void dataIO_clusterENet::reportAsReadyToSwap()
112{
113        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet reportAsReadyToSwap()" << std::endl;
114}
115
116bool dataIO_clusterENet::waitForSwap()
117{
118        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet waitForSwap()" << std::endl;
119
120        return true;
121}
122
[67]123
[65]124bool dataIO_clusterENet::waitForAllReadyToSwap()
125{
126        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet waitForAllReadyToSwap()" << std::endl;
127
128        return true;
129}
130
[67]131
[65]132bool dataIO_clusterENet::sendSwapCommand()
133{
134        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet sendSwapCommand()" << std::endl;
135
136        return true;
137}
Note: See TracBrowser for help on using the repository browser.