From 093c3cc0eaba94f8b15a52270ec8572db4cb7a53 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 18 Jun 2021 15:05:15 +0200 Subject: [PATCH] Test --- include/cmds.h | 37 ++++++++++++++++++++++ src/cmds.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 include/cmds.h create mode 100644 src/cmds.c diff --git a/include/cmds.h b/include/cmds.h new file mode 100644 index 0000000..dc2dc9a --- /dev/null +++ b/include/cmds.h @@ -0,0 +1,37 @@ +//=-------------------------------------------------------------------------=// +// Server supported commands definition // +// // +// 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 . // +//=-------------------------------------------------------------------------=// + +#ifndef BASE_H + #include "../include/base.h" +#endif + +void *loadServer(void*); + +struct { + const char *name; + void* (*execute)(void*); + const char *help; +} typedef Command_t; + +Command_t cmdList[] = +{ + {"launch scheduler", loadServer, "Launches a scheduler instance"}, +}; diff --git a/src/cmds.c b/src/cmds.c new file mode 100644 index 0000000..a4f4151 --- /dev/null +++ b/src/cmds.c @@ -0,0 +1,84 @@ +//=-------------------------------------------------------------------------=// +// Server management module // +// // +// 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 . // +//=-------------------------------------------------------------------------=// + +#include "../include/base.h" +#include "../include/scheduler.h" + +#define ARROW_NUMBER 150 +#define MAX_CYCLES 15 +#define MAX_THREAD 0 +#define XMAX 1000 +#define YMAX 1000 +#define ZMAX 0 +#define SPACE_SIZE (XMAX+1) * (YMAX+1) * (ZMAX+1) + +/* -------------------------------------------------------------------------- */ + +void *loadServer(void *args) +{ + Scheduler_t *scheduler0; + + // + // Creating structure for the Scheduler + // + scheduler0 = (Scheduler_t*) calloc(1, sizeof(Scheduler_t)); + + scheduler0->globalDrawingSpace = + (Space_t*) calloc(1, sizeof(Space_t)); + scheduler0->globalDrawingSpace->space = + (SpaceUnit_t*) calloc(SPACE_SIZE, sizeof(SpaceUnit_t)); + scheduler0->globalDrawingSpace->size = SPACE_SIZE; + scheduler0->globalDrawingSpace->xmax = SPACE_SIZE; + scheduler0->globalDrawingSpace->ymax = SPACE_SIZE; + scheduler0->globalDrawingSpace->zmax = SPACE_SIZE; + + scheduler0->arrowList = (ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); + scheduler0->arrowList->array = + (Arrow_t*) calloc(ARROW_NUMBER, sizeof(Arrow_t)); + scheduler0->arrowList->size = ARROW_NUMBER; + + printLog("Populating a random arrow list...\n"); + + for (int i = 0; i < ARROW_NUMBER; i++) { + + if (scheduler0->globalDrawingSpace->xmax) + scheduler0->arrowList->array[i].x = + rand() % (scheduler0->globalDrawingSpace->xmax + 1); + + if (scheduler0->globalDrawingSpace->ymax) + scheduler0->arrowList->array[i].y = + rand() % (scheduler0->globalDrawingSpace->ymax + 1); + + if (scheduler0->globalDrawingSpace->zmax) + scheduler0->arrowList->array[i].z = + rand() % (scheduler0->globalDrawingSpace->zmax + 1); + } + + scheduler0->nmaxThread = MAX_THREAD; + scheduler0->nmaxCycles = MAX_CYCLES; + + // + // Creating the Scheduler thread + // + SchedInit(scheduler0); + + return scheduler0; +}