From 94f7b98a5c537f65b11fd960008b0ccbee1bd7f9 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 30 Sep 2013 14:27:54 -0700 Subject: [PATCH] handle mutli-VS config in DS when creating static file --- domain-server/src/DomainServer.cpp | 49 ++++++++++++------ domain-server/src/DomainServer.h | 1 - .../voxel-server-library/src/VoxelServer.cpp | 50 ++----------------- .../voxel-server-library/src/VoxelServer.h | 2 - 4 files changed, 37 insertions(+), 65 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index e322513f74..3336540cc7 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -8,6 +8,8 @@ #include +#include + #include #include @@ -160,36 +162,53 @@ DomainServer::DomainServer(int argc, char* argv[]) : } void DomainServer::prepopulateStaticAssignmentFile() { - const uint NUM_FRESH_STATIC_ASSIGNMENTS = 3; + int numFreshStaticAssignments = 0; // write a fresh static assignment array to file - Assignment freshStaticAssignments[NUM_FRESH_STATIC_ASSIGNMENTS]; + Assignment freshStaticAssignments[MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS]; // pre-populate the first static assignment list with assignments for root AuM, AvM, VS - freshStaticAssignments[0] = Assignment(Assignment::CreateCommand, + freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand, Assignment::AudioMixerType, Assignment::LocalLocation); - freshStaticAssignments[1] = Assignment(Assignment::CreateCommand, + freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand, Assignment::AvatarMixerType, Assignment::LocalLocation); - Assignment voxelServerAssignment(Assignment::CreateCommand, Assignment::VoxelServerType, Assignment::LocalLocation); - // Handle Domain/Voxel Server configuration command line arguments if (_voxelServerConfig) { qDebug("Reading Voxel Server Configuration.\n"); - qDebug() << " config: " << _voxelServerConfig << "\n"; - int payloadLength = strlen(_voxelServerConfig) + sizeof(char); - voxelServerAssignment.setPayload((const uchar*)_voxelServerConfig, payloadLength); + qDebug() << "config: " << _voxelServerConfig << "\n"; + + QString multiConfig((const char*) _voxelServerConfig); + QStringList multiConfigList = multiConfig.split(";"); + + // read each config to a payload for a VS assignment + for (int i = 0; i < multiConfigList.size(); i++) { + QString config = multiConfigList.at(i); + + 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. + + int payloadLength = config.length() + sizeof(char); + voxelServerAssignment.setPayload((uchar*)config.toLocal8Bit().constData(), payloadLength); + + freshStaticAssignments[numFreshStaticAssignments++] = voxelServerAssignment; + } + } else { + Assignment rootVoxelServerAssignment(Assignment::CreateCommand, + Assignment::VoxelServerType, + Assignment::LocalLocation); + freshStaticAssignments[numFreshStaticAssignments++] = rootVoxelServerAssignment; } - freshStaticAssignments[2] = voxelServerAssignment; + qDebug() << "Adding" << numFreshStaticAssignments << "static assignments to fresh file.\n"; _staticAssignmentFile.open(QIODevice::WriteOnly); - - _staticAssignmentFile.write((char*) &NUM_FRESH_STATIC_ASSIGNMENTS, - sizeof(uint16_t)); _staticAssignmentFile.write((char*) &freshStaticAssignments, sizeof(freshStaticAssignments)); _staticAssignmentFile.resize(MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS * sizeof(Assignment)); _staticAssignmentFile.close(); @@ -360,9 +379,7 @@ int DomainServer::run() { _staticAssignmentFileData = _staticAssignmentFile.map(0, _staticAssignmentFile.size()); - _numAssignmentsInStaticFile = (uint16_t*) _staticAssignmentFileData; - _staticAssignments = (Assignment*) - (_staticAssignmentFileData + sizeof(*_numAssignmentsInStaticFile)); + _staticAssignments = (Assignment*) _staticAssignmentFileData; timeval startTime; gettimeofday(&startTime, NULL); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 0292fb7a36..5ecf00e843 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -57,7 +57,6 @@ private: QFile _staticAssignmentFile; uchar* _staticAssignmentFileData; - uint16_t* _numAssignmentsInStaticFile; Assignment* _staticAssignments; const char* _voxelServerConfig; diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index c53d63f770..22ddec1627 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -49,8 +49,7 @@ void attachVoxelNodeDataToNode(Node* newNode) { VoxelServer::VoxelServer(Assignment::Command command, Assignment::Location location) : Assignment(command, Assignment::VoxelServerType, location), - _serverTree(true), - _multiConfigList() { + _serverTree(true) { _argc = 0; _argv = NULL; @@ -72,8 +71,7 @@ VoxelServer::VoxelServer(Assignment::Command command, Assignment::Location locat } VoxelServer::VoxelServer(const unsigned char* dataBuffer, int numBytes) : Assignment(dataBuffer, numBytes), - _serverTree(true), - _multiConfigList() { + _serverTree(true) { _argc = 0; _argv = NULL; @@ -117,11 +115,9 @@ void VoxelServer::setArguments(int argc, char** argv) { void VoxelServer::parsePayload() { if (getNumPayloadBytes() > 0) { - QString multiConfig((const char*) _payload); - _multiConfigList = multiConfig.split(";"); + QString config((const char*) _payload); - // Now, parse the first config - QString config = _multiConfigList.at(0); + // Now, parse the config QStringList configList = config.split(" "); int argCount = configList.size() + 1; @@ -144,34 +140,6 @@ void VoxelServer::parsePayload() { } } -void VoxelServer::parseOtherServerConfigs() { - // There there are multiple configs, then this instance will run the first - // config, and launch Assignment requests for the additional configs. - if (_multiConfigList.size() > 1) { - qDebug("Voxel Server received assignment for multiple Configs... config count=%d\n", _multiConfigList.size()); - - // skip 0 - that's the one we'll run - for (int i = 1; i < _multiConfigList.size(); i++) { - QString config = _multiConfigList.at(i); - - qDebug(" config[%d]=%s\n", i, config.toLocal8Bit().constData()); - - Assignment voxelServerAssignment(Assignment::CreateCommand, - Assignment::VoxelServerType, - getLocation()); // use same location as we were created in. - - // match this create request with our UUID so the DS knows who the create request is from - voxelServerAssignment.setUUID(_uuid); - - int payloadLength = config.length() + sizeof(char); - voxelServerAssignment.setPayload((uchar*)config.toLocal8Bit().constData(), payloadLength); - - qDebug("Requesting additional Voxel Server assignment to handle config %d\n", i); - NodeList::getInstance()->sendAssignment(voxelServerAssignment); - } - } -} - //int main(int argc, const char * argv[]) { void VoxelServer::run() { @@ -360,8 +328,6 @@ void VoxelServer::run() { _voxelServerPacketProcessor->initialize(true); } - bool isFirstDomainPacket = true; - // loop to send to nodes requesting data while (true) { @@ -401,14 +367,6 @@ void VoxelServer::run() { // If the packet is a ping, let processNodeData handle it. NodeList::getInstance()->processNodeData(&senderAddress, packetData, packetLength); } else if (packetData[0] == PACKET_TYPE_DOMAIN) { - - if (isFirstDomainPacket) { - // this is the first packet we've received from the DS, parse the other server configs - // so we can make the appropriate create assignment requests - parseOtherServerConfigs(); - isFirstDomainPacket = false; - } - NodeList::getInstance()->processNodeData(&senderAddress, packetData, packetLength); } else if (packetData[0] == PACKET_TYPE_VOXEL_JURISDICTION_REQUEST) { if (_jurisdictionSender) { diff --git a/libraries/voxel-server-library/src/VoxelServer.h b/libraries/voxel-server-library/src/VoxelServer.h index b1d2228939..464938706e 100644 --- a/libraries/voxel-server-library/src/VoxelServer.h +++ b/libraries/voxel-server-library/src/VoxelServer.h @@ -80,10 +80,8 @@ private: EnvironmentData _environmentData[3]; NodeWatcher _nodeWatcher; // used to cleanup AGENT data when agents are killed - QStringList _multiConfigList; void parsePayload(); - void parseOtherServerConfigs(); }; #endif // __voxel_server__VoxelServer__