mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 20:23:06 +02:00
Merge pull request #1156 from birarda/assignment
fix scripted assignment delete before it is sent out
This commit is contained in:
commit
c70d0c3d88
1 changed files with 12 additions and 8 deletions
|
@ -214,14 +214,14 @@ const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
|
||||||
void DomainServer::civetwebUploadHandler(struct mg_connection *connection, const char *path) {
|
void DomainServer::civetwebUploadHandler(struct mg_connection *connection, 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* scriptAssignment = new Assignment(Assignment::CreateCommand,
|
||||||
Assignment::AgentType,
|
Assignment::AgentType,
|
||||||
NULL,
|
NULL,
|
||||||
Assignment::LocalLocation);
|
Assignment::LocalLocation);
|
||||||
|
|
||||||
// check how many instances of this assignment the user wants by checking the ASSIGNMENT-INSTANCES header
|
// 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 ASSIGNMENT_INSTANCES_HTTP_HEADER[] = "ASSIGNMENT-INSTANCES";
|
||||||
const char *requestInstancesHeader = mg_get_header(connection, ASSIGNMENT_INSTANCES_HTTP_HEADER);
|
const char* requestInstancesHeader = mg_get_header(connection, ASSIGNMENT_INSTANCES_HTTP_HEADER);
|
||||||
|
|
||||||
if (requestInstancesHeader) {
|
if (requestInstancesHeader) {
|
||||||
// the user has requested a number of instances greater than 1
|
// the user has requested a number of instances greater than 1
|
||||||
|
@ -457,14 +457,13 @@ Assignment* DomainServer::deployableAssignmentForRequest(Assignment& requestAssi
|
||||||
Assignment* deployableAssignment = *assignment;
|
Assignment* deployableAssignment = *assignment;
|
||||||
|
|
||||||
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 there is more than one instance to send out, simply decrease the number of instances
|
||||||
// or if there is more than one instance to send out, simpy decrease the number of instances
|
|
||||||
if ((*assignment)->getNumberOfInstances() > 1) {
|
if ((*assignment)->getNumberOfInstances() == 1) {
|
||||||
(*assignment)->decrementNumberOfInstances();
|
|
||||||
} else {
|
|
||||||
_assignmentQueue.erase(assignment);
|
_assignmentQueue.erase(assignment);
|
||||||
delete *assignment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(*assignment)->decrementNumberOfInstances();
|
||||||
} else {
|
} else {
|
||||||
// remove the assignment from the queue
|
// remove the assignment from the queue
|
||||||
_assignmentQueue.erase(assignment);
|
_assignmentQueue.erase(assignment);
|
||||||
|
@ -735,6 +734,11 @@ int DomainServer::run() {
|
||||||
nodeList->getNodeSocket()->send((sockaddr*) &senderAddress,
|
nodeList->getNodeSocket()->send((sockaddr*) &senderAddress,
|
||||||
broadcastPacket,
|
broadcastPacket,
|
||||||
numHeaderBytes + numAssignmentBytes);
|
numHeaderBytes + numAssignmentBytes);
|
||||||
|
|
||||||
|
if (assignmentToDeploy->getNumberOfInstances() == 0) {
|
||||||
|
// there are no more instances of this script to send out, delete it
|
||||||
|
delete assignmentToDeploy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue