From b4a2214d264ab9127c199b4a6d648274e5dfcf2c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 22 Oct 2013 11:43:06 -0700 Subject: [PATCH] add notion of pool back to assignment --- assignment-client/src/main.cpp | 7 ++++- domain-server/src/DomainServer.cpp | 21 ++++++--------- libraries/shared/src/Assignment.cpp | 23 +++++++++++++++- libraries/shared/src/Assignment.h | 5 ++++ .../voxel-server-library/src/VoxelServer.cpp | 26 ------------------- .../voxel-server-library/src/VoxelServer.h | 5 +--- 6 files changed, 42 insertions(+), 45 deletions(-) diff --git a/assignment-client/src/main.cpp b/assignment-client/src/main.cpp index 7597ea47f5..83790f7eec 100644 --- a/assignment-client/src/main.cpp +++ b/assignment-client/src/main.cpp @@ -35,6 +35,7 @@ pid_t* childForks = NULL; sockaddr_in customAssignmentSocket = {}; int numForks = 0; Assignment::Type overiddenAssignmentType = Assignment::AllTypes; +QString assignmentPool = QString(); int argc = 0; char** argv = NULL; @@ -64,7 +65,7 @@ void childClient() { sockaddr_in senderSocket = {}; // create a request assignment, accept assignments defined by the overidden type - Assignment requestAssignment(Assignment::RequestCommand, ::overiddenAssignmentType); + Assignment requestAssignment(Assignment::RequestCommand, ::overiddenAssignmentType, ::assignmentPool); qDebug() << "Waiting for assignment -" << requestAssignment << "\n"; @@ -219,6 +220,10 @@ int main(int argc, char* argv[]) { // so set that as the ::overridenAssignmentType to be used in requests ::overiddenAssignmentType = (Assignment::Type) atoi(assignmentTypeString); } + + const char ASSIGNMENT_POOL_OPTION[] = "--pool"; + const char* assignmentPoolString = getCmdOption(argc, (const char**) argv, ASSIGNMENT_POOL_OPTION); + ::assignmentPool = QString(assignmentPoolString); const char* NUM_FORKS_PARAMETER = "-n"; const char* numForksString = getCmdOption(argc, (const char**)argv, NUM_FORKS_PARAMETER); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 565dfb9e2b..25f53a2977 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -173,7 +173,10 @@ const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment"; void DomainServer::civetwebUploadHandler(struct mg_connection *connection, const char *path) { // create an assignment for this saved script, for now make it local only - Assignment *scriptAssignment = new Assignment(Assignment::CreateCommand, Assignment::AgentType, Assignment::LocalLocation); + Assignment *scriptAssignment = new Assignment(Assignment::CreateCommand, + Assignment::AgentType, + QString(), + Assignment::LocalLocation); // check how many instances of this assignment the user wants by checking the ASSIGNMENT-INSTANCES header const char ASSIGNMENT_INSTANCES_HTTP_HEADER[] = "ASSIGNMENT-INSTANCES"; @@ -302,12 +305,8 @@ void DomainServer::prepopulateStaticAssignmentFile() { Assignment freshStaticAssignments[MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS]; // pre-populate the first static assignment list with assignments for root AuM, AvM, VS - freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand, - Assignment::AudioMixerType, - Assignment::LocalLocation); - freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand, - Assignment::AvatarMixerType, - Assignment::LocalLocation); + freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand, Assignment::AudioMixerType); + freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand, Assignment::AvatarMixerType); // Handle Domain/Voxel Server configuration command line arguments if (_voxelServerConfig) { @@ -323,9 +322,7 @@ void DomainServer::prepopulateStaticAssignmentFile() { qDebug("config[%d]=%s\n", i, config.toLocal8Bit().constData()); - Assignment voxelServerAssignment(Assignment::CreateCommand, - Assignment::VoxelServerType, - Assignment::LocalLocation); // use same location as we were created in. + Assignment voxelServerAssignment(Assignment::CreateCommand, Assignment::VoxelServerType); int payloadLength = config.length() + sizeof(char); voxelServerAssignment.setPayload((uchar*)config.toLocal8Bit().constData(), payloadLength); @@ -333,9 +330,7 @@ void DomainServer::prepopulateStaticAssignmentFile() { freshStaticAssignments[numFreshStaticAssignments++] = voxelServerAssignment; } } else { - Assignment rootVoxelServerAssignment(Assignment::CreateCommand, - Assignment::VoxelServerType, - Assignment::LocalLocation); + Assignment rootVoxelServerAssignment(Assignment::CreateCommand, Assignment::VoxelServerType); freshStaticAssignments[numFreshStaticAssignments++] = rootVoxelServerAssignment; } diff --git a/libraries/shared/src/Assignment.cpp b/libraries/shared/src/Assignment.cpp index 83f1e4087c..3f17c5a07d 100644 --- a/libraries/shared/src/Assignment.cpp +++ b/libraries/shared/src/Assignment.cpp @@ -36,6 +36,7 @@ Assignment::Assignment() : _uuid(), _command(Assignment::RequestCommand), _type(Assignment::AllTypes), + _pool(), _location(Assignment::LocalLocation), _numberOfInstances(1), _payload(), @@ -44,9 +45,10 @@ Assignment::Assignment() : } -Assignment::Assignment(Assignment::Command command, Assignment::Type type, Assignment::Location location) : +Assignment::Assignment(Assignment::Command command, Assignment::Type type, const QString& pool, Assignment::Location location) : _command(command), _type(type), + _pool(pool), _location(location), _numberOfInstances(1), _payload(), @@ -65,6 +67,7 @@ Assignment::Assignment(const Assignment& otherAssignment) { _command = otherAssignment._command; _type = otherAssignment._type; _location = otherAssignment._location; + _pool = otherAssignment._pool; _numberOfInstances = otherAssignment._numberOfInstances; setPayload(otherAssignment._payload, otherAssignment._numPayloadBytes); @@ -83,6 +86,7 @@ void Assignment::swap(Assignment& otherAssignment) { swap(_command, otherAssignment._command); swap(_type, otherAssignment._type); swap(_location, otherAssignment._location); + swap(_pool, otherAssignment._pool); swap(_numberOfInstances, otherAssignment._numberOfInstances); for (int i = 0; i < MAX_PAYLOAD_BYTES; i++) { @@ -118,6 +122,14 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) : _uuid = QUuid::fromRfc4122(QByteArray((const char*) dataBuffer + numBytesRead, NUM_BYTES_RFC4122_UUID)); numBytesRead += NUM_BYTES_RFC4122_UUID; } + + if (dataBuffer[numBytesRead] != '\0') { + // read the pool from the data buffer + _pool = QString((char*) dataBuffer + numBytesRead); + } else { + // skip past the null pool + numBytesRead++; + } if (numBytes > numBytesRead) { setPayload(dataBuffer + numBytesRead, numBytes - numBytesRead); @@ -167,6 +179,15 @@ int Assignment::packToBuffer(unsigned char* buffer) { numPackedBytes += NUM_BYTES_RFC4122_UUID; } + if (!_pool.isEmpty()) { + // pack the pool for this assignment, it exists + memcpy(buffer + numPackedBytes, _pool.toLocal8Bit().constData(), _pool.toLocal8Bit().size()); + numPackedBytes += _pool.toLocal8Bit().size(); + } else { + // otherwise pack the null character + buffer[numPackedBytes++] = '\0'; + } + if (_numPayloadBytes) { memcpy(buffer + numPackedBytes, _payload, _numPayloadBytes); numPackedBytes += _numPayloadBytes; diff --git a/libraries/shared/src/Assignment.h b/libraries/shared/src/Assignment.h index 749622db46..34ba4a9856 100644 --- a/libraries/shared/src/Assignment.h +++ b/libraries/shared/src/Assignment.h @@ -46,6 +46,7 @@ public: Assignment(); Assignment(Assignment::Command command, Assignment::Type type, + const QString& pool = QString(), Assignment::Location location = Assignment::LocalLocation); Assignment(const Assignment& otherAssignment); Assignment& operator=(const Assignment &rhsAssignment); @@ -69,6 +70,9 @@ public: int getNumPayloadBytes() const { return _numPayloadBytes; } void setPayload(const uchar *payload, int numBytes); + void setPool(const QString& pool) { _pool = pool; } + const QString& getPool() const { return _pool; } + int getNumberOfInstances() const { return _numberOfInstances; } void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; } void decrementNumberOfInstances() { --_numberOfInstances; } @@ -94,6 +98,7 @@ protected: QUuid _uuid; /// the 16 byte UUID for this assignment Assignment::Command _command; /// the command for this assignment (Create, Deploy, Request) Assignment::Type _type; /// the type of the assignment, defines what the assignee will do + QString _pool; /// the destination pool for this assignment Assignment::Location _location; /// the location of the assignment, allows a domain to preferentially use local ACs int _numberOfInstances; /// the number of instances of this assignment uchar _payload[MAX_PAYLOAD_BYTES]; /// an optional payload attached to this assignment, a maximum for 1024 bytes will be packed diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index 3bacfd8462..772bad3f41 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -51,32 +51,6 @@ void attachVoxelNodeDataToNode(Node* newNode) { VoxelServer* VoxelServer::_theInstance = NULL; -VoxelServer::VoxelServer(Assignment::Command command, Assignment::Location location) : - Assignment(command, Assignment::VoxelServerType, location), - _serverTree(true) { - _argc = 0; - _argv = NULL; - - _packetsPerClientPerInterval = 10; - _wantVoxelPersist = true; - _wantLocalDomain = false; - _debugVoxelSending = false; - _shouldShowAnimationDebug = false; - _displayVoxelStats = false; - _debugVoxelReceiving = false; - _sendEnvironments = true; - _sendMinimalEnvironment = false; - _dumpVoxelsOnMove = false; - _jurisdiction = NULL; - _jurisdictionSender = NULL; - _voxelServerPacketProcessor = NULL; - _voxelPersistThread = NULL; - _parsedArgV = NULL; - - _theInstance = this; -} - - VoxelServer::VoxelServer(const unsigned char* dataBuffer, int numBytes) : Assignment(dataBuffer, numBytes), _serverTree(true) { _argc = 0; diff --git a/libraries/voxel-server-library/src/VoxelServer.h b/libraries/voxel-server-library/src/VoxelServer.h index 282943e28d..81bc68b03d 100644 --- a/libraries/voxel-server-library/src/VoxelServer.h +++ b/libraries/voxel-server-library/src/VoxelServer.h @@ -26,10 +26,7 @@ /// Handles assignments of type VoxelServer - sending voxels to various clients. class VoxelServer : public Assignment { -public: - VoxelServer(Assignment::Command command, - Assignment::Location location = Assignment::GlobalLocation); - +public: VoxelServer(const unsigned char* dataBuffer, int numBytes); ~VoxelServer();