Server get arguments from command line

This commit is contained in:
Adrien Bourmault 2021-08-24 18:25:44 +02:00
parent b8787a9f5f
commit 768366d626
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
5 changed files with 123 additions and 58 deletions

View File

@ -115,14 +115,17 @@ install:
# ---- Builder uses this target to run the application ----------------------- # # ---- Builder uses this target to run the application ----------------------- #
run: all run: all
bin/gem-graph-server @bin/gem-graph-server -C debian/etc -M debian/var/models \
-U debian/var/users
run-both: all run-both: all
bin/gem-graph-server & sleep 1 && bin/gem-graph-ctl @bin/gem-graph-server -C debian/etc -M debian/var/models \
-U debian/var/users & sleep 1 && bin/gem-graph-ctl
run-server: all run-server: all
bin/gem-graph-server @bin/gem-graph-server -C debian/etc -M debian/var/models \
-U debian/var/users
run-cli: all run-cli: all
bin/gem-graph-ctl @bin/gem-graph-ctl
run-tests: tests run-tests: tests
bin/tests/scheduler @bin/tests/scheduler
include $(DEPS) include $(DEPS)

4
debian/control vendored
View File

@ -5,6 +5,6 @@ Priority: optional
Depends: libxml2 Depends: libxml2
Architecture: amd64 Architecture: amd64
Essential: no Essential: no
Installed-Size: 1049 Installed-Size: 112760
Maintainer: The Gem-graph Project Maintainer: The Gem-graph Project
Description: The gem-graph computation server Description: The wonderful gem-graph computation server

View File

@ -117,7 +117,7 @@ static inline xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
} }
if (cur->xmlChildrenNode) { if (cur->xmlChildrenNode) {
if ((recur = findRoot(tagName, cur->xmlChildrenNode) != NULL)) if ((recur = findRoot(tagName, cur->xmlChildrenNode)) != NULL)
return recur; return recur;
} }

View File

