mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 20:23:06 +02:00
Merge branch 'master' of https://github.com/worklist/hifi into multi_VS_assigments
This commit is contained in:
commit
25d9281496
2 changed files with 50 additions and 14 deletions
|
@ -22,7 +22,9 @@ Assignment::Assignment(Assignment::Command command, Assignment::Type type, Assig
|
||||||
_location(location),
|
_location(location),
|
||||||
_attachedPublicSocket(NULL),
|
_attachedPublicSocket(NULL),
|
||||||
_attachedLocalSocket(NULL),
|
_attachedLocalSocket(NULL),
|
||||||
_numberOfInstances(1)
|
_numberOfInstances(1),
|
||||||
|
_payload(NULL),
|
||||||
|
_numPayloadBytes(0)
|
||||||
{
|
{
|
||||||
// set the create time on this assignment
|
// set the create time on this assignment
|
||||||
gettimeofday(&_time, NULL);
|
gettimeofday(&_time, NULL);
|
||||||
|
@ -37,7 +39,9 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
||||||
_location(GlobalLocation),
|
_location(GlobalLocation),
|
||||||
_attachedPublicSocket(NULL),
|
_attachedPublicSocket(NULL),
|
||||||
_attachedLocalSocket(NULL),
|
_attachedLocalSocket(NULL),
|
||||||
_numberOfInstances(1)
|
_numberOfInstances(1),
|
||||||
|
_payload(NULL),
|
||||||
|
_numPayloadBytes(0)
|
||||||
{
|
{
|
||||||
// set the create time on this assignment
|
// set the create time on this assignment
|
||||||
gettimeofday(&_time, NULL);
|
gettimeofday(&_time, NULL);
|
||||||
|
@ -63,32 +67,55 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
||||||
memcpy(&_type, dataBuffer + numBytesRead, sizeof(Assignment::Type));
|
memcpy(&_type, dataBuffer + numBytesRead, sizeof(Assignment::Type));
|
||||||
numBytesRead += sizeof(Assignment::Type);
|
numBytesRead += sizeof(Assignment::Type);
|
||||||
|
|
||||||
if (numBytes > numBytesRead) {
|
if (_command != Assignment::RequestCommand) {
|
||||||
|
|
||||||
sockaddr* newSocket = NULL;
|
sockaddr* newSocket = NULL;
|
||||||
|
|
||||||
if (dataBuffer[numBytesRead++] == IPv4_ADDRESS_DESIGNATOR) {
|
if (dataBuffer[numBytesRead++] == IPv4_ADDRESS_DESIGNATOR) {
|
||||||
// IPv4 address
|
// IPv4 address
|
||||||
newSocket = (sockaddr*) new sockaddr_in;
|
newSocket = (sockaddr*) new sockaddr_in;
|
||||||
unpackSocket(dataBuffer + numBytesRead, newSocket);
|
numBytesRead += unpackSocket(dataBuffer + numBytesRead, newSocket);
|
||||||
|
|
||||||
|
if (_command == Assignment::CreateCommand) {
|
||||||
|
delete _attachedLocalSocket;
|
||||||
|
_attachedLocalSocket = newSocket;
|
||||||
|
} else {
|
||||||
|
delete _attachedPublicSocket;
|
||||||
|
_attachedPublicSocket = newSocket;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// IPv6 address, or bad designator
|
// IPv6 address, or bad designator
|
||||||
qDebug("Received a socket that cannot be unpacked!\n");
|
qDebug("Received a socket that cannot be unpacked!\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (_command == Assignment::CreateCommand) {
|
|
||||||
delete _attachedLocalSocket;
|
if (numBytes > numBytesRead) {
|
||||||
_attachedLocalSocket = newSocket;
|
_numPayloadBytes = numBytes - numBytesRead;
|
||||||
} else {
|
memcpy(_payload, dataBuffer + numBytesRead, numBytes - numBytesRead);
|
||||||
delete _attachedPublicSocket;
|
|
||||||
_attachedPublicSocket = newSocket;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assignment::~Assignment() {
|
Assignment::~Assignment() {
|
||||||
delete _attachedPublicSocket;
|
delete _attachedPublicSocket;
|
||||||
delete _attachedLocalSocket;
|
delete _attachedLocalSocket;
|
||||||
|
delete _payload;
|
||||||
|
_numPayloadBytes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int MAX_PAYLOAD_BYTES = 1024;
|
||||||
|
|
||||||
|
void Assignment::setPayload(uchar* payload, int numBytes) {
|
||||||
|
_payload = payload;
|
||||||
|
|
||||||
|
if (numBytes > MAX_PAYLOAD_BYTES) {
|
||||||
|
qDebug("Set payload called with number of bytes greater than maximum (%d). Will only transfer %d bytes.\n",
|
||||||
|
MAX_PAYLOAD_BYTES,
|
||||||
|
MAX_PAYLOAD_BYTES);
|
||||||
|
|
||||||
|
_numPayloadBytes = 1024;
|
||||||
|
} else {
|
||||||
|
_numPayloadBytes = numBytes;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Assignment::getUUIDStringWithoutCurlyBraces() const {
|
QString Assignment::getUUIDStringWithoutCurlyBraces() const {
|
||||||
|
@ -140,7 +167,10 @@ int Assignment::packToBuffer(unsigned char* buffer) {
|
||||||
|
|
||||||
numPackedBytes += packSocket(buffer + numPackedBytes, socketToPack);
|
numPackedBytes += packSocket(buffer + numPackedBytes, socketToPack);
|
||||||
}
|
}
|
||||||
|
if (_numPayloadBytes) {
|
||||||
|
memcpy(buffer + numPackedBytes, _payload, _numPayloadBytes);
|
||||||
|
numPackedBytes += _numPayloadBytes;
|
||||||
|
}
|
||||||
return numPackedBytes;
|
return numPackedBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,10 @@ public:
|
||||||
Assignment::Location getLocation() const { return _location; }
|
Assignment::Location getLocation() const { return _location; }
|
||||||
const timeval& getTime() const { return _time; }
|
const timeval& getTime() const { return _time; }
|
||||||
|
|
||||||
|
uchar* getPayload() { return _payload; }
|
||||||
|
int getNumPayloadBytes() const { return _numPayloadBytes; }
|
||||||
|
void setPayload(uchar *payload, int numBytes);
|
||||||
|
|
||||||
int getNumberOfInstances() const { return _numberOfInstances; }
|
int getNumberOfInstances() const { return _numberOfInstances; }
|
||||||
void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; }
|
void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; }
|
||||||
void decrementNumberOfInstances() { --_numberOfInstances; }
|
void decrementNumberOfInstances() { --_numberOfInstances; }
|
||||||
|
@ -83,6 +87,8 @@ private:
|
||||||
sockaddr* _attachedLocalSocket; /// pointer to a local socket that relates to assignment, depends on direction
|
sockaddr* _attachedLocalSocket; /// pointer to a local socket that relates to assignment, depends on direction
|
||||||
timeval _time; /// time the assignment was created (set in constructor)
|
timeval _time; /// time the assignment was created (set in constructor)
|
||||||
int _numberOfInstances; /// the number of instances of this assignment
|
int _numberOfInstances; /// the number of instances of this assignment
|
||||||
|
uchar *_payload; /// an optional payload attached to this assignment, a maximum for 1024 bytes will be packed
|
||||||
|
int _numPayloadBytes; /// number of bytes in the payload, up to a maximum of 1024
|
||||||
};
|
};
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const Assignment &assignment);
|
QDebug operator<<(QDebug debug, const Assignment &assignment);
|
||||||
|
|
Loading…
Reference in a new issue