From f01e882c28f5da48b969668310a43215c0e37b38 Mon Sep 17 00:00:00 2001 From: "Adrien Bourmault (neox)" Date: Sun, 10 Mar 2024 22:19:12 +0200 Subject: [PATCH] WIP: rebooting server design Signed-off-by: Adrien Bourmault (neox) --- Makefile | 176 +++---- bin/.placeholder | 0 bin/tests/.placeholder | 0 debian/conffiles | 1 - debian/control | 10 - debian/copyright | 13 - debian/etc/server.conf | 2 - debian/var/models/.placeholder | 0 debian/var/models/example_0.2.xml | 111 ----- debian/var/models/schemas/.placeholder | 0 debian/var/models/schemas/model_0.2.xmls | 199 -------- debian/var/users/.placeholder | 0 include/arrows.h | 29 -- include/base.h | 159 ------- include/centers.h | 8 - include/cmds.h | 17 +- include/model.h | 22 +- include/parsing.h | 34 -- include/scheduler.h | 51 +-- include/server.h | 10 +- include/supervisor.h | 13 +- include/terminal.h | 22 +- include/worker.h | 12 +- include/xml.h | 35 -- manifest.scm | 26 ++ src/arrows.c | 4 - src/centers.c | 27 -- src/{ => cli}/cli.c | 0 src/cmds.c | 308 ++++++------- src/main.c | 54 +-- src/model.c | 282 ------------ src/parsing.c | 556 ----------------------- src/scheduler.c | 198 -------- src/server.c | 27 +- src/supervisor.c | 18 - src/tests/getchar | Bin 17096 -> 0 bytes src/tests/test_realloc | Bin 16720 -> 0 bytes src/tests/xml | Bin 17128 -> 0 bytes src/worker.c | 36 -- 39 files changed, 367 insertions(+), 2093 deletions(-) delete mode 100644 bin/.placeholder delete mode 100644 bin/tests/.placeholder delete mode 100644 debian/conffiles delete mode 100644 debian/control delete mode 100644 debian/copyright delete mode 100644 debian/etc/server.conf delete mode 100644 debian/var/models/.placeholder delete mode 100644 debian/var/models/example_0.2.xml delete mode 100644 debian/var/models/schemas/.placeholder delete mode 100644 debian/var/models/schemas/model_0.2.xmls delete mode 100644 debian/var/users/.placeholder delete mode 100644 include/xml.h create mode 100644 manifest.scm rename src/{ => cli}/cli.c (100%) delete mode 100755 src/tests/getchar delete mode 100755 src/tests/test_realloc delete mode 100755 src/tests/xml diff --git a/Makefile b/Makefile index 1d5cc68..a566609 100644 --- a/Makefile +++ b/Makefile @@ -20,120 +20,124 @@ # along with this program. If not, see . # #=----------------------------------------------------------------------------=# -CCOPTS=-pthread -Wall -g -Os -I/usr/include/libxml2 -LDFLAGS= -lc -lpthread -lxml2 +.PHONY: all clean install run build_system +.DELETE_ON_ERROR: $(BINDIR)/gem-graph-server +.DEFAULT_GOAL := all + +# +# Color codes +# +CL='\033[0;32m' +CL2='\033[1;36m' +CL3='\033[0m' +NC='\033[1;37m' + +# +# Variables & constants +# +NTHREADS= $(shell nproc) + +CC=gcc +WARNINGS= -Wall +DEBUG= -ggdb -fno-omit-frame-pointer -fdiagnostics-color=always -fsanitize=bounds -fstack-check + #-fsanitize=address \ + #-fsanitize=pointer-compare -fsanitize=pointer-subtract \ + #-fsanitize=leak -fsanitize=undefined -fsanitize=null -fsanitize=bounds +OPTIMIZE= -O3 +INCLUDE= $(shell pkg-config --cflags glib-2.0 libxml-2.0 gtk4) +LIBS= $(shell pkg-config --libs glib-2.0 libxml-2.0 gtk4) -lGL -lGLU -lm -lepoxy -lX11 -lGLEW BINDIR=bin -INCDIR=include +BUILDDIR=build SRCDIR=src -DEBDIR=debian +#vpath %.c $(SRCDIR) -SERVEROBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/worker.o \ - $(BINDIR)/centers.o $(BINDIR)/cmds.o $(BINDIR)/model.o \ - $(BINDIR)/main.o $(BINDIR)/arrows.o $(BINDIR)/parsing.o -CLIOBJ= $(BINDIR)/cli.o - -SRCS=$(patsubst $(BINDIR)/%.o,$(SRCDIR)/%.c,$(SERVEROBJ)) \ - $(patsubst $(BINDIR)/%.o,$(SRCDIR)/%.c,$(CLIOBJ)) - -DEPS=$(patsubst $(BINDIR)/%.o,$(BINDIR)/%.d,$(SERVEROBJ)) \ - $(patsubst $(BINDIR)/%.o,$(BINDIR)/%.d,$(CLIOBJ)) +SOURCES= $(shell find $(SRCDIR) -maxdepth 1 -type f -name "*.c") +BUILDBINS=$(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES)) +BUILDDEPS=$(patsubst %.c,$(BUILDDIR)/%.d,$(SOURCES)) -.DEFAULT_GOAL:= all -.PHONY: all clean deb tests install run run-cli run-tests dependencies +-include /etc/os-release -# ---- Dependencies enumeration ---------------------------------------------- # +# +# Directories +# +$(BUILDDIR): + @mkdir -p $@ + @echo -e ${CL2}[$@] ${CL}folder generated.${CL3} -dependencies: $(DEPS) +$(BINDIR): + @mkdir -p $@ + @echo -e ${CL2}[$@] ${CL}folder generated.${CL3} -$(BINDIR)/%.d: $(BINDIR)/%.o $(SRCDIR)/%.c - @$(CC) $(CFLAGS) -MM -MT $< $(word 2,$^) -MF $@ +# +# Dependencies +# +-include $(BUILDDEPS) -# ---- Tests enumeration ----------------------------------------------------- # -TEST_SCHEDULER=$(BINDIR)/tests/centers -TESTS=$(TEST_SCHEDULER) +$(BUILDDIR)/%.d: %.c | $(BUILDDIR) + @mkdir -p $(shell dirname $@) + @$(CC) -MM -MT $(@:%.d=%.o) -MF $@ $< + @echo -e ${CL2}[$@] ${CL}dependencies generated.${CL3} -$(BINDIR)/tests/centers: $(SRCDIR)/tests/centers.c - @echo "Compiling $<" - @$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) $(LDFLAGS) -o $@ $< +# +# Compilation +# +$(BINDIR)/gem-graph-server: $(BUILDBINS) | $(BINDIR) + @$(CC) -o $@ $(WARNINGS) $(DEBUG) $(OPTIMIZE) $^ $(INCLUDE) $(LIBS) + @echo -e ${CL2}[$@] ${CL}built.${CL3} -# ---- General recipes ------------------------------------------------------- # -$(BINDIR)/%.o: $(SRCDIR)/%.c - @echo "Compiling $<" - @$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) -c -o $@ $< +$(BUILDDIR)/%.o: %.c | $(BUILDDIR) + @mkdir -p $(shell dirname $@) + @$(CC) $(WARNINGS) $(DEBUG) $(OPTIMIZE) $(INCLUDE) -c $< -o $@ + @echo -e ${CL2}[$@] ${CL}compiled.${CL3} -# ---- Main recipe ----------------------------------------------------------- # -$(BINDIR)/main.o: $(SRCDIR)/main.c - @echo "Compiling $<" - @$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) -c -o $@ $< -$(BINDIR)/gem-graph-server: $(SERVEROBJ) - @echo "Building program to $@" - @$(CC) -o $@ $(SERVEROBJ) $(LDFLAGS) - @echo "Success!" - -$(BINDIR)/gem-graph-ctl: $(CLIOBJ) - @echo "Building program to $@" - @$(CC) -o $@ $(CLIOBJ) $(LDFLAGS) - @echo "Success!" - -# ---- Misc recipes ---------------------------------------------------------- # +# +# Virtual recipes +# clean: - -rm -f $(SRCDIR)/*.o $(BINDIR)/* $(BINDIR)/tests/* *.deb + @rm -rf $(BINDIR) + @rm -rf $(BUILDDIR) + @echo -e ${CL2}[$@] ${CL}done.${CL3} -all: dependencies $(BINDIR)/gem-graph-server $(BINDIR)/gem-graph-ctl - -tests: $(TESTS) - -# ---- Build debian package -------------------------------------------------- # -$(BINDIR)/gem-graph-server.deb: all $(DEBDIR)/control \ - $(DEBDIR)/conffiles \ - $(DEBDIR)/etc/server.conf \ - $(DEBDIR)/copyright - mkdir -p gem-graph-server/usr/bin - mkdir -p gem-graph-server/var/lib/gem-graph-server/models - mkdir -p gem-graph-server/var/lib/gem-graph-server/users - mkdir -p gem-graph-server/etc/gem-graph-server - mkdir -p gem-graph-server/usr/share/doc/gem-graph-server - mkdir -p gem-graph-server/DEBIAN - cp $(DEBDIR)/control gem-graph-server/DEBIAN/control - cp $(DEBDIR)/conffiles gem-graph-server/DEBIAN/conffiles - cp $(DEBDIR)/etc/* gem-graph-server/etc/gem-graph-server - cp $(BINDIR)/gem-graph-server gem-graph-server/usr/bin - cp $(BINDIR)/gem-graph-ctl gem-graph-server/usr/bin - cp $(DEBDIR)/copyright \ - gem-graph-server/usr/share/doc/gem-graph-server/copyright - dpkg-deb --build gem-graph-server - rm -rf gem-graph-server - -deb: $(BINDIR)/gem-graph-server.deb - -# ---- Builder will call this to install the application before running ------ # install: echo "Installing is not supported" -# ---- Builder uses this target to run the application ----------------------- # -run: all - @bin/gem-graph-server -C debian/etc -M debian/var/models \ - -U debian/var/users -run-gdb: all +build_system: + @echo -e ${CL2}[$@] ${CL}building...${CL3} + @make $(BINDIR)/gem-graph-server -j $(NTHREADS) + @echo -e ${CL2}[$@] ${CL}done.${CL3} + +run: build_system + @echo -e ${CL2}[$@] ${CL}executing...${CL3} @gdb bin/gem-graph-server \ -ex "set args -C debian/etc -M debian/var/models -U debian/var/users" + @echo -e ${CL2}[$@] ${CL}done.${CL3} -run-valgrind: all +debug: build_system + @echo -e ${CL2}[$@] ${CL}executing...${CL3} + @gdb $(BINDIR)/gem-graph-server + @echo -e ${CL2}[$@] ${CL}done.${CL3} + +valgrind: build_system + @echo -e ${CL2}[$@] ${CL}executing...${CL3} @valgrind --leak-check=full --show-leak-kinds=all -s \ bin/gem-graph-server -C debian/etc -M debian/var/models \ -U debian/var/users + @echo -e ${CL2}[$@] ${CL}done.${CL3} -run-both: all +run-both: build_system + @echo -e ${CL2}[$@] ${CL}executing...${CL3} @bin/gem-graph-server -C debian/etc -M debian/var/models \ -U debian/var/users & sleep 1 && bin/gem-graph-ctl -run-server: all + @echo -e ${CL2}[$@] ${CL}done.${CL3} +run-server: build_system + @echo -e ${CL2}[$@] ${CL}executing...${CL3} @bin/gem-graph-server -C debian/etc -M debian/var/models \ -U debian/var/users -run-cli: all - @bin/gem-graph-ctl -run-tests: tests - @bin/tests/scheduler + @echo -e ${CL2}[$@] ${CL}done.${CL3} + +all: build_system + @echo -e ${CL2}[$@] ${CL}done.${CL3} diff --git a/bin/.placeholder b/bin/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/bin/tests/.placeholder b/bin/tests/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/debian/conffiles b/debian/conffiles deleted file mode 100644 index 39f0001..0000000 --- a/debian/conffiles +++ /dev/null @@ -1 +0,0 @@ -/etc/gem-graph-server/server.conf diff --git a/debian/control b/debian/control deleted file mode 100644 index 8341870..0000000 --- a/debian/control +++ /dev/null @@ -1,10 +0,0 @@ -Package: gem-graph-server -Version: 0.0.1 -Section: custom -Priority: optional -Depends: libxml2 -Architecture: amd64 -Essential: no -Installed-Size: 112760 -Maintainer: Libre en Communs (contact@a-lec.org) -Description: The wonderful gem-graph computation server diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index 60bafbd..0000000 --- a/debian/copyright +++ /dev/null @@ -1,13 +0,0 @@ -This is a packacked upstream version of gem-graph-server - -The sources may be found at . - -Copyright © 2021 Libre en Communs (contact@a-lec.org) - - 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. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . diff --git a/debian/etc/server.conf b/debian/etc/server.conf deleted file mode 100644 index 7cb97ca..0000000 --- a/debian/etc/server.conf +++ /dev/null @@ -1,2 +0,0 @@ -# CECI EST UN FICHIER DE CONFIGURATION -server_enabled=true diff --git a/debian/var/models/.placeholder b/debian/var/models/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/debian/var/models/example_0.2.xml b/debian/var/models/example_0.2.xml deleted file mode 100644 index 849e357..0000000 --- a/debian/var/models/example_0.2.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - Modèle de test - - Gaston Lagaffe - - 2 - - 1629830000 - - 1.0 - - Ref - - - - - - 0 - 9 - - - - - 1 - - 3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/debian/var/models/schemas/.placeholder b/debian/var/models/schemas/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/debian/var/models/schemas/model_0.2.xmls b/debian/var/models/schemas/model_0.2.xmls deleted file mode 100644 index a4f255d..0000000 --- a/debian/var/models/schemas/model_0.2.xmls +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/debian/var/users/.placeholder b/debian/var/users/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/include/arrows.h b/include/arrows.h index ef887ff..27e9e74 100644 --- a/include/arrows.h +++ b/include/arrows.h @@ -27,33 +27,4 @@ /* -------------------------------------------------------------------------- */ -static inline int ArrowsInitLock(ArrowArray_t *arrowArray) -{ - return pthread_spin_init(&arrowArray->lock, PTHREAD_PROCESS_SHARED); -} -static inline int ArrowsDestroyLock(ArrowArray_t *arrowArray) -{ - return pthread_spin_destroy(&arrowArray->lock); -} - -static inline int ArrowsAcquireLock(ArrowArray_t *arrowArray) -{ - return pthread_spin_lock(&arrowArray->lock); -} - -static inline int ArrowsAcquireNonBlockingLock(ArrowArray_t *arrowArray) -{ - return pthread_spin_trylock(&arrowArray->lock); -} - -static inline int ArrowsReleaseLock(ArrowArray_t *arrowArray) -{ - return pthread_spin_unlock(&arrowArray->lock); -} - -Arrow_t *ArrowAdd(Scheduler_t *scheduler, int x, int y, int z, int siteId, - int weight); - -bool ArrowRemove(Scheduler_t *scheduler, int x, int y, int z, int siteId, - int weight); diff --git a/include/base.h b/include/base.h index c348dcf..8dec1f9 100644 --- a/include/base.h +++ b/include/base.h @@ -44,163 +44,4 @@ /* -------------------------------------------------------------------------- */ -struct IntArray_t { - size_t size; - int *space; -} typedef IntArray_t; -struct Arrow_t { - int x; - int y; - int z; - int siteId; - int weight; -} typedef Arrow_t; - -struct ArrowArray_t { - size_t size; - unsigned int freeSlotCount; - Arrow_t **freeSlots; - pthread_spinlock_t lock; - Arrow_t *array; -} typedef ArrowArray_t; - -struct Site_t { - char *label; - int nArrow; - Arrow_t *arrowsPtr; -} typedef Site_t; - -struct SpaceUnit_t { - int nSite; - char *label; - Site_t *sites; -} typedef SpaceUnit_t; - -struct Space_t { - int xMax; - int yMax; - int zMax; - size_t size; - SpaceUnit_t *space; -} typedef Space_t; - -/* -------------------------------------------------------------------------- */ - -// -// Scheduler -// -struct Scheduler_t { - pthread_t id; - bool pleaseStop; - Space_t *globalDrawingSpace; - IntArray_t *conditionTree; - ArrowArray_t *arrowArray; - int nMaxThread; - int nMaxCycles; - int ruleRadius; -} typedef Scheduler_t; - -/* -------------------------------------------------------------------------- */ - -// -// Local threads -// -struct Center_t { - int x; - int y; - int z; - struct Center_t *next; - struct Center_t *prev; -} typedef Center_t; - -struct Worker_t { - pthread_t id; - Center_t *localWorkAreaCenter; - Space_t *globalDrawingSpace; - IntArray_t *conditionTree; // XXX - ArrowArray_t *arrowArray; - bool pleaseStop; - bool terminated; - int returnValue; -} typedef Worker_t; - -/* -------------------------------------------------------------------------- */ - -// -// Server -// -struct Server_t { - pthread_t id; - bool pleaseStop; - int returnValue; - int sockfd; // Socket file descriptor -} typedef Server_t; - -struct ServerCommunication_t { - pthread_t id; - bool pleaseStop; - Server_t *associatedServer; - int sockfd; // Socket file descriptor - struct sockaddr_in clientAddr; - socklen_t sockLen; -} typedef ServerCommunication_t; - -/* -------------------------------------------------------------------------- */ - -// -// Supervisor -// -struct Supervisor_t { - pthread_t id; - bool pleaseStop; - int *workerCreationOccurency; // XXX ??? -} typedef Supervisor_t; - -/* -------------------------------------------------------------------------- */ - -// -// Model -// -struct Model_t { - // Identity - int id; - bool validated; // true if model has been correctly parsed - char *name; - char *owner; - char *owner_id; - time_t date; - char *version; - char *filename; - // Parameters - int space_xMax; // TODO more than 3 dimension ? - int space_yMax; - int space_zMax; - int nmaxThread; - int nmaxCycles; - int siteNumber; - // Model instance - bool isRunning; - Scheduler_t *scheduler; - Supervisor_t *supervisor; -} typedef Model_t; - -struct ModelField_t { - bool mandatory; // true if field must exist in file - char tag[25]; // XML tag attached to that field - char *destination; // data destination of that field - size_t size; // max size of data allowed - struct ModelField_t *son; // son in XML tree - struct ModelField_t *next; // brother in XML tree -} typedef ModelField_t; - -/* -------------------------------------------------------------------------- */ - -// -// Parameters -// -struct Parameters_t { - char *configDir; - char *modelDir; - char *userDir; -} typedef Parameters_t; diff --git a/include/centers.h b/include/centers.h index be2c188..27e9e74 100644 --- a/include/centers.h +++ b/include/centers.h @@ -27,12 +27,4 @@ /* -------------------------------------------------------------------------- */ -// -------------------------------------------------------------------------- // -// Add a center to the center list // -// -------------------------------------------------------------------------- // -Center_t *CenterAdd(Center_t *anyCenter, Center_t *newCenter); -// -------------------------------------------------------------------------- // -// Remove a center from the center list // -// -------------------------------------------------------------------------- // -void CenterRemove(Center_t *oldCenter); diff --git a/include/cmds.h b/include/cmds.h index 705f42b..f5e6293 100644 --- a/include/cmds.h +++ b/include/cmds.h @@ -32,19 +32,26 @@ /* -------------------------------------------------------------------------- */ -struct Command_t { +struct command_t { const char *name; char* (*execute)(char*, char**, Server_t*); const char *help; -} typedef Command_t; +} typedef command_t; /* -------------------------------------------------------------------------- */ // // Existing commands // -char *CmdModel(char*, char**, Server_t*); -char *CmdShutdown(char*, char**, Server_t*); -char *CmdHelp(char*, char**, Server_t*); +char *Cmd_model(char*, char**, Server_t*); +char *cmd_shutdown(char*, char**, Server_t*); +char *cmd_help(char*, char**, Server_t*); + +static command_t cmdList[] = +{ + {"help", cmd_help, "Help command"}, + {"model", cmd_model, "Model command"}, + {"shutdown", cmd_shutdown, "Shutdown command"}, +}; /* -------------------------------------------------------------------------- */ diff --git a/include/model.h b/include/model.h index 845b657..42d2946 100644 --- a/include/model.h +++ b/include/model.h @@ -27,6 +27,10 @@ #include #include +#include +#include +#include +#include /* -------------------------------------------------------------------------- */ @@ -47,44 +51,44 @@ // -------------------------------------------------------------------------- // // Model init function (and model discovery) // // -------------------------------------------------------------------------- // -void ModelSystemInit(Parameters_t *parameters); +void model_system_init (parameters_t *parameters); // -------------------------------------------------------------------------- // // Model stopping function // // -------------------------------------------------------------------------- // -void ModelSystemDestroy(void); +void model_system_shutdown (void); // -------------------------------------------------------------------------- // // Load a model ready to execute // // -------------------------------------------------------------------------- // -int ModelLoad(int id); +int model_load (int id); // -------------------------------------------------------------------------- // // Unload a model // // -------------------------------------------------------------------------- // -int ModelUnload(int id); +int model_unload (int id); // -------------------------------------------------------------------------- // // Add a model to the known model list // // -------------------------------------------------------------------------- // -void ModelAddToKnown(Model_t **newModel); +void model_add_to_known (model_t **newModel); // -------------------------------------------------------------------------- // // Print informations about all models (known and loaded) to the client // // -------------------------------------------------------------------------- // -void printModels(char *buf); +void print_models (char *buf); // -------------------------------------------------------------------------- // // Launch a model execution // // -------------------------------------------------------------------------- // -int ModelRun(int id); +int model_run (int id); // -------------------------------------------------------------------------- // // Stop a model execution // // -------------------------------------------------------------------------- // -int ModelStop(int id); +int model_stop (int id); // -------------------------------------------------------------------------- // // Stop and unload all loaded or running model // // -------------------------------------------------------------------------- // -void ModelShutdown(void); +void model_shutdown (void); diff --git a/include/parsing.h b/include/parsing.h index 128a1f9..06e9ec0 100644 --- a/include/parsing.h +++ b/include/parsing.h @@ -36,38 +36,4 @@ /* -------------------------------------------------------------------------- */ -struct ModelParserTableXML_t; -struct ParserTableXML_t -{ - const xmlChar *tag; - int (*parse) (xmlDoc*, - struct ModelParserTableXML_t*, - int currentParser, - xmlNode*); - void *destination; -} typedef ParserTableXML_t; - -struct ModelParserTableXML_t -{ - size_t len; - ParserTableXML_t *table; -} typedef ModelParserTableXML_t; - -/* -------------------------------------------------------------------------- */ - -int parseParentFieldXML(xmlDocPtr, - ModelParserTableXML_t*, - int, - xmlNodePtr); - -int parseTextField(xmlDocPtr, - ModelParserTableXML_t*, - int, - xmlNodePtr); - -int ParseModelXML(Model_t*); - -int ParseModelIdentityXML(Model_t*, Parameters_t*); - -/* -------------------------------------------------------------------------- */ diff --git a/include/scheduler.h b/include/scheduler.h index 83e1a95..0985ce1 100644 --- a/include/scheduler.h +++ b/include/scheduler.h @@ -32,47 +32,40 @@ // -------------------------------------------------------------------------- // // Scheduler init function // // -------------------------------------------------------------------------- // -void SchedInit(Scheduler_t *scheduler); +void sched_init(scheduler_t *scheduler); // -------------------------------------------------------------------------- // // Scheduler content destructor function // // -------------------------------------------------------------------------- // -static inline void SchedContentDestroy(Scheduler_t *scheduler) +static inline void sched_clean (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; + assert(scheduler); + + if (scheduler->globalDrawingSpace) { + if (scheduler->globalDrawingSpace->space) { + free(scheduler->globalDrawingSpace->space); + scheduler->globalDrawingSpace->space = NULL; } - if (scheduler->arrowArray) { - if (scheduler->arrowArray->array) { - free(scheduler->arrowArray->array); - scheduler->arrowArray->array = NULL; - } - free(scheduler->arrowArray); - scheduler->arrowArray = 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; } } // -------------------------------------------------------------------------- // // Scheduler destructor function // // -------------------------------------------------------------------------- // -static inline void SchedDestroy(Scheduler_t *scheduler) +static inline void sched_shutdown (scheduler_t *scheduler) { - if (scheduler) { - free(scheduler); - } -} - -// -------------------------------------------------------------------------- // -// Scheduler wait function // -// -------------------------------------------------------------------------- // -static inline void SchedWait(Scheduler_t *scheduler) -{ - pthread_join(scheduler->id, NULL); + assert(scheduler); + free(scheduler); + scheduler = NULL; } diff --git a/include/server.h b/include/server.h index 203938d..92e53a3 100644 --- a/include/server.h +++ b/include/server.h @@ -37,12 +37,4 @@ // -------------------------------------------------------------------------- // // Server init function // // -------------------------------------------------------------------------- // -void ServerInit(Server_t *server); - -// -------------------------------------------------------------------------- // -// Server wait function // -// -------------------------------------------------------------------------- // -static inline void ServerWait(Server_t *server) -{ - pthread_join(server->id, NULL); -} +void server_init (server_t *server); diff --git a/include/supervisor.h b/include/supervisor.h index 6605c87..144d296 100644 --- a/include/supervisor.h +++ b/include/supervisor.h @@ -30,19 +30,12 @@ // -------------------------------------------------------------------------- // // Supervisor init function // // -------------------------------------------------------------------------- // -void SupervisorInit(Supervisor_t *supervisor); +void superv_init (supervisor_t *supervisor); // -------------------------------------------------------------------------- // // Supervisor destructor function // // -------------------------------------------------------------------------- // -static inline void SupervisorDestroy(Supervisor_t *supervisor) +static inline void superv_destroy (supervisor_t *supervisor) { -} - -// -------------------------------------------------------------------------- // -// Supervisor wait function // -// -------------------------------------------------------------------------- // -static inline void SupervisorWait(Supervisor_t *supervisor) -{ - pthread_join(supervisor->id, NULL); + ; } diff --git a/include/terminal.h b/include/terminal.h index 436e6b1..c897e49 100644 --- a/include/terminal.h +++ b/include/terminal.h @@ -54,14 +54,14 @@ /* -------------------------------------------------------------------------- */ -volatile struct winsize TermWindowSize; +volatile struct winsize termWinSize; /* -------------------------------------------------------------------------- */ // -------------------------------------------------------------------------- // // Get a character code from the keyboard // // -------------------------------------------------------------------------- // -static inline int TermGetch(bool nonBlocking) +static inline int term_getch(bool nonBlocking) { int buf = 0; // old terminal @@ -123,16 +123,16 @@ static inline int TermGetch(bool nonBlocking) // -------------------------------------------------------------------------- // // Get the screen size // // -------------------------------------------------------------------------- // -static inline void TermGetScreenSize(int signum) +static inline void term_get_screensize(int signum) { // Get current terminal size - ioctl(STDOUT_FILENO, TIOCGWINSZ, &TermWindowSize); + ioctl(STDOUT_FILENO, TIOCGWINSZ, &termWinSize); } // -------------------------------------------------------------------------- // // Set cursor location // // -------------------------------------------------------------------------- // -static inline void TermSetCursorLocation(char x, char y) +static inline void term_set_cursor_location(char x, char y) { printf("\x1b[%d;%dH", y, x); } @@ -140,7 +140,7 @@ static inline void TermSetCursorLocation(char x, char y) // -------------------------------------------------------------------------- // // Save cursor location // // -------------------------------------------------------------------------- // -static inline void TermSaveCursorLocation(void) +static inline void term_save_cursor_location(void) { printf(C_SAVE_CURSORPOS); } @@ -148,7 +148,7 @@ static inline void TermSaveCursorLocation(void) // -------------------------------------------------------------------------- // // Restore cursor location // // -------------------------------------------------------------------------- // -static inline void TermRestoreCursorLocation(void) +static inline void term_restore_cursor_location(void) { printf(C_RESTORE_CURSORPOS); } @@ -156,7 +156,7 @@ static inline void TermRestoreCursorLocation(void) // -------------------------------------------------------------------------- // // Move cursor location to the right // // -------------------------------------------------------------------------- // -static inline void TermMoveCursorForward(void) +static inline void term_move_cursor_forward(void) { printf(C_CURSORRIGHT); } @@ -164,7 +164,7 @@ static inline void TermMoveCursorForward(void) // -------------------------------------------------------------------------- // // Move cursor location to the left // // -------------------------------------------------------------------------- // -static inline void TermMoveCursorBackward(void) +static inline void term_move_cursor_backward(void) { printf(C_CURSORLEFT); } @@ -172,10 +172,10 @@ static inline void TermMoveCursorBackward(void) // -------------------------------------------------------------------------- // // Clear screen // // -------------------------------------------------------------------------- // -static inline void TermClearScreen(void) +static inline void term_clear_screen(void) { printf(C_CLEARSCREEN); - TermSetCursorLocation(1,1); + term_set_cursor_location(1,1); fflush(stdout); } diff --git a/include/worker.h b/include/worker.h index c80a144..bee79c6 100644 --- a/include/worker.h +++ b/include/worker.h @@ -30,12 +30,12 @@ // -------------------------------------------------------------------------- // // Worker init function // // -------------------------------------------------------------------------- // -void WorkerInit(Worker_t *worker); +void worker_init(worker_t *worker); // -------------------------------------------------------------------------- // // Worker destructor function // // -------------------------------------------------------------------------- // -static inline void WorkerDestroy(Worker_t *worker) +static inline void worker_destroy(worker_t *worker) { worker->pleaseStop = false; worker->terminated = false; @@ -45,11 +45,3 @@ static inline void WorkerDestroy(Worker_t *worker) free(worker->localWorkAreaCenter); worker->localWorkAreaCenter = NULL; } - -// -------------------------------------------------------------------------- // -// Worker wait function // -// -------------------------------------------------------------------------- // -static inline void WorkerWait(Worker_t *worker) -{ - pthread_join(worker->id, NULL); -} diff --git a/include/xml.h b/include/xml.h deleted file mode 100644 index 4809a57..0000000 --- a/include/xml.h +++ /dev/null @@ -1,35 +0,0 @@ -//=-------------------------------------------------------------------------=// -// XML management tools // -// // -// Copyright © 2021 Libre en Communs (contact@a-lec.org) // -// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) // -// // -// 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 . // -//=-------------------------------------------------------------------------=// - -#pragma once -#ifndef BASE_H - #include "../include/base.h" -#endif - -/* -------------------------------------------------------------------------- */ - -#include -#include -#include -#include - - diff --git a/manifest.scm b/manifest.scm new file mode 100644 index 0000000..01a3a6d --- /dev/null +++ b/manifest.scm @@ -0,0 +1,26 @@ +;; +;; Dépendances sous GNU Guix +;; + + +(specifications->manifest + (list + "bash" + "coreutils" + "gcc-toolchain" + "pkg-config" + "valgrind" + "findutils" + "gdb" + "make" + "libxml2" + "glu" + "glew" + "glfw" + "cglm" + "libepoxy" + "glib" + "mesa-headers" + "mesa" + ) +) diff --git a/src/arrows.c b/src/arrows.c index d24e219..79f8f7f 100644 --- a/src/arrows.c +++ b/src/arrows.c @@ -25,7 +25,3 @@ /* -------------------------------------------------------------------------- */ - -static inline int location(Space_t *space, int x, int y, int z) { - return x + y * (space->xMax+1) + z * (space->xMax+1) * (space->zMax+1); -} diff --git a/src/centers.c b/src/centers.c index 2eba517..f9fdcdb 100644 --- a/src/centers.c +++ b/src/centers.c @@ -24,31 +24,4 @@ /* -------------------------------------------------------------------------- */ -Center_t *CenterAdd(Center_t *anyCenter, Center_t *newCenter) -{ - if (!newCenter) return NULL; - if (anyCenter->next) { - anyCenter->next->prev = newCenter; - } - newCenter->next = anyCenter->next; - anyCenter->next = newCenter; - newCenter->prev = anyCenter; - return newCenter; -} - -void CenterRemove(Center_t *oldCenter) -{ - register Center_t *prev; - register Center_t *next; - - //printLog("Removing center %p\n", oldCenter); - if (!oldCenter) return; - - prev = oldCenter->prev; - next = oldCenter->next; - - - if (prev) prev->next = oldCenter->next; - if (next) next->prev = oldCenter->prev; -} diff --git a/src/cli.c b/src/cli/cli.c similarity index 100% rename from src/cli.c rename to src/cli/cli.c diff --git a/src/cmds.c b/src/cmds.c index 4940869..c4ea45f 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -28,195 +28,195 @@ /* -------------------------------------------------------------------------- */ -char *CmdModel(char *buf, char **argv, Server_t *args) -{ - int id, eid; - Model_t *newModel; +/* char *cmd_model(char *buf, char **argv, server_t *args) */ +/* { */ +/* int id, eid; */ +/* model_t *newModel; */ - // invalid use - if (!argv[1]) { - strcat(buf, "{create | delete | load | unload | run | stop | list |" - "info}\n"); - goto CmdModelEnd; - } +/* // invalid use */ +/* if (!argv[1]) { */ +/* strcat(buf, "{create | delete | load | unload | run | stop | list |" */ +/* "info}\n"); */ +/* goto cmd_ModelEnd; */ +/* } */ - if (strcmp(argv[1], "create") == 0) { +/* if (strcmp(argv[1], "create") == 0) { */ - if (!argv[2] || !argv[3]) { - goto createEnd; - } +/* if (!argv[2] || !argv[3]) { */ +/* goto createEnd; */ +/* } */ - if (strncmp(argv[2], "name=", 5) == 0) { +/* if (strncmp(argv[2], "name=", 5) == 0) { */ - if (strncmp(argv[3], "file=", 5) == 0) { - // TODO get the file content (sent by the client) from args +/* if (strncmp(argv[3], "file=", 5) == 0) { */ +/* // TODO get the file content (sent by the client) from args */ - // Creating model - ModelAddToKnown(&newModel); +/* // Creating model */ +/* //XXX ModelAddToKnown(&newModel); */ - // TODO modify model according to things in file +/* // TODO modify model according to things in file */ - // Write name - strcpy(newModel->name, argv[2] + 5); +/* // Write name */ +/* strcpy(newModel->name, argv[2] + 5); */ - // Write filename - strcpy(newModel->filename, argv[3] + 5); +/* // Write filename */ +/* strcpy(newModel->filename, argv[3] + 5); */ - sprintf(buf + strlen(buf), "Model %s created with id %d\n", - newModel->name, newModel->id); - goto CmdModelEnd; +/* sprintf(buf + strlen(buf), "Model %s created with id %d\n", */ +/* newModel->name, newModel->id); */ +/* goto cmd_ModelEnd; */ - } else { - goto createEnd; - } - } else { - goto createEnd; - } +/* } else { */ +/* goto createEnd; */ +/* } */ +/* } else { */ +/* goto createEnd; */ +/* } */ - createEnd: - // invalid use - strcat(buf, "Creates a model structure\n"); - strcat(buf, "Usage: model create name=NAME file=FILENAME\n"); - goto CmdModelEnd; - } +/* createEnd: */ +/* // invalid use */ +/* strcat(buf, "Creates a model structure\n"); */ +/* strcat(buf, "Usage: model create name=NAME file=FILENAME\n"); */ +/* goto cmd_ModelEnd; */ +/* } */ - else if (strcmp(argv[1], "load") == 0) { - if (!argv[2]) { - goto loadEnd; - } +/* else if (strcmp(argv[1], "load") == 0) { */ +/* if (!argv[2]) { */ +/* goto loadEnd; */ +/* } */ - id = (int) strtol(argv[2] + 3, NULL, 10); +/* id = (int) strtol(argv[2] + 3, NULL, 10); */ - if (id == 0 || (eid = ModelLoad(id)) <= 0) { - sprintf(buf + strlen(buf), "Failed to load model id %d\n", id); - goto CmdModelEnd; - } +/* if (id == 0 || (eid = ModelLoad(id)) <= 0) { */ +/* sprintf(buf + strlen(buf), "Failed to load model id %d\n", id); */ +/* goto cmd_ModelEnd; */ +/* } */ - sprintf(buf + strlen(buf), "Model id %d loaded with effective " - "id %d\n", id, eid); - goto CmdModelEnd; - loadEnd: - // invalid use - strcat(buf, "Loads a model structure\n"); - strcat(buf, "Usage: model load id=ID\n"); - goto CmdModelEnd; - } +/* sprintf(buf + strlen(buf), "Model id %d loaded with effective " */ +/* "id %d\n", id, eid); */ +/* goto cmd_ModelEnd; */ +/* loadEnd: */ +/* // invalid use */ +/* strcat(buf, "Loads a model structure\n"); */ +/* strcat(buf, "Usage: model load id=ID\n"); */ +/* goto cmd_ModelEnd; */ +/* } */ - else if (strcmp(argv[1], "unload") == 0) { - if (!argv[2]) { - goto unloadEnd; - } +/* else if (strcmp(argv[1], "unload") == 0) { */ +/* if (!argv[2]) { */ +/* goto unloadEnd; */ +/* } */ - id = (int) strtol(argv[2] + 3, NULL, 10); +/* id = (int) strtol(argv[2] + 3, NULL, 10); */ - if (id == 0 || ModelUnload(id) < 0) { - printErr("Failed to unload model id %d\n", id); - sprintf(buf + strlen(buf), "Failed to unload model id %d\n", id); - goto CmdModelEnd; - } +/* if (id == 0 || ModelUnload(id) < 0) { */ +/* printErr("Failed to unload model id %d\n", id); */ +/* sprintf(buf + strlen(buf), "Failed to unload model id %d\n", id); */ +/* goto cmd_ModelEnd; */ +/* } */ - sprintf(buf + strlen(buf), "Model id %d unloaded\n", id); - goto CmdModelEnd; - unloadEnd: - // invalid use - strcat(buf, "Unloads a model structure\n"); - strcat(buf, "Usage: model unload id=ID\n"); - goto CmdModelEnd; - } +/* sprintf(buf + strlen(buf), "Model id %d unloaded\n", id); */ +/* goto cmd_ModelEnd; */ +/* unloadEnd: */ +/* // invalid use */ +/* strcat(buf, "Unloads a model structure\n"); */ +/* strcat(buf, "Usage: model unload id=ID\n"); */ +/* goto cmd_ModelEnd; */ +/* } */ - else if (strcmp(argv[1], "delete") == 0) { - if (!argv[2]) { - goto deleteEnd; - } - // TODO delete model - deleteEnd: - // invalid use - strcat(buf, "Deletes a model structure\n"); - strcat(buf, "Usage: model delete id=ID\n"); - goto CmdModelEnd; - } +/* else if (strcmp(argv[1], "delete") == 0) { */ +/* if (!argv[2]) { */ +/* goto deleteEnd; */ +/* } */ +/* // TODO delete model */ +/* deleteEnd: */ +/* // invalid use */ +/* strcat(buf, "Deletes a model structure\n"); */ +/* strcat(buf, "Usage: model delete id=ID\n"); */ +/* goto cmd_ModelEnd; */ +/* } */ - else if (strcmp(argv[1], "run") == 0) { - if (!argv[2]) { - goto runEnd; - } +/* else if (strcmp(argv[1], "run") == 0) { */ +/* if (!argv[2]) { */ +/* goto runEnd; */ +/* } */ - id = (int) strtol(argv[2] + 3, NULL, 10); +/* id = (int) strtol(argv[2] + 3, NULL, 10); */ - if (id == 0 || (!ModelRun(id))) { - sprintf(buf + strlen(buf), "Failed to run model id %d\n", id); - goto CmdModelEnd; - } +/* if (id == 0 || (!ModelRun(id))) { */ +/* sprintf(buf + strlen(buf), "Failed to run model id %d\n", id); */ +/* goto cmd_ModelEnd; */ +/* } */ - sprintf(buf + strlen(buf), "Model id %d is running\n", id); - goto CmdModelEnd; - runEnd: - // invalid use - strcat(buf, "Run a model simulation\n"); - strcat(buf, "Usage: model run id=ID\n"); - goto CmdModelEnd; - } +/* sprintf(buf + strlen(buf), "Model id %d is running\n", id); */ +/* goto cmd_ModelEnd; */ +/* runEnd: */ +/* // invalid use */ +/* strcat(buf, "Run a model simulation\n"); */ +/* strcat(buf, "Usage: model run id=ID\n"); */ +/* goto cmd_ModelEnd; */ +/* } */ - else if (strcmp(argv[1], "stop") == 0) { - if (!argv[2]) { - goto stopEnd; - } +/* else if (strcmp(argv[1], "stop") == 0) { */ +/* if (!argv[2]) { */ +/* goto stopEnd; */ +/* } */ - id = (int) strtol(argv[2] + 3, NULL, 10); +/* id = (int) strtol(argv[2] + 3, NULL, 10); */ - if (id == 0 || (!ModelStop(id))) { - sprintf(buf + strlen(buf), "Failed to stop model id %d\n", id); - goto CmdModelEnd; - } +/* if (id == 0 || (!ModelStop(id))) { */ +/* sprintf(buf + strlen(buf), "Failed to stop model id %d\n", id); */ +/* goto cmd_ModelEnd; */ +/* } */ - sprintf(buf + strlen(buf), "Model id %d is running\n", id); - goto CmdModelEnd; - stopEnd: - // invalid use - strcat(buf, "Stop a model simulation\n"); - strcat(buf, "Usage: model stop id=ID\n"); - goto CmdModelEnd; - } +/* sprintf(buf + strlen(buf), "Model id %d is running\n", id); */ +/* goto cmd_ModelEnd; */ +/* stopEnd: */ +/* // invalid use */ +/* strcat(buf, "Stop a model simulation\n"); */ +/* strcat(buf, "Usage: model stop id=ID\n"); */ +/* goto cmd_ModelEnd; */ +/* } */ - else if (strcmp(argv[1], "list") == 0) { - strcat(buf, "You asked for us to list models\n"); - printModels(buf); - } +/* else if (strcmp(argv[1], "list") == 0) { */ +/* strcat(buf, "You asked for us to list models\n"); */ +/* printModels(buf); */ +/* } */ - else if (strcmp(argv[1], "info") == 0) { - if (!argv[2]) { - goto infoEnd; - } - // TODO info model - infoEnd: - // invalid use - strcat(buf, "Print info about a model\n"); - strcat(buf, "Usage: model info id=ID\n"); - goto CmdModelEnd; - } +/* else if (strcmp(argv[1], "info") == 0) { */ +/* if (!argv[2]) { */ +/* goto infoEnd; */ +/* } */ +/* // TODO info model */ +/* infoEnd: */ +/* // invalid use */ +/* strcat(buf, "Print info about a model\n"); */ +/* strcat(buf, "Usage: model info id=ID\n"); */ +/* goto cmd_ModelEnd; */ +/* } */ - // invalid use - else strcat(buf, "{create | delete | load | unload | run | stop | list |" - "info}\n"); +/* // invalid use */ +/* else strcat(buf, "{create | delete | load | unload | run | stop | list |" */ +/* "info}\n"); */ -CmdModelEnd: - return buf; -} +/* cmd_ModelEnd: */ +/* return buf; */ +/* } */ -char *CmdShutdown(char *buf, char **argv, Server_t *args) -{ - args->pleaseStop = true; - strcat(buf, "Server stopping\n"); +/* char *cmd_shutdown(char *buf, char **argv, server_t *args) */ +/* { */ +/* args->pleaseStop = true; */ +/* strcat(buf, "Server stopping\n"); */ - ModelShutdown(); - strcat(buf, "All model shutted down\n"); +/* //XXX ModelShutdown(); */ +/* strcat(buf, "All model shutted down\n"); */ - return buf; -} +/* return buf; */ +/* } */ -char *CmdHelp(char *buf, char **argv, Server_t *args) -{ - strcat(buf, "List of known commands:\n"); +/* char *cmd_help(char *buf, char **argv, server_t *args) */ +/* { */ +/* strcat(buf, "List of known commands:\n"); */ - return buf; -} +/* return buf; */ +/* } */ diff --git a/src/main.c b/src/main.c index 42ded6c..2c004dd 100644 --- a/src/main.c +++ b/src/main.c @@ -26,23 +26,23 @@ /* -------------------------------------------------------------------------- */ -static Server_t *server; +static server_t *server; -static void sigtermHandler(int signum) -{ - server->pleaseStop = true; - printLog("Server stopping\n"); +/* static void sig_term_handler(int signum) */ +/* { */ +/* server->pleaseStop = true; */ +/* printLog("Server stopping\n"); */ - ModelShutdown(); - printLog("All model shutted down\n"); -} +/* //XXX ModelShutdown(); */ +/* printLog("All model shutted down\n"); */ +/* } */ int main(int argc, char **argv) { int options; time_t t; int returnValue = 0; - Parameters_t parameters; + parameters_t parameters; while ((options = getopt(argc, argv, ":C:M:U:")) != -1) { switch (options) { @@ -108,30 +108,30 @@ int main(int argc, char **argv) // Go! printLog("Starting gem-graph-server...\n"); - // Register new interrupt handler - signal(SIGINT, sigtermHandler); - signal(SIGTERM, sigtermHandler); + /* // Register new interrupt handler */ + /* signal(SIGINT, sig_term_handler); */ + /* signal(SIGTERM, sig_term_handler); */ - // Initializing random generator - t = time(&t); - srand((unsigned) t); + /* // Initializing random generator */ + /* t = time(&t); */ + /* srand((unsigned) t); */ - server = calloc(1, sizeof(*server)); + /* server = calloc(1, sizeof(*server)); */ - // Initializing model system - ModelSystemInit(¶meters); + /* // Initializing model system */ + /* model_system_init(¶meters); */ - // Launching server - ServerInit(server); + /* // Launching server */ + /* server_init(server); */ - // Waiting for termination - ServerWait(server); + /* // Waiting for termination */ + /* server_wait(server); */ - // Exiting - returnValue |= server->returnValue; - ModelSystemDestroy(); - free(server); - server = NULL; + /* // Exiting */ + /* returnValue |= server->returnValue; */ + /* ModelSystemDestroy(); */ + /* free(server); */ + /* server = NULL; */ free(parameters.userDir); free(parameters.modelDir); diff --git a/src/model.c b/src/model.c index db08dbd..0070ade 100644 --- a/src/model.c +++ b/src/model.c @@ -25,286 +25,4 @@ #include "../include/arrows.h" #include "../include/scheduler.h" -static Model_t **loadedModel; -static int loadedModelSize; // begins to 1 -static Model_t **knownModel; -static int knownModelSize; // begins to 1 - -Model_t *lastModel; -Model_t **lastModelAddr; - -/* -------------------------------------------------------------------------- */ - -void printModels(char *buf) -{ - sprintf(buf + strlen(buf),"Known models\n"); - for (int i = 0; i <= knownModelSize-1; i++) { - sprintf(buf + strlen(buf), "id: %d, addr: %p, name: %s, date: %lu, " - "owner: %s\n", - knownModel[i]->id, - knownModel[i], - knownModel[i]->name, - knownModel[i]->date, - knownModel[i]->owner - ); - } - - sprintf(buf + strlen(buf), "\nLoaded models\n"); - for (int i = 0; i <= loadedModelSize-1; i++) { - sprintf(buf + strlen(buf), "id: %d, addr: %p, name: %s\n", - loadedModel[i]->id, loadedModel[i], loadedModel[i]->name); - } -} - -int ModelLoad(int id) -{ - if (id <= 0 || id > knownModelSize) { - return -1; - } - - printLog("Loading model id %d (/%d models)...\n", id, knownModelSize); - - - // Creating structure for the Scheduler - knownModel[id-1]->scheduler = - calloc(1, sizeof(*knownModel[id-1]->scheduler)); - - loadedModelSize++; - - loadedModel = - (Model_t**) realloc(loadedModel, loadedModelSize * sizeof(Model_t*)); - - loadedModel[loadedModelSize-1] = knownModel[id-1]; - - // Parse model - ParseModelXML(loadedModel[loadedModelSize-1]); - - return loadedModelSize; -} - -int ModelUnload(int id) -{ - // Destroy scheduler - if (id > loadedModelSize) - return -1; - - SchedContentDestroy(loadedModel[id-1]->scheduler); - - SchedDestroy(loadedModel[id-1]->scheduler); - loadedModel[id-1]->scheduler = NULL; - - // Prevent fragmentation by moving data in the newly freed slot - if (id-1 < loadedModelSize) { - memmove(&loadedModel[id-1], - &loadedModel[id-1] + sizeof(Model_t*), - loadedModelSize - id); - } - - // Decrement loaded model index - loadedModelSize--; - - // Resize loaded model list - loadedModel = - (Model_t**) realloc(loadedModel, loadedModelSize * sizeof(Model_t*)); - - return 0; -} -/* -------------------------------------------------------------------------- */ - -int ModelRun(int id) -{ - if (id <= 0 || id > loadedModelSize) - return -1; - - if (!loadedModel[id-1]->scheduler) - return -2; - - if (loadedModel[id-1]->isRunning) - return -3; - - loadedModel[id-1]->scheduler->nMaxThread = knownModel[id-1]->nmaxThread; - loadedModel[id-1]->scheduler->nMaxCycles = knownModel[id-1]->nmaxCycles; - loadedModel[id-1]->scheduler->pleaseStop = false; - loadedModel[id-1]->isRunning = true; - - SchedInit(loadedModel[id-1]->scheduler); - - printLog("Model %d launched\n", id); - return 0; -} - -int ModelStop(int id) -{ - if (id <= 0 || id > loadedModelSize) { - return -1; - } - if (!loadedModel[id-1]->scheduler) { - return -2; - } - if (!loadedModel[id-1]->isRunning) { - return -3; - } - - // Stop model scheduler - loadedModel[id-1]->scheduler->pleaseStop = true; - printLog("Model %d stop bit set\n", id); - - // Wait for Shceduler to stop - SchedWait(loadedModel[id-1]->scheduler); - - // Disable running bit - loadedModel[id-1]->isRunning = false; - return 0; -} - -/* -------------------------------------------------------------------------- */ - -void ModelAddToKnown(Model_t **newModel) -{ - // increment index - knownModelSize++; - // create socket - knownModel = - (Model_t**) realloc(knownModel, knownModelSize * sizeof(*knownModel)); - // populate socket - knownModel[knownModelSize-1] = calloc(1, sizeof(**knownModel)); - // populate model - knownModel[knownModelSize-1]->id = knownModelSize; - // return value - *newModel = knownModel[knownModelSize-1]; - lastModel = knownModel[knownModelSize-1]; - lastModelAddr = &knownModel[knownModelSize-1]; - - // continue. model population - knownModel[knownModelSize-1]->name = - calloc(1, sizeof(char) * MODEL_STRING_SIZE); - - knownModel[knownModelSize-1]->filename = - calloc(1, sizeof(char) * MODEL_STRING_SIZE); - - knownModel[knownModelSize-1]->owner = - calloc(1, sizeof(char) * MODEL_STRING_SIZE); - - knownModel[knownModelSize-1]->version = - calloc(1, sizeof(char) * MODEL_STRING_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 fragmentation -{ - // Free a model structure - free(knownModel[id-1]->name); - knownModel[id-1]->name = NULL; - - free(knownModel[id-1]->filename); - knownModel[id-1]->filename = NULL; - - free(knownModel[id-1]->owner); - knownModel[id-1]->owner = NULL; - - free(knownModel[id-1]->version); - knownModel[id-1]->version = NULL; - - free(knownModel[id-1]); - knownModel[id-1] = NULL; -} - -void ModelShutdown(void) -{ - // Stop each model from running - for (int i = 0; i < loadedModelSize; i++) { - ModelStop(i); - ModelUnload(i); - } -} - -/* -------------------------------------------------------------------------- */ - -void ModelSystemInit(Parameters_t *parameters) -{ - struct dirent *modelDirEntry = NULL; - DIR *modelDir = NULL; - Model_t *newModel; - char *extensionPosition; - - loadedModel = calloc(1, sizeof(*loadedModel)); - - knownModel = calloc(1, sizeof(*knownModel)); - - knownModelSize = 0; - loadedModelSize = 0; - - printLog("Model system initiated with folder : %s\n", parameters->modelDir); - - // Open model directory - if ((modelDir = opendir(parameters->modelDir)) <= 0) { - printErr("Could not open %s\n", parameters->modelDir); - ModelSystemDestroy(); - kill(getpid(), SIGTERM); - return; - } - - while ((modelDirEntry = readdir(modelDir)) != NULL) { - if ((extensionPosition = strstr(modelDirEntry->d_name, ".xml"))) { - - // Creating model - ModelAddToKnown(&newModel); - - // Write file path in filename - strncpy(newModel->filename, parameters->modelDir, - strlen(parameters->modelDir)); - // Add a / separator - strcat(newModel->filename - + strlen(parameters->modelDir), - "/"); - // Add the file relative name - strncpy(newModel->filename - + strlen(parameters->modelDir) - + 1, - modelDirEntry->d_name, - strlen(modelDirEntry->d_name)); - - // Write model name - strncpy(newModel->name, modelDirEntry->d_name, - extensionPosition - modelDirEntry->d_name); - - // Ask to parse the new model - if (ParseModelIdentityXML(newModel, parameters) != 0) { - printErr("Deleting invalid model %s from known list\n", - newModel->name); - ModelDelete(newModel->id); - continue; - }; - - // Check model is valid and/or parsed - if (newModel->validated == false) { - printErr("Deleting invalid model %s from known list\n", - newModel->name); - ModelDelete(newModel->id); - continue; - } - - // Succeeded ! - printLog("Loaded model %s\n", newModel->name); - } - } - free(modelDir); -} - -void ModelSystemDestroy(void) -{ - for (int i = 0; i < loadedModelSize; i++) { - ModelDelete(i); - } - free(loadedModel); - loadedModel = NULL; - free(knownModel); - knownModel = NULL; -} diff --git a/src/parsing.c b/src/parsing.c index 35839cb..ec88c89 100644 --- a/src/parsing.c +++ b/src/parsing.c @@ -24,560 +24,4 @@ #include "../include/arrows.h" #include "../include/model.h" -// -------------------------------------------------------------------------- // -// Parsing NOTHING (but yeah that prints) // -// -------------------------------------------------------------------------- // -int parseStubFieldXML (xmlDocPtr doc, - ModelParserTableXML_t *ModelTable, - int currentParser, - xmlNodePtr currentNode) -{ - xmlChar *content, *contentText, *contentValueAttribute; - contentText = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1); - contentValueAttribute = xmlGetProp(currentNode, - (xmlChar*)"value"); - - if (contentText) { - content = contentText; - } else if (contentValueAttribute) { - content = contentValueAttribute; - - // Detect children - if (currentNode->xmlChildrenNode) { - printLog("%s (stub) has children\n", - ModelTable->table[currentParser].tag); - } - } - - printLog("%s (stub): %s\n", ModelTable->table[currentParser].tag, - content); - - if (!content) { - xmlFree(contentText); - xmlFree(contentValueAttribute); - return -1; - } - - xmlFree(contentText); - xmlFree(contentValueAttribute); - - return 0; -} - -// -------------------------------------------------------------------------- // -// Parsing an arrow (but yeah that prints) // -// -------------------------------------------------------------------------- // -int parseArrowFieldXML (xmlDocPtr doc, - ModelParserTableXML_t *ModelTable, - int currentParser, - xmlNodePtr currentNode) -{ - Model_t *destination = ModelTable->table[currentParser].destination; - xmlChar *x, *y, *z, *siteId, *weight; - - x = xmlGetProp(currentNode, (xmlChar*)"x"); - y = xmlGetProp(currentNode, (xmlChar*)"y"); - z = xmlGetProp(currentNode, (xmlChar*)"z"); - siteId = xmlGetProp(currentNode, (xmlChar*)"siteId"); - weight = xmlGetProp(currentNode, (xmlChar*)"weight"); - - // Detect children - if (currentNode->xmlChildrenNode) { - printLog("%s (stub) has children\n", - ModelTable->table[currentParser].tag); - } - - printLog("%s: x:%s, y:%s, z:%s\n", ModelTable->table[currentParser].tag, - x, y, z); - - if (!x || !y || !z) { - xmlFree(x); - xmlFree(y); - xmlFree(z); - return -1; - } - - // Create arrow in model - if (destination->scheduler) { - ArrowAdd(destination->scheduler, - atoi((char*)x), atoi((char*)y), atoi((char*)z), - atoi((char*)siteId), atoi((char*)weight)); - } else { - xmlFree(x); - xmlFree(y); - xmlFree(z); - - return -1; - } - - xmlFree(x); - xmlFree(y); - xmlFree(z); - - return 0; -} - -int parseSpaceSizeFieldXML (xmlDocPtr doc, - ModelParserTableXML_t *ModelTable, - int currentParser, - xmlNodePtr currentNode) -{ - xmlChar *x, *y, *z; - Model_t *destination = - (Model_t*)ModelTable->table[currentParser].destination; - - x = xmlGetProp(currentNode, (xmlChar*)"x"); - y = xmlGetProp(currentNode, (xmlChar*)"y"); - z = xmlGetProp(currentNode, (xmlChar*)"z"); - - // Detect children - if (currentNode->xmlChildrenNode) { - printLog("%s (stub) has children\n", - ModelTable->table[currentParser].tag); - } - - printLog("%s: x:%s, y:%s, z:%s\n", ModelTable->table[currentParser].tag, - x, y, z); - - if (!x || !y || !z) { - xmlFree(x); - xmlFree(y); - xmlFree(z); - return -1; - } - - // Store space size - destination->space_xMax = atoi((const char*)x); - destination->space_yMax = atoi((const char*)y); - destination->space_zMax = atoi((const char*)z); - - xmlFree(x); - xmlFree(y); - xmlFree(z); - - return 0; -} - -// -------------------------------------------------------------------------- // -// Parsing a text field // -// -------------------------------------------------------------------------- // -int parseTextFieldXML (xmlDocPtr doc, - ModelParserTableXML_t *ModelTable, - int currentParser, - xmlNodePtr currentNode) -{ - xmlChar *content, *contentText, *contentValueAttribute; - char *destination = (char*)ModelTable->table[currentParser].destination; - - contentText = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1); - contentValueAttribute = xmlGetProp(currentNode, - (xmlChar*)"value"); - - if (contentText) { - content = contentText; - } else if (contentValueAttribute) { - content = contentValueAttribute; - - // Detect children - if (currentNode->xmlChildrenNode) { - printLog("%s has children\n", ModelTable->table[currentParser].tag); - } - } - - printLog("%s: %s\n", ModelTable->table[currentParser].tag, - content); - - if (!content) { - xmlFree(contentText); - xmlFree(contentValueAttribute); - return -1; - } - - strcat(destination, " "); - strncpy(destination + strlen(destination), - (char *)content, MODEL_STRING_SIZE - strlen(destination)); - - xmlFree(contentText); - xmlFree(contentValueAttribute); - - return 0; -} - -// -------------------------------------------------------------------------- // -// Parsing an integer field // -// -------------------------------------------------------------------------- // -int parseIntFieldXML (xmlDocPtr doc, - ModelParserTableXML_t *ModelTable, - int currentParser, - xmlNodePtr currentNode) -{ - xmlChar *content, *contentText, *contentValueAttribute; - int *destination = (int*)ModelTable->table[currentParser].destination; - - contentText = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1); - contentValueAttribute = xmlGetProp(currentNode, - (xmlChar*)"value"); - - if (contentText) { - content = contentText; - } else if (contentValueAttribute) { - content = contentValueAttribute; - - // Detect children - if (currentNode->xmlChildrenNode) { - printLog("%s has children\n", ModelTable->table[currentParser].tag); - } - } - - printLog("%s: %s\n", ModelTable->table[currentParser].tag, - content); - - if (!content) { - xmlFree(contentText); - xmlFree(contentValueAttribute); - return -1; - } - - *destination = (int)atoi((char*)content); - - xmlFree(content); - return 0; -} - -// -------------------------------------------------------------------------- // -// Parsing a field that contains children fields // -// -------------------------------------------------------------------------- // -int parseParentFieldXML (xmlDocPtr doc, - ModelParserTableXML_t *ModelTable, - int currentParser, - xmlNodePtr currentNode) -{ - printLog("%s parsed\n", - ModelTable->table[currentParser].tag); - - // Getting children content - currentNode = currentNode->xmlChildrenNode; - while (currentNode != NULL) { - for (int i = 0; i < ModelTable->len; i++) { - if ((!xmlStrcmp(currentNode->name, - ModelTable->table[i].tag))) { - ModelTable->table[i].parse(doc, - ModelTable, - i, - currentNode); - break; - } - } - currentNode = currentNode->next; - } - return 0; -} - -// -------------------------------------------------------------------------- // -// Parsing a field that contains children fields with props // -// -------------------------------------------------------------------------- // -int parseParentFieldPropsXML (xmlDocPtr doc, - ModelParserTableXML_t *ModelTable, - int currentParser, - xmlNodePtr currentNode) -{ - xmlChar *id, *date, *author; - // (truc*)destination = (truc*)ModelTable->table[currentParser].destination; - - // Getting field identity - id = xmlGetProp(currentNode, (xmlChar*)"id"); - date = xmlGetProp(currentNode, (xmlChar*)"date"); - author = xmlGetProp(currentNode, (xmlChar*)"author"); - - printLog("%s parsed (id=%s, date=%s, author=%s)\n", - ModelTable->table[currentParser].tag, id, date, author); - - // Getting children content - currentNode = currentNode->xmlChildrenNode; - while (currentNode != NULL) { - for (int i = 0; i < ModelTable->len; i++) { - if ((!xmlStrcmp(currentNode->name, - ModelTable->table[i].tag))) { - ModelTable->table[i].parse(doc, - ModelTable, - i, - currentNode); - break; - } - } - currentNode = currentNode->next; - } - - free(id); - free(date); - free(author); - - return 0; -} - -// -------------------------------------------------------------------------- // -// Preparsing a model file // -// -------------------------------------------------------------------------- // -int ParseModelIdentityXML(Model_t *model, Parameters_t *params) -{ - xmlDocPtr xmlDocument; - xmlNodePtr currentNode; - xmlChar *version = NULL; - xmlSchemaPtr schemPtr; - xmlSchemaValidCtxtPtr schemValidator; - xmlSchemaParserCtxtPtr schemFile; - char *schemPath; - - ParserTableXML_t table[] = - { - // IDENTITY - {(const xmlChar *)"identity", parseParentFieldXML, NULL}, - {(const xmlChar *)"name", parseTextFieldXML, model->name}, - {(const xmlChar *)"owner", parseTextFieldXML, model->owner}, - - // TODO lacking implementation (model side) - {(const xmlChar *)"owner_id", parseStubFieldXML, model->owner_id}, - - {(const xmlChar *)"date", parseIntFieldXML, &model->date}, - {(const xmlChar *)"version", parseTextFieldXML, model->version}, - - // PARAMETERS - {(const xmlChar *)"parameters", parseParentFieldPropsXML, model}, - // MODELIZATION - {(const xmlChar *)"modelization", parseParentFieldXML, model}, - {(const xmlChar *)"max_thread", parseStubFieldXML, model}, - {(const xmlChar *)"max_cycles", parseStubFieldXML, model}, - // SPACE - {(const xmlChar *)"space_param", parseParentFieldXML, model}, - {(const xmlChar *)"dimension", parseStubFieldXML, model}, - {(const xmlChar *)"size", parseSpaceSizeFieldXML, model}, - {(const xmlChar *)"site_multiplicity", parseIntFieldXML, - &model->siteNumber}, - - // TODO lacking implementation (model side) - {(const xmlChar *)"boundaries", parseStubFieldXML, model}, - }; - - ModelParserTableXML_t identityParserTable = - { - LEN(table), - &table[0] - }; - - // Allocating space for schema file path - schemPath = calloc(1, strlen(params->modelDir) - + strlen("/schemas/model_ .xmls")); - - printLog("Preparsing model %s\n", model->name); - - // Opening document - xmlDocument = xmlReadFile(model->filename, NULL, 0); - - if (xmlDocument == NULL) { - printErr("Can't parse model file at '%s'.\n", model->filename); - return -1; - } - - // Getting root from XML model file - currentNode = xmlDocGetRootElement(xmlDocument); - - if (currentNode == NULL) { - printErr("Invalid model file at '%s', document empty !\n", - model->filename); - xmlFreeDoc(xmlDocument); - free(schemPath); - return -2; - } - - // Checking that XML file is actually a model - if (xmlStrcmp(currentNode->name, (const xmlChar *) "gem-graph-model")) { - printErr("Invalid model file at '%s', " - "root node is not !\n", - model->filename); - xmlFreeDoc(xmlDocument); - free(schemPath); - return -3; - } - - // Get gem-graph model version to parse - version = xmlGetProp(currentNode, (xmlChar*)"version"); - // Check version is present - if (!version) { - printErr("Missing version for model %s \n", model->name); - xmlFreeDoc(xmlDocument); - free(schemPath); - return -4; - } else if (strlen((char*)version) > MODEL_STRING_SIZE) { - printErr("Invalid version number for model %s \n", model->name); - free(version); - xmlFreeDoc(xmlDocument); - free(schemPath); - } - printLog("Gem-graph model version %s detected\n", version); - - // Retrieving schema file - sprintf(schemPath, "%s/schemas/model_%s.xmls", params->modelDir, version); - printLog("Loading schema %s\n", schemPath); - - // Loading schema file - schemFile = xmlSchemaNewParserCtxt(schemPath); - if (schemFile == NULL) { - printErr("Invalid gem-graph version %s in model %s: no schema present", - version, model->name); - free(version); - xmlFreeDoc(xmlDocument); - free(schemPath); - return -5; - } - - // Loading schema file content - schemPtr = xmlSchemaParse(schemFile); - if (schemPtr == NULL) { - printErr("Invalid schema file, version %s\n", version); - xmlSchemaFreeParserCtxt(schemFile); - free(version); - xmlFreeDoc(xmlDocument); - free(schemPath); - return -6; - } - - // Creating validating context - schemValidator = xmlSchemaNewValidCtxt(schemPtr); - if (schemValidator == NULL) { - xmlSchemaFreeParserCtxt(schemFile); - xmlSchemaFree(schemPtr); - free(version); - xmlFreeDoc(xmlDocument); - free(schemPath); - printErr("An error occured preparing schema file, version %s\n", version); - return -7; - } - - // Validate (and print errors) ! - xmlSchemaSetValidErrors(schemValidator, - (xmlSchemaValidityErrorFunc) fprintf, - (xmlSchemaValidityWarningFunc) fprintf, stderr); - - // Get the validation status - model->validated = - xmlSchemaValidateDoc(schemValidator, xmlDocument) == 0 ? true : false; - - // Reset node - currentNode = xmlDocGetRootElement(xmlDocument); - - // Parsing identity - currentNode = currentNode->xmlChildrenNode; - while (currentNode != NULL) { - for (int i = 0; i < identityParserTable.len; i++) { - if ((!xmlStrcmp(currentNode->name, - identityParserTable.table[i].tag))) { - identityParserTable.table[i].parse(xmlDocument, - &identityParserTable, - i, - currentNode); - } - } - currentNode = currentNode->next; - } - - xmlSchemaFreeParserCtxt(schemFile); - xmlSchemaFreeValidCtxt(schemValidator); - xmlSchemaFree(schemPtr); - free(version); - xmlFreeDoc(xmlDocument); - free(schemPath); - xmlCleanupParser(); - - return 0; -} - -// -------------------------------------------------------------------------- // -// Parsing a model file // -// -------------------------------------------------------------------------- // -int ParseModelXML(Model_t *model) -{ - xmlDocPtr xmlDocument; - xmlNodePtr currentNode; - - ParserTableXML_t table[] = - { - // OBJECTS - // {(const xmlChar *)"objects", parseParentFieldXML, model}, - // {(const xmlChar *)"object", parseParentFieldPropsXML, model}, - - // SAVESTATES - {(const xmlChar *)"savestates", parseParentFieldPropsXML, model}, - // SPACE - {(const xmlChar *)"space", parseParentFieldPropsXML, model}, - - // TRANSITIONS - {(const xmlChar *)"transitions", parseParentFieldPropsXML, model}, - // TRANSITION - // TODO probability - {(const xmlChar *)"transition", parseParentFieldPropsXML, model}, - {(const xmlChar *)"if", parseParentFieldXML, model}, - {(const xmlChar *)"then", parseParentFieldXML, model}, - - // ARROW - {(const xmlChar *)"arrow", parseArrowFieldXML, model}, - - // REF - {(const xmlChar *)"ref", parseStubFieldXML, model}, - - // QUOTE - {(const xmlChar *)"quote", parseStubFieldXML, model}, - }; - - ModelParserTableXML_t modelParserTable = - { - LEN(table), - &table[0] - }; - - printLog("Parsing model %s\n", model->name); - - xmlDocument = xmlReadFile(model->filename, NULL, 0); - - if (xmlDocument == NULL) { - printErr("Can't parse model file at '%s'.\n", model->filename); - return -1; - } - - currentNode = xmlDocGetRootElement(xmlDocument); - - if (currentNode == NULL) { - printErr("Invalid model file at '%s', document empty !\n", - model->filename); - xmlFreeDoc(xmlDocument); - return -2; - } - - if (xmlStrcmp(currentNode->name, (const xmlChar *) "gem-graph-model")) { - printErr("Invalid model file at '%s', " - "root node is not !\n", - model->filename); - xmlFreeDoc(xmlDocument); - return -3; - } - - currentNode = currentNode->xmlChildrenNode; - while (currentNode != NULL) { - for (int i = 0; i < modelParserTable.len; i++) { - if ((!xmlStrcmp(currentNode->name, - modelParserTable.table[i].tag))) { - modelParserTable.table[i].parse(xmlDocument, - &modelParserTable, - i, - currentNode); - } - } - - currentNode = currentNode->next; - } - - xmlFreeDoc(xmlDocument); - xmlCleanupParser(); - - return 0; -} diff --git a/src/scheduler.c b/src/scheduler.c index 1b317bd..402e744 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -27,202 +27,4 @@ #include -/* -------------------------------------------------------------------------- */ -static void *schedulerMain(void *scheduler); - -/* -------------------------------------------------------------------------- */ - -// -------------------------------------------------------------------------- // -// Scheduler init function // -// -------------------------------------------------------------------------- // -void SchedInit(Scheduler_t *scheduler) -{ - pthread_create(&scheduler->id, NULL, schedulerMain, scheduler); -} - -/* -------------------------------------------------------------------------- */ - -// -------------------------------------------------------------------------- // -// Scheduler area finder function // -// -------------------------------------------------------------------------- // -static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow, - int ruleRadius, int xmax, int ymax, int zmax) -{ - register Center_t *currentCenter, *newCenter; - - currentCenter = centersList->next; - newCenter = malloc(sizeof(Center_t)); - - while (currentCenter){ - if ( (xmax && (abs(electedArrow->x - currentCenter->x) <= ruleRadius)) - || (ymax && (abs(electedArrow->y - currentCenter->y) <= ruleRadius)) - || (zmax && (abs(electedArrow->z - currentCenter->z) <= ruleRadius)) - ){ - free(newCenter); - newCenter = NULL; - //printLog("Can't find a free area\n"); - return NULL; - } - currentCenter = currentCenter->next; - } - - newCenter->x = electedArrow->x; - newCenter->y = electedArrow->y; - newCenter->z = electedArrow->z; - return newCenter; -} - -/* -------------------------------------------------------------------------- */ - -// -------------------------------------------------------------------------- // -// Scheduler thread main function // -// -------------------------------------------------------------------------- // -static void *schedulerMain(void *scheduler) -{ - Scheduler_t *args; - Worker_t *workerArray; - // A center is a structure that defines, with a radius, a cubic preempted - // area for a worker to operate on (as an approximation of a spheric one) - Center_t *centersList, *workArea; - Arrow_t *electedArrow; - - int ncpu, nworker, err; - - // Getting scheduler argument structure - args = (Scheduler_t*) scheduler; - printLog("Scheduler #%lu online\n", args->id); - - if (!args->nMaxThread) { // nmaxthread = 0 => no minimum - ncpu = get_nprocs(); // allocating all the cpus available - } else { // n thread = min(cpu, nmaxthread) - ncpu = MIN(get_nprocs(), args->nMaxThread); - } - printLog("%d threads available.\n", ncpu); - - // Data structures - workerArray = calloc(ncpu, sizeof(*workerArray)); - nworker = 0; - centersList = calloc(1, sizeof(*centersList)); - - // Initiate the arrowArray lock - if (err = ArrowsInitLock(args->arrowArray), err != 0) { - printErr("Impossible to create the arrow array lock (error %d)\n", err); - return NULL; - } - // - // MAIN LOOP - // - while (!args->pleaseStop && 0 <= args->nMaxCycles) { //XXX count cycles - //printLog("Scheduler #%lu online: cycle %d\n", *args->id, ncycles); - // - - // TODO statistics here - - // Create a new thread - if (nworker < ncpu) { - - workArea = NULL; - - // Acquiring lock to consistently read the arrowArray - if (ArrowsAcquireNonBlockingLock(args->arrowArray)) { - // Random choice of an arrow - electedArrow = - &args->arrowArray->array[rand() % args->arrowArray->size]; // XXX - - // Find a local area - workArea = findWorkArea(centersList, - electedArrow, - args->ruleRadius, - args->globalDrawingSpace->xMax, - args->globalDrawingSpace->yMax, - args->globalDrawingSpace->zMax - ); - ArrowsReleaseLock(args->arrowArray); - } - - // If a free area exists, - if (workArea) { - // preempt it, - CenterAdd(centersList, workArea); - // find a worker socket, - for (int i = 0; i < ncpu; i++) { - // if a location is empty - if (workerArray[i].id == 0) { - // prepare the worker for the area, - workerArray[i].localWorkAreaCenter = workArea; - workerArray[i].globalDrawingSpace = - args->globalDrawingSpace; - workerArray[i].conditionTree = - args->conditionTree; - workerArray[i].arrowArray = - args->arrowArray; - // create the worker, - WorkerInit(&workerArray[i]); - // and increment worker count. - nworker++; - printLog("Added worker at rank %d with center %p, now %d worker(s)\n", - i, - workArea, - nworker - ); - // Increment partial cycle TODO - break; - } - } - } - } - - // Delete finished workers - for (int i = 0; i < ncpu; i++) { - if (workerArray[i].id) { - //printLog("Checking termination of worker #%lu\n", *workerArray[i].id); - // Check worker termination - if (workerArray[i].terminated) { - // Join the thread to act his termination - WorkerWait(&workerArray[i]); - // Remove preemption on space - CenterRemove(workerArray[i].localWorkAreaCenter); - printLog("Worker #%lu terminated with return %d. Cleaning...\n", - workerArray[i].id, - workerArray[i].returnValue - ); - // Remove Worker - WorkerDestroy(&workerArray[i]); - nworker--; - } - } - } - } - - // Exiting scheduler properly - printLog("Stopping scheduler... (waiting for workers)\n"); - // Waiting for remaining workers - for (int i = 0; i < ncpu; i++) { - if (workerArray[i].id) { - printLog("Waiting for termination of worker #%lu\n", workerArray[i].id); - // Join the thread to wait for his termination - WorkerWait(&workerArray[i]); - // Remove preemption on space - CenterRemove(workerArray[i].localWorkAreaCenter); - printLog("Worker #%lu terminated with return %d. Cleaning...\n", - workerArray[i].id, - workerArray[i].returnValue - ); - // Remove Worker - WorkerDestroy(&workerArray[i]); - } - } - - printLog("Scheduler #%lu offline\n", args->id); - - - ArrowsDestroyLock(args->arrowArray); - - free(workerArray); - workerArray = NULL; - free(centersList); - centersList = NULL; - - return NULL; -} diff --git a/src/server.c b/src/server.c index ff738a8..a82fc68 100644 --- a/src/server.c +++ b/src/server.c @@ -25,37 +25,22 @@ /* -------------------------------------------------------------------------- */ -static Command_t cmdList[] = -{ - {"help", CmdHelp, "Help command"}, - {"model", CmdModel, "Model command"}, - {"shutdown", CmdShutdown, "Shutdown command"}, -}; - -static void *serverMain(void *server); +static void *server_main(void *server); /* -------------------------------------------------------------------------- */ -// -------------------------------------------------------------------------- // -// Server init function // -// -------------------------------------------------------------------------- // -void ServerInit(Server_t *server) -{ - pthread_create(&server->id, NULL, serverMain, server); -} - #define SEND_BUFFER_SIZE 80 * 24 #define RECEIVE_BUFFER_SIZE 80 -void *serverCommunicationInstance(void *serverCom) +void *server_communication_instance(void *serverCom) { - ServerCommunication_t *args; + servercom_t *args; char **argv = NULL; char receiveBuff[RECEIVE_BUFFER_SIZE]; char sendBuff[SEND_BUFFER_SIZE]; int tokenIndex, bytesReceived, clientPort; char clientIP[16]; - args = (ServerCommunication_t*) serverCom; + args = (servercom_t*) serverCom; // Get ip address from client inet_ntop(AF_INET, @@ -132,7 +117,7 @@ void *serverCommunicationInstance(void *serverCom) #define PORT 9000 #define MAX_CONNECTION 100 -static void *serverMain(void *server) +static void *server_main(void *server) { Server_t *args; ServerCommunication_t serverSlots[MAX_CONNECTION] = {0}; @@ -235,7 +220,7 @@ static void *serverMain(void *server) // Create thread threadStatus = pthread_create(&serverSlots[serverSlotIndex].id, NULL, - serverCommunicationInstance, + server_communication_instance, (void*)&serverSlots[serverSlotIndex]); if(threadStatus != 0) { printErr("Error from pthread: %d (%s)\n", diff --git a/src/supervisor.c b/src/supervisor.c index 03cf758..3d8fae5 100644 --- a/src/supervisor.c +++ b/src/supervisor.c @@ -24,22 +24,4 @@ /* -------------------------------------------------------------------------- */ -static void *supervisorMain(void *supervisor); -/* -------------------------------------------------------------------------- */ - -// -------------------------------------------------------------------------- // -// Supervisor init function // -// -------------------------------------------------------------------------- // -void SupervisorInit(Supervisor_t *supervisor) -{ - pthread_create(&supervisor->id, NULL, supervisorMain, supervisor); -} - -// -------------------------------------------------------------------------- // -// Supervisor thread main function // -// -------------------------------------------------------------------------- // -static void *supervisorMain(void *supervisor) -{ - return NULL; -} diff --git a/src/tests/getchar b/src/tests/getchar deleted file mode 100755 index 79b5550f461522eae1012f175b3bdf6eb7fd6005..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17096 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 B3331c diff --git a/src/tests/test_realloc b/src/tests/test_realloc deleted file mode 100755 index 03248fc77c4135b2b61aea905a96301596c465da..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16720 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 diff --git a/src/tests/xml b/src/tests/xml deleted file mode 100755 index b0826726346e8356badc37d0491a90faf21a9e8a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17128 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 cO@xu&a5?94m6YZ#id, NULL, WorkerMain, worker)) { - printLog("Worker #%lu can't be initialized!\n", worker->id); - return; - } -} - -// -------------------------------------------------------------------------- // -// Worker thread main function // -// -------------------------------------------------------------------------- // -static void *WorkerMain(void *worker) -{ - Worker_t *args; - int a = rand()%__INT_MAX__; - - args = (Worker_t*) worker; - printLog("Worker #%lu online\n", args->id); - - int size = args->globalDrawingSpace->size; - - // TODO execute rule comparison - - args->returnValue = a; - args->terminated = true; - - printLog("Worker #%lu offline\n", args->id); - - return NULL; -}