From b3bd159d0926eab96ce5ddfe0317d9da0e0315c6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 30 Sep 2013 13:57:42 -0700 Subject: [PATCH] don't send create assignment request until connection to DS --- .../voxel-server-library/src/VoxelServer.cpp | 71 +++++++++++-------- .../voxel-server-library/src/VoxelServer.h | 4 ++ 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index 5044c62a72..a30668928a 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -50,7 +49,8 @@ void attachVoxelNodeDataToNode(Node* newNode) { VoxelServer::VoxelServer(Assignment::Command command, Assignment::Location location) : Assignment(command, Assignment::VoxelServerType, location), - _serverTree(true) { + _serverTree(true), + _multiConfigList() { _argc = 0; _argv = NULL; @@ -72,7 +72,8 @@ VoxelServer::VoxelServer(Assignment::Command command, Assignment::Location locat } VoxelServer::VoxelServer(const unsigned char* dataBuffer, int numBytes) : Assignment(dataBuffer, numBytes), - _serverTree(true) { + _serverTree(true), + _multiConfigList() { _argc = 0; _argv = NULL; @@ -116,34 +117,11 @@ void VoxelServer::setArguments(int argc, char** argv) { void VoxelServer::parsePayload() { if (getNumPayloadBytes() > 0) { - QString multiConfig((const char*)getPayload()); - QStringList multiConfigList = multiConfig.split(";"); - - // 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. - - 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); - } - } + QString multiConfig((const char*) _payload); + _multiConfigList = multiConfig.split(";"); // Now, parse the first config - QString config = multiConfigList.at(0); + QString config = _multiConfigList.at(0); QStringList configList = config.split(" "); int argCount = configList.size() + 1; @@ -166,6 +144,31 @@ 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. + + 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() { @@ -354,6 +357,8 @@ void VoxelServer::run() { _voxelServerPacketProcessor->initialize(true); } + bool isFirstDomainPacket = true; + // loop to send to nodes requesting data while (true) { @@ -393,6 +398,14 @@ 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 776ce0cd1e..b1d2228939 100644 --- a/libraries/voxel-server-library/src/VoxelServer.h +++ b/libraries/voxel-server-library/src/VoxelServer.h @@ -10,6 +10,8 @@ #ifndef __voxel_server__VoxelServer__ #define __voxel_server__VoxelServer__ +#include + #include #include @@ -78,8 +80,10 @@ 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__