Changeset 66 for osgVisual


Ignore:
Timestamp:
Jul 11, 2010, 10:48:39 AM (14 years ago)
Author:
Torben Dannhauer
Message:

ENet debugging/improvements

Location:
osgVisual
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/include/cluster/dataIO_clusterENet.h

    r65 r66  
    2020
    2121#include <dataIO_cluster.h>
     22#include <dataIO_clusterENet_implementation.h>
    2223
    2324namespace osgVisual
     
    4849        bool waitForAllReadyToSwap();
    4950        bool sendSwapCommand();
     51
     52private:
     53        osg::ref_ptr<osgVisual::dataIO_clusterENet_implementation> enet_impl;
    5054};
    5155
  • osgVisual/include/cluster/dataIO_clusterENet_implementation.h

    r65 r66  
    44#endif // _MSC_VER > 1000
    55
     6#include <osg/referenced>
    67#include <enet/enet.h>
    78#include <iostream>
     
    910#include <vector>
    1011
     12namespace osgVisual
     13{
    1114
    12 
    13 class ENet_implementation
     15class dataIO_clusterENet_implementation :       public osg::Referenced
    1416{
    1517public:
    16         ENet_implementation();
    17         ~ENet_implementation();
     18        dataIO_clusterENet_implementation();
     19        ~dataIO_clusterENet_implementation();
    1820
    1921        enum role {SERVER, CLIENT};
    2022
    21         bool init( ENet_implementation::role role_, unsigned short port_, int maxClients_=10, int maxChannels_=2, int maxInBandwidth_=0, int maxOutBandwidth_=0 );      // client & server                                                              // Done
     23        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
    2224        bool connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_=0,  int channelToAlloc_=2 );   // only as client                                                                       // Done
    2325        void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_=0, bool autoFlush_=false );   // by PeerID    // Done
     
    3234protected:
    3335        unsigned short port;
    34         ENet_implementation::role currentRole;
     36        dataIO_clusterENet_implementation::role currentRole;
    3537        static int activeENetInstances;
    3638        bool serverInitialized; // shows if the complete server is initialized. (After init())
     
    4042        ENetEvent event;
    4143};
     44
     45}       // END NAMESPACE
  • osgVisual/src/cluster/dataIO_clusterENet.cpp

    r65 r66  
    3131void dataIO_clusterENet::init( osg::ArgumentParser& arguments_, clustermode clusterMode_, osgVisual::dataIO_transportContainer* sendContainer_, bool compressionEnabled_, bool asAscii_ )
    3232{
     33        OSG_NOTIFY( osg::ALWAYS ) << "clusterENet init();" << std::endl;
     34       
    3335        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();
    3539}
    3640
  • osgVisual/src/cluster/dataIO_clusterENet_implementation.cpp

    r65 r66  
    11#include "dataIO_clusterENet_implementation.h"
    22
    3 int ENet_implementation::activeENetInstances = 0;
    4 
    5 ENet_implementation::ENet_implementation()
     3using namespace osgVisual;
     4
     5int dataIO_clusterENet_implementation::activeENetInstances = 0;
     6
     7dataIO_clusterENet_implementation::dataIO_clusterENet_implementation()
    68{
    79        std::cout << "Instantiated server class# "<< activeENetInstances << std::endl;
     
    2123}
    2224
    23 ENet_implementation::~ENet_implementation()
     25dataIO_clusterENet_implementation::~dataIO_clusterENet_implementation()
    2426{
    2527        // Delete Host Object
     
    3537}
    3638
    37 bool ENet_implementation::init(ENet_implementation::role role_, unsigned short port_, int maxClients_, int maxChannels_, int maxInBandwidth_, int maxOutBandwidth_)
     39bool dataIO_clusterENet_implementation::init(dataIO_clusterENet_implementation::role role_, unsigned short port_, int maxClients_, int maxChannels_, int maxInBandwidth_, int maxOutBandwidth_)
    3840{
    3941        port = port_;
    4042        currentRole = role_;
    4143
    42         if(currentRole == ENet_implementation::SERVER)
     44        if(currentRole == dataIO_clusterENet_implementation::SERVER)
    4345        {
    4446                /* Bind the server to the default localhost.     */
     
    6264        }       // IF SERVER END
    6365
    64         if(currentRole == ENet_implementation::CLIENT)
     66        if(currentRole == dataIO_clusterENet_implementation::CLIENT)
    6567        {
    6668                 host = enet_host_create (NULL /* create a client host */,
     
    8183}
    8284
    83 void ENet_implementation::processEvents(int timeout_ms_)
     85void dataIO_clusterENet_implementation::processEvents(int timeout_ms_)
    8486{
    8587        if(!serverInitialized)
     
    117119}
    118120
    119 void ENet_implementation::sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_, bool autoFlush_ )
     121void dataIO_clusterENet_implementation::sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_, bool autoFlush_ )
    120122{
    121123        // are connected peers available?
    122124        if( peerList.size() == 0 )
    123125        {
    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;
    125127                return;
    126128        }
    127129
    128130        // Client
    129         if(currentRole == ENet_implementation::CLIENT)
     131        if(currentRole == dataIO_clusterENet_implementation::CLIENT)
    130132        {
    131133                enet_peer_send (peerList[0], channelID_, packet_);
     
    133135
    134136        // Server
    135         if(currentRole == ENet_implementation::SERVER)
     137        if(currentRole == dataIO_clusterENet_implementation::SERVER)
    136138        {
    137139                if(peerID_ < peerList.size())
    138140                        enet_peer_send (peerList[peerID_], channelID_, packet_);
    139141                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;
    141143        }
    142144
     
    145147}
    146148
    147 void ENet_implementation::sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_ )
     149void dataIO_clusterENet_implementation::sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_ )
    148150{
    149151                // are connected peers available?
    150152        if( peerList.size() == 0 )
    151153        {
    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;
    153155                return;
    154156        }
    155157
    156158        // Client
    157         if(currentRole == ENet_implementation::CLIENT)
     159        if(currentRole == dataIO_clusterENet_implementation::CLIENT)
    158160        {
    159161                enet_peer_send (peerList[0], channelID_, packet_);
     
    161163
    162164        // Server
    163         if(currentRole == ENet_implementation::SERVER)
     165        if(currentRole == dataIO_clusterENet_implementation::SERVER)
    164166        {
    165167                int peerID_=-1;
     
    175177                        enet_peer_send (peerList[peerID_], channelID_, packet_);
    176178                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;
    178180        }
    179181
     
    182184}
    183185
    184 void ENet_implementation::broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_ )
    185 {
    186         if(currentRole != ENet_implementation::SERVER)
     186void dataIO_clusterENet_implementation::broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_ )
     187{
     188        if(currentRole != dataIO_clusterENet_implementation::SERVER)
    187189                return;
    188190
     
    192194}
    193195
    194 bool ENet_implementation::connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_,  int channelToAlloc_ )
    195 {
    196         if(currentRole != ENet_implementation::CLIENT)
     196bool dataIO_clusterENet_implementation::connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_,  int channelToAlloc_ )
     197{
     198        if(currentRole != dataIO_clusterENet_implementation::CLIENT)
    197199                return false;
    198200
     
    235237}
    236238
    237 void ENet_implementation::onReceivePacket(ENetEvent* event_)
     239void dataIO_clusterENet_implementation::onReceivePacket(ENetEvent* event_)
    238240{
    239241                std::string datastring;
     
    250252}
    251253
    252 void ENet_implementation::onConnect(ENetEvent* event_)
     254void dataIO_clusterENet_implementation::onConnect(ENetEvent* event_)
    253255{
    254256        /* Get connect remote IP */
     
    266268}
    267269
    268 void ENet_implementation::onDisconnect(ENetEvent* event_)
     270void dataIO_clusterENet_implementation::onDisconnect(ENetEvent* event_)
    269271{
    270272        // remove peer pionter from peerList
     
    280282
    281283
    282         if(currentRole == ENet_implementation::SERVER)
     284        if(currentRole == dataIO_clusterENet_implementation::SERVER)
    283285        {
    284286                std::cout << "Client " << (char*)event_->peer->data << " disconnected." << std::endl;
     
    289291        }
    290292
    291         if(currentRole == ENet_implementation::CLIENT)
     293        if(currentRole == dataIO_clusterENet_implementation::CLIENT)
    292294        {
    293295                std::cout << "Server "<< (char*)event_->peer->data<<"disconnected." << std::endl;
Note: See TracChangeset for help on using the changeset viewer.