handle mutli-VS config in DS when creating static file

This commit is contained in:
Stephen Birarda 2013-09-30 14:27:54 -07:00
parent fb27e37607
commit 94f7b98a5c
4 changed files with 37 additions and 65 deletions

View file

@ -8,6 +8,8 @@
#include <signal.h>
#include <QStringList>
#include <PacketHeaders.h>
#include <SharedUtil.h>
@ -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);

View file

@ -57,7 +57,6 @@ private:
QFile _staticAssignmentFile;
uchar* _staticAssignmentFileData;
uint16_t* _numAssignmentsInStaticFile;
Assignment* _staticAssignments;
const char* _voxelServerConfig;

View file

@ -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) {

View file

@ -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__