mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:01:18 +02:00
refactor Agent constructor to call member variable constructors
This commit is contained in:
parent
48b57c92bd
commit
f333aaf809
2 changed files with 16 additions and 19 deletions
|
@ -32,32 +32,27 @@ int packAgentId(unsigned char *packStore, uint16_t agentId) {
|
||||||
return sizeof(uint16_t);
|
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)
|
_isAlive(true)
|
||||||
{
|
{
|
||||||
if (agentPublicSocket) {
|
if (publicSocket) {
|
||||||
_publicSocket = new sockaddr;
|
_publicSocket = new sockaddr(*publicSocket);
|
||||||
memcpy(_publicSocket, agentPublicSocket, sizeof(sockaddr));
|
|
||||||
} else {
|
} else {
|
||||||
_publicSocket = NULL;
|
_publicSocket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (agentLocalSocket) {
|
if (localSocket) {
|
||||||
_localSocket = new sockaddr;
|
_localSocket = new sockaddr(*localSocket);
|
||||||
memcpy(_localSocket, agentLocalSocket, sizeof(sockaddr));
|
|
||||||
} else {
|
} else {
|
||||||
_localSocket = NULL;
|
_localSocket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_type = agentType;
|
|
||||||
_agentID = thisAgentID;
|
|
||||||
|
|
||||||
_wakeMicrostamp = usecTimestampNow();
|
|
||||||
_lastHeardMicrostamp = usecTimestampNow();
|
|
||||||
|
|
||||||
_activeSocket = NULL;
|
|
||||||
_linkedData = NULL;
|
|
||||||
_bytesReceivedMovingAverage = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Agent::Agent(const Agent &otherAgent) {
|
Agent::Agent(const Agent &otherAgent) {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
class Agent {
|
class Agent {
|
||||||
public:
|
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(const Agent &otherAgent);
|
||||||
~Agent();
|
~Agent();
|
||||||
Agent& operator=(Agent otherAgent);
|
Agent& operator=(Agent otherAgent);
|
||||||
|
@ -68,11 +68,13 @@ public:
|
||||||
private:
|
private:
|
||||||
void swap(Agent &first, Agent &second);
|
void swap(Agent &first, Agent &second);
|
||||||
|
|
||||||
sockaddr* _publicSocket, *_localSocket, *_activeSocket;
|
|
||||||
char _type;
|
char _type;
|
||||||
uint16_t _agentID;
|
uint16_t _agentID;
|
||||||
double _wakeMicrostamp;
|
double _wakeMicrostamp;
|
||||||
double _lastHeardMicrostamp;
|
double _lastHeardMicrostamp;
|
||||||
|
sockaddr* _publicSocket;
|
||||||
|
sockaddr* _localSocket;
|
||||||
|
sockaddr* _activeSocket;
|
||||||
SimpleMovingAverage* _bytesReceivedMovingAverage;
|
SimpleMovingAverage* _bytesReceivedMovingAverage;
|
||||||
AgentData* _linkedData;
|
AgentData* _linkedData;
|
||||||
bool _isAlive;
|
bool _isAlive;
|
||||||
|
|
Loading…
Reference in a new issue