Model can be run and stop
This commit is contained in:
parent
1d5463c1c5
commit
4c1763f6c4
|
@ -161,6 +161,7 @@ struct {
|
|||
int nmaxThread;
|
||||
int nmaxCycles;
|
||||
int siteNumber;
|
||||
bool isRunning;
|
||||
Scheduler_t *scheduler;
|
||||
Supervisor_t *supervisor;
|
||||
} typedef Model_t;
|
||||
|
|
|
@ -33,11 +33,24 @@ void SchedInit(Scheduler_t *scheduler);
|
|||
// -------------------------------------------------------------------------- //
|
||||
static inline void SchedDestroy(Scheduler_t *scheduler)
|
||||
{
|
||||
if (scheduler) {
|
||||
if (scheduler->globalDrawingSpace) {
|
||||
if (scheduler->globalDrawingSpace->space) {
|
||||
free(scheduler->globalDrawingSpace->space);
|
||||
scheduler->globalDrawingSpace->space = NULL;
|
||||
}
|
||||
free(scheduler->globalDrawingSpace);
|
||||
|
||||
scheduler->globalDrawingSpace = NULL;
|
||||
}
|
||||
if (scheduler->arrowArray) {
|
||||
if (scheduler->arrowArray->array) {
|
||||
free(scheduler->arrowArray->array);
|
||||
scheduler->arrowArray->array = NULL;
|
||||
}
|
||||
free(scheduler->arrowArray);
|
||||
scheduler->arrowArray = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
|
|
@ -104,7 +104,7 @@ void connectedCommunication(int sockfd)
|
|||
curLineLength = 0;
|
||||
continueReadLine = 1;
|
||||
historyModifier = -1;
|
||||
while (continueReadLine && (curChar = getch())) {
|
||||
while (continueReadLine && (curChar = getch())) { //TODO empty line in history
|
||||
|
||||
switch (curChar) {
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ int main(int argc, char **argv)
|
|||
ServerDestroy(server0);
|
||||
ModelSystemDestroy();
|
||||
free(server0);
|
||||
server0 = NULL;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
|
53
src/model.c
53
src/model.c
|
@ -102,22 +102,6 @@ int ModelLoad(int id) // TODO unload !
|
|||
// Creating structure for the Scheduler
|
||||
knownModel[id-1]->scheduler = (Scheduler_t*) calloc(1, sizeof(Scheduler_t));
|
||||
|
||||
knownModel[id-1]->scheduler->globalDrawingSpace =
|
||||
(Space_t*) calloc(1, sizeof(Space_t)); // TODO free this
|
||||
|
||||
knownModel[id-1]->scheduler->nMaxThread = knownModel[id-1]->nmaxThread;
|
||||
knownModel[id-1]->scheduler->nMaxCycles = knownModel[id-1]->nmaxCycles;
|
||||
|
||||
// Preparing global drawing space
|
||||
ModelPrepareSpace(knownModel[id-1]->scheduler->globalDrawingSpace,
|
||||
knownModel[id-1]);
|
||||
|
||||
knownModel[id-1]->scheduler->arrowArray =
|
||||
(ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); // TODO free this
|
||||
|
||||
ModelPrepareArrows(knownModel[id-1]->scheduler->globalDrawingSpace,
|
||||
knownModel[id-1]->scheduler->arrowArray, knownModel[id-1]);
|
||||
|
||||
loadedModel =
|
||||
(Model_t**) realloc(loadedModel, ++loadedModelSize * sizeof(Model_t*));
|
||||
|
||||
|
@ -129,14 +113,37 @@ int ModelLoad(int id) // TODO unload !
|
|||
|
||||
int ModelRun(int id)
|
||||
{
|
||||
if (id <= 0 || id > loadedModelSize) {
|
||||
if (id <= 0 || id > loadedModelSize)
|
||||
return 0;
|
||||
}
|
||||
if (!loadedModel[id-1]->scheduler) {
|
||||
|
||||
if (!loadedModel[id-1]->scheduler)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (loadedModel[id-1]->isRunning)
|
||||
return 0;
|
||||
|
||||
loadedModel[id-1]->scheduler->globalDrawingSpace =
|
||||
(Space_t*) calloc(1, sizeof(Space_t)); // TODO free this
|
||||
|
||||
loadedModel[id-1]->scheduler->nMaxThread = knownModel[id-1]->nmaxThread;
|
||||
loadedModel[id-1]->scheduler->nMaxCycles = knownModel[id-1]->nmaxCycles;
|
||||
|
||||
// Preparing global drawing space
|
||||
ModelPrepareSpace(loadedModel[id-1]->scheduler->globalDrawingSpace,
|
||||
loadedModel[id-1]);
|
||||
|
||||
loadedModel[id-1]->scheduler->arrowArray =
|
||||
(ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); // TODO free this
|
||||
|
||||
ModelPrepareArrows(loadedModel[id-1]->scheduler->globalDrawingSpace,
|
||||
loadedModel[id-1]->scheduler->arrowArray,
|
||||
loadedModel[id-1]);
|
||||
|
||||
loadedModel[id-1]->scheduler->pleaseStop = false;
|
||||
loadedModel[id-1]->isRunning = true;
|
||||
|
||||
SchedInit(loadedModel[id-1]->scheduler);
|
||||
|
||||
printLog("Model %d launched\n", id);
|
||||
return 1;
|
||||
}
|
||||
|
@ -156,14 +163,16 @@ int ModelStop(int id)
|
|||
SchedWait(loadedModel[id-1]->scheduler);
|
||||
SchedDestroy(loadedModel[id-1]->scheduler);
|
||||
|
||||
loadedModel[id-1]->scheduler->pleaseStop = false;
|
||||
loadedModel[id-1]->isRunning = false;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ModelDelete(int id)
|
||||
{
|
||||
free(knownModel[id]->name);
|
||||
knownModel[id]->name = NULL;
|
||||
free(knownModel[id]);
|
||||
knownModel[id] = NULL;
|
||||
}
|
||||
|
||||
void ModelShutdown(void)
|
||||
|
@ -190,7 +199,9 @@ void ModelSystemDestroy(void)
|
|||
ModelDelete(i);
|
||||
}
|
||||
free(loadedModel);
|
||||
loadedModel = NULL;
|
||||
free(knownModel);
|
||||
knownModel = NULL;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
|
|
@ -57,6 +57,7 @@ static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow,
|
|||
|| (zmax && (abs(electedArrow->z - currentCenter->z) <= ruleRadius))
|
||||
){
|
||||
free(newCenter);
|
||||
newCenter = NULL;
|
||||
//printLog("Can't find a free area\n");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -213,7 +214,9 @@ static void *schedulerMain(void *scheduler)
|
|||
printLog("Scheduler #%lu offline\n", args->id);
|
||||
|
||||
free(workerArray);
|
||||
workerArray = NULL;
|
||||
free(centersList);
|
||||
centersList = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -112,8 +112,10 @@ void *serverCommunicationInstance(void *server)
|
|||
}
|
||||
|
||||
close(args->sockfd);
|
||||
if (argv)
|
||||
if (argv) {
|
||||
free(argv);
|
||||
argv = NULL;
|
||||
}
|
||||
printLog("Disconnected from %s:%d\n", clientIP, clientPort);
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue