From f333aaf8091ab4e9b5aaf74de659e5604d79a600 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 15 May 2013 14:16:15 -0700 Subject: [PATCH] refactor Agent constructor to call member variable constructors --- libraries/shared/src/Agent.cpp | 29 ++++++++++++----------------- libraries/shared/src/Agent.h | 6 ++++-- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/libraries/shared/src/Agent.cpp b/libraries/shared/src/Agent.cpp index 8feaae8547..c107eedbdc 100644 --- a/libraries/shared/src/Agent.cpp +++ b/libraries/shared/src/Agent.cpp @@ -32,32 +32,27 @@ 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 *publicSocket, sockaddr *localSocket, char type, uint16_t agentID) : + _type(type), + _agentID(agentID), + _wakeMicrostamp(usecTimestampNow()), + _lastHeardMicrostamp(usecTimestampNow()), + _activeSocket(NULL), + _bytesReceivedMovingAverage(NULL), + _linkedData(NULL), _isAlive(true) { - if (agentPublicSocket) { - _publicSocket = new sockaddr; - memcpy(_publicSocket, agentPublicSocket, sizeof(sockaddr)); + if (publicSocket) { + _publicSocket = new sockaddr(*publicSocket); } else { _publicSocket = NULL; } - if (agentLocalSocket) { - _localSocket = new sockaddr; - memcpy(_localSocket, agentLocalSocket, sizeof(sockaddr)); + if (localSocket) { + _localSocket = new sockaddr(*localSocket); } else { _localSocket = NULL; } - - _type = agentType; - _agentID = thisAgentID; - - _wakeMicrostamp = usecTimestampNow(); - _lastHeardMicrostamp = usecTimestampNow(); - - _activeSocket = NULL; - _linkedData = NULL; - _bytesReceivedMovingAverage = NULL; } Agent::Agent(const Agent &otherAgent) { diff --git a/libraries/shared/src/Agent.h b/libraries/shared/src/Agent.h index 2b33f3f999..94cba536b9 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 *publicSocket, sockaddr *localSocket, char type, uint16_t agentID); Agent(const Agent &otherAgent); ~Agent(); Agent& operator=(Agent otherAgent); @@ -68,11 +68,13 @@ public: private: void swap(Agent &first, Agent &second); - sockaddr* _publicSocket, *_localSocket, *_activeSocket; char _type; uint16_t _agentID; double _wakeMicrostamp; double _lastHeardMicrostamp; + sockaddr* _publicSocket; + sockaddr* _localSocket; + sockaddr* _activeSocket; SimpleMovingAverage* _bytesReceivedMovingAverage; AgentData* _linkedData; bool _isAlive;