Merge branch 'master' of https://github.com/highfidelity/hifi into 19561

This commit is contained in:
Thijs Wenker 2014-04-21 21:40:01 +02:00
commit e348f66151
3 changed files with 58 additions and 43 deletions

View file

@ -278,6 +278,7 @@ void DomainServer::createScriptedAssignmentsFromArray(const QJsonArray &configAr
qDebug() << "Adding scripted assignment to queue -" << *scriptAssignment; qDebug() << "Adding scripted assignment to queue -" << *scriptAssignment;
qDebug() << "URL for script is" << assignmentURL; qDebug() << "URL for script is" << assignmentURL;
// scripts passed on CL or via JSON are static - so they are added back to the queue if the node dies
_assignmentQueue.enqueue(SharedAssignmentPointer(scriptAssignment)); _assignmentQueue.enqueue(SharedAssignmentPointer(scriptAssignment));
} }
} }
@ -343,7 +344,6 @@ const NodeSet STATICALLY_ASSIGNED_NODES = NodeSet() << NodeType::AudioMixer
<< NodeType::AvatarMixer << NodeType::VoxelServer << NodeType::ParticleServer << NodeType::AvatarMixer << NodeType::VoxelServer << NodeType::ParticleServer
<< NodeType::MetavoxelServer; << NodeType::MetavoxelServer;
void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr) { void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packet, const HifiSockAddr& senderSockAddr) {
NodeType_t nodeType; NodeType_t nodeType;
@ -352,34 +352,40 @@ void DomainServer::addNodeToNodeListAndConfirmConnection(const QByteArray& packe
int numPreInterestBytes = parseNodeDataFromByteArray(nodeType, publicSockAddr, localSockAddr, packet, senderSockAddr); int numPreInterestBytes = parseNodeDataFromByteArray(nodeType, publicSockAddr, localSockAddr, packet, senderSockAddr);
QUuid assignmentUUID = uuidFromPacketHeader(packet); QUuid assignmentUUID = uuidFromPacketHeader(packet);
SharedAssignmentPointer matchingAssignment; bool isStaticAssignment = _staticAssignmentHash.contains(assignmentUUID);
SharedAssignmentPointer matchingAssignment = SharedAssignmentPointer();
if (!assignmentUUID.isNull() && (matchingAssignment = matchingStaticAssignmentForCheckIn(assignmentUUID, nodeType)) if (isStaticAssignment) {
&& matchingAssignment) { // this is a static assignment, make sure the UUID sent is for an assignment we're actually trying to give out
// this is an assigned node, make sure the UUID sent is for an assignment we're actually trying to give out matchingAssignment = matchingQueuedAssignmentForCheckIn(assignmentUUID, nodeType);
// remove the matching assignment from the assignment queue so we don't take the next check in if (matchingAssignment) {
// (if it exists) // remove the matching assignment from the assignment queue so we don't take the next check in
removeMatchingAssignmentFromQueue(matchingAssignment); // (if it exists)
removeMatchingAssignmentFromQueue(matchingAssignment);
}
} else { } else {
assignmentUUID = QUuid(); assignmentUUID = QUuid();
} }
// create a new session UUID for this node // make sure this was either not a static assignment or it was and we had a matching one in teh queue
QUuid nodeUUID = QUuid::createUuid(); if ((!isStaticAssignment && !STATICALLY_ASSIGNED_NODES.contains(nodeType)) || (isStaticAssignment && matchingAssignment)) {
// create a new session UUID for this node
SharedNodePointer newNode = LimitedNodeList::getInstance()->addOrUpdateNode(nodeUUID, nodeType, QUuid nodeUUID = QUuid::createUuid();
publicSockAddr, localSockAddr);
SharedNodePointer newNode = LimitedNodeList::getInstance()->addOrUpdateNode(nodeUUID, nodeType,
// when the newNode is created the linked data is also created publicSockAddr, localSockAddr);
// if this was a static assignment set the UUID, set the sendingSockAddr
DomainServerNodeData* nodeData = reinterpret_cast<DomainServerNodeData*>(newNode->getLinkedData()); // when the newNode is created the linked data is also created
// if this was a static assignment set the UUID, set the sendingSockAddr
nodeData->setStaticAssignmentUUID(assignmentUUID); DomainServerNodeData* nodeData = reinterpret_cast<DomainServerNodeData*>(newNode->getLinkedData());
nodeData->setSendingSockAddr(senderSockAddr);
nodeData->setStaticAssignmentUUID(assignmentUUID);
// reply back to the user with a PacketTypeDomainList nodeData->setSendingSockAddr(senderSockAddr);
sendDomainListToNode(newNode, senderSockAddr, nodeInterestListFromPacket(packet, numPreInterestBytes));
// reply back to the user with a PacketTypeDomainList
sendDomainListToNode(newNode, senderSockAddr, nodeInterestListFromPacket(packet, numPreInterestBytes));
}
} }
int DomainServer::parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr& publicSockAddr, int DomainServer::parseNodeDataFromByteArray(NodeType_t& nodeType, HifiSockAddr& publicSockAddr,
@ -740,6 +746,16 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) {
return nodeJson; return nodeJson;
} }
const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
QString pathForAssignmentScript(const QUuid& assignmentUUID) {
QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION);
newPath += "/";
// append the UUID for this script as the new filename, remove the curly braces
newPath += uuidStringWithoutCurlyBraces(assignmentUUID);
return newPath;
}
bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url) { bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url) {
const QString JSON_MIME_TYPE = "application/json"; const QString JSON_MIME_TYPE = "application/json";
@ -870,17 +886,13 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
assignmentPool = QString(assignmentPoolValue); assignmentPool = QString(assignmentPoolValue);
} }
const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
for (int i = 0; i < numInstances; i++) { for (int i = 0; i < numInstances; i++) {
// create an assignment for this saved script // create an assignment for this saved script
Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand, Assignment::AgentType, assignmentPool); Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand, Assignment::AgentType, assignmentPool);
QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION); QString newPath = pathForAssignmentScript(scriptAssignment->getUUID());
newPath += "/";
// append the UUID for this script as the new filename, remove the curly braces
newPath += uuidStringWithoutCurlyBraces(scriptAssignment->getUUID());
// create a file with the GUID of the assignment in the script host location // create a file with the GUID of the assignment in the script host location
QFile scriptFile(newPath); QFile scriptFile(newPath);
@ -945,6 +957,11 @@ void DomainServer::refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer&
qDebug() << "Reset UUID for assignment -" << *assignment.data() << "- and added to queue. Old UUID was" qDebug() << "Reset UUID for assignment -" << *assignment.data() << "- and added to queue. Old UUID was"
<< uuidStringWithoutCurlyBraces(oldUUID); << uuidStringWithoutCurlyBraces(oldUUID);
if (assignment->getType() == Assignment::AgentType && assignment->getPayload().isEmpty()) {
// if this was an Agent without a script URL, we need to rename the old file so it can be retrieved at the new UUID
QFile::rename(pathForAssignmentScript(oldUUID), pathForAssignmentScript(assignment->getUUID()));
}
// add the static assignment back under the right UUID, and to the queue // add the static assignment back under the right UUID, and to the queue
_staticAssignmentHash.insert(assignment->getUUID(), assignment); _staticAssignmentHash.insert(assignment->getUUID(), assignment);
@ -992,7 +1009,7 @@ void DomainServer::nodeKilled(SharedNodePointer node) {
} }
} }
SharedAssignmentPointer DomainServer::matchingStaticAssignmentForCheckIn(const QUuid& checkInUUID, NodeType_t nodeType) { SharedAssignmentPointer DomainServer::matchingQueuedAssignmentForCheckIn(const QUuid& checkInUUID, NodeType_t nodeType) {
QQueue<SharedAssignmentPointer>::iterator i = _assignmentQueue.begin(); QQueue<SharedAssignmentPointer>::iterator i = _assignmentQueue.begin();
while (i != _assignmentQueue.end()) { while (i != _assignmentQueue.end()) {
@ -1019,22 +1036,21 @@ SharedAssignmentPointer DomainServer::deployableAssignmentForRequest(const Assig
bool assignmentPoolsMatch = assignment->getPool() == requestAssignment.getPool(); bool assignmentPoolsMatch = assignment->getPool() == requestAssignment.getPool();
if ((requestIsAllTypes || assignmentTypesMatch) && (nietherHasPool || assignmentPoolsMatch)) { if ((requestIsAllTypes || assignmentTypesMatch) && (nietherHasPool || assignmentPoolsMatch)) {
if (assignment->getType() == Assignment::AgentType) { // remove the assignment from the queue
// if there is more than one instance to send out, simply decrease the number of instances SharedAssignmentPointer deployableAssignment = _assignmentQueue.takeAt(sharedAssignment
return _assignmentQueue.takeAt(sharedAssignment - _assignmentQueue.begin()); - _assignmentQueue.begin());
} else {
// remove the assignment from the queue if (deployableAssignment->getType() != Assignment::AgentType
SharedAssignmentPointer deployableAssignment = _assignmentQueue.takeAt(sharedAssignment || _staticAssignmentHash.contains(deployableAssignment->getUUID())) {
- _assignmentQueue.begin()); // this is a static assignment
// until we get a check-in from that GUID // until we get a check-in from that GUID
// put assignment back in queue but stick it at the back so the others have a chance to go out // put assignment back in queue but stick it at the back so the others have a chance to go out
_assignmentQueue.enqueue(deployableAssignment); _assignmentQueue.enqueue(deployableAssignment);
// stop looping, we've handed out an assignment
return deployableAssignment;
} }
// stop looping, we've handed out an assignment
return deployableAssignment;
} else { } else {
// push forward the iterator to check the next assignment // push forward the iterator to check the next assignment
++sharedAssignment; ++sharedAssignment;

View file

@ -70,7 +70,7 @@ private:
void createStaticAssignmentsForType(Assignment::Type type, const QJsonArray& configArray); void createStaticAssignmentsForType(Assignment::Type type, const QJsonArray& configArray);
void populateDefaultStaticAssignmentsExcludingTypes(const QSet<Assignment::Type>& excludedTypes); void populateDefaultStaticAssignmentsExcludingTypes(const QSet<Assignment::Type>& excludedTypes);
SharedAssignmentPointer matchingStaticAssignmentForCheckIn(const QUuid& checkInUUID, NodeType_t nodeType); SharedAssignmentPointer matchingQueuedAssignmentForCheckIn(const QUuid& checkInUUID, NodeType_t nodeType);
SharedAssignmentPointer deployableAssignmentForRequest(const Assignment& requestAssignment); SharedAssignmentPointer deployableAssignmentForRequest(const Assignment& requestAssignment);
void removeMatchingAssignmentFromQueue(const SharedAssignmentPointer& removableAssignment); void removeMatchingAssignmentFromQueue(const SharedAssignmentPointer& removableAssignment);
void refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer& assignment); void refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer& assignment);

View file

@ -1068,7 +1068,6 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo)
delete _audioOutput; delete _audioOutput;
_audioOutput = NULL; _audioOutput = NULL;
_numInputCallbackBytes = 0;
_loopbackOutputDevice = NULL; _loopbackOutputDevice = NULL;
delete _loopbackAudioOutput; delete _loopbackAudioOutput;