mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-10 07:57:27 +02:00
add both fulfilled and queued assignments to DS json
This commit is contained in:
parent
4cb657fa24
commit
1ed2b3d8fe
3 changed files with 43 additions and 4 deletions
|
@ -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<Assignment*>::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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue