Merge pull request #1098 from birarda/assignment

add back pools for assignments
This commit is contained in:
Philip Rosedale 2013-10-22 17:13:02 -07:00
commit 873a479f99
6 changed files with 114 additions and 81 deletions

View file

@ -35,6 +35,7 @@ pid_t* childForks = NULL;
sockaddr_in customAssignmentSocket = {}; sockaddr_in customAssignmentSocket = {};
int numForks = 0; int numForks = 0;
Assignment::Type overiddenAssignmentType = Assignment::AllTypes; Assignment::Type overiddenAssignmentType = Assignment::AllTypes;
const char* assignmentPool = NULL;
int argc = 0; int argc = 0;
char** argv = NULL; char** argv = NULL;
@ -64,7 +65,7 @@ void childClient() {
sockaddr_in senderSocket = {}; sockaddr_in senderSocket = {};
// create a request assignment, accept assignments defined by the overidden type // 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"; qDebug() << "Waiting for assignment -" << requestAssignment << "\n";
@ -219,6 +220,9 @@ int main(int argc, char* argv[]) {
// so set that as the ::overridenAssignmentType to be used in requests // so set that as the ::overridenAssignmentType to be used in requests
::overiddenAssignmentType = (Assignment::Type) atoi(assignmentTypeString); ::overiddenAssignmentType = (Assignment::Type) atoi(assignmentTypeString);
} }
const char ASSIGNMENT_POOL_OPTION[] = "--pool";
::assignmentPool = getCmdOption(argc, (const char**) argv, ASSIGNMENT_POOL_OPTION);
const char* NUM_FORKS_PARAMETER = "-n"; const char* NUM_FORKS_PARAMETER = "-n";
const char* numForksString = getCmdOption(argc, (const char**)argv, NUM_FORKS_PARAMETER); const char* numForksString = getCmdOption(argc, (const char**)argv, NUM_FORKS_PARAMETER);

View file

