- Timestamp:
- Dec 28, 2010, 4:46:42 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network6/src/libraries/network/Connection.h
r7801 r7823 44 44 45 45 #include <deque> 46 #include <map> 46 47 #include <enet/enet.h> 48 #include <boost/concept_check.hpp> 47 49 48 50 namespace boost … … 59 61 const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5; 60 62 63 namespace incomingEventType 64 { 65 enum Value 66 { 67 receivePacket = 1, // incoming packet 68 peerConnect = 2, // incoming connect request 69 peerDisconnect = 3 // incoming disconnect request 70 }; 71 72 } 73 61 74 namespace outgoingEventType 62 75 { 63 76 enum Value 64 77 { 65 sendPacket = 1, 66 disconnectPeer = 2, 67 broadcastPacket = 3 78 sendPacket = 1, // outgoing packet 79 broadcastPacket = 2, // outgoing broadcast packet 80 disconnectPeer = 3, // outgoing disconnect request 81 disconnectPeers = 4 // outgoing disconnect request 68 82 }; 69 83 70 84 } 71 85 86 struct _NetworkExport incomingEvent 87 { 88 uint32_t peerID; 89 incomingEventType::Value type; 90 packet::Packet* packet; 91 }; 92 72 93 struct _NetworkExport outgoingEvent 73 94 { 74 ENetPeer* peer;95 uint32_t peerID; 75 96 outgoingEventType::Value type; 76 97 ENetPacket* packet; … … 83 104 virtual ~Connection(); 84 105 85 void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);86 void broadcastPacket(ENetPacket* packet, uint8_t channelID);87 // ENetHost* getHost(){ return this->host_; }88 89 106 protected: 90 107 Connection(); 91 // static Connection* getInstance(){ return Connection::instance_; } 92 93 // int service(ENetEvent* event); 108 94 109 void startCommunicationThread(); 95 110 void stopCommunicationThread(); 96 void communicationThread(); 97 virtual void disconnectPeer(ENetPeer *peer); 111 112 void addPacket(ENetPacket *packet, uint32_t peerID, uint8_t channelID); 113 void broadcastPacket(ENetPacket* packet, uint8_t channelID); 114 void disconnectPeer(uint32_t peerID); 115 void disconnectPeers(); 98 116 99 117 void enableCompression(); 100 118 101 119 void processQueue(); 102 virtual void addPeer( ENetEvent* event)=0;103 virtual void removePeer( ENetEvent* event)=0;120 virtual void addPeer(uint32_t peerID)=0; 121 virtual void removePeer(uint32_t peerID)=0; 104 122 virtual void processPacket( packet::Packet* packet)=0; 105 virtual packet::Packet* createPacket(ENetEvent* event); 123 124 incomingEvent preprocessConnectEvent(ENetEvent& event); 125 incomingEvent preprocessDisconnectEvent(ENetEvent& event); 126 incomingEvent preprocessReceiveEvent(ENetEvent& event); 127 128 void processIncomingEvent(ENetEvent& event); 129 void processOutgoingEvent(outgoingEvent& event); 106 130 107 ENetHost* host_;131 ENetHost* host_; 108 132 private: 109 boost::thread* communicationThread_; 110 bool bCommunicationThreadRunning_; 111 ENetAddress* bindAddress_; 112 std::deque<ENetEvent> incomingEvents_; 113 std::deque<outgoingEvent> outgoingEvents_; 114 boost::mutex* incomingEventsMutex_; 115 boost::mutex* outgoingEventsMutex_; 133 void communicationThread(); 134 135 boost::thread* communicationThread_; 136 bool bCommunicationThreadRunning_; 137 ENetAddress* bindAddress_; 138 std::deque<incomingEvent> incomingEvents_; 139 std::deque<outgoingEvent> outgoingEvents_; 140 boost::mutex* incomingEventsMutex_; 141 boost::mutex* outgoingEventsMutex_; 142 std::map<uint32_t, ENetPeer*> peerMap_; 143 std::map<ENetPeer*, uint32_t> peerIDMap_; 144 uint32_t nextPeerID_; 116 145 117 146 // static Connection *instance_;
Note: See TracChangeset
for help on using the changeset viewer.