From 9a514f56e5d2aa562f5c05a45d0e9997d36e988c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 19 Feb 2013 17:34:34 -0800 Subject: [PATCH] have AgentList control the required UDPSocket instance --- interface/src/main.cpp | 6 +++--- shared/src/AgentList.cpp | 8 ++++++++ shared/src/AgentList.h | 4 ++++ shared/src/AgentSocket.h | 2 -- shared/src/UDPSocket.h | 11 +---------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index d98292176c..1f1cba5e99 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -57,7 +57,7 @@ const int MAX_PACKET_SIZE = 1500; char DOMAIN_HOSTNAME[] = "highfidelity.below92.com"; char DOMAIN_IP[100] = ""; // IP Address will be used first if not empty string const int DOMAINSERVER_PORT = 40102; -UDPSocket agentSocket(AGENT_SOCKET_LISTEN_PORT); + AgentList agentList; // For testing, add milliseconds of delay for received UDP packets @@ -226,7 +226,7 @@ void Timer(int extra) sprintf(output, "%c %f,%f,%f,%s %hd", 'I', location[0], location[1], location[2], localAddressBuffer, AGENT_SOCKET_LISTEN_PORT); std::cout << "sending " << output << " to domain server\n"; int packet_size = strlen(output); - agentSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, output, packet_size); + agentList.getAgentSocket()->send(DOMAIN_IP, DOMAINSERVER_PORT, output, packet_size); // Ping the agents we can see // pingAgents(&agentSocket); @@ -765,7 +765,7 @@ void *networkReceive(void *args) sockaddr_in senderAddress; ssize_t bytesReceived; while (true) { - if (agentSocket.receive(&senderAddress, (void *)incomingPacket, &bytesReceived)) { + if (agentList.getAgentSocket()->receive(&senderAddress, (void *)incomingPacket, &bytesReceived)) { packetcount++; bytescount += bytesReceived; diff --git a/shared/src/AgentList.cpp b/shared/src/AgentList.cpp index 0e965e406d..3a4a9603ba 100644 --- a/shared/src/AgentList.cpp +++ b/shared/src/AgentList.cpp @@ -8,6 +8,14 @@ #include "AgentList.h" +AgentList::AgentList() : agentSocket(AGENT_SOCKET_LISTEN_PORT) { + +} + +UDPSocket * AgentList::getAgentSocket() { + return &agentSocket; +} + int AgentList::updateList(char *packetData) { int readAgents = 0; int scannedItems = 0; diff --git a/shared/src/AgentList.h b/shared/src/AgentList.h index 72b15ec9fe..d98da3ea4d 100644 --- a/shared/src/AgentList.h +++ b/shared/src/AgentList.h @@ -12,18 +12,22 @@ #include #include #include "Agent.h" +#include "UDPSocket.h" const unsigned short AGENT_SOCKET_LISTEN_PORT = 40103; class AgentList { public: + AgentList(); std::vector agents; int updateList(char *packetData); int processAgentData(char *address, unsigned short port, char *packetData, size_t dataBytes); int broadcastToAgents(char *broadcastData, size_t dataBytes, bool sendToSelf); void pingAgents(); + UDPSocket* getAgentSocket(); private: + UDPSocket agentSocket; int addAgent(AgentSocket *publicSocket, AgentSocket *localSocket, char agentType); int indexOfMatchingAgent(AgentSocket *publicSocket, AgentSocket *privateSocket, char agentType); diff --git a/shared/src/AgentSocket.h b/shared/src/AgentSocket.h index de828aec30..ee460977fe 100644 --- a/shared/src/AgentSocket.h +++ b/shared/src/AgentSocket.h @@ -17,8 +17,6 @@ class AgentSocket { AgentSocket(const AgentSocket &otherAgentSocket); AgentSocket& operator=(AgentSocket otherAgentSocket); ~AgentSocket(); - - char *address; unsigned short port; diff --git a/shared/src/UDPSocket.h b/shared/src/UDPSocket.h index 7acd6511d2..500b50c838 100644 --- a/shared/src/UDPSocket.h +++ b/shared/src/UDPSocket.h @@ -16,7 +16,7 @@ #define MAX_BUFFER_LENGTH_BYTES 1024 class UDPSocket { - public: + public: UDPSocket(int listening_port); ~UDPSocket(); int send(sockaddr_in *destAddress, const void *data, size_t byteLength); @@ -25,15 +25,6 @@ class UDPSocket { bool receive(sockaddr_in *recvAddress, void *receivedData, ssize_t *receivedBytes); private: int handle; - - UDPSocket(); // private default constructor - - struct AgentData { - char * address; - int listening_port; - }; - - AgentData *known_agents; }; #endif /* defined(__interface__UDPSocket__) */