change DS json to use unique UUIDs for keys

This commit is contained in:
Stephen Birarda 2013-10-24 16:27:05 -07:00
parent f8369ea29a
commit d3ac055add

View file

@ -42,27 +42,28 @@ QJsonObject jsonForSocket(sockaddr* socket) {
return socketJSON;
}
const char JSON_KEY_UUID[] = "UUID";
const char JSON_KEY_TYPE[] = "type";
const char JSON_KEY_PUBLIC_SOCKET[] = "public";
const char JSON_KEY_LOCAL_SOCKET[] = "local";
void addNodeToJsonObject(Node* node, QJsonObject& jsonObject) {
QJsonObject nodeJson;
// add the UUID
QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID());
nodeJson[JSON_KEY_UUID] = uuidString;
// add the node socket information
nodeJson[JSON_KEY_PUBLIC_SOCKET] = jsonForSocket(node->getPublicSocket());
nodeJson[JSON_KEY_LOCAL_SOCKET] = jsonForSocket(node->getLocalSocket());
// re-format the type name so it matches the target name
QString nodeTypeName(node->getTypeName());
nodeTypeName = nodeTypeName.toLower();
nodeTypeName.replace(' ', '-');
jsonObject[nodeTypeName] = nodeJson;
// add the node type
nodeJson[JSON_KEY_TYPE] = nodeTypeName;
// add the node socket information
nodeJson[JSON_KEY_PUBLIC_SOCKET] = jsonForSocket(node->getPublicSocket());
nodeJson[JSON_KEY_LOCAL_SOCKET] = jsonForSocket(node->getLocalSocket());
// add the node using the UUID as the key
QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID());
jsonObject[uuidString] = nodeJson;
}
@ -106,10 +107,10 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
QJsonObject queuedAssignmentJSON;
QString uuidString = uuidStringWithoutCurlyBraces((*assignment)->getUUID());
queuedAssignmentJSON[JSON_KEY_UUID] = uuidString;
queuedAssignmentJSON[JSON_KEY_TYPE] = QString((*assignment)->getTypeName());
// add this queued assignment to the JSON
queuedAssignmentsJSON[(*assignment)->getTypeName()] = queuedAssignmentJSON;
queuedAssignmentsJSON[uuidString] = queuedAssignmentJSON;
// push forward the iterator to check the next assignment
assignment++;