Detect xml models

This commit is contained in:
Adrien Bourmault 2021-08-20 16:10:18 +02:00
parent 5ba60afe7b
commit 876b0deb8b
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
4 changed files with 54 additions and 8 deletions

View File

@ -158,6 +158,7 @@ struct {
struct { struct {
int id; int id;
char *name; char *name;
char *filename;
int space_xMax; int space_xMax;
int space_yMax; int space_yMax;
int space_zMax; int space_zMax;

View File

@ -57,8 +57,12 @@ char *CmdModel(char *buf, char **argv, Server_t *args)
// TODO modify model according to things in file // TODO modify model according to things in file
// Write name
strcpy(newModel->name, argv[2] + 5); strcpy(newModel->name, argv[2] + 5);
// Write filename
strcpy(newModel->filename, argv[3] + 5);
sprintf(buf + strlen(buf), "Model %s created with id %d\n", sprintf(buf + strlen(buf), "Model %s created with id %d\n",
newModel->name, newModel->id); newModel->name, newModel->id);
goto CmdModelEnd; goto CmdModelEnd;

View File

@ -25,7 +25,7 @@
static Server_t *server; static Server_t *server;
void SigIntTermHandler(int signum) static void SigIntTermHandler(int signum)
{ {
server->pleaseStop = true; server->pleaseStop = true;
printLog("Server stopping\n"); printLog("Server stopping\n");
@ -34,7 +34,6 @@ void SigIntTermHandler(int signum)
printLog("All model shutted down\n"); printLog("All model shutted down\n");
} }
// TODO parse args to discover : // TODO parse args to discover :
// - config files directory // - config files directory
// - models & users directories // - models & users directories
@ -46,14 +45,14 @@ 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"));
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"));
strcpy(parameters->modelDir, "../debian/etc"); strcpy(parameters->modelDir, "debian/var/models");
parameters->userDir = (char*) malloc(strlen("../debian/var/users")); parameters->userDir = (char*) malloc(strlen("debian/var/users"));
strcpy(parameters->userDir, "../debian/etc"); strcpy(parameters->userDir, "debian/var/users");
// Go! // Go!
printLog("Starting gem-graph-server...\n"); printLog("Starting gem-graph-server...\n");

View File

@ -23,6 +23,9 @@
#include "../include/arrows.h" #include "../include/arrows.h"
#include "../include/scheduler.h" #include "../include/scheduler.h"
#include <dirent.h>
#include <signal.h>
#define MAX_MODEL_NUMBER 1 #define MAX_MODEL_NUMBER 1
#define MAX_MODEL_NAME_SIZE 255 #define MAX_MODEL_NAME_SIZE 255
#define ARROW_NUMBER 6 #define ARROW_NUMBER 6
@ -48,6 +51,9 @@ static void ModelPrepareArrows(Space_t *globalDrawingSpace,
ArrowArray_t *arrowArray, ArrowArray_t *arrowArray,
Model_t *model); Model_t *model);
void ModelSystemDestroy(void);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots
{ {
@ -68,6 +74,8 @@ void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots
// cont. model population // cont. model population
knownModel[knownModelSize-1]->name = knownModel[knownModelSize-1]->name =
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE); (char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
knownModel[knownModelSize-1]->filename =
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
knownModel[knownModelSize-1]->space_xMax = XMAX; knownModel[knownModelSize-1]->space_xMax = XMAX;
knownModel[knownModelSize-1]->space_yMax = YMAX; knownModel[knownModelSize-1]->space_yMax = YMAX;
knownModel[knownModelSize-1]->space_zMax = ZMAX; knownModel[knownModelSize-1]->space_zMax = ZMAX;
@ -184,6 +192,11 @@ void ModelShutdown(void)
void ModelSystemInit(Parameters_t *parameters) void ModelSystemInit(Parameters_t *parameters)
{ {
struct dirent *modelDirEntry = NULL;
DIR *modelDir = NULL;
Model_t *newModel;
char *extensionPosition;
loadedModel = (Model_t**) calloc(1, sizeof(Model_t*)); loadedModel = (Model_t**) calloc(1, sizeof(Model_t*));
knownModel = (Model_t**) calloc(1, sizeof(Model_t*)); knownModel = (Model_t**) calloc(1, sizeof(Model_t*));
@ -192,6 +205,35 @@ void ModelSystemInit(Parameters_t *parameters)
loadedModelSize = 0; loadedModelSize = 0;
printLog("Model system initiated with folder : %s\n", parameters->modelDir); printLog("Model system initiated with folder : %s\n", parameters->modelDir);
if ((modelDir = opendir(parameters->modelDir)) <= 0) {
printLog("Could not open %s\n", parameters->modelDir);
ModelSystemDestroy();
kill(getpid(), SIGTERM);
return;
}
printLog("Detected models : ");
while ((modelDirEntry = readdir(modelDir)) != NULL) {
if ((extensionPosition = strstr(modelDirEntry->d_name, ".xml"))) {
// Creating model
ModelCreate(&newModel);
// TODO modify model according to things in file
// Write filename
strncpy(newModel->filename, modelDirEntry->d_name,
strlen(modelDirEntry->d_name));
// Write name
strncpy(newModel->name, modelDirEntry->d_name,
extensionPosition - modelDirEntry->d_name);
printf("%s ", newModel->name);
}
}
printf("\n");
} }
void ModelSystemDestroy(void) void ModelSystemDestroy(void)