Ready to parse
This commit is contained in:
parent
876b0deb8b
commit
16753c7eff
|
@ -0,0 +1,26 @@
|
||||||
|
//=-------------------------------------------------------------------------=//
|
||||||
|
// XML management tools //
|
||||||
|
// //
|
||||||
|
// Copyright © 2021 The Gem-graph Project //
|
||||||
|
// //
|
||||||
|
// This file is part of gem-graph. //
|
||||||
|
// //
|
||||||
|
// This program is free software: you can redistribute it and/or modify //
|
||||||
|
// it under the terms of the GNU Affero General Public License as //
|
||||||
|
// published by the Free Software Foundation, either version 3 of the //
|
||||||
|
// License, or (at your option) any later version. //
|
||||||
|
// //
|
||||||
|
// This program is distributed in the hope that it will be useful, //
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||||
|
// GNU Affero General Public License for more details. //
|
||||||
|
// //
|
||||||
|
// You should have received a copy of the GNU Affero General Public License //
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
|
#ifndef BASE_H
|
||||||
|
#include "../include/base.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
12
src/main.c
12
src/main.c
|
@ -45,13 +45,13 @@ int main(int argc, char **argv)
|
||||||
// Get parameters TODO from args
|
// Get parameters TODO from args
|
||||||
Parameters_t *parameters = (Parameters_t*) calloc(sizeof(Parameters_t), 1);
|
Parameters_t *parameters = (Parameters_t*) calloc(sizeof(Parameters_t), 1);
|
||||||
|
|
||||||
parameters->configDir = (char*) malloc(strlen("debian/etc"));
|
parameters->configDir = (char*) malloc(strlen("debian/etc") + 1);
|
||||||
strcpy(parameters->configDir, "debian/etc");
|
strcpy(parameters->configDir, "debian/etc");
|
||||||
|
|
||||||
parameters->modelDir = (char*) malloc(strlen("debian/var/models"));
|
parameters->modelDir = (char*) malloc(strlen("debian/var/models") + 1);
|
||||||
strcpy(parameters->modelDir, "debian/var/models");
|
strcpy(parameters->modelDir, "debian/var/models");
|
||||||
|
|
||||||
parameters->userDir = (char*) malloc(strlen("debian/var/users"));
|
parameters->userDir = (char*) malloc(strlen("debian/var/users") + 1);
|
||||||
strcpy(parameters->userDir, "debian/var/users");
|
strcpy(parameters->userDir, "debian/var/users");
|
||||||
|
|
||||||
// Go!
|
// Go!
|
||||||
|
@ -83,5 +83,11 @@ int main(int argc, char **argv)
|
||||||
free(server);
|
free(server);
|
||||||
server = NULL;
|
server = NULL;
|
||||||
|
|
||||||
|
free(parameters->userDir);
|
||||||
|
free(parameters->modelDir);
|
||||||
|
free(parameters->configDir);
|
||||||
|
free(parameters);
|
||||||
|
parameters = NULL;
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
90
src/model.c
90
src/model.c
|
@ -20,6 +20,7 @@
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
|
#include "../include/xml.h"
|
||||||
#include "../include/arrows.h"
|
#include "../include/arrows.h"
|
||||||
#include "../include/scheduler.h"
|
#include "../include/scheduler.h"
|
||||||
|
|
||||||
|
@ -46,10 +47,8 @@ static int knownModelSize; // begins to 1
|
||||||
Model_t *lastModel;
|
Model_t *lastModel;
|
||||||
Model_t **lastModelAddr;
|
Model_t **lastModelAddr;
|
||||||
|
|
||||||
static void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model);
|
|
||||||
static void ModelPrepareArrows(Space_t *globalDrawingSpace,
|
static void ModelParseFile(Model_t *model);
|
||||||
ArrowArray_t *arrowArray,
|
|
||||||
Model_t *model);
|
|
||||||
|
|
||||||
|
|
||||||
void ModelSystemDestroy(void);
|
void ModelSystemDestroy(void);
|
||||||
|
@ -81,7 +80,7 @@ void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots
|
||||||
knownModel[knownModelSize-1]->space_zMax = ZMAX;
|
knownModel[knownModelSize-1]->space_zMax = ZMAX;
|
||||||
knownModel[knownModelSize-1]->nmaxThread = MAX_THREAD;
|
knownModel[knownModelSize-1]->nmaxThread = MAX_THREAD;
|
||||||
knownModel[knownModelSize-1]->nmaxCycles = MAX_CYCLES;
|
knownModel[knownModelSize-1]->nmaxCycles = MAX_CYCLES;
|
||||||
knownModel[knownModelSize-1]->siteNumber = SITE_NUMBER;
|
knownModel[knownModelSize-1]->siteNumber = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printModels(char *buf)
|
void printModels(char *buf)
|
||||||
|
@ -137,15 +136,12 @@ int ModelRun(int id)
|
||||||
loadedModel[id-1]->scheduler->nMaxCycles = knownModel[id-1]->nmaxCycles;
|
loadedModel[id-1]->scheduler->nMaxCycles = knownModel[id-1]->nmaxCycles;
|
||||||
|
|
||||||
// Preparing global drawing space
|
// Preparing global drawing space
|
||||||
ModelPrepareSpace(loadedModel[id-1]->scheduler->globalDrawingSpace,
|
// TODO Load space
|
||||||
loadedModel[id-1]);
|
|
||||||
|
|
||||||
loadedModel[id-1]->scheduler->arrowArray =
|
loadedModel[id-1]->scheduler->arrowArray =
|
||||||
(ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); // TODO free this
|
(ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); // TODO free this
|
||||||
|
|
||||||
ModelPrepareArrows(loadedModel[id-1]->scheduler->globalDrawingSpace,
|
// TODO Load arrows
|
||||||
loadedModel[id-1]->scheduler->arrowArray,
|
|
||||||
loadedModel[id-1]);
|
|
||||||
|
|
||||||
loadedModel[id-1]->scheduler->pleaseStop = false;
|
loadedModel[id-1]->scheduler->pleaseStop = false;
|
||||||
loadedModel[id-1]->isRunning = true;
|
loadedModel[id-1]->isRunning = true;
|
||||||
|
@ -175,12 +171,14 @@ int ModelStop(int id)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelDelete(int id)
|
void ModelDelete(int id) //XXX
|
||||||
{
|
{
|
||||||
free(knownModel[id]->name);
|
free(knownModel[id-1]->name);
|
||||||
knownModel[id]->name = NULL;
|
knownModel[id-1]->name = NULL;
|
||||||
free(knownModel[id]);
|
free(knownModel[id-1]->filename);
|
||||||
knownModel[id] = NULL;
|
knownModel[id-1]->name = NULL;
|
||||||
|
free(knownModel[id-1]);
|
||||||
|
knownModel[id-1] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelShutdown(void)
|
void ModelShutdown(void)
|
||||||
|
@ -220,8 +218,6 @@ void ModelSystemInit(Parameters_t *parameters)
|
||||||
// Creating model
|
// Creating model
|
||||||
ModelCreate(&newModel);
|
ModelCreate(&newModel);
|
||||||
|
|
||||||
// TODO modify model according to things in file
|
|
||||||
|
|
||||||
// Write filename
|
// Write filename
|
||||||
strncpy(newModel->filename, modelDirEntry->d_name,
|
strncpy(newModel->filename, modelDirEntry->d_name,
|
||||||
strlen(modelDirEntry->d_name));
|
strlen(modelDirEntry->d_name));
|
||||||
|
@ -230,6 +226,14 @@ void ModelSystemInit(Parameters_t *parameters)
|
||||||
strncpy(newModel->name, modelDirEntry->d_name,
|
strncpy(newModel->name, modelDirEntry->d_name,
|
||||||
extensionPosition - modelDirEntry->d_name);
|
extensionPosition - modelDirEntry->d_name);
|
||||||
|
|
||||||
|
ModelParseFile(newModel);
|
||||||
|
|
||||||
|
// Check model is valid and/or parsed
|
||||||
|
if (newModel->siteNumber == 0) {
|
||||||
|
ModelDelete(newModel->id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
printf("%s ", newModel->name);
|
printf("%s ", newModel->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,54 +253,8 @@ void ModelSystemDestroy(void)
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model)
|
static void ModelParseFile(Model_t *model)
|
||||||
{
|
{
|
||||||
globalDrawingSpace->size =
|
// TODO modify model according to things in file
|
||||||
(model->space_xMax+1) * (model->space_yMax+1) * (model->space_zMax+1);
|
;
|
||||||
globalDrawingSpace->xMax = model->space_xMax;
|
|
||||||
globalDrawingSpace->yMax = model->space_yMax;
|
|
||||||
globalDrawingSpace->zMax = model->space_zMax;
|
|
||||||
|
|
||||||
globalDrawingSpace->space =
|
|
||||||
(SpaceUnit_t*) calloc(globalDrawingSpace->size, sizeof(SpaceUnit_t));
|
|
||||||
|
|
||||||
for (int i = 0; i < globalDrawingSpace->size; i++) {
|
|
||||||
globalDrawingSpace->space[i].nSite = model->siteNumber;
|
|
||||||
globalDrawingSpace->space[i].sites =
|
|
||||||
(Site_t*) calloc(model->siteNumber, sizeof(Site_t));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ModelPrepareArrows(Space_t *globalDrawingSpace,
|
|
||||||
ArrowArray_t *arrowArray,
|
|
||||||
Model_t *model)
|
|
||||||
{
|
|
||||||
arrowArray->array = (Arrow_t*) calloc(ARROW_NUMBER, sizeof(Arrow_t));
|
|
||||||
arrowArray->size = ARROW_NUMBER; //XXX hardcoded
|
|
||||||
|
|
||||||
// Creating some arrows XXX random walking
|
|
||||||
/* In each cell: the West (left) site is 0, the East (right) site is 1 */
|
|
||||||
globalDrawingSpace->space[1].sites[1].nArrow = 1;
|
|
||||||
arrowArray->array[0].siteId = 1;
|
|
||||||
arrowArray->array[0].x = 1;
|
|
||||||
|
|
||||||
globalDrawingSpace->space[2].sites[0].nArrow = 1;
|
|
||||||
arrowArray->array[1].siteId = 0;
|
|
||||||
arrowArray->array[1].x = 2;
|
|
||||||
|
|
||||||
globalDrawingSpace->space[3].sites[1].nArrow = 1;
|
|
||||||
arrowArray->array[2].siteId = 1;
|
|
||||||
arrowArray->array[2].x = 3;
|
|
||||||
|
|
||||||
globalDrawingSpace->space[4].sites[0].nArrow = 1;
|
|
||||||
arrowArray->array[3].siteId = 0;
|
|
||||||
arrowArray->array[3].x = 4;
|
|
||||||
|
|
||||||
globalDrawingSpace->space[10].sites[1].nArrow = 1;
|
|
||||||
arrowArray->array[4].siteId = 1;
|
|
||||||
arrowArray->array[4].x = 10;
|
|
||||||
|
|
||||||
globalDrawingSpace->space[11].sites[0].nArrow = 1;
|
|
||||||
arrowArray->array[5].siteId = 0;
|
|
||||||
arrowArray->array[5].x = 11;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
//=-------------------------------------------------------------------------=//
|
||||||
|
// XML management tools //
|
||||||
|
// //
|
||||||
|
// Copyright © 2021 The Gem-graph Project //
|
||||||
|
// //
|
||||||
|
// This file is part of gem-graph. //
|
||||||
|
// //
|
||||||
|
// This program is free software: you can redistribute it and/or modify //
|
||||||
|
// it under the terms of the GNU Affero General Public License as //
|
||||||
|
// published by the Free Software Foundation, either version 3 of the //
|
||||||
|
// License, or (at your option) any later version. //
|
||||||
|
// //
|
||||||
|
// This program is distributed in the hope that it will be useful, //
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||||
|
// GNU Affero General Public License for more details. //
|
||||||
|
// //
|
||||||
|
// You should have received a copy of the GNU Affero General Public License //
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
|
#include "../include/base.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue