fixes to payload in Assignment

This commit is contained in:
Stephen Birarda 2013-09-18 10:19:45 -07:00
parent b6548303d1
commit 3fde2887a3
3 changed files with 9 additions and 6 deletions

View file

@ -167,7 +167,7 @@ int main(int argc, const char* argv[]) {
if (voxelServerConfig) {
qDebug("Reading Voxel Server Configuration.\n");
qDebug() << " config: " << voxelServerConfig << "\n";
voxelServerAssignment.setPayload((uchar*)voxelServerConfig, strlen(voxelServerConfig) + 1);
voxelServerAssignment.copyPayload((uchar*)voxelServerConfig, strlen(voxelServerConfig) + 1);
}
// construct a local socket to send with our created assignments to the global AS

View file

@ -88,21 +88,21 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
if (numBytes > numBytesRead) {
_numPayloadBytes = numBytes - numBytesRead;
memcpy(_payload, dataBuffer + numBytesRead, numBytes - numBytesRead);
_payload = new uchar[_numPayloadBytes];
memcpy(_payload, dataBuffer + numBytesRead, _numPayloadBytes);
}
}
Assignment::~Assignment() {
delete _attachedPublicSocket;
delete _attachedLocalSocket;
delete _payload;
delete[] _payload;
_numPayloadBytes = 0;
}
const int MAX_PAYLOAD_BYTES = 1024;
void Assignment::setPayload(uchar* payload, int numBytes) {
_payload = payload;
void Assignment::copyPayload(uchar* payload, int numBytes) {
if (numBytes > MAX_PAYLOAD_BYTES) {
qDebug("Set payload called with number of bytes greater than maximum (%d). Will only transfer %d bytes.\n",
@ -114,6 +114,9 @@ void Assignment::setPayload(uchar* payload, int numBytes) {
_numPayloadBytes = numBytes;
}
delete[] _payload;
_payload = new uchar[_numPayloadBytes];
memcpy(_payload, payload, _numPayloadBytes);
}
QString Assignment::getUUIDStringWithoutCurlyBraces() const {

View file

@ -61,7 +61,7 @@ public:
uchar* getPayload() { return _payload; }
int getNumPayloadBytes() const { return _numPayloadBytes; }
void setPayload(uchar *payload, int numBytes);
void copyPayload(uchar *payload, int numBytes);
int getNumberOfInstances() const { return _numberOfInstances; }
void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; }