@ -173,7 +173,10 @@ const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
void DomainServer::civetwebUploadHandler(struct mg_connection *connection, const char *path) { void DomainServer::civetwebUploadHandler(struct mg_connection *connection, const char *path) {
// create an assignment for this saved script, for now make it local only // 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,
NULL,
Assignment::LocalLocation);
// check how many instances of this assignment the user wants by checking the ASSIGNMENT-INSTANCES header // check how many instances of this assignment the user wants by checking the ASSIGNMENT-INSTANCES header
const char ASSIGNMENT_INSTANCES_HTTP_HEADER[] = "ASSIGNMENT-INSTANCES"; const char ASSIGNMENT_INSTANCES_HTTP_HEADER[] = "ASSIGNMENT-INSTANCES";
@ -302,12 +305,8 @@ void DomainServer::prepopulateStaticAssignmentFile() {
Assignment freshStaticAssignments[MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS]; Assignment freshStaticAssignments[MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS];
// pre-populate the first static assignment list with assignments for root AuM, AvM, VS // pre-populate the first static assignment list with assignments for root AuM, AvM, VS
freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand, freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand, Assignment::AudioMixerType);
Assignment::AudioMixerType, freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand, Assignment::AvatarMixerType);
Assignment::LocalLocation);
freshStaticAssignments[numFreshStaticAssignments++] = Assignment(Assignment::CreateCommand,
Assignment::AvatarMixerType,
Assignment::LocalLocation);
// Handle Domain/Voxel Server configuration command line arguments // Handle Domain/Voxel Server configuration command line arguments
if (_voxelServerConfig) { if (_voxelServerConfig) {
@ -323,9 +322,23 @@ void DomainServer::prepopulateStaticAssignmentFile() {
qDebug("config[%d]=%s\n", i, config.toLocal8Bit().constData()); qDebug("config[%d]=%s\n", i, config.toLocal8Bit().constData());
// Now, parse the config to check for a pool
const char ASSIGNMENT_CONFIG_POOL_OPTION[] = "--pool";
QString assignmentPool;
int poolIndex = config.indexOf(ASSIGNMENT_CONFIG_POOL_OPTION);
if (poolIndex >= 0) {
int spaceBeforePoolIndex = config.indexOf(' ', poolIndex);
int spaceAfterPoolIndex = config.indexOf(' ', spaceBeforePoolIndex);
assignmentPool = config.mid(spaceBeforePoolIndex + 1, spaceAfterPoolIndex);
qDebug() << "The pool for this voxel-assignment is" << assignmentPool << "\n";
}
Assignment voxelServerAssignment(Assignment::CreateCommand, Assignment voxelServerAssignment(Assignment::CreateCommand,
Assignment::VoxelServerType, Assignment::VoxelServerType,
Assignment::LocalLocation); // use same location as we were created in. (assignmentPool.isEmpty() ? NULL : assignmentPool.toLocal8Bit().constData()));
int payloadLength = config.length() + sizeof(char); int payloadLength = config.length() + sizeof(char);
voxelServerAssignment.setPayload((uchar*)config.toLocal8Bit().constData(), payloadLength); voxelServerAssignment.setPayload((uchar*)config.toLocal8Bit().constData(), payloadLength);
@ -333,9 +346,7 @@ void DomainServer::prepopulateStaticAssignmentFile() {
freshStaticAssignments[numFreshStaticAssignments++] = voxelServerAssignment; freshStaticAssignments[numFreshStaticAssignments++] = voxelServerAssignment;
} }
} else { } else {
Assignment rootVoxelServerAssignment(Assignment::CreateCommand, Assignment rootVoxelServerAssignment(Assignment::CreateCommand, Assignment::VoxelServerType);
Assignment::VoxelServerType,
Assignment::LocalLocation);
freshStaticAssignments[numFreshStaticAssignments++] = rootVoxelServerAssignment; freshStaticAssignments[numFreshStaticAssignments++] = rootVoxelServerAssignment;
} }
@ -390,9 +401,14 @@ Assignment* DomainServer::deployableAssignmentForRequest(Assignment& requestAssi
std::deque<Assignment*>::iterator assignment = _assignmentQueue.begin(); std::deque<Assignment*>::iterator assignment = _assignmentQueue.begin();
while (assignment != _assignmentQueue.end()) { while (assignment != _assignmentQueue.end()) {
bool requestIsAllTypes = requestAssignment.getType() == Assignment::AllTypes;
bool assignmentTypesMatch = (*assignment)->getType() == requestAssignment.getType();
bool nietherHasPool = !(*assignment)->hasPool() && !requestAssignment.hasPool();
bool assignmentPoolsMatch = memcmp((*assignment)->getPool(),
requestAssignment.getPool(),
MAX_ASSIGNMENT_POOL_BYTES) == 0;
if (requestAssignment.getType() == Assignment::AllTypes || if ((requestIsAllTypes || assignmentTypesMatch) && (nietherHasPool || assignmentPoolsMatch)) {
(*assignment)->getType() == requestAssignment.getType()) {
Assignment* deployableAssignment = *assignment; Assignment* deployableAssignment = *assignment;

View file

@ -41,10 +41,10 @@ Assignment::Assignment() :
_payload(), _payload(),
_numPayloadBytes(0) _numPayloadBytes(0)
{ {
setPool(NULL);
} }
Assignment::Assignment(Assignment::Command command, Assignment::Type type, Assignment::Location location) : Assignment::Assignment(Assignment::Command command, Assignment::Type type, const char* pool, Assignment::Location location) :
_command(command), _command(command),
_type(type), _type(type),
_location(location), _location(location),
@ -56,40 +56,8 @@ Assignment::Assignment(Assignment::Command command, Assignment::Type type, Assig
// this is a newly created assignment, generate a random UUID // this is a newly created assignment, generate a random UUID
_uuid = QUuid::createUuid(); _uuid = QUuid::createUuid();
} }
}
Assignment::Assignment(const Assignment& otherAssignment) {
_uuid = otherAssignment._uuid; setPool(pool);
_command = otherAssignment._command;
_type = otherAssignment._type;
_location = otherAssignment._location;
_numberOfInstances = otherAssignment._numberOfInstances;
setPayload(otherAssignment._payload, otherAssignment._numPayloadBytes);
}
Assignment& Assignment::operator=(const Assignment& rhsAssignment) {
Assignment temp(rhsAssignment);
swap(temp);
return *this;
}
void Assignment::swap(Assignment& otherAssignment) {
using std::swap;
swap(_uuid, otherAssignment._uuid);
swap(_command, otherAssignment._command);
swap(_type, otherAssignment._type);
swap(_location, otherAssignment._location);
swap(_numberOfInstances, otherAssignment._numberOfInstances);
for (int i = 0; i < MAX_PAYLOAD_BYTES; i++) {
swap(_payload[i], otherAssignment._payload[i]);
}
swap(_numPayloadBytes, otherAssignment._numPayloadBytes);
} }
Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) : Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
@ -97,7 +65,7 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
_numberOfInstances(1), _numberOfInstances(1),
_payload(), _payload(),
_numPayloadBytes(0) _numPayloadBytes(0)
{ {
int numBytesRead = 0; int numBytesRead = 0;
if (dataBuffer[0] == PACKET_TYPE_REQUEST_ASSIGNMENT) { if (dataBuffer[0] == PACKET_TYPE_REQUEST_ASSIGNMENT) {
@ -118,12 +86,61 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
_uuid = QUuid::fromRfc4122(QByteArray((const char*) dataBuffer + numBytesRead, NUM_BYTES_RFC4122_UUID)); _uuid = QUuid::fromRfc4122(QByteArray((const char*) dataBuffer + numBytesRead, NUM_BYTES_RFC4122_UUID));
numBytesRead += NUM_BYTES_RFC4122_UUID; numBytesRead += NUM_BYTES_RFC4122_UUID;
} }
if (dataBuffer[numBytesRead] != '\0') {
// read the pool from the data buffer
setPool((const char*) dataBuffer + numBytesRead);
} else {
// skip past the null pool and null out our pool
setPool(NULL);
numBytesRead++;
}
if (numBytes > numBytesRead) { if (numBytes > numBytesRead) {
setPayload(dataBuffer + numBytesRead, numBytes - numBytesRead); setPayload(dataBuffer + numBytesRead, numBytes - numBytesRead);
} }
} }
Assignment::Assignment(const Assignment& otherAssignment) {
_uuid = otherAssignment._uuid;
_command = otherAssignment._command;
_type = otherAssignment._type;
_location = otherAssignment._location;
setPool(otherAssignment._pool);
_numberOfInstances = otherAssignment._numberOfInstances;
setPayload(otherAssignment._payload, otherAssignment._numPayloadBytes);
}
Assignment& Assignment::operator=(const Assignment& rhsAssignment) {
Assignment temp(rhsAssignment);
swap(temp);
return *this;
}
void Assignment::swap(Assignment& otherAssignment) {
using std::swap;
swap(_uuid, otherAssignment._uuid);
swap(_command, otherAssignment._command);
swap(_type, otherAssignment._type);
swap(_location, otherAssignment._location);
for (int i = 0; i < sizeof(_pool); i++) {
swap(_pool[i], otherAssignment._pool[i]);
}
swap(_numberOfInstances, otherAssignment._numberOfInstances);
for (int i = 0; i < MAX_PAYLOAD_BYTES; i++) {
swap(_payload[i], otherAssignment._payload[i]);
}
swap(_numPayloadBytes, otherAssignment._numPayloadBytes);
}
void Assignment::setPayload(const uchar* payload, int numBytes) { void Assignment::setPayload(const uchar* payload, int numBytes) {
if (numBytes > MAX_PAYLOAD_BYTES) { if (numBytes > MAX_PAYLOAD_BYTES) {
@ -140,6 +157,14 @@ void Assignment::setPayload(const uchar* payload, int numBytes) {
memcpy(_payload, payload, _numPayloadBytes); memcpy(_payload, payload, _numPayloadBytes);
} }
void Assignment::setPool(const char* pool) {
memset(_pool, '\0', sizeof(_pool));
if (pool) {
strcpy(_pool, pool);
}
}
const char* Assignment::getTypeName() const { const char* Assignment::getTypeName() const {
switch (_type) { switch (_type) {
case Assignment::AudioMixerType: case Assignment::AudioMixerType:
@ -167,6 +192,16 @@ int Assignment::packToBuffer(unsigned char* buffer) {
numPackedBytes += NUM_BYTES_RFC4122_UUID; numPackedBytes += NUM_BYTES_RFC4122_UUID;
} }
if (_pool) {
// pack the pool for this assignment, it exists
int numBytesNullTerminatedPool = strlen(_pool) + sizeof('\0');
memcpy(buffer + numPackedBytes, _pool, numBytesNullTerminatedPool);
numPackedBytes += numBytesNullTerminatedPool;
} else {
// otherwise pack the null character
buffer[numPackedBytes++] = '\0';
}
if (_numPayloadBytes) { if (_numPayloadBytes) {
memcpy(buffer + numPackedBytes, _payload, _numPayloadBytes); memcpy(buffer + numPackedBytes, _payload, _numPayloadBytes);
numPackedBytes += _numPayloadBytes; numPackedBytes += _numPayloadBytes;

View file

@ -16,6 +16,7 @@
#include "NodeList.h" #include "NodeList.h"
const int MAX_PAYLOAD_BYTES = 1024; const int MAX_PAYLOAD_BYTES = 1024;
const int MAX_ASSIGNMENT_POOL_BYTES = 64 + sizeof('\0');
/// Holds information used for request, creation, and deployment of assignments /// Holds information used for request, creation, and deployment of assignments
class Assignment : public NodeData { class Assignment : public NodeData {
@ -46,6 +47,7 @@ public:
Assignment(); Assignment();
Assignment(Assignment::Command command, Assignment(Assignment::Command command,
Assignment::Type type, Assignment::Type type,
const char* pool = NULL,
Assignment::Location location = Assignment::LocalLocation); Assignment::Location location = Assignment::LocalLocation);
Assignment(const Assignment& otherAssignment); Assignment(const Assignment& otherAssignment);
Assignment& operator=(const Assignment &rhsAssignment); Assignment& operator=(const Assignment &rhsAssignment);
@ -69,6 +71,10 @@ public:
int getNumPayloadBytes() const { return _numPayloadBytes; } int getNumPayloadBytes() const { return _numPayloadBytes; }
void setPayload(const uchar *payload, int numBytes); void setPayload(const uchar *payload, int numBytes);
void setPool(const char* pool);
const char* getPool() const { return _pool; }
bool hasPool() const { return (bool) strlen(_pool); }
int getNumberOfInstances() const { return _numberOfInstances; } int getNumberOfInstances() const { return _numberOfInstances; }
void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; } void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; }
void decrementNumberOfInstances() { --_numberOfInstances; } void decrementNumberOfInstances() { --_numberOfInstances; }
@ -94,6 +100,7 @@ protected:
QUuid _uuid; /// the 16 byte UUID for this assignment QUuid _uuid; /// the 16 byte UUID for this assignment
Assignment::Command _command; /// the command for this assignment (Create, Deploy, Request) 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 Assignment::Type _type; /// the type of the assignment, defines what the assignee will do
char _pool[MAX_ASSIGNMENT_POOL_BYTES]; /// the destination pool for this assignment
Assignment::Location _location; /// the location of the assignment, allows a domain to preferentially use local ACs 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 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 uchar _payload[MAX_PAYLOAD_BYTES]; /// an optional payload attached to this assignment, a maximum for 1024 bytes will be packed

View file

@ -51,32 +51,6 @@ void attachVoxelNodeDataToNode(Node* newNode) {
VoxelServer* VoxelServer::_theInstance = NULL; 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), VoxelServer::VoxelServer(const unsigned char* dataBuffer, int numBytes) : Assignment(dataBuffer, numBytes),
_serverTree(true) { _serverTree(true) {
_argc = 0; _argc = 0;

View file

@ -26,10 +26,7 @@
/// Handles assignments of type VoxelServer - sending voxels to various clients. /// Handles assignments of type VoxelServer - sending voxels to various clients.
class VoxelServer : public Assignment { class VoxelServer : public Assignment {
public: public:
VoxelServer(Assignment::Command command,
Assignment::Location location = Assignment::GlobalLocation);
VoxelServer(const unsigned char* dataBuffer, int numBytes); VoxelServer(const unsigned char* dataBuffer, int numBytes);
~VoxelServer(); ~VoxelServer();