#pragma once /* -*-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 #include #include #include #include namespace osgVisual { class dataIO_clusterENet_implementation : public osg::Referenced { public: dataIO_clusterENet_implementation(); ~dataIO_clusterENet_implementation(); enum role {SERVER, CLIENT}; 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 bool connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_=0, int channelToAlloc_=2 ); // only as client // Done void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_=0, bool autoFlush_=false ); // by PeerID // Done void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_=false ); // by peer name // Done void broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_=false ); // only as server. // Done void processEvents( int timeout_ms_ = 0 ); // Done virtual inline void onReceivePacket(ENetEvent* event_); virtual inline void onConnect(ENetEvent* event_); // This function will be called only by the host waiting for the connection. virtual inline void onDisconnect(ENetEvent* event_); protected: unsigned short port; dataIO_clusterENet_implementation::role currentRole; static int activeENetInstances; bool serverInitialized; // shows if the complete server is initialized. (After init()) ENetAddress address; ENetHost* host; std::vector peerList; // client: only one peer to server, Server: multiple peers for all clients ENetEvent event; }; } // END NAMESPACE