mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
disallow Agent copying
This commit is contained in:
parent
2c17f04d40
commit
12bf23e4c8
3 changed files with 7 additions and 68 deletions
|
@ -55,67 +55,6 @@ Agent::Agent(sockaddr* publicSocket, sockaddr* localSocket, char type, uint16_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Agent::Agent(const Agent &otherAgent) :
|
|
||||||
_type(otherAgent._type),
|
|
||||||
_agentID(otherAgent._agentID),
|
|
||||||
_wakeMicrostamp(otherAgent._wakeMicrostamp),
|
|
||||||
_lastHeardMicrostamp(otherAgent._lastHeardMicrostamp),
|
|
||||||
_isAlive(otherAgent._isAlive)
|
|
||||||
{
|
|
||||||
if (otherAgent._publicSocket) {
|
|
||||||
_publicSocket = new sockaddr(*otherAgent._localSocket);
|
|
||||||
} else {
|
|
||||||
_publicSocket = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (otherAgent._localSocket) {
|
|
||||||
_localSocket = new sockaddr(*otherAgent._localSocket);
|
|
||||||
} else {
|
|
||||||
_localSocket = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (otherAgent._activeSocket == otherAgent._publicSocket) {
|
|
||||||
_activeSocket = _publicSocket;
|
|
||||||
} else if (otherAgent._activeSocket == otherAgent._localSocket) {
|
|
||||||
_activeSocket = _localSocket;
|
|
||||||
} else {
|
|
||||||
_activeSocket = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (otherAgent._linkedData) {
|
|
||||||
_linkedData = otherAgent._linkedData->clone();
|
|
||||||
} else {
|
|
||||||
_linkedData = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (otherAgent._bytesReceivedMovingAverage != NULL) {
|
|
||||||
_bytesReceivedMovingAverage = new SimpleMovingAverage(100);
|
|
||||||
memcpy(_bytesReceivedMovingAverage, otherAgent._bytesReceivedMovingAverage, sizeof(SimpleMovingAverage));
|
|
||||||
} else {
|
|
||||||
_bytesReceivedMovingAverage = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Agent& Agent::operator=(Agent otherAgent) {
|
|
||||||
swap(*this, otherAgent);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
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._wakeMicrostamp, second._wakeMicrostamp);
|
|
||||||
swap(first._lastHeardMicrostamp, second._lastHeardMicrostamp);
|
|
||||||
swap(first._bytesReceivedMovingAverage, second._bytesReceivedMovingAverage);
|
|
||||||
}
|
|
||||||
|
|
||||||
Agent::~Agent() {
|
Agent::~Agent() {
|
||||||
delete _publicSocket;
|
delete _publicSocket;
|
||||||
delete _localSocket;
|
delete _localSocket;
|
||||||
|
|
|
@ -24,9 +24,8 @@
|
||||||
class Agent {
|
class Agent {
|
||||||
public:
|
public:
|
||||||
Agent(sockaddr* publicSocket, sockaddr* localSocket, char type, uint16_t agentID);
|
Agent(sockaddr* publicSocket, sockaddr* localSocket, char type, uint16_t agentID);
|
||||||
Agent(const Agent &otherAgent);
|
|
||||||
~Agent();
|
~Agent();
|
||||||
Agent& operator=(Agent otherAgent);
|
|
||||||
bool operator==(const Agent& otherAgent);
|
bool operator==(const Agent& otherAgent);
|
||||||
|
|
||||||
bool matches(sockaddr* otherPublicSocket, sockaddr* otherLocalSocket, char otherAgentType);
|
bool matches(sockaddr* otherPublicSocket, sockaddr* otherLocalSocket, char otherAgentType);
|
||||||
|
@ -66,7 +65,9 @@ public:
|
||||||
|
|
||||||
static void printLog(Agent const&);
|
static void printLog(Agent const&);
|
||||||
private:
|
private:
|
||||||
void swap(Agent &first, Agent &second);
|
// privatize copy and assignment operator to disallow Agent copying
|
||||||
|
Agent(const Agent &otherAgent);
|
||||||
|
Agent& operator=(Agent otherAgent);
|
||||||
|
|
||||||
char _type;
|
char _type;
|
||||||
uint16_t _agentID;
|
uint16_t _agentID;
|
||||||
|
|
|
@ -10,10 +10,9 @@
|
||||||
#define hifi_AgentData_h
|
#define hifi_AgentData_h
|
||||||
|
|
||||||
class AgentData {
|
class AgentData {
|
||||||
public:
|
public:
|
||||||
virtual ~AgentData() = 0;
|
virtual ~AgentData() = 0;
|
||||||
virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0;
|
virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0;
|
||||||
virtual AgentData* clone() const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue