From 1ed2b3d8fe6738a13e1427962b1c41bdb6c76b16 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 15 Oct 2013 15:38:43 -0700 Subject: [PATCH] add both fulfilled and queued assignments to DS json --- domain-server/src/DomainServer.cpp | 30 +++++++++++++++++++++++++---- libraries/shared/src/Assignment.cpp | 15 +++++++++++++++ libraries/shared/src/Assignment.h | 2 ++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 36cc3a5a97..270608d07c 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -33,11 +33,11 @@ void DomainServer::setDomainServerInstance(DomainServer* domainServer) { int DomainServer::civetwebRequestHandler(struct mg_connection *connection) { const struct mg_request_info* ri = mg_get_request_info(connection); - const char TWO_HUNDRED_RESPONSE[] = "HTTP/1.0 200 OK\r\n\r\n"; + const char RESPONSE_200[] = "HTTP/1.0 200 OK\r\n\r\n"; if (strcmp(ri->uri, "/assignment") == 0 && strcmp(ri->request_method, "POST") == 0) { // return a 200 - mg_printf(connection, "%s", TWO_HUNDRED_RESPONSE); + mg_printf(connection, "%s", RESPONSE_200); // upload the file mg_upload(connection, "/tmp"); @@ -46,7 +46,7 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) { // user is asking for json list of assignments // start with a 200 response - mg_printf(connection, "%s", TWO_HUNDRED_RESPONSE); + mg_printf(connection, "%s", RESPONSE_200); // setup the JSON QJsonObject assignmentJSON; @@ -85,8 +85,30 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) { } } + assignmentJSON["fulfilled"] = assignedNodesJSON; + + QJsonObject queuedAssignmentsJSON; + + // add the queued but unfilled assignments to the json + std::deque::iterator assignment = domainServerInstance->_assignmentQueue.begin(); + + while (assignment != domainServerInstance->_assignmentQueue.end()) { + QJsonObject queuedAssignmentJSON; + + QString uuidString = uuidStringWithoutCurlyBraces((*assignment)->getUUID()); + queuedAssignmentJSON[ASSIGNMENT_JSON_UUID_KEY] = uuidString; + + // add this queued assignment to the JSON + queuedAssignmentsJSON[(*assignment)->getTypeName()] = queuedAssignmentJSON; + + // push forward the iterator to check the next assignment + assignment++; + } + + assignmentJSON["queued"] = queuedAssignmentsJSON; + // print out the created JSON - QJsonDocument assignmentDocument(assignedNodesJSON); + QJsonDocument assignmentDocument(assignmentJSON); mg_printf(connection, "%s", assignmentDocument.toJson().constData()); // we've processed this request diff --git a/libraries/shared/src/Assignment.cpp b/libraries/shared/src/Assignment.cpp index 6829a8b266..6a7f62c91b 100644 --- a/libraries/shared/src/Assignment.cpp +++ b/libraries/shared/src/Assignment.cpp @@ -139,6 +139,21 @@ void Assignment::setPayload(const uchar* payload, int numBytes) { memcpy(_payload, payload, _numPayloadBytes); } +const char* Assignment::getTypeName() const { + switch (_type) { + case Assignment::AudioMixerType: + return "audio-mixer"; + case Assignment::AvatarMixerType: + return "avatar-mixer"; + case Assignment::AgentType: + return "agent"; + case Assignment::VoxelServerType: + return "voxel-server"; + default: + return "unknown"; + } +} + int Assignment::packToBuffer(unsigned char* buffer) { int numPackedBytes = 0; diff --git a/libraries/shared/src/Assignment.h b/libraries/shared/src/Assignment.h index 694be61e0e..cc528e9bd4 100644 --- a/libraries/shared/src/Assignment.h +++ b/libraries/shared/src/Assignment.h @@ -73,6 +73,8 @@ public: int getNumberOfInstances() const { return _numberOfInstances; } void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; } void decrementNumberOfInstances() { --_numberOfInstances; } + + const char* getTypeName() const; /// Packs the assignment to the passed buffer /// \param buffer the buffer in which to pack the assignment