diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 88cfb9d1bf..b7132954e2 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -114,10 +114,10 @@ int main(int argc, const char* argv[]) { if (agentBuffer->getEndOfLastWrite()) { if (!agentBuffer->isStarted() && agentBuffer->diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + JITTER_BUFFER_SAMPLES) { - printf("Held back buffer for agent with ID %d.\n", agent->getAgentId()); + printf("Held back buffer for agent with ID %d.\n", agent->getAgentID()); agentBuffer->setShouldBeAddedToMix(false); } else if (agentBuffer->diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { - printf("Buffer from agent with ID %d starved.\n", agent->getAgentId()); + printf("Buffer from agent with ID %d starved.\n", agent->getAgentID()); agentBuffer->setStarted(false); agentBuffer->setShouldBeAddedToMix(false); } else { diff --git a/avatar-mixer/src/main.cpp b/avatar-mixer/src/main.cpp index 2f031a6f0a..1da884110c 100644 --- a/avatar-mixer/src/main.cpp +++ b/avatar-mixer/src/main.cpp @@ -37,7 +37,7 @@ const int AVATAR_LISTEN_PORT = 55444; unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { - currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); + currentPosition += packAgentId(currentPosition, agentToAdd->getAgentID()); AvatarData *agentData = (AvatarData *)agentToAdd->getLinkedData(); currentPosition += agentData->getBroadcastData(currentPosition); diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index be906e194d..0192eb9a37 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -50,7 +50,7 @@ int lastActiveCount = 0; unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) { *currentPosition++ = agentToAdd->getType(); - currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); + currentPosition += packAgentId(currentPosition, agentToAdd->getAgentID()); currentPosition += packSocket(currentPosition, agentToAdd->getPublicSocket()); currentPosition += packSocket(currentPosition, agentToAdd->getLocalSocket()); @@ -149,7 +149,7 @@ int main(int argc, const char * argv[]) agent->setLastHeardMicrostamp(timeNow); // grab the ID for this agent so we can send it back with the packet - packetAgentID = agent->getAgentId(); + packetAgentID = agent->getAgentID(); if (packetData[0] == PACKET_HEADER_DOMAIN_RFD && memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) { diff --git a/libraries/shared/src/Agent.cpp b/libraries/shared/src/Agent.cpp index acdce6a671..8feaae8547 100644 --- a/libraries/shared/src/Agent.cpp +++ b/libraries/shared/src/Agent.cpp @@ -32,69 +32,67 @@ int packAgentId(unsigned char *packStore, uint16_t agentId) { return sizeof(uint16_t); } -Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId) : +Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentID) : _isAlive(true) { - if (agentPublicSocket != NULL) { - publicSocket = new sockaddr; - memcpy(publicSocket, agentPublicSocket, sizeof(sockaddr)); + if (agentPublicSocket) { + _publicSocket = new sockaddr; + memcpy(_publicSocket, agentPublicSocket, sizeof(sockaddr)); } else { - publicSocket = NULL; + _publicSocket = NULL; } - if (agentLocalSocket != NULL) { - localSocket = new sockaddr; - memcpy(localSocket, agentLocalSocket, sizeof(sockaddr)); + if (agentLocalSocket) { + _localSocket = new sockaddr; + memcpy(_localSocket, agentLocalSocket, sizeof(sockaddr)); } else { - localSocket = NULL; + _localSocket = NULL; } - type = agentType; - agentId = thisAgentId; + _type = agentType; + _agentID = thisAgentID; _wakeMicrostamp = usecTimestampNow(); _lastHeardMicrostamp = usecTimestampNow(); - activeSocket = NULL; - linkedData = NULL; + _activeSocket = NULL; + _linkedData = NULL; _bytesReceivedMovingAverage = NULL; } Agent::Agent(const Agent &otherAgent) { _isAlive = otherAgent._isAlive; - if (otherAgent.publicSocket != NULL) { - publicSocket = new sockaddr; - memcpy(publicSocket, otherAgent.publicSocket, sizeof(sockaddr)); + if (otherAgent._publicSocket) { + _publicSocket = new sockaddr(*otherAgent._localSocket); } else { - publicSocket = NULL; + _publicSocket = NULL; } - if (otherAgent.localSocket != NULL) { - localSocket = new sockaddr; - memcpy(localSocket, otherAgent.localSocket, sizeof(sockaddr)); + if (otherAgent._localSocket) { + _localSocket = new sockaddr(*otherAgent._localSocket); } else { - localSocket = NULL; + _localSocket = NULL; } - agentId = otherAgent.agentId; + _agentID = otherAgent._agentID; - if (otherAgent.activeSocket == otherAgent.publicSocket) { - activeSocket = publicSocket; - } else if (otherAgent.activeSocket == otherAgent.localSocket) { - activeSocket = localSocket; + if (otherAgent._activeSocket == otherAgent._publicSocket) { + _activeSocket = _publicSocket; + } else if (otherAgent._activeSocket == otherAgent._localSocket) { + _activeSocket = _localSocket; } else { - activeSocket = NULL; + _activeSocket = NULL; } _wakeMicrostamp = otherAgent._wakeMicrostamp; _lastHeardMicrostamp = otherAgent._lastHeardMicrostamp; - type = otherAgent.type; + _type = otherAgent._type; - if (otherAgent.linkedData != NULL) { - linkedData = otherAgent.linkedData->clone(); + if (otherAgent._linkedData) { + _linkedData = otherAgent._linkedData->clone(); } else { - linkedData = NULL; + _linkedData = NULL; } if (otherAgent._bytesReceivedMovingAverage != NULL) { @@ -114,28 +112,24 @@ void Agent::swap(Agent &first, Agent &second) { using std::swap; swap(first._isAlive, second._isAlive); - swap(first.publicSocket, second.publicSocket); - swap(first.localSocket, second.localSocket); - swap(first.activeSocket, second.activeSocket); - swap(first.type, second.type); - swap(first.linkedData, second.linkedData); - swap(first.agentId, second.agentId); + swap(first._publicSocket, second._publicSocket); + swap(first._localSocket, second._localSocket); + swap(first._activeSocket, second._activeSocket); + swap(first._type, second._type); + swap(first._linkedData, second._linkedData); + swap(first._agentID, second._agentID); swap(first._wakeMicrostamp, second._wakeMicrostamp); swap(first._lastHeardMicrostamp, second._lastHeardMicrostamp); swap(first._bytesReceivedMovingAverage, second._bytesReceivedMovingAverage); } Agent::~Agent() { - delete publicSocket; - delete localSocket; - delete linkedData; + delete _publicSocket; + delete _localSocket; + delete _linkedData; delete _bytesReceivedMovingAverage; } -char Agent::getType() const { - return type; -} - // Names of Agent Types const char* AGENT_TYPE_NAME_DOMAIN = "Domain"; const char* AGENT_TYPE_NAME_VOXEL = "Voxel Server"; @@ -146,7 +140,7 @@ const char* AGENT_TYPE_NAME_AUDIO_INJECTOR = "Audio Injector"; const char* AGENT_TYPE_NAME_UNKNOWN = "Unknown"; const char* Agent::getTypeName() const { - switch (this->type) { + switch (this->_type) { case AGENT_TYPE_DOMAIN: return AGENT_TYPE_NAME_DOMAIN; case AGENT_TYPE_VOXEL: @@ -164,63 +158,23 @@ const char* Agent::getTypeName() const { } } -void Agent::setType(char newType) { - type = newType; -} - -uint16_t Agent::getAgentId() { - return agentId; -} - -void Agent::setAgentId(uint16_t thisAgentId) { - agentId = thisAgentId; -} - -sockaddr* Agent::getPublicSocket() { - return publicSocket; -} - -void Agent::setPublicSocket(sockaddr *newSocket) { - publicSocket = newSocket; -} - -sockaddr* Agent::getLocalSocket() { - return localSocket; -} - -void Agent::setLocalSocket(sockaddr *newSocket) { - publicSocket = newSocket; -} - -sockaddr* Agent::getActiveSocket() { - return activeSocket; -} - void Agent::activateLocalSocket() { - activeSocket = localSocket; + _activeSocket = _localSocket; } void Agent::activatePublicSocket() { - activeSocket = publicSocket; -} - -AgentData* Agent::getLinkedData() { - return linkedData; -} - -void Agent::setLinkedData(AgentData *newData) { - linkedData = newData; + _activeSocket = _publicSocket; } bool Agent::operator==(const Agent& otherAgent) { - return matches(otherAgent.publicSocket, otherAgent.localSocket, otherAgent.type); + return matches(otherAgent._publicSocket, otherAgent._localSocket, otherAgent._type); } bool Agent::matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, char otherAgentType) { // checks if two agent objects are the same agent (same type + local + public address) - return type == otherAgentType - && socketMatch(publicSocket, otherPublicSocket) - && socketMatch(localSocket, otherLocalSocket); + return _type == otherAgentType + && socketMatch(_publicSocket, otherPublicSocket) + && socketMatch(_localSocket, otherLocalSocket); } void Agent::recordBytesReceived(int bytesReceived) { @@ -250,15 +204,15 @@ float Agent::getAverageKilobitsPerSecond() { void Agent::printLog(Agent const& agent) { char publicAddressBuffer[16] = {'\0'}; - unsigned short publicAddressPort = loadBufferWithSocketInfo(publicAddressBuffer, agent.publicSocket); + unsigned short publicAddressPort = loadBufferWithSocketInfo(publicAddressBuffer, agent._publicSocket); //char localAddressBuffer[16] = {'\0'}; //unsigned short localAddressPort = loadBufferWithSocketInfo(localAddressBuffer, agent.localSocket); ::printLog("# %d %s (%c) @ %s:%d\n", - agent.agentId, + agent._agentID, agent.getTypeName(), - agent.type, + agent._type, publicAddressBuffer, publicAddressPort); } \ No newline at end of file diff --git a/libraries/shared/src/Agent.h b/libraries/shared/src/Agent.h index b611770593..2b33f3f999 100644 --- a/libraries/shared/src/Agent.h +++ b/libraries/shared/src/Agent.h @@ -23,7 +23,7 @@ class Agent { public: - Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId); + Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentID); Agent(const Agent &otherAgent); ~Agent(); Agent& operator=(Agent otherAgent); @@ -31,12 +31,12 @@ public: bool matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, char otherAgentType); - char getType() const; + char getType() const { return _type; } + void setType(char type) { _type = type; } const char* getTypeName() const; - void setType(char newType); - uint16_t getAgentId(); - void setAgentId(uint16_t thisAgentId); + uint16_t getAgentID() const { return _agentID; } + void setAgentID(uint16_t agentID) { _agentID = agentID;} double getWakeMicrostamp() const { return _wakeMicrostamp; } void setWakeMicrostamp(double wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; } @@ -44,17 +44,18 @@ public: double getLastHeardMicrostamp() const { return _lastHeardMicrostamp; } void setLastHeardMicrostamp(double lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; } - sockaddr* getPublicSocket(); - void setPublicSocket(sockaddr *newSocket); - sockaddr* getLocalSocket(); - void setLocalSocket(sockaddr *newSocket); - sockaddr* getActiveSocket(); + sockaddr* getPublicSocket() const { return _publicSocket; } + void setPublicSocket(sockaddr *publicSocket) { _publicSocket = publicSocket; } + sockaddr* getLocalSocket() const { return _localSocket; } + void setLocalSocket(sockaddr *localSocket) { _localSocket = localSocket; } + + sockaddr* getActiveSocket() const { return _activeSocket; } void activatePublicSocket(); void activateLocalSocket(); - AgentData* getLinkedData(); - void setLinkedData(AgentData *newData); + AgentData* getLinkedData() const { return _linkedData; } + void setLinkedData(AgentData *linkedData) { _linkedData = linkedData; } bool isAlive() const { return _isAlive; }; void setAlive(bool isAlive) { _isAlive = isAlive; }; @@ -67,13 +68,13 @@ public: private: void swap(Agent &first, Agent &second); - sockaddr *publicSocket, *localSocket, *activeSocket; - char type; - uint16_t agentId; + sockaddr* _publicSocket, *_localSocket, *_activeSocket; + char _type; + uint16_t _agentID; double _wakeMicrostamp; double _lastHeardMicrostamp; SimpleMovingAverage* _bytesReceivedMovingAverage; - AgentData* linkedData; + AgentData* _linkedData; bool _isAlive; }; diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 3bca0fa12b..40a9e41722 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -184,7 +184,7 @@ Agent* AgentList::agentWithAddress(sockaddr *senderAddress) { Agent* AgentList::agentWithID(uint16_t agentID) { for(AgentList::iterator agent = begin(); agent != end(); agent++) { - if (agent->getAgentId() == agentID) { + if (agent->getAgentID() == agentID) { return &(*agent); } }