@ -25,7 +25,7 @@
static Server_t *server; static Server_t *server;
static void ExitingHandler(int signum) static void SigIntTermHandler(int signum)
{ {
server->pleaseStop = true; server->pleaseStop = true;
printLog("Server stopping\n"); printLog("Server stopping\n");
@ -39,27 +39,84 @@ static void ExitingHandler(int signum)
// - models & users directories // - models & users directories
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int options;
time_t t; time_t t;
int returnValue = 0; int returnValue = 0;
Parameters_t *parameters;
// Get parameters TODO from args // Get parameters TODO from args
Parameters_t *parameters = (Parameters_t*) calloc(sizeof(Parameters_t), 1); parameters = (Parameters_t*) calloc(sizeof(Parameters_t), 1);
parameters->configDir = (char*) malloc(255 * sizeof(char)); while ((options = getopt(argc, argv, ":C:M:U:")) != -1) {
realpath("./debian/etc", parameters->configDir); switch (options) {
case 'C':
printLog("Config : %s\n", optarg);
parameters->configDir = (char*) malloc(strlen(optarg) + 1);
strcpy(parameters->configDir, optarg);
break;
case 'M':
printLog("Models : %s\n", optarg);
parameters->modelDir = (char*) malloc(strlen(optarg) + 1);
strcpy(parameters->modelDir, optarg);
break;
case 'U':
printLog("User : %s\n", optarg);
parameters->userDir = (char*) malloc(strlen(optarg) + 1);
strcpy(parameters->userDir, optarg);
break;
case ':':
printLog("Option missing argument : %c\n", optopt);
if (parameters->configDir)
free(parameters->configDir);
parameters->modelDir = (char*) malloc(255 * sizeof(char)); if (parameters->modelDir)
realpath("./debian/var/models", parameters->modelDir); free(parameters->modelDir);
parameters->userDir = (char*) malloc(255 * sizeof(char)); if (parameters->userDir)
realpath("./debian/var/users", parameters->userDir); free(parameters->userDir);
free(parameters);
return ENOSYS;
break;
case '?':
printLog("Unknown option : %c\n", optopt);
if (parameters->configDir)
free(parameters->configDir);
if (parameters->modelDir)
free(parameters->modelDir);
if (parameters->userDir)
free(parameters->userDir);
free(parameters);
return ENOSYS;
break;
}
}
if (!parameters->configDir | !parameters->modelDir | !parameters->userDir) {
printLog("Missing arguments\n");
if (parameters->configDir)
free(parameters->configDir);
if (parameters->modelDir)
free(parameters->modelDir);
if (parameters->userDir)
free(parameters->userDir);
free(parameters);
return ENOSYS;
}
// Go! // Go!
printLog("Starting gem-graph-server...\n"); printLog("Starting gem-graph-server...\n");
// Register new interrupt handler // Register new interrupt handler
signal(SIGINT, ExitingHandler); signal(SIGINT, SigIntTermHandler);
signal(SIGTERM, ExitingHandler); signal(SIGTERM, SigIntTermHandler);
// Initializing random generator // Initializing random generator
t = time(&t); t = time(&t);

View File

@ -48,48 +48,10 @@ Model_t *lastModel;
Model_t **lastModelAddr; Model_t **lastModelAddr;
static int ModelParseFile(Model_t *model); static inline int ModelParseFile(Model_t *model);
void ModelSystemDestroy(void); void ModelSystemDestroy(void);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots
{
// increment index
knownModelSize++;
// create socket
knownModel =
(Model_t**) realloc(knownModel, knownModelSize * sizeof(Model_t*));
// populate socket
knownModel[knownModelSize-1] = (Model_t*) calloc(1, sizeof(Model_t));
// populate model
knownModel[knownModelSize-1]->id = knownModelSize;
// return value
*newModel = knownModel[knownModelSize-1];
lastModel = knownModel[knownModelSize-1];
lastModelAddr = &knownModel[knownModelSize-1];
// cont. model population
knownModel[knownModelSize-1]->name =
(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]->author =
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
knownModel[knownModelSize-1]->version =
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
knownModel[knownModelSize-1]->space_xMax = XMAX;
knownModel[knownModelSize-1]->space_yMax = YMAX;
knownModel[knownModelSize-1]->space_zMax = ZMAX;
knownModel[knownModelSize-1]->nmaxThread = MAX_THREAD;
knownModel[knownModelSize-1]->nmaxCycles = MAX_CYCLES;
knownModel[knownModelSize-1]->siteNumber = 0;
}
void printModels(char *buf) void printModels(char *buf)
{ {
@ -126,6 +88,8 @@ int ModelLoad(int id) // TODO unload !
return loadedModelSize; return loadedModelSize;
} }
/* -------------------------------------------------------------------------- */
int ModelRun(int id) int ModelRun(int id)
{ {
if (id <= 0 || id > loadedModelSize) if (id <= 0 || id > loadedModelSize)
@ -179,6 +143,45 @@ int ModelStop(int id)
return 1; return 1;
} }
/* -------------------------------------------------------------------------- */
void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots
{
// increment index
knownModelSize++;
// create socket
knownModel =
(Model_t**) realloc(knownModel, knownModelSize * sizeof(Model_t*));
// populate socket
knownModel[knownModelSize-1] = (Model_t*) calloc(1, sizeof(Model_t));
// populate model
knownModel[knownModelSize-1]->id = knownModelSize;
// return value
*newModel = knownModel[knownModelSize-1];
lastModel = knownModel[knownModelSize-1];
lastModelAddr = &knownModel[knownModelSize-1];
// cont. model population
knownModel[knownModelSize-1]->name =
(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]->author =
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
knownModel[knownModelSize-1]->version =
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
knownModel[knownModelSize-1]->space_xMax = XMAX;
knownModel[knownModelSize-1]->space_yMax = YMAX;
knownModel[knownModelSize-1]->space_zMax = ZMAX;
knownModel[knownModelSize-1]->nmaxThread = MAX_THREAD;
knownModel[knownModelSize-1]->nmaxCycles = MAX_CYCLES;
knownModel[knownModelSize-1]->siteNumber = 0;
}
void ModelDelete(int id) //XXX void ModelDelete(int id) //XXX
{ {
free(knownModel[id-1]->name); free(knownModel[id-1]->name);
@ -206,6 +209,8 @@ void ModelShutdown(void)
} }
} }
/* -------------------------------------------------------------------------- */
void ModelSystemInit(Parameters_t *parameters) void ModelSystemInit(Parameters_t *parameters)
{ {
struct dirent *modelDirEntry = NULL; struct dirent *modelDirEntry = NULL;
@ -282,7 +287,7 @@ void ModelSystemDestroy(void)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int ModelParseFile(Model_t *model) static inline int ModelParseFile(Model_t *model)
{ {
ModelField_t identityField; ModelField_t identityField;
ModelField_t authorField; ModelField_t authorField;