mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:27:04 +02:00
add handling for number of instances to domain-server
This commit is contained in:
parent
17fda717fe
commit
0e19d9a53a
2 changed files with 37 additions and 17 deletions
|
@ -76,9 +76,20 @@ static int mongooseRequestHandler(struct mg_connection *conn) {
|
||||||
const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
|
const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
|
||||||
|
|
||||||
static void mongooseUploadHandler(struct mg_connection *conn, const char *path) {
|
static void mongooseUploadHandler(struct mg_connection *conn, 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, Assignment::LocalLocation);
|
||||||
|
|
||||||
|
// 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 *requestInstancesHeader = mg_get_header(conn, ASSIGNMENT_INSTANCES_HTTP_HEADER);
|
||||||
|
|
||||||
|
if (requestInstancesHeader) {
|
||||||
|
// the user has requested a number of instances greater than 1
|
||||||
|
// so set that on the created assignment
|
||||||
|
scriptAssignment->setNumberOfInstances(atoi(requestInstancesHeader));
|
||||||
|
}
|
||||||
|
|
||||||
QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION);
|
QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION);
|
||||||
newPath += "/";
|
newPath += "/";
|
||||||
// append the UUID for this script as the new filename, remove the curly braces
|
// append the UUID for this script as the new filename, remove the curly braces
|
||||||
|
@ -94,7 +105,6 @@ static void mongooseUploadHandler(struct mg_connection *conn, const char *path)
|
||||||
::assignmentQueueMutex.lock();
|
::assignmentQueueMutex.lock();
|
||||||
::assignmentQueue.push_back(scriptAssignment);
|
::assignmentQueue.push_back(scriptAssignment);
|
||||||
::assignmentQueueMutex.unlock();
|
::assignmentQueueMutex.unlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
|
@ -172,21 +182,21 @@ int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
// ::assignmentQueueMutex.lock();
|
::assignmentQueueMutex.lock();
|
||||||
// // check if our audio-mixer or avatar-mixer are dead and we don't have existing assignments in the queue
|
// check if our audio-mixer or avatar-mixer are dead and we don't have existing assignments in the queue
|
||||||
// // so we can add those assignments back to the front of the queue since they are high-priority
|
// so we can add those assignments back to the front of the queue since they are high-priority
|
||||||
// if (!nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER) &&
|
if (!nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER) &&
|
||||||
// std::find(::assignmentQueue.begin(), assignmentQueue.end(), &avatarMixerAssignment) == ::assignmentQueue.end()) {
|
std::find(::assignmentQueue.begin(), assignmentQueue.end(), &avatarMixerAssignment) == ::assignmentQueue.end()) {
|
||||||
// qDebug("Missing an avatar mixer and assignment not in queue. Adding.\n");
|
qDebug("Missing an avatar mixer and assignment not in queue. Adding.\n");
|
||||||
// ::assignmentQueue.push_front(&avatarMixerAssignment);
|
::assignmentQueue.push_front(&avatarMixerAssignment);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (!nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER) &&
|
if (!nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER) &&
|
||||||
// std::find(::assignmentQueue.begin(), ::assignmentQueue.end(), &audioMixerAssignment) == ::assignmentQueue.end()) {
|
std::find(::assignmentQueue.begin(), ::assignmentQueue.end(), &audioMixerAssignment) == ::assignmentQueue.end()) {
|
||||||
// qDebug("Missing an audio mixer and assignment not in queue. Adding.\n");
|
qDebug("Missing an audio mixer and assignment not in queue. Adding.\n");
|
||||||
// ::assignmentQueue.push_front(&audioMixerAssignment);
|
::assignmentQueue.push_front(&audioMixerAssignment);
|
||||||
// }
|
}
|
||||||
// ::assignmentQueueMutex.unlock();
|
::assignmentQueueMutex.unlock();
|
||||||
|
|
||||||
while (nodeList->getNodeSocket()->receive((sockaddr *)&nodePublicAddress, packetData, &receivedBytes) &&
|
while (nodeList->getNodeSocket()->receive((sockaddr *)&nodePublicAddress, packetData, &receivedBytes) &&
|
||||||
packetVersionMatch(packetData)) {
|
packetVersionMatch(packetData)) {
|
||||||
|
@ -308,7 +318,12 @@ int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
if ((*assignment)->getType() == Assignment::AgentType) {
|
if ((*assignment)->getType() == Assignment::AgentType) {
|
||||||
// if this is a script assignment we need to delete it to avoid a memory leak
|
// if this is a script assignment we need to delete it to avoid a memory leak
|
||||||
delete *assignment;
|
// or if there is more than one instance to send out, simpy decrease the number of instances
|
||||||
|
if ((*assignment)->getNumberOfInstances() > 1) {
|
||||||
|
(*assignment)->decrementNumberOfInstances();
|
||||||
|
} else {
|
||||||
|
delete *assignment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop looping, we've handed out an assignment
|
// stop looping, we've handed out an assignment
|
||||||
|
|
|
@ -55,6 +55,10 @@ public:
|
||||||
Assignment::Location getLocation() const { return _location; }
|
Assignment::Location getLocation() const { return _location; }
|
||||||
const timeval& getTime() const { return _time; }
|
const timeval& getTime() const { return _time; }
|
||||||
|
|
||||||
|
int getNumberOfInstances() const { return _numberOfInstances; }
|
||||||
|
void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; }
|
||||||
|
void decrementNumberOfInstances() { --_numberOfInstances; }
|
||||||
|
|
||||||
const sockaddr* getAttachedPublicSocket() { return _attachedPublicSocket; }
|
const sockaddr* getAttachedPublicSocket() { return _attachedPublicSocket; }
|
||||||
void setAttachedPublicSocket(const sockaddr* attachedPublicSocket);
|
void setAttachedPublicSocket(const sockaddr* attachedPublicSocket);
|
||||||
|
|
||||||
|
@ -77,6 +81,7 @@ private:
|
||||||
sockaddr* _attachedPublicSocket; /// pointer to a public socket that relates to assignment, depends on direction
|
sockaddr* _attachedPublicSocket; /// pointer to a public socket that relates to assignment, depends on direction
|
||||||
sockaddr* _attachedLocalSocket; /// pointer to a local socket that relates to assignment, depends on direction
|
sockaddr* _attachedLocalSocket; /// pointer to a local socket that relates to assignment, depends on direction
|
||||||
timeval _time; /// time the assignment was created (set in constructor)
|
timeval _time; /// time the assignment was created (set in constructor)
|
||||||
|
int _numberOfInstances; /// the number of instances of this assignment
|
||||||
};
|
};
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const Assignment &assignment);
|
QDebug operator<<(QDebug debug, const Assignment &assignment);
|
||||||
|
|
Loading…
Reference in a new issue