- Timestamp:
- Jul 11, 2010, 10:48:39 AM (14 years ago)
- Location:
- osgVisual
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
osgVisual/include/cluster/dataIO_clusterENet.h
r65 r66 20 20 21 21 #include <dataIO_cluster.h> 22 #include <dataIO_clusterENet_implementation.h> 22 23 23 24 namespace osgVisual … … 48 49 bool waitForAllReadyToSwap(); 49 50 bool sendSwapCommand(); 51 52 private: 53 osg::ref_ptr<osgVisual::dataIO_clusterENet_implementation> enet_impl; 50 54 }; 51 55 -
osgVisual/include/cluster/dataIO_clusterENet_implementation.h
r65 r66 4 4 #endif // _MSC_VER > 1000 5 5 6 #include <osg/referenced> 6 7 #include <enet/enet.h> 7 8 #include <iostream> … … 9 10 #include <vector> 10 11 12 namespace osgVisual 13 { 11 14 12 13 class ENet_implementation 15 class dataIO_clusterENet_implementation : public osg::Referenced 14 16 { 15 17 public: 16 ENet_implementation();17 ~ ENet_implementation();18 dataIO_clusterENet_implementation(); 19 ~dataIO_clusterENet_implementation(); 18 20 19 21 enum role {SERVER, CLIENT}; 20 22 21 bool init( ENet_implementation::role role_, unsigned short port_, int maxClients_=10, int maxChannels_=2, int maxInBandwidth_=0, int maxOutBandwidth_=0 ); // client & server // Done23 bool init( dataIO_clusterENet_implementation::role role_, unsigned short port_, int maxClients_=10, int maxChannels_=2, int maxInBandwidth_=0, int maxOutBandwidth_=0 ); // client & server // Done 22 24 bool connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_=0, int channelToAlloc_=2 ); // only as client // Done 23 25 void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_=0, bool autoFlush_=false ); // by PeerID // Done … … 32 34 protected: 33 35 unsigned short port; 34 ENet_implementation::role currentRole;36 dataIO_clusterENet_implementation::role currentRole; 35 37 static int activeENetInstances; 36 38 bool serverInitialized; // shows if the complete server is initialized. (After init()) … … 40 42 ENetEvent event; 41 43 }; 44 45 } // END NAMESPACE -
osgVisual/src/cluster/dataIO_clusterENet.cpp
r65 r66 31 31 void dataIO_clusterENet::init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ ) 32 32 { 33 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet init();" << std::endl; 34 33 35 sendContainer = sendContainer_; 34 OSG_NOTIFY( osg::ALWAYS ) << "clusterENet init();" << std::endl; 36 37 // create ENet implementation object. 38 enet_impl = new osgVisual::dataIO_clusterENet_implementation(); 35 39 } 36 40 -
osgVisual/src/cluster/dataIO_clusterENet_implementation.cpp
r65 r66 1 1 #include "dataIO_clusterENet_implementation.h" 2 2 3 int ENet_implementation::activeENetInstances = 0; 4 5 ENet_implementation::ENet_implementation() 3 using namespace osgVisual; 4 5 int dataIO_clusterENet_implementation::activeENetInstances = 0; 6 7 dataIO_clusterENet_implementation::dataIO_clusterENet_implementation() 6 8 { 7 9 std::cout << "Instantiated server class# "<< activeENetInstances << std::endl; … … 21 23 } 22 24 23 ENet_implementation::~ENet_implementation()25 dataIO_clusterENet_implementation::~dataIO_clusterENet_implementation() 24 26 { 25 27 // Delete Host Object … … 35 37 } 36 38 37 bool ENet_implementation::init(ENet_implementation::role role_, unsigned short port_, int maxClients_, int maxChannels_, int maxInBandwidth_, int maxOutBandwidth_)39 bool dataIO_clusterENet_implementation::init(dataIO_clusterENet_implementation::role role_, unsigned short port_, int maxClients_, int maxChannels_, int maxInBandwidth_, int maxOutBandwidth_) 38 40 { 39 41 port = port_; 40 42 currentRole = role_; 41 43 42 if(currentRole == ENet_implementation::SERVER)44 if(currentRole == dataIO_clusterENet_implementation::SERVER) 43 45 { 44 46 /* Bind the server to the default localhost. */ … … 62 64 } // IF SERVER END 63 65 64 if(currentRole == ENet_implementation::CLIENT)66 if(currentRole == dataIO_clusterENet_implementation::CLIENT) 65 67 { 66 68 host = enet_host_create (NULL /* create a client host */, … … 81 83 } 82 84 83 void ENet_implementation::processEvents(int timeout_ms_)85 void dataIO_clusterENet_implementation::processEvents(int timeout_ms_) 84 86 { 85 87 if(!serverInitialized) … … 117 119 } 118 120 119 void ENet_implementation::sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_, bool autoFlush_ )121 void dataIO_clusterENet_implementation::sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_, bool autoFlush_ ) 120 122 { 121 123 // are connected peers available? 122 124 if( peerList.size() == 0 ) 123 125 { 124 std::cout << " ENet_implementation::sendPacket() - ERROR: No connected peer available!" << std::endl;126 std::cout << "dataIO_clusterENet_implementation::sendPacket() - ERROR: No connected peer available!" << std::endl; 125 127 return; 126 128 } 127 129 128 130 // Client 129 if(currentRole == ENet_implementation::CLIENT)131 if(currentRole == dataIO_clusterENet_implementation::CLIENT) 130 132 { 131 133 enet_peer_send (peerList[0], channelID_, packet_); … … 133 135 134 136 // Server 135 if(currentRole == ENet_implementation::SERVER)137 if(currentRole == dataIO_clusterENet_implementation::SERVER) 136 138 { 137 139 if(peerID_ < peerList.size()) 138 140 enet_peer_send (peerList[peerID_], channelID_, packet_); 139 141 else 140 std::cout << " ENet_implementation::sendPacket() - ERROR: Peer #"<<peerID_<<" is not available, only peers 0-"<<(peerList.size()-1)<<" are connected!" << std::endl;142 std::cout << "dataIO_clusterENet_implementation::sendPacket() - ERROR: Peer #"<<peerID_<<" is not available, only peers 0-"<<(peerList.size()-1)<<" are connected!" << std::endl; 141 143 } 142 144 … … 145 147 } 146 148 147 void ENet_implementation::sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_ )149 void dataIO_clusterENet_implementation::sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_ ) 148 150 { 149 151 // are connected peers available? 150 152 if( peerList.size() == 0 ) 151 153 { 152 std::cout << " ENet_implementation::sendPacket() - ERROR: No connected peer available!" << std::endl;154 std::cout << "dataIO_clusterENet_implementation::sendPacket() - ERROR: No connected peer available!" << std::endl; 153 155 return; 154 156 } 155 157 156 158 // Client 157 if(currentRole == ENet_implementation::CLIENT)159 if(currentRole == dataIO_clusterENet_implementation::CLIENT) 158 160 { 159 161 enet_peer_send (peerList[0], channelID_, packet_); … … 161 163 162 164 // Server 163 if(currentRole == ENet_implementation::SERVER)165 if(currentRole == dataIO_clusterENet_implementation::SERVER) 164 166 { 165 167 int peerID_=-1; … … 175 177 enet_peer_send (peerList[peerID_], channelID_, packet_); 176 178 else 177 std::cout << " ENet_implementation::sendPacket() - ERROR: Peer #"<<peerID_<<" is not available, only peers 0-"<<(peerList.size()-1)<<" are connected!" << std::endl;179 std::cout << "dataIO_clusterENet_implementation::sendPacket() - ERROR: Peer #"<<peerID_<<" is not available, only peers 0-"<<(peerList.size()-1)<<" are connected!" << std::endl; 178 180 } 179 181 … … 182 184 } 183 185 184 void ENet_implementation::broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_ )185 { 186 if(currentRole != ENet_implementation::SERVER)186 void dataIO_clusterENet_implementation::broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_ ) 187 { 188 if(currentRole != dataIO_clusterENet_implementation::SERVER) 187 189 return; 188 190 … … 192 194 } 193 195 194 bool ENet_implementation::connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_, int channelToAlloc_ )195 { 196 if(currentRole != ENet_implementation::CLIENT)196 bool dataIO_clusterENet_implementation::connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_, int channelToAlloc_ ) 197 { 198 if(currentRole != dataIO_clusterENet_implementation::CLIENT) 197 199 return false; 198 200 … … 235 237 } 236 238 237 void ENet_implementation::onReceivePacket(ENetEvent* event_)239 void dataIO_clusterENet_implementation::onReceivePacket(ENetEvent* event_) 238 240 { 239 241 std::string datastring; … … 250 252 } 251 253 252 void ENet_implementation::onConnect(ENetEvent* event_)254 void dataIO_clusterENet_implementation::onConnect(ENetEvent* event_) 253 255 { 254 256 /* Get connect remote IP */ … … 266 268 } 267 269 268 void ENet_implementation::onDisconnect(ENetEvent* event_)270 void dataIO_clusterENet_implementation::onDisconnect(ENetEvent* event_) 269 271 { 270 272 // remove peer pionter from peerList … … 280 282 281 283 282 if(currentRole == ENet_implementation::SERVER)284 if(currentRole == dataIO_clusterENet_implementation::SERVER) 283 285 { 284 286 std::cout << "Client " << (char*)event_->peer->data << " disconnected." << std::endl; … … 289 291 } 290 292 291 if(currentRole == ENet_implementation::CLIENT)293 if(currentRole == dataIO_clusterENet_implementation::CLIENT) 292 294 { 293 295 std::cout << "Server "<< (char*)event_->peer->data<<"disconnected." << std::endl;
Note: See TracChangeset
for help on using the changeset viewer.