[65] | 1 | #pragma once |
---|
[68] | 2 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer |
---|
| 3 | * |
---|
| 4 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
| 5 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
| 6 | * (at your option) any later version. The full license is in LICENSE file |
---|
| 7 | * included with this distribution, and on the openscenegraph.org website. |
---|
| 8 | * |
---|
| 9 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
| 10 | * You have to aquire licenses for all used proprietary modules. |
---|
| 11 | * |
---|
| 12 | * This library is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * OpenSceneGraph Public License for more details. |
---|
| 16 | */ |
---|
[65] | 17 | |
---|
[68] | 18 | |
---|
[66] | 19 | #include <osg/referenced> |
---|
[65] | 20 | #include <enet/enet.h> |
---|
| 21 | #include <iostream> |
---|
| 22 | #include <string> |
---|
| 23 | #include <vector> |
---|
| 24 | |
---|
[66] | 25 | namespace osgVisual |
---|
| 26 | { |
---|
[65] | 27 | |
---|
[66] | 28 | class dataIO_clusterENet_implementation : public osg::Referenced |
---|
[65] | 29 | { |
---|
| 30 | public: |
---|
[69] | 31 | dataIO_clusterENet_implementation(std::string& receivedTransportContainer_); |
---|
[66] | 32 | ~dataIO_clusterENet_implementation(); |
---|
[65] | 33 | |
---|
| 34 | enum role {SERVER, CLIENT}; |
---|
| 35 | |
---|
[66] | 36 | 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 |
---|
[65] | 37 | bool connectTo( const char* remoteAddr_, int connectTimeout_ms_, int clientInfo_=0, int channelToAlloc_=2 ); // only as client // Done |
---|
| 38 | void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, unsigned int peerID_=0, bool autoFlush_=false ); // by PeerID // Done |
---|
| 39 | void sendPacket( ENetPacket* packet_, enet_uint8 channelID_, std::string peerName_, bool autoFlush_=false ); // by peer name // Done |
---|
| 40 | void broadcastPacket( enet_uint8 channelID_, ENetPacket* packet_, bool autoFlush_=false ); // only as server. // Done |
---|
| 41 | void processEvents( int timeout_ms_ = 0 ); // Done |
---|
| 42 | |
---|
| 43 | virtual inline void onReceivePacket(ENetEvent* event_); |
---|
| 44 | virtual inline void onConnect(ENetEvent* event_); // This function will be called only by the host waiting for the connection. |
---|
| 45 | virtual inline void onDisconnect(ENetEvent* event_); |
---|
| 46 | |
---|
| 47 | protected: |
---|
| 48 | unsigned short port; |
---|
[66] | 49 | dataIO_clusterENet_implementation::role currentRole; |
---|
[65] | 50 | static int activeENetInstances; |
---|
| 51 | bool serverInitialized; // shows if the complete server is initialized. (After init()) |
---|
| 52 | ENetAddress address; |
---|
| 53 | ENetHost* host; |
---|
| 54 | std::vector<ENetPeer*> peerList; // client: only one peer to server, Server: multiple peers for all clients |
---|
| 55 | ENetEvent event; |
---|
[69] | 56 | std::string& receivedTransportContainer; |
---|
[66] | 57 | }; |
---|
| 58 | |
---|
| 59 | } // END NAMESPACE |
---|