WIP: devel : travail du mois de mars/avril #28
|
@ -2,3 +2,5 @@
|
||||||
*.o
|
*.o
|
||||||
*.deb
|
*.deb
|
||||||
bin/**
|
bin/**
|
||||||
|
build/**
|
||||||
|
|
||||||
|
|
191
Makefile
191
Makefile
|
@ -20,120 +20,123 @@
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
#=----------------------------------------------------------------------------=#
|
#=----------------------------------------------------------------------------=#
|
||||||
|
|
||||||
CCOPTS=-pthread -Wall -g -Os -I/usr/include/libxml2
|
.PHONY: all clean install run build_system
|
||||||
LDFLAGS= -lc -lpthread -lxml2
|
.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 -fopenmp \
|
||||||
|
-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
|
BINDIR=bin
|
||||||
INCDIR=include
|
BUILDDIR=build
|
||||||
SRCDIR=src
|
SRCDIR=src
|
||||||
DEBDIR=debian
|
#vpath %.c $(SRCDIR)
|
||||||
|
|
||||||
SERVEROBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/worker.o \
|
SOURCES= $(shell find $(SRCDIR) -maxdepth 1 -type f -name "*.c")
|
||||||
$(BINDIR)/centers.o $(BINDIR)/cmds.o $(BINDIR)/model.o \
|
BUILDBINS=$(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES))
|
||||||
$(BINDIR)/main.o $(BINDIR)/arrows.o $(BINDIR)/parsing.o
|
BUILDDEPS=$(patsubst %.c,$(BUILDDIR)/%.d,$(SOURCES))
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
.DEFAULT_GOAL:= all
|
-include /etc/os-release
|
||||||
.PHONY: all clean deb tests install run run-cli run-tests dependencies
|
|
||||||
|
|
||||||
# ---- 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 ----------------------------------------------------- #
|
$(BUILDDIR)/%.d: %.c | $(BUILDDIR)
|
||||||
TEST_SCHEDULER=$(BINDIR)/tests/centers
|
@mkdir -p $(shell dirname $@)
|
||||||
TESTS=$(TEST_SCHEDULER)
|
@$(CC) -MM -MT $(@:%.d=%.o) -MF $@ $<
|
||||||
|
@echo -e ${CL2}[$@] ${CL}dependencies generated.${CL3}
|
||||||
|
|
||||||
$(BINDIR)/tests/centers: $(SRCDIR)/tests/centers.c
|
#
|
||||||
@echo "Compiling $<"
|
# Compilation
|
||||||
@$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) $(LDFLAGS) -o $@ $<
|
#
|
||||||
|
$(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
|
$(BUILDDIR)/%.o: %.c | $(BUILDDIR)
|
||||||
@echo "Compiling $<"
|
@mkdir -p $(shell dirname $@)
|
||||||
@$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) -c -o $@ $<
|
@$(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 $@"
|
# Virtual recipes
|
||||||
@$(CC) -o $@ $(SERVEROBJ) $(LDFLAGS)
|
#
|
||||||
@echo "Success!"
|
|
||||||
|
|
||||||
$(BINDIR)/gem-graph-ctl: $(CLIOBJ)
|
|
||||||
@echo "Building program to $@"
|
|
||||||
@$(CC) -o $@ $(CLIOBJ) $(LDFLAGS)
|
|
||||||
@echo "Success!"
|
|
||||||
|
|
||||||
# ---- Misc recipes ---------------------------------------------------------- #
|
|
||||||
clean:
|
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:
|
install:
|
||||||
echo "Installing is not supported"
|
echo "Installing is not supported"
|
||||||
|
|
||||||
# ---- Builder uses this target to run the application ----------------------- #
|
build_system:
|
||||||
run: all
|
@echo -e ${CL2}[$@] ${CL}building...${CL3}
|
||||||
@bin/gem-graph-server -C debian/etc -M debian/var/models \
|
@make $(BINDIR)/gem-graph-server -j $(NTHREADS)
|
||||||
-U debian/var/users
|
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||||
run-gdb: all
|
|
||||||
@gdb bin/gem-graph-server \
|
|
||||||
-ex "set args -C debian/etc -M debian/var/models -U debian/var/users"
|
|
||||||
|
|
||||||
run-valgrind: all
|
run: build_system
|
||||||
|
@echo -e ${CL2}[$@] ${CL}executing...${CL3}
|
||||||
|
@bin/gem-graph-server -C data/config -M data/models -U data/users
|
||||||
|
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||||
|
|
||||||
|
debug: build_system
|
||||||
|
@echo -e ${CL2}[$@] ${CL}executing...${CL3}
|
||||||
|
@gdb --args $(BINDIR)/gem-graph-server -C data/config -M data/models \
|
||||||
|
-U data/users
|
||||||
|
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||||
|
|
||||||
|
valgrind: build_system
|
||||||
|
@echo -e ${CL2}[$@] ${CL}executing...${CL3}
|
||||||
@valgrind --leak-check=full --show-leak-kinds=all -s \
|
@valgrind --leak-check=full --show-leak-kinds=all -s \
|
||||||
bin/gem-graph-server -C debian/etc -M debian/var/models \
|
bin/gem-graph-server -C data/config -M data/models -U data/users
|
||||||
-U debian/var/users
|
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||||
|
|
||||||
run-both: all
|
run-both: build_system
|
||||||
@bin/gem-graph-server -C debian/etc -M debian/var/models \
|
@echo -e ${CL2}[$@] ${CL}executing...${CL3}
|
||||||
-U debian/var/users & sleep 1 && bin/gem-graph-ctl
|
@bin/gem-graph-server -C data/config -M data/models -U data/users\
|
||||||
run-server: all
|
& sleep 1 && bin/gem-graph-ctl
|
||||||
@bin/gem-graph-server -C debian/etc -M debian/var/models \
|
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||||
-U debian/var/users
|
run-server: build_system
|
||||||
run-cli: all
|
@echo -e ${CL2}[$@] ${CL}executing...${CL3}
|
||||||
@bin/gem-graph-ctl
|
@bin/gem-graph-server -C data/config -M data/models -U data/users
|
||||||
run-tests: tests
|
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||||
@bin/tests/scheduler
|
|
||||||
|
all: build_system
|
||||||
|
@echo -e ${CL2}[$@] ${CL}done.${CL3}
|
||||||
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<gem-graph-model version="0.2.1">
|
||||||
|
|
||||||
|
<identity>
|
||||||
|
<name>Modèle de test</name>
|
||||||
|
|
||||||
|
<owner>Léontine Patinette</owner>
|
||||||
|
|
||||||
|
<owner_id>2</owner_id>
|
||||||
|
|
||||||
|
<date>1630000000</date>
|
||||||
|
|
||||||
|
<version>1.0</version>
|
||||||
|
|
||||||
|
<g_ref id="Cause" date="1630000000" author="toujours" lang="en">Ref</g_ref>
|
||||||
|
</identity>
|
||||||
|
|
||||||
|
<parameters id="texte" date="0" author="Léontine Trottine.">
|
||||||
|
<simulation>
|
||||||
|
<max_thread>0</max_thread>
|
||||||
|
<max_cycles>9</max_cycles>
|
||||||
|
|
||||||
|
</simulation>
|
||||||
|
|
||||||
|
<space-param>
|
||||||
|
<!-- loop_on_zero="true" anything moved before zero reenters at the end of space-->
|
||||||
|
<!-- loop_on_zero="false" anything moved before zero is lost-->
|
||||||
|
<!-- loop_on_max="true" anything moved beyond max reenters at the zero of space-->
|
||||||
|
<!-- loop_on_max="false" anything moved beyond max is lost-->
|
||||||
|
|
||||||
|
<dimension x="29"/>
|
||||||
|
|
||||||
|
<!-- Site_multiplicity = number of sites in a space unit. -->
|
||||||
|
<!-- Each site points towards a neighbouring space unit. -->
|
||||||
|
<!-- Several arrows can be stacked in the same site. -->
|
||||||
|
|
||||||
|
<site_multiplicity>2</site_multiplicity>
|
||||||
|
|
||||||
|
</space-param>
|
||||||
|
|
||||||
|
</parameters>
|
||||||
|
|
||||||
|
<!-- Model objects definition -->
|
||||||
|
|
||||||
|
<objects id="only dimers in this model" date="1630000000" author="inanimés,... âme ?">
|
||||||
|
<object id="a dimer" date="1630000000" author="Alphonse">
|
||||||
|
<arrow site="1" weight="1" x="0"/>
|
||||||
|
<arrow site="2" weight="1" x="1"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
</objects>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Saved space description (initial space is sequence 0) -->
|
||||||
|
|
||||||
|
<savedstates id="texte" date="1630000000" author="Qui courrait dans l'herbe'">
|
||||||
|
<state id="initial" date="1630000000" author="Une souris verte">
|
||||||
|
<arrow site="0" weight="1" x="0"/>
|
||||||
|
<arrow site="1" weight="1" x="1"/>
|
||||||
|
<arrow site="0" weight="1" x="10"/>
|
||||||
|
<arrow site="1" weight="1" x="11"/>
|
||||||
|
<arrow site="0" weight="1" x="20"/>
|
||||||
|
<arrow site="1" weight="1" x="21"/>
|
||||||
|
|
||||||
|
<!-- Three dimers 1-1 are drawn in the global space
|
||||||
|
at locations (0,1) (10,11) and (20,21) -->
|
||||||
|
|
||||||
|
</state>
|
||||||
|
|
||||||
|
</savedstates>
|
||||||
|
|
||||||
|
<!-- Model transitions definition (rules) -->
|
||||||
|
<!-- In this version : <xs:sequence minOccurs="0" maxOccurs="unbounded">-->
|
||||||
|
<!-- Transitions should be edited by hand and written in a 'human-readable' format -->
|
||||||
|
|
||||||
|
<conditions id="random walk of dimers" date="1630000000" author="Zazard le lézard !">
|
||||||
|
|
||||||
|
<condition site="0" weight="1" node_id="1" parent="0" x="0"/>
|
||||||
|
<condition site="1" weight="1" node_id="2" parent="1" x="1"/>
|
||||||
|
<!-- as soon as conditions 1 and 2 are satisfied, a dimer is identified at atation (0,1). -->
|
||||||
|
|
||||||
|
<condition site="0" weight="0" node_id="3" parent="2" x="2"/>
|
||||||
|
<!-- as soon as condition 3 is satisfied,
|
||||||
|
the neighbouring space unit to East of the dimer is empty
|
||||||
|
and the dimer identified by conditions (0,1) can be moved to East. -->
|
||||||
|
|
||||||
|
<condition site="1" weight="0" node_id="4" parent="2" x="-1"/>
|
||||||
|
<!-- as soon as condition 4 is satisfied,
|
||||||
|
the neighbouring space unit to West of the dimer is empty
|
||||||
|
and the dimer identified by conditions (0,1) can be moved to West. -->
|
||||||
|
|
||||||
|
</conditions>
|
||||||
|
|
||||||
|
<transitions>
|
||||||
|
|
||||||
|
<transition id="move_a_dimer_to_east" date="1630000000" author="Pas moi..."
|
||||||
|
parent="3" probability="1">
|
||||||
|
|
||||||
|
<arrow site="1" weight="0" x="0"/>
|
||||||
|
<arrow site="2" weight="0" x="1"/>
|
||||||
|
<arrow site="1" weight="1" x="1"/>
|
||||||
|
<arrow site="2" weight="1" x="2"/>
|
||||||
|
|
||||||
|
</transition>
|
||||||
|
|
||||||
|
<transition id="move_a_dimer_to_west" date="1630000000" author="Ni moi !"
|
||||||
|
parent="4" probability="1">
|
||||||
|
|
||||||
|
<arrow site="1" weight="0" x="0"/>
|
||||||
|
<arrow site="2" weight="0" x="1"/>
|
||||||
|
<arrow site="2" weight="1" x="0"/>
|
||||||
|
<arrow site="1" weight="1" x="1"/>
|
||||||
|
|
||||||
|
</transition>
|
||||||
|
|
||||||
|
</transitions>
|
||||||
|
|
||||||
|
</gem-graph-model>
|
||||||
|
|
|
@ -0,0 +1,145 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<gem-graph-model version="0.2.1">
|
||||||
|
|
||||||
|
<identity>
|
||||||
|
<name>Test 21-03-2023</name>
|
||||||
|
|
||||||
|
<owner>J</owner>
|
||||||
|
|
||||||
|
<owner_id>J</owner_id>
|
||||||
|
|
||||||
|
<date>time_stamp</date>
|
||||||
|
|
||||||
|
<version>1.0</version>
|
||||||
|
|
||||||
|
<g_ref id="Cause" date="time_stamp" author="J" lang="en">Ref</g_ref>
|
||||||
|
</identity>
|
||||||
|
|
||||||
|
<parameters id="texte" date="0" author="J">
|
||||||
|
<simulation>
|
||||||
|
<max_thread>0</max_thread>
|
||||||
|
<max_cycles>9</max_cycles>
|
||||||
|
|
||||||
|
</simulation>
|
||||||
|
|
||||||
|
<space-param>
|
||||||
|
<!-- loop_on_zero="true" anything moved before zero reenters at the end of space-->
|
||||||
|
<!-- loop_on_zero="false" anything moved before zero is lost-->
|
||||||
|
<!-- loop_on_max="true" anything moved beyond max reenters at the zero of space-->
|
||||||
|
<!-- loop_on_max="false" anything moved beyond max is lost-->
|
||||||
|
|
||||||
|
<dimension x="22" y="4" z="8"/>
|
||||||
|
|
||||||
|
<!-- Site_multiplicity = number of sites in a space unit. -->
|
||||||
|
<!-- Each site points towards a neighbouring space unit. -->
|
||||||
|
<!-- Several arrows can be stacked in the same site. -->
|
||||||
|
|
||||||
|
<site_multiplicity>2</site_multiplicity>
|
||||||
|
|
||||||
|
</space-param>
|
||||||
|
|
||||||
|
</parameters>
|
||||||
|
|
||||||
|
<!-- Model objects definition -->
|
||||||
|
|
||||||
|
<objects id="only dimers in this model" date="time_stamp" author="J">
|
||||||
|
<object id="a dimer" date="time_stamp" author="J">
|
||||||
|
<arrow site="1" weight="1" x="0"/>
|
||||||
|
<arrow site="2" weight="1" x="1"/>
|
||||||
|
</object>
|
||||||
|
|
||||||
|
</objects>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Saved space description (initial space is sequence 0) -->
|
||||||
|
|
||||||
|
<savedstates id="texte" date="time_stamp" author="J">
|
||||||
|
<state id="initial" date="time_stamp" author="J">
|
||||||
|
<arrow site="1" weight="1" x="0"/>
|
||||||
|
<arrow site="2" weight="1" x="1"/>
|
||||||
|
<arrow site="1" weight="1" x="10"/>
|
||||||
|
<arrow site="2" weight="1" x="11"/>
|
||||||
|
<arrow site="1" weight="1" x="20"/>
|
||||||
|
<arrow site="2" weight="1" x="21"/>
|
||||||
|
|
||||||
|
<!-- Three dimers 1-1 are drawn in the global space
|
||||||
|
at locations (0,1) (10,11) and (20,21) -->
|
||||||
|
|
||||||
|
</state>
|
||||||
|
|
||||||
|
</savedstates>
|
||||||
|
|
||||||
|
<!-- Model transitions definition (rules) -->
|
||||||
|
<!-- In this version : <xs:sequence minOccurs="0" maxOccurs="unbounded">-->
|
||||||
|
<!-- Transitions should be edited by hand and written in a 'human-readable' format -->
|
||||||
|
|
||||||
|
<conditions_tree>
|
||||||
|
<condition_anonym site="1" weight="1" x="0">
|
||||||
|
<condition_anonym site="2" weight="1" x="1">
|
||||||
|
<condition_anonym site="1" weight="0" x="2">
|
||||||
|
<transition_anonym id="move_a_dimer_to_east"
|
||||||
|
date="time_stamp"
|
||||||
|
author="J"
|
||||||
|
probability="0.5"/>
|
||||||
|
<arrow site="1" weight="0" x="0"/>
|
||||||
|
<arrow site="2" weight="0" x="1"/>
|
||||||
|
<arrow site="1" weight="1" x="1"/>
|
||||||
|
<arrow site="2" weight="1" x="2"/>
|
||||||
|
</condition_anonym>
|
||||||
|
<condition_anonym site="2" weight="0" x="-1">
|
||||||
|
<transition_anonym id="move_a_dimer_to_west"
|
||||||
|
date="time_stamp"
|
||||||
|
author="J"
|
||||||
|
probability="0.5"/>
|
||||||
|
<arrow site="1" weight="0" x="0"/>
|
||||||
|
<arrow site="2" weight="0" x="1"/>
|
||||||
|
<arrow site="2" weight="1" x="0"/>
|
||||||
|
<arrow site="1" weight="1" x="1"/>
|
||||||
|
</condition_anonym>
|
||||||
|
</condition_anonym>
|
||||||
|
</condition_anonym>
|
||||||
|
</conditions_tree>
|
||||||
|
|
||||||
|
<conditionslist id="random walk of dimers" date="time_stamp" author="J">
|
||||||
|
|
||||||
|
<condition site="1" weight="1" node_id="1" parent="0" x="0"/>
|
||||||
|
<condition site="2" weight="1" node_id="2" parent="1" x="1"/>
|
||||||
|
<!-- as soon as conditions 1 and 2 are satisfied, a dimer is identified at atation (0,1). -->
|
||||||
|
|
||||||
|
<condition site="1" weight="0" node_id="3" parent="2" x="2"/>
|
||||||
|
<!-- as soon as condition 3 is satisfied,
|
||||||
|
the neighbouring space unit to East of the dimer is empty
|
||||||
|
and the dimer identified by conditions (1,2) can be moved to East. -->
|
||||||
|
|
||||||
|
<condition site="2" weight="0" node_id="4" parent="2" x="-1"/>
|
||||||
|
<!-- as soon as condition 4 is satisfied,
|
||||||
|
the neighbouring space unit to West of the dimer is empty
|
||||||
|
and the dimer identified by conditions (1,2) can be moved to West. -->
|
||||||
|
|
||||||
|
</conditionslist>
|
||||||
|
|
||||||
|
<transitionslist>
|
||||||
|
|
||||||
|
<transition id="move_a_dimer_to_east" date="time_stamp" author="J"
|
||||||
|
parent="3" probability="1">
|
||||||
|
|
||||||
|
<arrow site="1" weight="0" x="0"/>
|
||||||
|
<arrow site="2" weight="0" x="1"/>
|
||||||
|
<arrow site="1" weight="1" x="1"/>
|
||||||
|
<arrow site="2" weight="1" x="2"/>
|
||||||
|
|
||||||
|
</transition>
|
||||||
|
|
||||||
|
<transition id="move_a_dimer_to_west" date="time_stamp" author="J"
|
||||||
|
parent="4" probability="1">
|
||||||
|
|
||||||
|
<arrow site="1" weight="0" x="0"/>
|
||||||
|
<arrow site="2" weight="0" x="1"/>
|
||||||
|
<arrow site="2" weight="1" x="0"/>
|
||||||
|
<arrow site="1" weight="1" x="1"/>
|
||||||
|
|
||||||
|
</transition>
|
||||||
|
|
||||||
|
</transitionslist>
|
||||||
|
|
||||||
|
</gem-graph-model>
|
|
@ -1,9 +1,9 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
<!-- https://www.freeformatter.com/xml-validator-xsd.html -->
|
<!-- https://www.freeformatter.com/xml-validator-xsd.html -->
|
||||||
<!-- https://www.w3schools.com/xml/el_attribute.asp -->
|
|
||||||
<xs:attribute name="id" type="xs:string"/>
|
<xs:attribute name="id" type="xs:string"/>
|
||||||
<xs:attribute name="node_id" type="xs:integer"/>
|
<xs:attribute name="node_id" type="xs:integer"/>
|
||||||
|
<xs:attribute name="parent" type="xs:integer"/>
|
||||||
<xs:attribute name="date" type="xs:integer"/>
|
<xs:attribute name="date" type="xs:integer"/>
|
||||||
<xs:attribute name="name" type="xs:string"/>
|
<xs:attribute name="name" type="xs:string"/>
|
||||||
<xs:attribute name="lang" type="xs:string"/>
|
<xs:attribute name="lang" type="xs:string"/>
|
||||||
|
@ -11,14 +11,16 @@
|
||||||
<xs:attribute name="owner_id" type="xs:integer"/>
|
<xs:attribute name="owner_id" type="xs:integer"/>
|
||||||
<xs:attribute name="author" type="xs:string"/>
|
<xs:attribute name="author" type="xs:string"/>
|
||||||
<xs:attribute name="version" type="xs:float"/>
|
<xs:attribute name="version" type="xs:float"/>
|
||||||
<xs:attribute name="sequence" type="xs:integer"/>
|
|
||||||
<xs:attribute name="probability" type="xs:integer"/>
|
<xs:attribute name="probability" type="xs:integer"/>
|
||||||
<xs:attribute name="parent" type="xs:integer"/>
|
|
||||||
<xs:attribute name="x" type="xs:integer" default="0"/>
|
|
||||||
<xs:attribute name="y" type="xs:integer" default="0"/>
|
|
||||||
<xs:attribute name="z" type="xs:integer" default="0"/>
|
|
||||||
<xs:attribute name="site" type="xs:integer" default="0"/>
|
<xs:attribute name="site" type="xs:integer" default="0"/>
|
||||||
<xs:attribute name="weight" type="xs:integer" default="0"/>
|
<xs:attribute name="weight" type="xs:integer" default="0"/>
|
||||||
|
<xs:attribute name="u" type="xs:integer"/>
|
||||||
|
<xs:attribute name="v" type="xs:integer"/>
|
||||||
|
<xs:attribute name="w" type="xs:integer"/>
|
||||||
|
<xs:attribute name="x" type="xs:integer"/>
|
||||||
|
<xs:attribute name="y" type="xs:integer"/>
|
||||||
|
<xs:attribute name="z" type="xs:integer"/>
|
||||||
|
<xs:attribute name="t" type="xs:integer"/>
|
||||||
|
|
||||||
|
|
||||||
<xs:attributeGroup name="id_date_author">
|
<xs:attributeGroup name="id_date_author">
|
||||||
|
@ -27,14 +29,6 @@
|
||||||
<xs:attribute ref="author"/>
|
<xs:attribute ref="author"/>
|
||||||
</xs:attributeGroup>
|
</xs:attributeGroup>
|
||||||
|
|
||||||
<xs:attributeGroup name="xyz_site_nb">
|
|
||||||
<xs:attribute ref="x"/>
|
|
||||||
<xs:attribute ref="y"/>
|
|
||||||
<xs:attribute ref="z"/>
|
|
||||||
<xs:attribute ref="site"/>
|
|
||||||
<xs:attribute ref="weight"/>
|
|
||||||
</xs:attributeGroup>
|
|
||||||
|
|
||||||
<xs:element name="g_ref">
|
<xs:element name="g_ref">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:simpleContent>
|
<xs:simpleContent>
|
||||||
|
@ -48,23 +42,45 @@
|
||||||
|
|
||||||
<xs:element name="quote" substitutionGroup="g_ref"/>
|
<xs:element name="quote" substitutionGroup="g_ref"/>
|
||||||
|
|
||||||
|
<xs:element name="dimension">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute ref="u" use="optional"/>
|
||||||
|
<xs:attribute ref="v" use="optional"/>
|
||||||
|
<xs:attribute ref="w" use="optional"/>
|
||||||
|
<xs:attribute ref="x" use="optional"/>
|
||||||
|
<xs:attribute ref="y" use="optional"/>
|
||||||
|
<xs:attribute ref="z" use="optional"/>
|
||||||
|
<xs:attribute ref="t" use="optional"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
<xs:element name="arrow">
|
<xs:element name="arrow">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence>
|
<xs:attribute ref="site" use="required"/>
|
||||||
<xs:element minOccurs="0" ref="quote"/>
|
<xs:attribute ref="weight" use="required"/>
|
||||||
</xs:sequence>
|
<xs:attribute ref="u" use="optional"/>
|
||||||
<xs:attributeGroup ref="xyz_site_nb"/>
|
<xs:attribute ref="v" use="optional"/>
|
||||||
|
<xs:attribute ref="w" use="optional"/>
|
||||||
|
<xs:attribute ref="x" use="optional"/>
|
||||||
|
<xs:attribute ref="y" use="optional"/>
|
||||||
|
<xs:attribute ref="z" use="optional"/>
|
||||||
|
<xs:attribute ref="t" use="optional"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|
||||||
<xs:element name="condition">
|
<xs:element name="condition">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence>
|
<xs:attribute ref="site" use="required"/>
|
||||||
<xs:element minOccurs="0" ref="quote"/>
|
<xs:attribute ref="weight" use="required"/>
|
||||||
</xs:sequence>
|
|
||||||
<xs:attributeGroup ref="xyz_site_nb"/>
|
|
||||||
<xs:attribute ref="node_id" use="required"/>
|
<xs:attribute ref="node_id" use="required"/>
|
||||||
<xs:attribute ref="parent" use="required"/>
|
<xs:attribute ref="parent" use="required"/>
|
||||||
|
<xs:attribute ref="u" use="optional"/>
|
||||||
|
<xs:attribute ref="v" use="optional"/>
|
||||||
|
<xs:attribute ref="w" use="optional"/>
|
||||||
|
<xs:attribute ref="x" use="optional"/>
|
||||||
|
<xs:attribute ref="y" use="optional"/>
|
||||||
|
<xs:attribute ref="z" use="optional"/>
|
||||||
|
<xs:attribute ref="t" use="optional"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|
||||||
|
@ -79,16 +95,6 @@
|
||||||
|
|
||||||
<xs:element name="object" substitutionGroup="state"/>
|
<xs:element name="object" substitutionGroup="state"/>
|
||||||
|
|
||||||
<xs:element name="space">
|
|
||||||
<xs:complexType>
|
|
||||||
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
|
||||||
<xs:element ref="arrow"/>
|
|
||||||
</xs:sequence>
|
|
||||||
<xs:attributeGroup ref="id_date_author"/>
|
|
||||||
<xs:attribute ref="sequence" use="required"/>
|
|
||||||
</xs:complexType>
|
|
||||||
</xs:element>
|
|
||||||
|
|
||||||
<xs:element name="transition">
|
<xs:element name="transition">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
||||||
|
@ -103,50 +109,38 @@
|
||||||
|
|
||||||
<xs:element name="gem-graph-model">
|
<xs:element name="gem-graph-model">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence>
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
<xs:element name="identity">
|
<xs:element name="identity">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence>
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
<xs:element name="name" type="xs:string"/>
|
<xs:element name="name" type="xs:string"/>
|
||||||
<xs:element name="owner" type="xs:string"/>
|
<xs:element name="owner" type="xs:string"/>
|
||||||
<xs:element name="owner_id" type="xs:integer"/>
|
<xs:element name="owner_id" type="xs:integer"/>
|
||||||
<xs:element name="date" type="xs:integer"/>
|
<xs:element name="date" type="xs:integer"/>
|
||||||
<xs:element name="version" type="xs:float"/>
|
<xs:element name="version" type="xs:float"/>
|
||||||
<xs:element minOccurs="0" ref="g_ref"/>
|
<xs:element ref="g_ref" minOccurs="1" maxOccurs="1"/>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|
||||||
<xs:element name="parameters">
|
<xs:element name="parameters">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence>
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
|
|
||||||
<xs:element name="simulation">
|
<xs:element name="simulation">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence>
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
|
|
||||||
<xs:element name="max_thread" type="xs:integer"/>
|
<xs:element name="max_thread" type="xs:integer"/>
|
||||||
|
|
||||||
<xs:element name="max_cycles" type="xs:integer"/>
|
<xs:element name="max_cycles" type="xs:integer"/>
|
||||||
|
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|
||||||
<xs:element name="space-param">
|
<xs:element name="space-param">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence>
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
|
<xs:element ref="dimension"/>
|
||||||
<xs:element name="dimension" type="xs:integer"/>
|
|
||||||
|
|
||||||
<xs:element name="size">
|
|
||||||
<xs:complexType>
|
|
||||||
<xs:attributeGroup ref="xyz_site_nb"/>
|
|
||||||
</xs:complexType>
|
|
||||||
</xs:element>
|
|
||||||
|
|
||||||
<xs:element name="site_multiplicity" type="xs:integer"/>
|
<xs:element name="site_multiplicity" type="xs:integer"/>
|
||||||
|
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
@ -159,16 +153,16 @@
|
||||||
<xs:element name="objects">
|
<xs:element name="objects">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
||||||
<xs:element ref="state"/>
|
<xs:element ref="object"/>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
<xs:attributeGroup ref="id_date_author"/>
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|
||||||
<xs:element name="savestates">
|
<xs:element name="savedstates">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence minOccurs="0" maxOccurs="unbounded">
|
<xs:sequence minOccurs="0" maxOccurs="unbounded">
|
||||||
<xs:element ref="space"/>
|
<xs:element ref="state"/>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
<xs:attributeGroup ref="id_date_author"/>
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
@ -197,3 +191,4 @@
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:schema>
|
</xs:schema>
|
||||||
|
|
|
@ -0,0 +1,235 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<!-- https://www.freeformatter.com/xml-validator-xsd.html -->
|
||||||
|
<xs:attribute name="id" type="xs:string"/>
|
||||||
|
<xs:attribute name="node_id" type="xs:integer"/>
|
||||||
|
<xs:attribute name="parent" type="xs:integer"/>
|
||||||
|
<xs:attribute name="date" type="xs:integer"/>
|
||||||
|
<xs:attribute name="name" type="xs:string"/>
|
||||||
|
<xs:attribute name="lang" type="xs:string"/>
|
||||||
|
<xs:attribute name="owner" type="xs:string"/>
|
||||||
|
<xs:attribute name="owner_id" type="xs:integer"/>
|
||||||
|
<xs:attribute name="author" type="xs:string"/>
|
||||||
|
<xs:attribute name="version" type="xs:float"/>
|
||||||
|
<xs:attribute name="probability" type="xs:integer"/>
|
||||||
|
<xs:attribute name="site" type="xs:integer" default="0"/>
|
||||||
|
<xs:attribute name="weight" type="xs:integer" default="0"/>
|
||||||
|
<xs:attribute name="u" type="xs:integer"/>
|
||||||
|
<xs:attribute name="v" type="xs:integer"/>
|
||||||
|
<xs:attribute name="w" type="xs:integer"/>
|
||||||
|
<xs:attribute name="x" type="xs:integer"/>
|
||||||
|
<xs:attribute name="y" type="xs:integer"/>
|
||||||
|
<xs:attribute name="z" type="xs:integer"/>
|
||||||
|
<xs:attribute name="t" type="xs:integer"/>
|
||||||
|
|
||||||
|
|
||||||
|
<xs:attributeGroup name="id_date_author">
|
||||||
|
<xs:attribute ref="id"/>
|
||||||
|
<xs:attribute ref="date"/>
|
||||||
|
<xs:attribute ref="author"/>
|
||||||
|
</xs:attributeGroup>
|
||||||
|
|
||||||
|
<xs:element name="g_ref">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:simpleContent>
|
||||||
|
<xs:extension base="xs:string">
|
||||||
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
|
<xs:attribute ref="lang" use="required"/>
|
||||||
|
</xs:extension>
|
||||||
|
</xs:simpleContent>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="quote" substitutionGroup="g_ref"/>
|
||||||
|
|
||||||
|
<xs:element name="dimension">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute ref="u" use="optional"/>
|
||||||
|
<xs:attribute ref="v" use="optional"/>
|
||||||
|
<xs:attribute ref="w" use="optional"/>
|
||||||
|
<xs:attribute ref="x" use="optional"/>
|
||||||
|
<xs:attribute ref="y" use="optional"/>
|
||||||
|
<xs:attribute ref="z" use="optional"/>
|
||||||
|
<xs:attribute ref="t" use="optional"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="arrow">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute ref="site" use="required"/>
|
||||||
|
<xs:attribute ref="weight" use="required"/>
|
||||||
|
<xs:attribute ref="u" use="optional"/>
|
||||||
|
<xs:attribute ref="v" use="optional"/>
|
||||||
|
<xs:attribute ref="w" use="optional"/>
|
||||||
|
<xs:attribute ref="x" use="required"/>
|
||||||
|
<xs:attribute ref="y" use="optional"/>
|
||||||
|
<xs:attribute ref="z" use="optional"/>
|
||||||
|
<xs:attribute ref="t" use="optional"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="condition">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute ref="site" use="required"/>
|
||||||
|
<xs:attribute ref="weight" use="required"/>
|
||||||
|
<xs:attribute ref="node_id" use="required"/>
|
||||||
|
<xs:attribute ref="parent" use="required"/>
|
||||||
|
<xs:attribute ref="u" use="optional"/>
|
||||||
|
<xs:attribute ref="v" use="optional"/>
|
||||||
|
<xs:attribute ref="w" use="optional"/>
|
||||||
|
<xs:attribute ref="x" use="required"/>
|
||||||
|
<xs:attribute ref="y" use="optional"/>
|
||||||
|
<xs:attribute ref="z" use="optional"/>
|
||||||
|
<xs:attribute ref="t" use="optional"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="condition_anonym">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="condition_anonym"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:sequence minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="arrow"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute ref="site" use="required"/>
|
||||||
|
<xs:attribute ref="weight" use="required"/>
|
||||||
|
<xs:attribute ref="u" use="optional"/>
|
||||||
|
<xs:attribute ref="v" use="optional"/>
|
||||||
|
<xs:attribute ref="w" use="optional"/>
|
||||||
|
<xs:attribute ref="x" use="required"/>
|
||||||
|
<xs:attribute ref="y" use="optional"/>
|
||||||
|
<xs:attribute ref="z" use="optional"/>
|
||||||
|
<xs:attribute ref="t" use="optional"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="state">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="arrow"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="object" substitutionGroup="state"/>
|
||||||
|
|
||||||
|
<xs:element name="transition">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
||||||
|
<xs:element minOccurs="0" ref="quote"/>
|
||||||
|
<xs:element ref="arrow"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
|
<xs:attribute ref="parent" use="required"/>
|
||||||
|
<xs:attribute ref="probability" use="required"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="transition_anonym">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
|
<xs:attribute ref="probability" use="required"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="gem-graph-model">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
|
<xs:element name="identity">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
|
<xs:element name="name" type="xs:string"/>
|
||||||
|
<xs:element name="owner" type="xs:string"/>
|
||||||
|
<xs:element name="owner_id" type="xs:integer"/>
|
||||||
|
<xs:element name="date" type="xs:integer"/>
|
||||||
|
<xs:element name="version" type="xs:float"/>
|
||||||
|
<xs:element ref="g_ref" minOccurs="1" maxOccurs="1"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="parameters">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
|
|
||||||
|
<xs:element name="simulation">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
|
<xs:element name="max_thread" type="xs:integer"/>
|
||||||
|
<xs:element name="max_cycles" type="xs:integer"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="space-param">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="1" maxOccurs="1">
|
||||||
|
<xs:element ref="dimension"/>
|
||||||
|
<xs:element name="site_multiplicity" type="xs:integer"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="objects">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="object"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="savedstates">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="state"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="conditionslist">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:element minOccurs="0" ref="quote"/>
|
||||||
|
<xs:element ref="condition"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attributeGroup ref="id_date_author"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="transitionslist">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="transition"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="conditionstree">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:sequence minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="condition_anonym"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:sequence minOccurs="0" maxOccurs="1">
|
||||||
|
<xs:element ref="transition_anonym"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:sequence minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="arrow"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute ref="version" use="required"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
/etc/gem-graph-server/server.conf
|
|
|
@ -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
|
|
|
@ -1,13 +0,0 @@
|
||||||
This is a packacked upstream version of gem-graph-server
|
|
||||||
|
|
||||||
The sources may be found at <https://gitlab.os-k.eu/gem-graph-team/gem-graph-server>.
|
|
||||||
|
|
||||||
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 <https://www.gnu.org/licenses/#AGPL>.
|
|
|
@ -1,2 +0,0 @@
|
||||||
# CECI EST UN FICHIER DE CONFIGURATION
|
|
||||||
server_enabled=true
|
|
|
@ -1,111 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<gem-graph-model version="0.2">
|
|
||||||
|
|
||||||
<!-- Model identity informations -->
|
|
||||||
<identity>
|
|
||||||
<name>Modèle de test</name>
|
|
||||||
|
|
||||||
<owner>Gaston Lagaffe</owner>
|
|
||||||
|
|
||||||
<owner_id>2</owner_id>
|
|
||||||
|
|
||||||
<date>1629830000</date>
|
|
||||||
|
|
||||||
<version>1.0</version>
|
|
||||||
|
|
||||||
<g_ref id="texte" date="1629830000" author="Jean" lang="en">Ref</g_ref>
|
|
||||||
</identity>
|
|
||||||
|
|
||||||
<!-- Model parameters -->
|
|
||||||
<parameters id="texte" date="0" author="Gaston Lagaffe">
|
|
||||||
<simulation>
|
|
||||||
<max_thread>0</max_thread>
|
|
||||||
<max_cycles>9</max_cycles>
|
|
||||||
|
|
||||||
</simulation>
|
|
||||||
|
|
||||||
<space-param>
|
|
||||||
<dimension>1</dimension>
|
|
||||||
<size x="29" y="0" z="0"/>
|
|
||||||
<site_multiplicity>3</site_multiplicity>
|
|
||||||
|
|
||||||
</space-param>
|
|
||||||
|
|
||||||
</parameters>
|
|
||||||
|
|
||||||
<!-- Model objects definition -->
|
|
||||||
<objects id="texte" date="1629830000" author="Jean Sirmai">
|
|
||||||
<object id="dimer 1-1" date="1629830000" author="Jean Sirmai">
|
|
||||||
<arrow x="0" y="0" z="0" site="1" weight="1"/>
|
|
||||||
<arrow x="1" y="0" z="0" site="2" weight="1"/>
|
|
||||||
|
|
||||||
</object>
|
|
||||||
|
|
||||||
<object id="dimer 2-2" date="1629830000" author="Jean Sirmai">
|
|
||||||
<arrow x="0" y="0" z="0" site="1" weight="2"/>
|
|
||||||
<arrow x="1" y="0" z="0" site="2" weight="2"/>
|
|
||||||
|
|
||||||
</object>
|
|
||||||
|
|
||||||
<object id="dimer 3-3" date="1629830000" author="Jean Sirmai">
|
|
||||||
<arrow x="0" y="0" z="0" site="1" weight="3"/>
|
|
||||||
<arrow x="1" y="0" z="0" site="2" weight="3"/>
|
|
||||||
|
|
||||||
</object>
|
|
||||||
|
|
||||||
</objects>
|
|
||||||
|
|
||||||
<!-- Saved space description (initial space is sequence 0) -->
|
|
||||||
<savestates id="texte" date="1629830000" author="THE MATRIX">
|
|
||||||
<space id="initial" date="1629830000" author="Jean Sirmai" sequence="0">
|
|
||||||
<arrow x="0" y="0" z="0" site="1" weight="1"/>
|
|
||||||
<arrow x="1" y="0" z="0" site="2" weight="1"/>
|
|
||||||
|
|
||||||
<arrow x="10" y="0" z="0" site="1" weight="1"/>
|
|
||||||
<arrow x="11" y="0" z="0" site="2" weight="1"/>
|
|
||||||
|
|
||||||
<arrow x="20" y="0" z="0" site="1" weight="1"/>
|
|
||||||
<arrow x="21" y="0" z="0" site="2" weight="1"/>
|
|
||||||
|
|
||||||
</space>
|
|
||||||
|
|
||||||
</savestates>
|
|
||||||
|
|
||||||
<!-- Model transitions definition (rules) -->
|
|
||||||
<!-- In this version : <xs:sequence minOccurs="0" maxOccurs="unbounded">-->
|
|
||||||
<!-- As long as there is no client, transitions have to be edited by hand
|
|
||||||
and should be written using a 'human-readable' format -->
|
|
||||||
<conditions id="random walk of dimers" date="1629822222" author="Jean">
|
|
||||||
|
|
||||||
<condition x= "0" y="0" z="0" site="1" weight="1" node_id="1" parent="0"/>
|
|
||||||
<condition x= "1" y="0" z="0" site="2" weight="1" node_id="2" parent="1"/>
|
|
||||||
<condition x= "2" y="0" z="0" site="1" weight="0" node_id="3" parent="2"/>
|
|
||||||
<condition x="-1" y="0" z="0" site="2" weight="0" node_id="4" parent="2"/>
|
|
||||||
|
|
||||||
</conditions>
|
|
||||||
|
|
||||||
<transitions>
|
|
||||||
|
|
||||||
<transition id="move_a_dimer_to_east" date="1629811111" author="Jean"
|
|
||||||
parent="3" probability="1">
|
|
||||||
|
|
||||||
<arrow x="0" y="0" z="0" site="1" weight="0"/>
|
|
||||||
<arrow x="1" y="0" z="0" site="2" weight="0"/>
|
|
||||||
<arrow x="1" y="0" z="0" site="1" weight="1"/>
|
|
||||||
<arrow x="2" y="0" z="0" site="2" weight="1"/>
|
|
||||||
|
|
||||||
</transition>
|
|
||||||
|
|
||||||
<transition id="move_a_dimer_to_west" date="1629811112" author="Jean"
|
|
||||||
parent="4" probability="1">
|
|
||||||
|
|
||||||
<arrow x= "0" y="0" z="0" site="1" weight="0"/>
|
|
||||||
<arrow x= "1" y="0" z="0" site="2" weight="0"/>
|
|
||||||
<arrow x= "0" y="0" z="0" site="2" weight="1"/>
|
|
||||||
<arrow x="-1" y="0" z="0" site="1" weight="1"/>
|
|
||||||
|
|
||||||
</transition>
|
|
||||||
|
|
||||||
</transitions>
|
|
||||||
|
|
||||||
</gem-graph-model>
|
|
|
@ -27,33 +27,38 @@
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static inline int ArrowsInitLock(ArrowArray_t *arrowArray)
|
/*
|
||||||
{
|
* Structure describing an arrow
|
||||||
return pthread_spin_init(&arrowArray->lock, PTHREAD_PROCESS_SHARED);
|
*/
|
||||||
}
|
struct arrow_t {
|
||||||
|
uint load;
|
||||||
|
uint site;
|
||||||
|
uint x;
|
||||||
|
uint y;
|
||||||
|
uint z;
|
||||||
|
|
||||||
static inline int ArrowsDestroyLock(ArrowArray_t *arrowArray)
|
struct arrow_t *next;
|
||||||
{
|
struct arrow_t *prev;
|
||||||
return pthread_spin_destroy(&arrowArray->lock);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
static inline int ArrowsAcquireLock(ArrowArray_t *arrowArray)
|
struct condition_t {
|
||||||
{
|
uint id;
|
||||||
return pthread_spin_lock(&arrowArray->lock);
|
uint load;
|
||||||
}
|
uint site;
|
||||||
|
uint x;
|
||||||
|
uint y;
|
||||||
|
uint z;
|
||||||
|
|
||||||
static inline int ArrowsAcquireNonBlockingLock(ArrowArray_t *arrowArray)
|
struct condition_t *child;
|
||||||
{
|
struct condition_t *parent;
|
||||||
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,
|
struct arrow_t *arrow_new(struct arrow_t *self);
|
||||||
int weight);
|
|
||||||
|
|
||||||
bool ArrowRemove(Scheduler_t *scheduler, int x, int y, int z, int siteId,
|
struct arrow_t *arrow_destroy(struct arrow_t *self);
|
||||||
int weight);
|
|
||||||
|
struct condition_t *condition_new(struct condition_t *self);
|
||||||
|
|
||||||
|
struct condition_t *condition_destroy(struct condition_t *self);
|
||||||
|
|
187
include/base.h
187
include/base.h
|
@ -22,185 +22,44 @@
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <pthread.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <omp.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define BASE_H
|
#define BASE_H
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#define LOGMSG "[%s]"
|
#define LOGMSG "<%s:%s()>"
|
||||||
#define printLog(FORMAT, ...) printf("\e[0m" LOGMSG " " FORMAT "\e[0m", \
|
|
||||||
__func__, ##__VA_ARGS__)
|
#define printlog(FORMAT, ...) printf("\e[0;36m" LOGMSG "\e[0m" " " FORMAT \
|
||||||
#define printErr(FORMAT,...) fprintf(stderr, "\e[0m" LOGMSG " " FORMAT "\e[0m",\
|
"\e[0m", __FILE__,__func__, ##__VA_ARGS__)
|
||||||
__func__, ##__VA_ARGS__)
|
|
||||||
|
#define printerr(FORMAT,...) fprintf(stderr, "\e[0;31m" LOGMSG "\e[0m" " " \
|
||||||
|
FORMAT "\e[0m", __FILE__,__func__, \
|
||||||
|
##__VA_ARGS__)
|
||||||
|
|
||||||
#define LEN(x) (sizeof(x) / sizeof((x)[0]))
|
#define LEN(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
struct IntArray_t {
|
struct parameters_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 *configDir;
|
||||||
char *modelDir;
|
|
||||||
char *userDir;
|
char *userDir;
|
||||||
} typedef Parameters_t;
|
char *modelDir;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
//=-------------------------------------------------------------------------=//
|
|
||||||
// Local workers definition //
|
|
||||||
// //
|
|
||||||
// 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 <https://www.gnu.org/licenses/>. //
|
|
||||||
//=-------------------------------------------------------------------------=//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#ifndef BASE_H
|
|
||||||
#include "../include/base.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
// 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);
|
|
|
@ -32,19 +32,26 @@
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
struct Command_t {
|
// struct command_t {
|
||||||
const char *name;
|
// const char *name;
|
||||||
char* (*execute)(char*, char**, Server_t*);
|
// char* (*execute)(char*, char**, Server_t*);
|
||||||
const char *help;
|
// const char *help;
|
||||||
} typedef Command_t;
|
// } typedef command_t;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
//
|
//
|
||||||
// Existing commands
|
// Existing commands
|
||||||
//
|
//
|
||||||
char *CmdModel(char*, char**, Server_t*);
|
// char *Cmd_model(char*, char**, Server_t*);
|
||||||
char *CmdShutdown(char*, char**, Server_t*);
|
// char *cmd_shutdown(char*, char**, Server_t*);
|
||||||
char *CmdHelp(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"},
|
||||||
|
// };
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
121
include/model.h
121
include/model.h
|
@ -27,6 +27,12 @@
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <libxml/parser.h>
|
||||||
|
#include <libxml/xmlschemas.h>
|
||||||
|
|
||||||
|
#include "../include/arrows.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
@ -44,47 +50,144 @@
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
struct space_unit_t
|
||||||
|
{
|
||||||
|
uint id;
|
||||||
|
struct arrow_t *sites[]; // Array of struct arrow_t elements
|
||||||
|
// - lenght is multiplicity
|
||||||
|
};
|
||||||
|
|
||||||
|
struct space_t
|
||||||
|
{
|
||||||
|
// Dimensions of space.
|
||||||
|
int x_dim;
|
||||||
|
int y_dim;
|
||||||
|
int z_dim;
|
||||||
|
|
||||||
|
struct space_unit_t *units; // (flat) arraw of space_unit_t elements :
|
||||||
|
// - lenght is x_dim * y_dim * z_dim
|
||||||
|
// - access to the (x,y,z) is done by
|
||||||
|
// units[ x
|
||||||
|
// + dim_x * y
|
||||||
|
// + dim_x * dim_y * z ]
|
||||||
|
};
|
||||||
|
|
||||||
|
struct state_t
|
||||||
|
{
|
||||||
|
// Metadata
|
||||||
|
char id[25];
|
||||||
|
int owner_id;
|
||||||
|
time_t date;
|
||||||
|
|
||||||
|
struct space_t *space;
|
||||||
|
struct arrow_t *arrows;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct model_t
|
||||||
|
{
|
||||||
|
// Metadata
|
||||||
|
char id;
|
||||||
|
int owner_id;
|
||||||
|
time_t date;
|
||||||
|
union version
|
||||||
|
{
|
||||||
|
int major;
|
||||||
|
int minor;
|
||||||
|
};
|
||||||
|
|
||||||
|
// XML handlers
|
||||||
|
xmlDocPtr doc;
|
||||||
|
xmlHashTablePtr hashtable;
|
||||||
|
|
||||||
|
// User friendly metadata
|
||||||
|
char *owner_name;
|
||||||
|
char *model_name;
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
// Model parameters
|
||||||
|
int multiplicity; // number of sites in a space_unit
|
||||||
|
int dimension; // number of space dimensions
|
||||||
|
|
||||||
|
// Simulation parameters
|
||||||
|
int max_thread;
|
||||||
|
int max_cycles;
|
||||||
|
|
||||||
|
// Handler to the current space of the model
|
||||||
|
struct space_t *space;
|
||||||
|
|
||||||
|
// Handler to the conditions
|
||||||
|
struct condition_t *conditions;
|
||||||
|
|
||||||
|
// Handler to the arrows
|
||||||
|
struct arrow_t *arrows;
|
||||||
|
size_t n_arrows;
|
||||||
|
|
||||||
|
// Handler to the saved states array
|
||||||
|
struct state_t *states;
|
||||||
|
size_t n_states;
|
||||||
|
|
||||||
|
struct model_t *next;
|
||||||
|
struct model_t *prev;
|
||||||
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Model init function (and model discovery) //
|
// Model init function (and model discovery) //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void ModelSystemInit(Parameters_t *parameters);
|
void model_system_init (struct parameters_t *parameters);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Model stopping function //
|
// Model stopping function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void ModelSystemDestroy(void);
|
void model_system_shutdown (void);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Load a model ready to execute //
|
// Load a model ready to execute //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
int ModelLoad(int id);
|
bool model_load (struct model_t *self);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Unload a model //
|
// Unload a model //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
int ModelUnload(int id);
|
// int model_unload (int id);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Add a model to the known model list //
|
// 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 //
|
// Print informations about all models (known and loaded) to the client //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void printModels(char *buf);
|
// void print_models (char *buf);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Launch a model execution //
|
// Launch a model execution //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
int ModelRun(int id);
|
// int model_run (int id);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Stop a model execution //
|
// Stop a model execution //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
int ModelStop(int id);
|
// int model_stop (int id);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Stop and unload all loaded or running model //
|
// Stop and unload all loaded or running model //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void ModelShutdown(void);
|
// void model_shutdown (void);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Parsing primitives //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
char model_get_dim(struct model_t *self);
|
||||||
|
|
||||||
|
long model_get_dim_value(struct model_t *self, const char *axis);
|
||||||
|
|
||||||
|
char model_get_multiplicity(struct model_t *self);
|
||||||
|
|
||||||
|
bool model_get_next_state(struct model_t *self, char *new_state_id);
|
||||||
|
|
||||||
|
bool model_get_next_arrow(struct model_t *self,
|
||||||
|
struct arrow_t *new_arrow,
|
||||||
|
const char *state_id,
|
||||||
|
char dimension);
|
||||||
|
|
|
@ -1,73 +0,0 @@
|
||||||
//=-------------------------------------------------------------------------=//
|
|
||||||
// XML parsing module //
|
|
||||||
// //
|
|
||||||
// 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 <https://www.gnu.org/licenses/>. //
|
|
||||||
//=-------------------------------------------------------------------------=//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#ifndef BASE_H
|
|
||||||
#include "../include/base.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <libxml/parser.h>
|
|
||||||
#include <libxml/xmlschemas.h>
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
#define NO_DESTINATION NULL
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
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*);
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
|
@ -27,52 +27,72 @@
|
||||||
|
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
|
|
||||||
|
#include "../include/worker.h"
|
||||||
|
#include "../include/model.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
// quitting values
|
||||||
|
SCHED_NORMAL_EXIT,
|
||||||
|
SCHED_OMP_ERROR,
|
||||||
|
SCHED_UNKNOWN_ERROR,
|
||||||
|
|
||||||
|
// non-quitting / non-fatal errors
|
||||||
|
SCHED_NON_FATAL_ERRORS, //meta-code
|
||||||
|
SCHED_MODEL_ERROR,
|
||||||
|
|
||||||
|
SCHED_CONTINUE
|
||||||
|
};
|
||||||
|
|
||||||
|
struct scheduler_t
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
int n_workers;
|
||||||
|
int pleaseStop;
|
||||||
|
|
||||||
|
struct model_t **models;
|
||||||
|
struct worker_t **workers;
|
||||||
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Scheduler init function //
|
// Scheduler main function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void SchedInit(Scheduler_t *scheduler);
|
int sched_start (struct scheduler_t *scheduler, struct parameters_t *parameters);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Scheduler content destructor function //
|
// Scheduler content destructor function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void SchedContentDestroy(Scheduler_t *scheduler)
|
// static inline void sched_clean (scheduler_t *scheduler)
|
||||||
{
|
// {
|
||||||
if (scheduler) {
|
// assert(scheduler);
|
||||||
if (scheduler->globalDrawingSpace) {
|
|
||||||
if (scheduler->globalDrawingSpace->space) {
|
// if (scheduler->globalDrawingSpace) {
|
||||||
free(scheduler->globalDrawingSpace->space);
|
// if (scheduler->globalDrawingSpace->space) {
|
||||||
scheduler->globalDrawingSpace->space = NULL;
|
// free(scheduler->globalDrawingSpace->space);
|
||||||
}
|
// scheduler->globalDrawingSpace->space = NULL;
|
||||||
free(scheduler->globalDrawingSpace);
|
// }
|
||||||
scheduler->globalDrawingSpace = NULL;
|
// free(scheduler->globalDrawingSpace);
|
||||||
}
|
// scheduler->globalDrawingSpace = NULL;
|
||||||
if (scheduler->arrowArray) {
|
// }
|
||||||
if (scheduler->arrowArray->array) {
|
|
||||||
free(scheduler->arrowArray->array);
|
// if (scheduler->arrowArray) {
|
||||||
scheduler->arrowArray->array = NULL;
|
// if (scheduler->arrowArray->array) {
|
||||||
}
|
// free(scheduler->arrowArray->array);
|
||||||
free(scheduler->arrowArray);
|
// scheduler->arrowArray->array = NULL;
|
||||||
scheduler->arrowArray = NULL;
|
// }
|
||||||
}
|
// free(scheduler->arrowArray);
|
||||||
}
|
// scheduler->arrowArray = NULL;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Scheduler destructor function //
|
// Scheduler destructor function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void SchedDestroy(Scheduler_t *scheduler)
|
// static inline void sched_shutdown (scheduler_t *scheduler)
|
||||||
{
|
// {
|
||||||
if (scheduler) {
|
// assert(scheduler);
|
||||||
free(scheduler);
|
// free(scheduler);
|
||||||
}
|
// scheduler = NULL;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
// Scheduler wait function //
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
static inline void SchedWait(Scheduler_t *scheduler)
|
|
||||||
{
|
|
||||||
pthread_join(scheduler->id, NULL);
|
|
||||||
}
|
|
||||||
|
|
|
@ -37,12 +37,4 @@
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Server init function //
|
// Server init function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void ServerInit(Server_t *server);
|
//void server_init (server_t *server);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
// Server wait function //
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
static inline void ServerWait(Server_t *server)
|
|
||||||
{
|
|
||||||
pthread_join(server->id, NULL);
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,19 +30,12 @@
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Supervisor init function //
|
// Supervisor init function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void SupervisorInit(Supervisor_t *supervisor);
|
//void superv_init (supervisor_t *supervisor);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Supervisor destructor function //
|
// 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);
|
|
||||||
}
|
|
||||||
|
|
|
@ -54,14 +54,14 @@
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
volatile struct winsize TermWindowSize;
|
volatile struct winsize termWinSize;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Get a character code from the keyboard //
|
// Get a character code from the keyboard //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline int TermGetch(bool nonBlocking)
|
static inline int term_getch(bool nonBlocking)
|
||||||
{
|
{
|
||||||
int buf = 0;
|
int buf = 0;
|
||||||
// old terminal
|
// old terminal
|
||||||
|
@ -123,16 +123,16 @@ static inline int TermGetch(bool nonBlocking)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Get the screen size //
|
// Get the screen size //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void TermGetScreenSize(int signum)
|
static inline void term_get_screensize(int signum)
|
||||||
{
|
{
|
||||||
// Get current terminal size
|
// Get current terminal size
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &TermWindowSize);
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &termWinSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Set cursor location //
|
// 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);
|
printf("\x1b[%d;%dH", y, x);
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ static inline void TermSetCursorLocation(char x, char y)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Save cursor location //
|
// Save cursor location //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void TermSaveCursorLocation(void)
|
static inline void term_save_cursor_location(void)
|
||||||
{
|
{
|
||||||
printf(C_SAVE_CURSORPOS);
|
printf(C_SAVE_CURSORPOS);
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ static inline void TermSaveCursorLocation(void)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Restore cursor location //
|
// Restore cursor location //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void TermRestoreCursorLocation(void)
|
static inline void term_restore_cursor_location(void)
|
||||||
{
|
{
|
||||||
printf(C_RESTORE_CURSORPOS);
|
printf(C_RESTORE_CURSORPOS);
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ static inline void TermRestoreCursorLocation(void)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Move cursor location to the right //
|
// Move cursor location to the right //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void TermMoveCursorForward(void)
|
static inline void term_move_cursor_forward(void)
|
||||||
{
|
{
|
||||||
printf(C_CURSORRIGHT);
|
printf(C_CURSORRIGHT);
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ static inline void TermMoveCursorForward(void)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Move cursor location to the left //
|
// Move cursor location to the left //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void TermMoveCursorBackward(void)
|
static inline void term_move_cursor_backward(void)
|
||||||
{
|
{
|
||||||
printf(C_CURSORLEFT);
|
printf(C_CURSORLEFT);
|
||||||
}
|
}
|
||||||
|
@ -172,10 +172,10 @@ static inline void TermMoveCursorBackward(void)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Clear screen //
|
// Clear screen //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void TermClearScreen(void)
|
static inline void term_clear_screen(void)
|
||||||
{
|
{
|
||||||
printf(C_CLEARSCREEN);
|
printf(C_CLEARSCREEN);
|
||||||
TermSetCursorLocation(1,1);
|
term_set_cursor_location(1,1);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,31 +25,51 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "../include/scheduler.h"
|
||||||
|
#include "../include/arrows.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
// quitting values
|
||||||
|
WORKER_NORMAL_EXIT,
|
||||||
|
WORKER_OMP_ERROR,
|
||||||
|
WORKER_UNKNOWN_ERROR,
|
||||||
|
|
||||||
|
// non-quitting / non-fatal errors
|
||||||
|
WORKER_NON_FATAL_ERRORS, //meta-code
|
||||||
|
WORKER_MODEL_ERROR,
|
||||||
|
|
||||||
|
WORKER_CONTINUE
|
||||||
|
};
|
||||||
|
|
||||||
|
struct scheduler_t;
|
||||||
|
|
||||||
|
struct worker_t
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
int thread_num;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
struct arrow_t *elected_arrow;
|
||||||
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Worker init function //
|
// Worker init function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void WorkerInit(Worker_t *worker);
|
void worker_start(struct worker_t *self, struct scheduler_t *scheduler);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Worker destructor function //
|
// Worker destructor function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void WorkerDestroy(Worker_t *worker)
|
// static inline void worker_destroy(worker_t *worker)
|
||||||
{
|
// {
|
||||||
worker->pleaseStop = false;
|
// worker->pleaseStop = false;
|
||||||
worker->terminated = false;
|
// worker->terminated = false;
|
||||||
worker->returnValue = false;
|
// worker->returnValue = false;
|
||||||
|
|
||||||
worker->id = 0;
|
// worker->id = 0;
|
||||||
free(worker->localWorkAreaCenter);
|
// free(worker->localWorkAreaCenter);
|
||||||
worker->localWorkAreaCenter = NULL;
|
// worker->localWorkAreaCenter = NULL;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
// Worker wait function //
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
static inline void WorkerWait(Worker_t *worker)
|
|
||||||
{
|
|
||||||
pthread_join(worker->id, 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 <https://www.gnu.org/licenses/>. //
|
|
||||||
//=-------------------------------------------------------------------------=//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#ifndef BASE_H
|
|
||||||
#include "../include/base.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <libxml2/libxml/xmlmemory.h>
|
|
||||||
#include <libxml2/libxml/parser.h>
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
;;
|
||||||
|
;; 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"
|
||||||
|
"libomp"
|
||||||
|
)
|
||||||
|
)
|
64
src/arrows.c
64
src/arrows.c
|
@ -25,7 +25,67 @@
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
struct arrow_t *arrow_new(struct arrow_t *self)
|
||||||
|
{
|
||||||
|
if (self == NULL) {
|
||||||
|
return calloc (1, sizeof(struct arrow_t));
|
||||||
|
}
|
||||||
|
|
||||||
static inline int location(Space_t *space, int x, int y, int z) {
|
self->next = calloc (1, sizeof(struct arrow_t));
|
||||||
return x + y * (space->xMax+1) + z * (space->xMax+1) * (space->zMax+1);
|
self->next->prev = self;
|
||||||
|
|
||||||
|
return self->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct arrow_t *arrow_destroy(struct arrow_t *self)
|
||||||
|
{
|
||||||
|
struct arrow_t *res = NULL;
|
||||||
|
|
||||||
|
if (self->next)
|
||||||
|
if (self->prev) {
|
||||||
|
self->prev->next = self->next;
|
||||||
|
} else {
|
||||||
|
res = self->next;
|
||||||
|
self->next->prev = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->prev)
|
||||||
|
if (self->next) {
|
||||||
|
self->next->prev = self->prev;
|
||||||
|
} else {
|
||||||
|
res = self->prev;
|
||||||
|
self->prev->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(self);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct condition_t *condition_new(struct condition_t *self)
|
||||||
|
{
|
||||||
|
if (self == NULL) {
|
||||||
|
return calloc (1, sizeof(struct condition_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
self->child = calloc (1, sizeof(struct condition_t));
|
||||||
|
self->child->parent = self;
|
||||||
|
|
||||||
|
return self->child;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct condition_t *condition_destroy(struct condition_t *self)
|
||||||
|
{
|
||||||
|
struct condition_t *res = NULL;
|
||||||
|
|
||||||
|
if (self->child) {
|
||||||
|
condition_destroy(self->child);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->parent)
|
||||||
|
self->parent->child = NULL;
|
||||||
|
|
||||||
|
free(self);
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
//=-------------------------------------------------------------------------=//
|
|
||||||
// Centers management module //
|
|
||||||
// //
|
|
||||||
// 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 <https://www.gnu.org/licenses/>. //
|
|
||||||
//=-------------------------------------------------------------------------=//
|
|
||||||
|
|
||||||
#include "../include/centers.h"
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
309
src/cmds.c
309
src/cmds.c
|
@ -20,6 +20,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
|
#include "../include/base.h"
|
||||||
#include "../include/cmds.h"
|
#include "../include/cmds.h"
|
||||||
#include "../include/scheduler.h"
|
#include "../include/scheduler.h"
|
||||||
#include "../include/model.h"
|
#include "../include/model.h"
|
||||||
|
@ -28,195 +29,195 @@
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *CmdModel(char *buf, char **argv, Server_t *args)
|
/* char *cmd_model(char *buf, char **argv, server_t *args) */
|
||||||
{
|
/* { */
|
||||||
int id, eid;
|
/* int id, eid; */
|
||||||
Model_t *newModel;
|
/* model_t *newModel; */
|
||||||
|
|
||||||
// invalid use
|
/* // invalid use */
|
||||||
if (!argv[1]) {
|
/* if (!argv[1]) { */
|
||||||
strcat(buf, "{create | delete | load | unload | run | stop | list |"
|
/* strcat(buf, "{create | delete | load | unload | run | stop | list |" */
|
||||||
"info}\n");
|
/* "info}\n"); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if (strcmp(argv[1], "create") == 0) {
|
/* if (strcmp(argv[1], "create") == 0) { */
|
||||||
|
|
||||||
if (!argv[2] || !argv[3]) {
|
/* if (!argv[2] || !argv[3]) { */
|
||||||
goto createEnd;
|
/* goto createEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
if (strncmp(argv[2], "name=", 5) == 0) {
|
/* if (strncmp(argv[2], "name=", 5) == 0) { */
|
||||||
|
|
||||||
if (strncmp(argv[3], "file=", 5) == 0) {
|
/* if (strncmp(argv[3], "file=", 5) == 0) { */
|
||||||
// TODO get the file content (sent by the client) from args
|
/* // TODO get the file content (sent by the client) from args */
|
||||||
|
|
||||||
// Creating model
|
/* // Creating model */
|
||||||
ModelAddToKnown(&newModel);
|
/* //XXX ModelAddToKnown(&newModel); */
|
||||||
|
|
||||||
// TODO modify model according to things in file
|
/* // TODO modify model according to things in file */
|
||||||
|
|
||||||
// Write name
|
/* // Write name */
|
||||||
strcpy(newModel->name, argv[2] + 5);
|
/* strcpy(newModel->name, argv[2] + 5); */
|
||||||
|
|
||||||
// Write filename
|
/* // Write filename */
|
||||||
strcpy(newModel->filename, argv[3] + 5);
|
/* 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 cmd_ModelEnd; */
|
||||||
|
|
||||||
} else {
|
/* } else { */
|
||||||
goto createEnd;
|
/* goto createEnd; */
|
||||||
}
|
/* } */
|
||||||
} else {
|
/* } else { */
|
||||||
goto createEnd;
|
/* goto createEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
createEnd:
|
/* createEnd: */
|
||||||
// invalid use
|
/* // invalid use */
|
||||||
strcat(buf, "Creates a model structure\n");
|
/* strcat(buf, "Creates a model structure\n"); */
|
||||||
strcat(buf, "Usage: model create name=NAME file=FILENAME\n");
|
/* strcat(buf, "Usage: model create name=NAME file=FILENAME\n"); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
else if (strcmp(argv[1], "load") == 0) {
|
/* else if (strcmp(argv[1], "load") == 0) { */
|
||||||
if (!argv[2]) {
|
/* if (!argv[2]) { */
|
||||||
goto loadEnd;
|
/* 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) {
|
/* if (id == 0 || (eid = ModelLoad(id)) <= 0) { */
|
||||||
sprintf(buf + strlen(buf), "Failed to load model id %d\n", id);
|
/* sprintf(buf + strlen(buf), "Failed to load model id %d\n", id); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
sprintf(buf + strlen(buf), "Model id %d loaded with effective "
|
/* sprintf(buf + strlen(buf), "Model id %d loaded with effective " */
|
||||||
"id %d\n", id, eid);
|
/* "id %d\n", id, eid); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
loadEnd:
|
/* loadEnd: */
|
||||||
// invalid use
|
/* // invalid use */
|
||||||
strcat(buf, "Loads a model structure\n");
|
/* strcat(buf, "Loads a model structure\n"); */
|
||||||
strcat(buf, "Usage: model load id=ID\n");
|
/* strcat(buf, "Usage: model load id=ID\n"); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
else if (strcmp(argv[1], "unload") == 0) {
|
/* else if (strcmp(argv[1], "unload") == 0) { */
|
||||||
if (!argv[2]) {
|
/* if (!argv[2]) { */
|
||||||
goto unloadEnd;
|
/* goto unloadEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
id = (int) strtol(argv[2] + 3, NULL, 10);
|
/* id = (int) strtol(argv[2] + 3, NULL, 10); */
|
||||||
|
|
||||||
if (id == 0 || ModelUnload(id) < 0) {
|
/* if (id == 0 || ModelUnload(id) < 0) { */
|
||||||
printErr("Failed to unload model id %d\n", id);
|
/* printErr("Failed to unload model id %d\n", id); */
|
||||||
sprintf(buf + strlen(buf), "Failed to unload model id %d\n", id);
|
/* sprintf(buf + strlen(buf), "Failed to unload model id %d\n", id); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
sprintf(buf + strlen(buf), "Model id %d unloaded\n", id);
|
/* sprintf(buf + strlen(buf), "Model id %d unloaded\n", id); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
unloadEnd:
|
/* unloadEnd: */
|
||||||
// invalid use
|
/* // invalid use */
|
||||||
strcat(buf, "Unloads a model structure\n");
|
/* strcat(buf, "Unloads a model structure\n"); */
|
||||||
strcat(buf, "Usage: model unload id=ID\n");
|
/* strcat(buf, "Usage: model unload id=ID\n"); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
else if (strcmp(argv[1], "delete") == 0) {
|
/* else if (strcmp(argv[1], "delete") == 0) { */
|
||||||
if (!argv[2]) {
|
/* if (!argv[2]) { */
|
||||||
goto deleteEnd;
|
/* goto deleteEnd; */
|
||||||
}
|
/* } */
|
||||||
// TODO delete model
|
/* // TODO delete model */
|
||||||
deleteEnd:
|
/* deleteEnd: */
|
||||||
// invalid use
|
/* // invalid use */
|
||||||
strcat(buf, "Deletes a model structure\n");
|
/* strcat(buf, "Deletes a model structure\n"); */
|
||||||
strcat(buf, "Usage: model delete id=ID\n");
|
/* strcat(buf, "Usage: model delete id=ID\n"); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
else if (strcmp(argv[1], "run") == 0) {
|
/* else if (strcmp(argv[1], "run") == 0) { */
|
||||||
if (!argv[2]) {
|
/* if (!argv[2]) { */
|
||||||
goto runEnd;
|
/* goto runEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
id = (int) strtol(argv[2] + 3, NULL, 10);
|
/* id = (int) strtol(argv[2] + 3, NULL, 10); */
|
||||||
|
|
||||||
if (id == 0 || (!ModelRun(id))) {
|
/* if (id == 0 || (!ModelRun(id))) { */
|
||||||
sprintf(buf + strlen(buf), "Failed to run model id %d\n", id);
|
/* sprintf(buf + strlen(buf), "Failed to run model id %d\n", id); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
sprintf(buf + strlen(buf), "Model id %d is running\n", id);
|
/* sprintf(buf + strlen(buf), "Model id %d is running\n", id); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
runEnd:
|
/* runEnd: */
|
||||||
// invalid use
|
/* // invalid use */
|
||||||
strcat(buf, "Run a model simulation\n");
|
/* strcat(buf, "Run a model simulation\n"); */
|
||||||
strcat(buf, "Usage: model run id=ID\n");
|
/* strcat(buf, "Usage: model run id=ID\n"); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
else if (strcmp(argv[1], "stop") == 0) {
|
/* else if (strcmp(argv[1], "stop") == 0) { */
|
||||||
if (!argv[2]) {
|
/* if (!argv[2]) { */
|
||||||
goto stopEnd;
|
/* goto stopEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
id = (int) strtol(argv[2] + 3, NULL, 10);
|
/* id = (int) strtol(argv[2] + 3, NULL, 10); */
|
||||||
|
|
||||||
if (id == 0 || (!ModelStop(id))) {
|
/* if (id == 0 || (!ModelStop(id))) { */
|
||||||
sprintf(buf + strlen(buf), "Failed to stop model id %d\n", id);
|
/* sprintf(buf + strlen(buf), "Failed to stop model id %d\n", id); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
sprintf(buf + strlen(buf), "Model id %d is running\n", id);
|
/* sprintf(buf + strlen(buf), "Model id %d is running\n", id); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
stopEnd:
|
/* stopEnd: */
|
||||||
// invalid use
|
/* // invalid use */
|
||||||
strcat(buf, "Stop a model simulation\n");
|
/* strcat(buf, "Stop a model simulation\n"); */
|
||||||
strcat(buf, "Usage: model stop id=ID\n");
|
/* strcat(buf, "Usage: model stop id=ID\n"); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
else if (strcmp(argv[1], "list") == 0) {
|
/* else if (strcmp(argv[1], "list") == 0) { */
|
||||||
strcat(buf, "You asked for us to list models\n");
|
/* strcat(buf, "You asked for us to list models\n"); */
|
||||||
printModels(buf);
|
/* printModels(buf); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
else if (strcmp(argv[1], "info") == 0) {
|
/* else if (strcmp(argv[1], "info") == 0) { */
|
||||||
if (!argv[2]) {
|
/* if (!argv[2]) { */
|
||||||
goto infoEnd;
|
/* goto infoEnd; */
|
||||||
}
|
/* } */
|
||||||
// TODO info model
|
/* // TODO info model */
|
||||||
infoEnd:
|
/* infoEnd: */
|
||||||
// invalid use
|
/* // invalid use */
|
||||||
strcat(buf, "Print info about a model\n");
|
/* strcat(buf, "Print info about a model\n"); */
|
||||||
strcat(buf, "Usage: model info id=ID\n");
|
/* strcat(buf, "Usage: model info id=ID\n"); */
|
||||||
goto CmdModelEnd;
|
/* goto cmd_ModelEnd; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
// invalid use
|
/* // invalid use */
|
||||||
else strcat(buf, "{create | delete | load | unload | run | stop | list |"
|
/* else strcat(buf, "{create | delete | load | unload | run | stop | list |" */
|
||||||
"info}\n");
|
/* "info}\n"); */
|
||||||
|
|
||||||
CmdModelEnd:
|
/* cmd_ModelEnd: */
|
||||||
return buf;
|
/* return buf; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
char *CmdShutdown(char *buf, char **argv, Server_t *args)
|
/* char *cmd_shutdown(char *buf, char **argv, server_t *args) */
|
||||||
{
|
/* { */
|
||||||
args->pleaseStop = true;
|
/* args->pleaseStop = true; */
|
||||||
strcat(buf, "Server stopping\n");
|
/* strcat(buf, "Server stopping\n"); */
|
||||||
|
|
||||||
ModelShutdown();
|
/* //XXX ModelShutdown(); */
|
||||||
strcat(buf, "All model shutted down\n");
|
/* strcat(buf, "All model shutted down\n"); */
|
||||||
|
|
||||||
return buf;
|
/* return buf; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
char *CmdHelp(char *buf, char **argv, Server_t *args)
|
/* char *cmd_help(char *buf, char **argv, server_t *args) */
|
||||||
{
|
/* { */
|
||||||
strcat(buf, "List of known commands:\n");
|
/* strcat(buf, "List of known commands:\n"); */
|
||||||
|
|
||||||
return buf;
|
/* return buf; */
|
||||||
}
|
/* } */
|
||||||
|
|
74
src/main.c
74
src/main.c
|
@ -21,48 +21,48 @@
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#include "../include/server.h"
|
#include "../include/scheduler.h"
|
||||||
#include "../include/model.h"
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static Server_t *server;
|
/* static server_t *server; */
|
||||||
|
|
||||||
static void sigtermHandler(int signum)
|
/* static void sig_term_handler(int signum) */
|
||||||
{
|
/* { */
|
||||||
server->pleaseStop = true;
|
/* server->pleaseStop = true; */
|
||||||
printLog("Server stopping\n");
|
/* printlog("Server stopping\n"); */
|
||||||
|
|
||||||
ModelShutdown();
|
/* //XXX ModelShutdown(); */
|
||||||
printLog("All model shutted down\n");
|
/* printlog("All model shutted down\n"); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int options;
|
int options;
|
||||||
time_t t;
|
time_t t;
|
||||||
int returnValue = 0;
|
int returnValue = SCHED_CONTINUE;
|
||||||
Parameters_t parameters;
|
struct parameters_t parameters = {0};
|
||||||
|
struct scheduler_t scheduler = {0};
|
||||||
|
|
||||||
while ((options = getopt(argc, argv, ":C:M:U:")) != -1) {
|
while ((options = getopt(argc, argv, ":C:M:U:")) != -1) {
|
||||||
switch (options) {
|
switch (options) {
|
||||||
case 'C':
|
case 'C':
|
||||||
printLog("Config : %s\n", optarg);
|
printlog("Config : %s\n", optarg);
|
||||||
parameters.configDir = calloc(1, strlen(optarg) + 1);
|
parameters.configDir = calloc(1, strlen(optarg) + 1);
|
||||||
strcpy(parameters.configDir, optarg);
|
strcpy(parameters.configDir, optarg);
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
printLog("Models : %s\n", optarg);
|
printlog("Models : %s\n", optarg);
|
||||||
parameters.modelDir = calloc(1, strlen(optarg) + 1);
|
parameters.modelDir = calloc(1, strlen(optarg) + 1);
|
||||||
strcpy(parameters.modelDir, optarg);
|
strcpy(parameters.modelDir, optarg);
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
printLog("Users : %s\n", optarg);
|
printlog("Users : %s\n", optarg);
|
||||||
parameters.userDir = calloc(1, strlen(optarg) + 1);
|
parameters.userDir = calloc(1, strlen(optarg) + 1);
|
||||||
strcpy(parameters.userDir, optarg);
|
strcpy(parameters.userDir, optarg);
|
||||||
break;
|
break;
|
||||||
case ':':
|
case ':':
|
||||||
printErr("Option missing argument : %c\n", optopt);
|
printerr("Option missing argument : %c\n", optopt);
|
||||||
if (parameters.configDir)
|
if (parameters.configDir)
|
||||||
free(parameters.configDir);
|
free(parameters.configDir);
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ int main(int argc, char **argv)
|
||||||
return ENOSYS;
|
return ENOSYS;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
printErr("Unknown option : %c\n", optopt);
|
printerr("Unknown option : %c\n", optopt);
|
||||||
if (parameters.configDir)
|
if (parameters.configDir)
|
||||||
free(parameters.configDir);
|
free(parameters.configDir);
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parameters.configDir | !parameters.modelDir | !parameters.userDir) {
|
if (!parameters.configDir | !parameters.modelDir | !parameters.userDir) {
|
||||||
printErr("Missing arguments\n");
|
printerr("Missing arguments\n");
|
||||||
|
|
||||||
if (parameters.configDir)
|
if (parameters.configDir)
|
||||||
free(parameters.configDir);
|
free(parameters.configDir);
|
||||||
|
@ -106,32 +106,38 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go!
|
// Go!
|
||||||
printLog("Starting gem-graph-server...\n");
|
printlog("Starting gem-graph-server...\n");
|
||||||
|
|
||||||
// Register new interrupt handler
|
/* // Register new interrupt handler */
|
||||||
signal(SIGINT, sigtermHandler);
|
/* signal(SIGINT, sig_term_handler); */
|
||||||
signal(SIGTERM, sigtermHandler);
|
/* signal(SIGTERM, sig_term_handler); */
|
||||||
|
|
||||||
// Initializing random generator
|
// Initializing random generator
|
||||||
t = time(&t);
|
t = time(&t);
|
||||||
srand((unsigned) t);
|
srand ((unsigned)t);
|
||||||
|
|
||||||
server = calloc(1, sizeof(*server));
|
/* server = calloc(1, sizeof(*server)); */
|
||||||
|
|
||||||
// Initializing model system
|
// Initializing model system
|
||||||
ModelSystemInit(¶meters);
|
model_system_init (¶meters);
|
||||||
|
|
||||||
// Launching server
|
/* // Launching server */
|
||||||
ServerInit(server);
|
/* server_init(server); */
|
||||||
|
|
||||||
// Waiting for termination
|
/* // Waiting for termination */
|
||||||
ServerWait(server);
|
/* server_wait(server); */
|
||||||
|
|
||||||
// Exiting
|
/* // Exiting */
|
||||||
returnValue |= server->returnValue;
|
/* returnValue |= server->returnValue; */
|
||||||
ModelSystemDestroy();
|
/* ModelSystemDestroy(); */
|
||||||
free(server);
|
/* free(server); */
|
||||||
server = NULL;
|
/* server = NULL; */
|
||||||
|
|
||||||
|
while (returnValue > SCHED_NON_FATAL_ERRORS) {
|
||||||
|
returnValue = sched_start (&scheduler, ¶meters);
|
||||||
|
}
|
||||||
|
|
||||||
|
model_system_shutdown();
|
||||||
|
|
||||||
free(parameters.userDir);
|
free(parameters.userDir);
|
||||||
free(parameters.modelDir);
|
free(parameters.modelDir);
|
||||||
|
|
830
src/model.c
830
src/model.c
|
@ -2,7 +2,7 @@
|
||||||
// Model management module //
|
// Model management module //
|
||||||
// //
|
// //
|
||||||
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
|
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
|
||||||
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
|
// Copyright © 2021-2024 Adrien Bourmault (neox@a-lec.org) //
|
||||||
// //
|
// //
|
||||||
// This file is part of gem-graph. //
|
// This file is part of gem-graph. //
|
||||||
// //
|
// //
|
||||||
|
@ -20,291 +20,601 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
|
#include "../include/base.h"
|
||||||
#include "../include/model.h"
|
#include "../include/model.h"
|
||||||
#include "../include/parsing.h"
|
|
||||||
#include "../include/arrows.h"
|
#include "../include/arrows.h"
|
||||||
#include "../include/scheduler.h"
|
|
||||||
|
|
||||||
static Model_t **loadedModel;
|
#define ALLOWED_RADIUS 10
|
||||||
static int loadedModelSize; // begins to 1
|
#define READ_SITE 1 << 0
|
||||||
|
#define READ_WEIGHT 1 << 1
|
||||||
static Model_t **knownModel;
|
#define READ_X 1 << 2
|
||||||
static int knownModelSize; // begins to 1
|
#define READ_Y 1 << 3
|
||||||
|
#define READ_Z 1 << 4
|
||||||
Model_t *lastModel;
|
#define SUCCESSFUL_READ_ARROW_X (READ_SITE | READ_WEIGHT | READ_X)
|
||||||
Model_t **lastModelAddr;
|
#define SUCCESSFUL_READ_ARROW_XY (READ_SITE | READ_WEIGHT | READ_X | READ_Y)
|
||||||
|
#define SUCCESSFUL_READ_ARROW_XYZ (READ_SITE | READ_WEIGHT | READ_X | READ_Y | READ_Z)
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void printModels(char *buf)
|
struct model_t *knownModels = NULL;
|
||||||
{
|
|
||||||
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)
|
/**
|
||||||
|
* Recursively populates a hash table with XML nodes, using the node paths as keys.
|
||||||
|
*
|
||||||
|
* @param self The self structure containing hash table containing
|
||||||
|
* nodes indexed by their paths to populate
|
||||||
|
* @param node The current node being processed.
|
||||||
|
* @param currentPath The path to the current node.
|
||||||
|
*/
|
||||||
|
void model_populate_hashtable (struct model_t *self, xmlNode *node, char *currentPath)
|
||||||
{
|
{
|
||||||
// increment index
|
if (node == NULL) return;
|
||||||
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
|
assert(self->hashtable == NULL);
|
||||||
knownModel[knownModelSize-1]->name =
|
|
||||||
calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
|
||||||
|
|
||||||
knownModel[knownModelSize-1]->filename =
|
// Skip text nodes and others that are not element nodes
|
||||||
calloc(1, sizeof(char) * MODEL_STRING_SIZE);
|
if (node->type != XML_ELEMENT_NODE) {
|
||||||
|
model_populate_hashtable (node->next, self->hashtable, currentPath);
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((modelDirEntry = readdir(modelDir)) != NULL) {
|
// Calculate new path
|
||||||
if ((extensionPosition = strstr(modelDirEntry->d_name, ".xml"))) {
|
char newPath[1024]; // large enough
|
||||||
|
if (currentPath && strlen(currentPath) > 0) {
|
||||||
|
snprintf (newPath, sizeof(newPath), "%s/%s", currentPath, node->name);
|
||||||
|
} else {
|
||||||
|
snprintf (newPath, sizeof(newPath), "%s", node->name); // Root element
|
||||||
|
}
|
||||||
|
|
||||||
// Creating model
|
// Add current node to hash table with its path as the key
|
||||||
ModelAddToKnown(&newModel);
|
xmlHashAddEntry (self->hashtable, (const xmlChar *)newPath, node);
|
||||||
|
|
||||||
// Write file path in filename
|
// Recurse into child nodes with the updated path
|
||||||
strncpy(newModel->filename, parameters->modelDir,
|
model_populate_hashtable (self, node->children, newPath);
|
||||||
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
|
// Continue with the next sibling
|
||||||
strncpy(newModel->name, modelDirEntry->d_name,
|
model_populate_hashtable (self, node->next, currentPath);
|
||||||
extensionPosition - modelDirEntry->d_name);
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Finds a node by a path of tags.
|
||||||
|
*
|
||||||
|
* @param self The self structure containing hash table containing
|
||||||
|
* nodes indexed by their paths.
|
||||||
|
* @param path The path to the tag, with '/' as the delimiter.
|
||||||
|
* @return The content of the tag at the end of the path, or NULL if not found.
|
||||||
|
*/
|
||||||
|
xmlNodePtr model_get_node (struct model_t *self, const char *path)
|
||||||
|
{
|
||||||
|
assert(self->hashtable != NULL);
|
||||||
|
|
||||||
|
return (xmlNodePtr)xmlHashLookup (self->hashtable, (const xmlChar *)path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modifies the content of an XML node identified by its path in the hash table.
|
||||||
|
*
|
||||||
|
* @param self The self structure containing hash table containing
|
||||||
|
* nodes indexed by their paths.
|
||||||
|
* @param path The path to the node to modify.
|
||||||
|
* @param newContent The new content to set for the node.
|
||||||
|
* @return 1 if the node was found and modified, 0 otherwise.
|
||||||
|
*/
|
||||||
|
int model_modify_node (struct model_t *self,
|
||||||
|
const char *path,
|
||||||
|
const char *newContent)
|
||||||
|
{
|
||||||
|
assert(self->hashtable != NULL);
|
||||||
|
|
||||||
|
xmlNodePtr node = model_get_node (self, path);
|
||||||
|
if (node) {
|
||||||
|
// Free the current content of the node, if any
|
||||||
|
xmlNodeSetContent (node, (const xmlChar *)""); // Clear existing content
|
||||||
|
// Set new content
|
||||||
|
xmlNodeSetContent (node, (const xmlChar *)newContent);
|
||||||
|
return 1; // Success
|
||||||
|
}
|
||||||
|
return 0; // Node not found or unable to modify
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the value of an attribute for a node identified by its path.
|
||||||
|
*
|
||||||
|
* @param self The self structure containing hash table containing
|
||||||
|
* nodes indexed by their paths.
|
||||||
|
* @param nodePath The path to the node.
|
||||||
|
* @param attributeName The name of the attribute.
|
||||||
|
* @return The value of the attribute, or NULL if not found.
|
||||||
|
*/
|
||||||
|
char *model_get_attribute (struct model_t *self,
|
||||||
|
const char* nodePath,
|
||||||
|
const char* attributeName)
|
||||||
|
{
|
||||||
|
assert(self->hashtable != NULL);
|
||||||
|
|
||||||
|
xmlNodePtr node = (xmlNodePtr)xmlHashLookup (self->hashtable, (const xmlChar*)nodePath);
|
||||||
|
if (node) {
|
||||||
|
return getAttributeValue (node, attributeName);
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets or updates the value of an attribute for a node identified by its path.
|
||||||
|
*
|
||||||
|
* @param self The self structure containing hash table containing
|
||||||
|
* nodes indexed by their paths.
|
||||||
|
* @param nodePath The path to the node.
|
||||||
|
* @param attributeName The name of the attribute to set.
|
||||||
|
* @param attributeValue The value to set for the attribute.
|
||||||
|
* @return 1 on success, 0 on failure.
|
||||||
|
*/
|
||||||
|
int model_set_attribute (struct model_t *self,
|
||||||
|
const char* nodePath,
|
||||||
|
const char* attributeName,
|
||||||
|
const char* attributeValue)
|
||||||
|
{
|
||||||
|
assert(self->hashtable != NULL);
|
||||||
|
|
||||||
|
xmlNodePtr node = (xmlNodePtr)xmlHashLookup (self->hashtable, (const xmlChar*)nodePath);
|
||||||
|
if (node) {
|
||||||
|
return setAttributeValue (node, attributeName, attributeValue);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a node recursively to a new sibling node with a modified attribute and updates the self->hashtable.
|
||||||
|
*
|
||||||
|
* @param node The node to copy.
|
||||||
|
* @param self The self structure for tracking nodes by path.
|
||||||
|
* @param originalNodePath The path of the original node in the self->hashtable.
|
||||||
|
* @param attributeName The name of the attribute to modify in the copied node.
|
||||||
|
* @param newAttributeValue The new value for the specified attribute in the copied node.
|
||||||
|
* @return The copied node with the modified attribute, or NULL on failure.
|
||||||
|
*/
|
||||||
|
xmlNodePtr model_copy_node(struct model_t *self,
|
||||||
|
xmlNodePtr node,
|
||||||
|
const char* originalNodePath,
|
||||||
|
const char* attributeName,
|
||||||
|
const char* newAttributeValue)
|
||||||
|
{
|
||||||
|
assert(self->hashtable != NULL);
|
||||||
|
|
||||||
|
// Deep copy the node
|
||||||
|
xmlNodePtr copiedNode = xmlDocCopyNode(node, self->doc, 1);
|
||||||
|
if (copiedNode == NULL) {
|
||||||
|
return NULL; // Failed to copy
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modify the specified attribute in the copied node
|
||||||
|
xmlSetProp (copiedNode, (const xmlChar*)attributeName, (const xmlChar*)newAttributeValue);
|
||||||
|
|
||||||
|
// Insert the copied node as the next sibling of the original node
|
||||||
|
xmlAddNextSibling (node, copiedNode);
|
||||||
|
|
||||||
|
// Calculate the new node's path.
|
||||||
|
char newPath[1024];
|
||||||
|
snprintf (newPath, sizeof(newPath), "%s_copy", originalNodePath);
|
||||||
|
|
||||||
|
// Update the self->hashtable with the new node's path
|
||||||
|
xmlHashAddEntry (self->hashtable, (const xmlChar*)newPath, copiedNode);
|
||||||
|
|
||||||
|
return copiedNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates over all sibling nodes of a given node, typically used to process
|
||||||
|
* each child of a specific parent node.
|
||||||
|
*
|
||||||
|
* This function takes a starting node (expected to be a parent node like <states>)
|
||||||
|
* and iterates through all of its child nodes.
|
||||||
|
* It calls a user-provided callback function for each child node that is an
|
||||||
|
* element node (ignores text and other types of nodes).
|
||||||
|
*
|
||||||
|
* @param node The starting node whose siblings (children) will be iterated
|
||||||
|
* over. This node is not processed by the callback, only its siblings are.
|
||||||
|
* @param processNode A callback function that will be called for each sibling
|
||||||
|
* node. This function should have a signature of
|
||||||
|
* void functionName(xmlNodePtr node, void* userData), where
|
||||||
|
* 'node' is the current sibling element node, and
|
||||||
|
* 'userData' is a pointer to user-defined data passed
|
||||||
|
* through iterateSiblings.
|
||||||
|
* @param userData A void pointer to user-defined data. This can be used to pass
|
||||||
|
* additional information to the callback function. It is passed
|
||||||
|
* directly through to the callback function as its second argument.
|
||||||
|
*/
|
||||||
|
void model_iterate_node(struct model_t *self,
|
||||||
|
xmlNodePtr node,
|
||||||
|
void (*processNode)(xmlNodePtr node, void* userData), void* userData)
|
||||||
|
{
|
||||||
|
for (xmlNodePtr curNode = node->children; curNode; curNode = curNode->next) {
|
||||||
|
if (curNode->type == XML_ELEMENT_NODE) {
|
||||||
|
processNode (curNode, userData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
char model_get_dim (struct model_t *self)
|
||||||
|
{
|
||||||
|
xmlAttr *attribute;
|
||||||
|
xmlChar* value;
|
||||||
|
xmlNodePtr node = model_get_node(self,
|
||||||
|
(xmlChar *)"parameters/space-param/dimension");
|
||||||
|
|
||||||
|
if (xmlHasProp (node, (xmlChar *) "z")) return 3;
|
||||||
|
if (xmlHasProp (node, (xmlChar *) "y")) return 2;
|
||||||
|
if (xmlHasProp (node, (xmlChar *) "x")) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
long model_get_dim_value (struct model_t *self, const char *axis)
|
||||||
|
{
|
||||||
|
xmlAttr *attribute;
|
||||||
|
xmlChar *value;
|
||||||
|
long ret_value;
|
||||||
|
xmlNodePtr node = model_get_node(self,
|
||||||
|
(xmlChar *)"parameters/space-param/dimension");
|
||||||
|
|
||||||
|
return model_get_node_long_attrib(node, axis);
|
||||||
|
}
|
||||||
|
|
||||||
|
char model_get_multiplicity (struct model_t *self)
|
||||||
|
{
|
||||||
|
xmlAttr *attribute;
|
||||||
|
xmlChar* value;
|
||||||
|
xmlNodePtr node = model_get_node(self,
|
||||||
|
(xmlChar *)"parameters/space-param/site_multiplicity");
|
||||||
|
|
||||||
|
if (node->children)
|
||||||
|
if (node->children->content)
|
||||||
|
return (char)strtol((char *)node->children->content, NULL, 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static bool model_init(struct model_t *self)
|
||||||
|
{
|
||||||
|
xmlNode *node;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* this initialize the library and check potential ABI mismatches
|
||||||
|
* between the version it was compiled for and the actual shared
|
||||||
|
* library used.
|
||||||
|
*/
|
||||||
|
LIBXML_TEST_VERSION
|
||||||
|
|
||||||
|
self->doc = xmlReadFile(self->filename, NULL, 0);
|
||||||
|
|
||||||
|
if (self->doc == NULL ) {
|
||||||
|
printerr("Error trying to open the XML model !\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = xmlDocGetRootElement(self->doc);
|
||||||
|
|
||||||
|
if (node == NULL) {
|
||||||
|
printerr("Empty XML model !\n");
|
||||||
|
xmlFreeDoc(self->doc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xmlStrcmp(node->name, (xmlChar *) "gem-graph-model")) {
|
||||||
|
printerr("document of the wrong type, root node != gem-graph-model\n");
|
||||||
|
xmlFreeDoc(self->doc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
model_populate_hashtable(self, node, "");
|
||||||
|
|
||||||
|
if (self->hashtable == NULL) {
|
||||||
|
printerr("Can't create model hash table !\n");
|
||||||
|
xmlFreeDoc(self->doc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool model_shutdown(struct model_t *self)
|
||||||
|
{
|
||||||
|
xmlFreeDoc(self->doc);
|
||||||
|
xmlHashFree(self->hashtable, NULL);
|
||||||
|
// This is to debug memory for regression tests
|
||||||
|
//xmlMemoryDump();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
bool model_load (struct model_t *self)
|
||||||
|
{
|
||||||
|
char state_id[30] = {0};
|
||||||
|
char conditions_id[30] = {0};
|
||||||
|
struct arrow_t *arrow;
|
||||||
|
struct arrow_t *arrow_next;
|
||||||
|
struct arrow_t *arrow_prev;
|
||||||
|
int n_conditions;
|
||||||
|
|
||||||
|
|
||||||
|
if (!model_init (self))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
printlog ("Loading %s...\n", self->filename);
|
||||||
|
|
||||||
|
// Dimension
|
||||||
|
self->dimension = model_get_dim (self);
|
||||||
|
printlog ("Dimension : %d\n", self->dimension);
|
||||||
|
|
||||||
|
// Dimensions
|
||||||
|
self->space = calloc (1, sizeof(struct space_t));
|
||||||
|
self->space->x_dim = 0;
|
||||||
|
self->space->y_dim = 0;
|
||||||
|
self->space->z_dim = 0;
|
||||||
|
|
||||||
|
switch(self->dimension) {
|
||||||
|
case 3:
|
||||||
|
self->space->z_dim = model_get_dim_value (self, "z");
|
||||||
|
case 2:
|
||||||
|
self->space->y_dim = model_get_dim_value (self, "y");
|
||||||
|
case 1:
|
||||||
|
self->space->x_dim = model_get_dim_value (self, "x");
|
||||||
|
|
||||||
|
printlog("x_dim=%d, y_dim=%d, z_dim=%d\n",
|
||||||
|
self->space->x_dim,
|
||||||
|
self->space->y_dim,
|
||||||
|
self->space->z_dim);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printerr ("Invalid dimension value : %d\n", self->dimension);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Space allocation
|
||||||
|
self->space->units = calloc (self->space->x_dim
|
||||||
|
* self->space->y_dim
|
||||||
|
* self->space->z_dim,
|
||||||
|
sizeof(struct space_unit_t)
|
||||||
|
+ self->multiplicity * sizeof(struct arrow_t*));
|
||||||
|
|
||||||
|
// Multiplicity
|
||||||
|
self->multiplicity = model_get_multiplicity(self);
|
||||||
|
printlog("Multiplicity : %d\n", self->multiplicity);
|
||||||
|
|
||||||
|
// States and initial state
|
||||||
|
if (!model_get_next_state(self, &state_id)) {
|
||||||
|
printerr("No valid state to load\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->states = calloc (1, sizeof(struct state_t));
|
||||||
|
self->n_states = 1;
|
||||||
|
memcpy(&self->states[0].id, &state_id, 25);
|
||||||
|
self->states[0].space = self->space;
|
||||||
|
|
||||||
|
printlog("Initial state : %s\n", &self->states[0].id);
|
||||||
|
|
||||||
|
// Initial state arrows
|
||||||
|
while (arrow = arrow_new (self->arrows),
|
||||||
|
model_get_next_arrow(self,
|
||||||
|
arrow,
|
||||||
|
&self->states[0].id,
|
||||||
|
self->dimension)) {
|
||||||
|
if (arrow->x > self->space->x_dim ||
|
||||||
|
arrow->y > self->space->y_dim ||
|
||||||
|
arrow->z > self->space->z_dim) {
|
||||||
|
printerr("Invalid coordinates for arrow %d (%d,%d,%d)\n",
|
||||||
|
self->n_arrows,
|
||||||
|
arrow->x,
|
||||||
|
arrow->y,
|
||||||
|
arrow->z);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
printlog("Loading arrow %d (%d,%d,%d, %d)\n",
|
||||||
|
self->n_arrows,
|
||||||
|
arrow->x,
|
||||||
|
arrow->y,
|
||||||
|
arrow->z,
|
||||||
|
arrow->site);
|
||||||
|
|
||||||
|
self->space->units [
|
||||||
|
arrow->x
|
||||||
|
+ self->space->x_dim * arrow->y
|
||||||
|
+ self->space->x_dim * self->space->y_dim * arrow->z
|
||||||
|
].sites[arrow->site] = arrow;
|
||||||
|
|
||||||
|
if (self->n_arrows == 0) {
|
||||||
|
self->arrows = arrow;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->n_arrows++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printlog("Loaded %d arrows\n", self->n_arrows);
|
||||||
|
|
||||||
|
self->states[0].arrows = self->arrows;
|
||||||
|
|
||||||
|
// Conditions
|
||||||
|
if (!model_get_next_conditions(self, &conditions_id)) {
|
||||||
|
printerr("No valid conditions to load\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loading each condition
|
||||||
|
self->conditions = condition_new (self->conditions);
|
||||||
|
|
||||||
|
if (model_get_next_condition(self,
|
||||||
|
self->conditions,
|
||||||
|
&conditions_id,
|
||||||
|
self->dimension)) {
|
||||||
|
n_conditions = 1;
|
||||||
|
while (model_get_next_arrow(self,
|
||||||
|
condition_new (self->conditions),
|
||||||
|
&conditions_id,
|
||||||
|
self->dimension)) {
|
||||||
|
n_conditions++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printlog("Loaded %d conditions\n", n_conditions);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool model_unload (struct model_t *self)
|
||||||
|
{
|
||||||
|
if (!model_shutdown (self))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (self->owner_name) {
|
||||||
|
free(self->owner_name);
|
||||||
|
self->owner_name = NULL;
|
||||||
|
}
|
||||||
|
if (self->model_name) {
|
||||||
|
free(self->model_name);
|
||||||
|
self->model_name = NULL;
|
||||||
|
}
|
||||||
|
if (self->space) {
|
||||||
|
if (self->space->units) {
|
||||||
|
free(self->space->units);
|
||||||
|
self->space->units = NULL;
|
||||||
|
}
|
||||||
|
free(self->space);
|
||||||
|
self->space = NULL;
|
||||||
|
}
|
||||||
|
if (self->arrows) {
|
||||||
|
while (self->arrows) {
|
||||||
|
self->arrows = arrow_destroy (self->arrows);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (self->states) {
|
||||||
|
free(self->states);
|
||||||
|
self->states = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct model_t *model_new(const char *path, const char *basename)
|
||||||
|
{
|
||||||
|
struct model_t *self = NULL;
|
||||||
|
struct model_t *prev = NULL;
|
||||||
|
|
||||||
|
// Allocate and insert in the list
|
||||||
|
self = calloc (1, sizeof(struct model_t));
|
||||||
|
|
||||||
|
// We want a cyclic chain
|
||||||
|
// This is the first model
|
||||||
|
if (!knownModels) {
|
||||||
|
knownModels = self;
|
||||||
|
self->next = self;
|
||||||
|
self->prev = self;
|
||||||
|
|
||||||
|
// This is not the first model
|
||||||
|
} else {
|
||||||
|
self->next = knownModels->next;
|
||||||
|
knownModels->next = self;
|
||||||
|
self->prev = knownModels;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate filename with trailing '\0'
|
||||||
|
self->filename =
|
||||||
|
calloc (1, strlen (path)
|
||||||
|
+ sizeof((char)'/')
|
||||||
|
+ strlen (basename)
|
||||||
|
+ sizeof((char)'\0'));
|
||||||
|
|
||||||
|
memcpy (self->filename,
|
||||||
|
path,
|
||||||
|
strlen (path));
|
||||||
|
|
||||||
|
self->filename[
|
||||||
|
strlen (path)] = '/';
|
||||||
|
|
||||||
|
memcpy (self->filename
|
||||||
|
+ strlen (path)
|
||||||
|
+ sizeof((char)'/'),
|
||||||
|
basename,
|
||||||
|
strlen (basename));
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void model_destroy(struct model_t *self)
|
||||||
|
{
|
||||||
|
if (self->filename) {
|
||||||
|
free(self->filename);
|
||||||
|
self->filename = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->next != self) {
|
||||||
|
self->prev->next = self->next;
|
||||||
|
self->next->prev = self->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
void model_system_init (struct parameters_t *parameters)
|
||||||
|
{
|
||||||
|
struct dirent *modelDirEntry = NULL;
|
||||||
|
struct model_t *new_model;
|
||||||
|
DIR *modelDir = NULL;
|
||||||
|
char *extensionPosition;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// Open model directory
|
||||||
|
if ((modelDir = opendir (parameters->modelDir)) <= 0) {
|
||||||
|
printerr ("Could not open %s\n", parameters->modelDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((modelDirEntry = readdir (modelDir)) != NULL) {
|
||||||
|
if ((extensionPosition = strstr (modelDirEntry->d_name, ".xml"))) {
|
||||||
|
|
||||||
|
new_model = model_new (parameters->modelDir, modelDirEntry->d_name);
|
||||||
|
|
||||||
// Ask to parse the new model
|
// Ask to parse the new model
|
||||||
if (ParseModelIdentityXML(newModel, parameters) != 0) {
|
if (model_load (new_model)) {
|
||||||
printErr("Deleting invalid model %s from known list\n",
|
// XXX Check model is valid and/or parsed
|
||||||
newModel->name);
|
printlog ("Loaded %s\n", new_model->filename);
|
||||||
ModelDelete(newModel->id);
|
} else {
|
||||||
continue;
|
printerr ("Failed to load %s\n", new_model->filename);
|
||||||
};
|
model_unload (new_model);
|
||||||
|
model_destroy (new_model);
|
||||||
// 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);
|
free(modelDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelSystemDestroy(void)
|
void model_system_shutdown (void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < loadedModelSize; i++) {
|
struct model_t *model = knownModels;
|
||||||
ModelDelete(i);
|
struct model_t *next = NULL;
|
||||||
|
|
||||||
|
while ((model != model->next)) {
|
||||||
|
printlog ("Freeing %s\n", model->filename);
|
||||||
|
next = model->next;
|
||||||
|
model_unload(model);
|
||||||
|
model_destroy(model);
|
||||||
|
model = next;
|
||||||
}
|
}
|
||||||
free(loadedModel);
|
|
||||||
loadedModel = NULL;
|
if (model) {
|
||||||
free(knownModel);
|
model_unload (model);
|
||||||
knownModel = NULL;
|
model_destroy (model);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup function for the XML library
|
||||||
|
xmlCleanupParser();
|
||||||
}
|
}
|
||||||
|
|
583
src/parsing.c
583
src/parsing.c
|
@ -1,583 +0,0 @@
|
||||||
//=-------------------------------------------------------------------------=//
|
|
||||||
// XML parsing module //
|
|
||||||
// //
|
|
||||||
// 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 <https://www.gnu.org/licenses/>. //
|
|
||||||
//=-------------------------------------------------------------------------=//
|
|
||||||
|
|
||||||
#include "../include/parsing.h"
|
|
||||||
#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 <gem-graph-model> !\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 <gem-graph-model> !\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;
|
|
||||||
}
|
|
267
src/scheduler.c
267
src/scheduler.c
|
@ -20,209 +20,114 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
|
#include "../include/base.h"
|
||||||
#include "../include/scheduler.h"
|
#include "../include/scheduler.h"
|
||||||
#include "../include/centers.h"
|
|
||||||
#include "../include/worker.h"
|
#include "../include/worker.h"
|
||||||
#include "../include/arrows.h"
|
|
||||||
|
|
||||||
#include <sys/sysinfo.h>
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *schedulerMain(void *scheduler);
|
//
|
||||||
|
//
|
||||||
/* -------------------------------------------------------------------------- */
|
//
|
||||||
|
//
|
||||||
// -------------------------------------------------------------------------- //
|
static int sched_new_id (void)
|
||||||
// Scheduler init function //
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
void SchedInit(Scheduler_t *scheduler)
|
|
||||||
{
|
{
|
||||||
pthread_create(&scheduler->id, NULL, schedulerMain, scheduler);
|
static int id = 0;
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
//
|
||||||
|
//
|
||||||
// -------------------------------------------------------------------------- //
|
//
|
||||||
// Scheduler area finder function //
|
//
|
||||||
// -------------------------------------------------------------------------- //
|
static int sched_run(struct scheduler_t *self,
|
||||||
static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow,
|
struct parameters_t *parameters,
|
||||||
int ruleRadius, int xmax, int ymax, int zmax)
|
struct model_t *model)
|
||||||
{
|
{
|
||||||
register Center_t *currentCenter, *newCenter;
|
int n_threads = omp_get_max_threads();
|
||||||
|
int n_arrows;
|
||||||
|
int workers_per_cycle;
|
||||||
|
int max_cycles;
|
||||||
|
int max_workers;
|
||||||
|
|
||||||
currentCenter = centersList->next;
|
self->pleaseStop = false;
|
||||||
newCenter = malloc(sizeof(Center_t));
|
self->n_workers = 0;
|
||||||
|
n_arrows = 2000;
|
||||||
|
max_cycles = 1;
|
||||||
|
workers_per_cycle = (int) round((double)n_arrows / (double)n_threads);
|
||||||
|
max_workers = workers_per_cycle * n_threads * max_cycles;
|
||||||
|
|
||||||
while (currentCenter){
|
printlog("Begin simulation of model %d with %d workers per cycle"
|
||||||
if ( (xmax && (abs(electedArrow->x - currentCenter->x) <= ruleRadius))
|
" (%d arrows to work on)\n",
|
||||||
|| (ymax && (abs(electedArrow->y - currentCenter->y) <= ruleRadius))
|
model->id,
|
||||||
|| (zmax && (abs(electedArrow->z - currentCenter->z) <= ruleRadius))
|
workers_per_cycle,
|
||||||
){
|
n_arrows);
|
||||||
free(newCenter);
|
|
||||||
newCenter = NULL;
|
|
||||||
//printLog("Can't find a free area\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
currentCenter = currentCenter->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
newCenter->x = electedArrow->x;
|
#pragma omp parallel
|
||||||
newCenter->y = electedArrow->y;
|
{
|
||||||
newCenter->z = electedArrow->z;
|
int thread_num;
|
||||||
return newCenter;
|
thread_num = omp_get_thread_num();
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
while (!self->pleaseStop) {
|
||||||
|
// Get an ID;
|
||||||
|
self->workers[thread_num]->id = self->n_workers;
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// Elect an arrow (XXX TODO)
|
||||||
// Scheduler thread main function //
|
self->workers[thread_num]->elected_arrow = NULL;
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
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;
|
// Launch evaluation
|
||||||
|
worker_start(self->workers[thread_num], self);
|
||||||
|
|
||||||
// Getting scheduler argument structure
|
// Check if this is the end
|
||||||
args = (Scheduler_t*) scheduler;
|
if (self->n_workers > max_workers) {
|
||||||
printLog("Scheduler #%lu online\n", args->id);
|
self->pleaseStop = true;
|
||||||
|
|
||||||
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("End of simulation (%d workers executed)\n",
|
||||||
printLog("Stopping scheduler... (waiting for workers)\n");
|
self->n_workers);
|
||||||
// Waiting for remaining workers
|
|
||||||
for (int i = 0; i < ncpu; i++) {
|
return SCHED_NORMAL_EXIT;
|
||||||
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",
|
int sched_start (struct scheduler_t *self, struct parameters_t *parameters)
|
||||||
workerArray[i].id,
|
{
|
||||||
workerArray[i].returnValue
|
int n_threads = omp_get_max_threads();
|
||||||
);
|
int returnValue;
|
||||||
// Remove Worker
|
struct model_t *model;
|
||||||
WorkerDestroy(&workerArray[i]);
|
self->id = sched_new_id();
|
||||||
}
|
|
||||||
|
printlog("Scheduler %d initialized with %d threads\n",
|
||||||
|
self->id,
|
||||||
|
n_threads);
|
||||||
|
|
||||||
|
|
||||||
|
// Allocating workers
|
||||||
|
self->workers = calloc(n_threads, sizeof(struct worker_t*));
|
||||||
|
for (int i = 0; i < n_threads; i++) {
|
||||||
|
self->workers[i] = calloc(1, sizeof(struct worker_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
printLog("Scheduler #%lu offline\n", args->id);
|
// Retrieve models
|
||||||
|
model = self->models;
|
||||||
|
while(model) {
|
||||||
|
printlog ("Scheduling model %d\n", model->id);
|
||||||
|
returnValue = sched_run(self, parameters, self->models);
|
||||||
|
model = model->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Freeing workers
|
||||||
|
for (int i = 0; i < n_threads; i++) {
|
||||||
|
free(self->workers[i]);
|
||||||
|
}
|
||||||
|
free(self->workers);
|
||||||
|
|
||||||
ArrowsDestroyLock(args->arrowArray);
|
return returnValue;
|
||||||
|
|
||||||
free(workerArray);
|
|
||||||
workerArray = NULL;
|
|
||||||
free(centersList);
|
|
||||||
centersList = NULL;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
384
src/server.c
384
src/server.c
|
@ -20,243 +20,229 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
|
#include "../include/base.h"
|
||||||
#include "../include/server.h"
|
#include "../include/server.h"
|
||||||
#include "../include/cmds.h"
|
#include "../include/cmds.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static Command_t cmdList[] =
|
/* static void *server_main(void *server); */
|
||||||
{
|
|
||||||
{"help", CmdHelp, "Help command"},
|
|
||||||
{"model", CmdModel, "Model command"},
|
|
||||||
{"shutdown", CmdShutdown, "Shutdown command"},
|
|
||||||
};
|
|
||||||
|
|
||||||
static void *serverMain(void *server);
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
/* #define SEND_BUFFER_SIZE 80 * 24 */
|
||||||
// Server init function //
|
/* #define RECEIVE_BUFFER_SIZE 80 */
|
||||||
// -------------------------------------------------------------------------- //
|
/* void *server_communication_instance(void *serverCom) */
|
||||||
void ServerInit(Server_t *server)
|
/* { */
|
||||||
{
|
/* servercom_t *args; */
|
||||||
pthread_create(&server->id, NULL, serverMain, server);
|
/* char **argv = NULL; */
|
||||||
}
|
/* char receiveBuff[RECEIVE_BUFFER_SIZE]; */
|
||||||
|
/* char sendBuff[SEND_BUFFER_SIZE]; */
|
||||||
|
/* int tokenIndex, bytesReceived, clientPort; */
|
||||||
|
/* char clientIP[16]; */
|
||||||
|
|
||||||
#define SEND_BUFFER_SIZE 80 * 24
|
/* args = (servercom_t*) serverCom; */
|
||||||
#define RECEIVE_BUFFER_SIZE 80
|
|
||||||
void *serverCommunicationInstance(void *serverCom)
|
|
||||||
{
|
|
||||||
ServerCommunication_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;
|
/* // Get ip address from client */
|
||||||
|
/* inet_ntop(AF_INET, */
|
||||||
|
/* &args->clientAddr.sin_addr, */
|
||||||
|
/* clientIP, */
|
||||||
|
/* args->sockLen); */
|
||||||
|
|
||||||
// Get ip address from client
|
/* // Get port number from client */
|
||||||
inet_ntop(AF_INET,
|
/* clientPort = ntohs(args->clientAddr.sin_port); */
|
||||||
&args->clientAddr.sin_addr,
|
|
||||||
clientIP,
|
|
||||||
args->sockLen);
|
|
||||||
|
|
||||||
// Get port number from client
|
/* //Accept and incoming connection */
|
||||||
clientPort = ntohs(args->clientAddr.sin_port);
|
/* while(!args->pleaseStop) { */
|
||||||
|
|
||||||
//Accept and incoming connection
|
/* // Zeroing buffer */
|
||||||
while(!args->pleaseStop) {
|
/* bzero(receiveBuff, RECEIVE_BUFFER_SIZE); */
|
||||||
|
/* //printLog("Waiting for commands...\n"); */
|
||||||
|
|
||||||
// Zeroing buffer
|
/* // Read the message from client and copy it in buffer */
|
||||||
bzero(receiveBuff, RECEIVE_BUFFER_SIZE);
|
/* bytesReceived = recv(args->sockfd, receiveBuff, RECEIVE_BUFFER_SIZE, 0); */
|
||||||
//printLog("Waiting for commands...\n");
|
/* if (bytesReceived == -1) { */
|
||||||
|
/* printErr("Could not receive data! (%s)\n", strerror(errno)); */
|
||||||
|
/* break; */
|
||||||
|
/* }; */
|
||||||
|
|
||||||
// Read the message from client and copy it in buffer
|
/* // Ignore null-sized request */
|
||||||
bytesReceived = recv(args->sockfd, receiveBuff, RECEIVE_BUFFER_SIZE, 0);
|
/* if (bytesReceived == 0) */
|
||||||
if (bytesReceived == -1) {
|
/* break; */
|
||||||
printErr("Could not receive data! (%s)\n", strerror(errno));
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Ignore null-sized request
|
/* // Print buffer which contains the client request */
|
||||||
if (bytesReceived == 0)
|
/* printLog("Client %s:%d request : '%s'\n", */
|
||||||
break;
|
/* clientIP, */
|
||||||
|
/* clientPort, */
|
||||||
|
/* receiveBuff); */
|
||||||
|
|
||||||
// Print buffer which contains the client request
|
/* if (receiveBuff[0] == '\0') //XXX */
|
||||||
printLog("Client %s:%d request : '%s'\n",
|
/* break; */
|
||||||
clientIP,
|
|
||||||
clientPort,
|
|
||||||
receiveBuff);
|
|
||||||
|
|
||||||
if (receiveBuff[0] == '\0') //XXX
|
/* // get args in an array */
|
||||||
break;
|
/* tokenIndex = 0; */
|
||||||
|
/* argv = (char**) realloc(argv, 1 * sizeof(char*)); */
|
||||||
|
/* argv[0] = strtok(receiveBuff, " "); */
|
||||||
|
/* while (argv[tokenIndex]) { */
|
||||||
|
/* tokenIndex++; */
|
||||||
|
/* argv = (char**) realloc(argv, (tokenIndex+1) * sizeof(char*)); */
|
||||||
|
/* argv[tokenIndex] = strtok(NULL, " "); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
// get args in an array
|
/* // Zeroing buffer */
|
||||||
tokenIndex = 0;
|
/* bzero(sendBuff, RECEIVE_BUFFER_SIZE); */
|
||||||
argv = (char**) realloc(argv, 1 * sizeof(char*));
|
|
||||||
argv[0] = strtok(receiveBuff, " ");
|
|
||||||
while (argv[tokenIndex]) {
|
|
||||||
tokenIndex++;
|
|
||||||
argv = (char**) realloc(argv, (tokenIndex+1) * sizeof(char*));
|
|
||||||
argv[tokenIndex] = strtok(NULL, " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zeroing buffer
|
/* // Execute command by first arg in cmdList */
|
||||||
bzero(sendBuff, RECEIVE_BUFFER_SIZE);
|
/* for (int i = 0; i < LEN(cmdList); i++) { */
|
||||||
|
/* if (strcmp(cmdList[i].name, argv[0]) == 0) { */
|
||||||
|
/* cmdList[i].execute(sendBuff, argv, args->associatedServer); */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
|
||||||
// Execute command by first arg in cmdList
|
/* // and send that buffer to client */
|
||||||
for (int i = 0; i < LEN(cmdList); i++) {
|
/* send(args->sockfd, sendBuff, SEND_BUFFER_SIZE, 0); */
|
||||||
if (strcmp(cmdList[i].name, argv[0]) == 0) {
|
/* } */
|
||||||
cmdList[i].execute(sendBuff, argv, args->associatedServer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// and send that buffer to client
|
/* close(args->sockfd); */
|
||||||
send(args->sockfd, sendBuff, SEND_BUFFER_SIZE, 0);
|
/* if (argv) { */
|
||||||
}
|
/* free(argv); */
|
||||||
|
/* argv = NULL; */
|
||||||
|
/* } */
|
||||||
|
/* printLog("Disconnected from %s:%d\n", clientIP, clientPort); */
|
||||||
|
/* return NULL; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
close(args->sockfd);
|
/* // -------------------------------------------------------------------------- // */
|
||||||
if (argv) {
|
/* // Server main function // */
|
||||||
free(argv);
|
/* // -------------------------------------------------------------------------- // */
|
||||||
argv = NULL;
|
/* #define PORT 9000 */
|
||||||
}
|
/* #define MAX_CONNECTION 100 */
|
||||||
printLog("Disconnected from %s:%d\n", clientIP, clientPort);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
/* static void *server_main(void *server) */
|
||||||
// Server main function //
|
/* { */
|
||||||
// -------------------------------------------------------------------------- //
|
/* Server_t *args; */
|
||||||
#define PORT 9000
|
/* ServerCommunication_t serverSlots[MAX_CONNECTION] = {0}; */
|
||||||
#define MAX_CONNECTION 100
|
/* int connfd, flags, threadStatus, serverSlotIndex = 0; */
|
||||||
|
/* uint socklen; */
|
||||||
|
/* struct sockaddr_in servaddr; */
|
||||||
|
/* char clientIP[16]; */
|
||||||
|
|
||||||
static void *serverMain(void *server)
|
/* // Get args */
|
||||||
{
|
/* args = (Server_t*) server; */
|
||||||
Server_t *args;
|
/* args->returnValue = 0; */
|
||||||
ServerCommunication_t serverSlots[MAX_CONNECTION] = {0};
|
/* printLog("Server #%lu online\n", args->id); */
|
||||||
int connfd, flags, threadStatus, serverSlotIndex = 0;
|
|
||||||
uint socklen;
|
|
||||||
struct sockaddr_in servaddr;
|
|
||||||
char clientIP[16];
|
|
||||||
|
|
||||||
// Get args
|
/* // Create socket */
|
||||||
args = (Server_t*) server;
|
/* args->sockfd = socket(AF_INET, SOCK_STREAM, 0); */
|
||||||
args->returnValue = 0;
|
/* if (args->sockfd == -1) { */
|
||||||
printLog("Server #%lu online\n", args->id);
|
/* printErr("Socket creation failed! (%s)\n", strerror(errno)); */
|
||||||
|
/* args->returnValue = 1; */
|
||||||
|
/* goto serverExiting; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
// Create socket
|
/* // Get socket flags */
|
||||||
args->sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
/* flags = fcntl(args->sockfd, F_GETFL); */
|
||||||
if (args->sockfd == -1) {
|
/* if (flags == -1) { */
|
||||||
printErr("Socket creation failed! (%s)\n", strerror(errno));
|
/* printErr("Socket parameters getting failed! (%s)\n", strerror(errno)); */
|
||||||
args->returnValue = 1;
|
/* args->returnValue = 1; */
|
||||||
goto serverExiting;
|
/* goto serverExiting; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
// Get socket flags
|
/* // Change socket flags to non-blocking */
|
||||||
flags = fcntl(args->sockfd, F_GETFL);
|
/* if (fcntl(args->sockfd, F_SETFL, flags | O_NONBLOCK) < 0) { */
|
||||||
if (flags == -1) {
|
/* printErr("Socket non-blocking setting failed! (%s)\n", strerror(errno)); */
|
||||||
printErr("Socket parameters getting failed! (%s)\n", strerror(errno));
|
/* args->returnValue = 1; */
|
||||||
args->returnValue = 1;
|
/* goto serverExiting; */
|
||||||
goto serverExiting;
|
/* } */
|
||||||
}
|
|
||||||
|
|
||||||
// Change socket flags to non-blocking
|
/* // Prepare binding structure */
|
||||||
if (fcntl(args->sockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
/* bzero(&servaddr, sizeof(servaddr)); */
|
||||||
printErr("Socket non-blocking setting failed! (%s)\n", strerror(errno));
|
|
||||||
args->returnValue = 1;
|
|
||||||
goto serverExiting;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare binding structure
|
/* // Assign IP and PORT */
|
||||||
bzero(&servaddr, sizeof(servaddr));
|
/* servaddr.sin_family = AF_INET; */
|
||||||
|
/* servaddr.sin_addr.s_addr = htonl(INADDR_ANY); */
|
||||||
|
/* servaddr.sin_port = htons(PORT); */
|
||||||
|
|
||||||
// Assign IP and PORT
|
/* // Binding newly created socket */
|
||||||
servaddr.sin_family = AF_INET;
|
/* if ((bind(args->sockfd, (struct sockaddr*)&servaddr, */
|
||||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
/* sizeof(servaddr))) == -1) { */
|
||||||
servaddr.sin_port = htons(PORT);
|
/* printErr("Socket bind failed! (%s)\n", strerror(errno)); */
|
||||||
|
/* args->returnValue = 1; */
|
||||||
|
/* goto serverExiting; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
// Binding newly created socket
|
/* // Now server is ready to listen and verification */
|
||||||
if ((bind(args->sockfd, (struct sockaddr*)&servaddr,
|
/* if (listen(args->sockfd, MAX_CONNECTION) == -1) { */
|
||||||
sizeof(servaddr))) == -1) {
|
/* printErr("Socket listening failed! (%s)\n", strerror(errno)); */
|
||||||
printErr("Socket bind failed! (%s)\n", strerror(errno));
|
/* args->returnValue = 1; */
|
||||||
args->returnValue = 1;
|
/* goto serverExiting; */
|
||||||
goto serverExiting;
|
/* } */
|
||||||
}
|
|
||||||
|
|
||||||
// Now server is ready to listen and verification
|
/* socklen = sizeof(struct sockaddr_in); */
|
||||||
if (listen(args->sockfd, MAX_CONNECTION) == -1) {
|
|
||||||
printErr("Socket listening failed! (%s)\n", strerror(errno));
|
|
||||||
args->returnValue = 1;
|
|
||||||
goto serverExiting;
|
|
||||||
}
|
|
||||||
|
|
||||||
socklen = sizeof(struct sockaddr_in);
|
/* // Get server socket address structure */
|
||||||
|
/* if (getsockname(args->sockfd, (struct sockaddr *)&servaddr, &socklen) */
|
||||||
|
/* == -1) { */
|
||||||
|
/* printErr("Could not get socket structure! (%s)\n", strerror(errno)); */
|
||||||
|
/* args->returnValue = 1; */
|
||||||
|
/* goto serverExiting; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
// Get server socket address structure
|
/* printLog("Server listening...\n"); */
|
||||||
if (getsockname(args->sockfd, (struct sockaddr *)&servaddr, &socklen)
|
|
||||||
== -1) {
|
|
||||||
printErr("Could not get socket structure! (%s)\n", strerror(errno));
|
|
||||||
args->returnValue = 1;
|
|
||||||
goto serverExiting;
|
|
||||||
}
|
|
||||||
|
|
||||||
printLog("Server listening...\n");
|
/* while (!args->pleaseStop) { */
|
||||||
|
|
||||||
while (!args->pleaseStop) {
|
/* // Accept the data packet from client */
|
||||||
|
/* connfd = accept(args->sockfd, */
|
||||||
|
/* (struct sockaddr*) &serverSlots[serverSlotIndex].clientAddr, */
|
||||||
|
/* &socklen); */
|
||||||
|
/* if (connfd < 0) { */
|
||||||
|
/* // If error is not due to lack of clients connecting, this is error */
|
||||||
|
/* if (errno != EWOULDBLOCK && errno != EAGAIN) { */
|
||||||
|
/* printErr("Server acccept failed! (%s)\n", strerror(errno)); */
|
||||||
|
/* goto serverExiting; */
|
||||||
|
/* } */
|
||||||
|
/* sleep(1); */
|
||||||
|
/* } else { */
|
||||||
|
/* // Client connected */
|
||||||
|
/* // get IP addr from client */
|
||||||
|
/* inet_ntop(AF_INET, */
|
||||||
|
/* &(serverSlots[serverSlotIndex].clientAddr.sin_addr), */
|
||||||
|
/* clientIP, socklen); */
|
||||||
|
/* printLog("Client accepted from %s:%d\n", */
|
||||||
|
/* clientIP, */
|
||||||
|
/* ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread */
|
||||||
|
|
||||||
// Accept the data packet from client
|
/* // Populate communicator slot */
|
||||||
connfd = accept(args->sockfd,
|
/* serverSlots[serverSlotIndex].sockLen = socklen; // XXX */
|
||||||
(struct sockaddr*) &serverSlots[serverSlotIndex].clientAddr,
|
/* serverSlots[serverSlotIndex].sockfd = connfd; */
|
||||||
&socklen);
|
/* serverSlots[serverSlotIndex].associatedServer = args; */
|
||||||
if (connfd < 0) {
|
|
||||||
// If error is not due to lack of clients connecting, this is error
|
|
||||||
if (errno != EWOULDBLOCK && errno != EAGAIN) {
|
|
||||||
printErr("Server acccept failed! (%s)\n", strerror(errno));
|
|
||||||
goto serverExiting;
|
|
||||||
}
|
|
||||||
sleep(1);
|
|
||||||
} else {
|
|
||||||
// Client connected
|
|
||||||
// get IP addr from client
|
|
||||||
inet_ntop(AF_INET,
|
|
||||||
&(serverSlots[serverSlotIndex].clientAddr.sin_addr),
|
|
||||||
clientIP, socklen);
|
|
||||||
printLog("Client accepted from %s:%d\n",
|
|
||||||
clientIP,
|
|
||||||
ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread
|
|
||||||
|
|
||||||
// Populate communicator slot
|
/* // Create thread */
|
||||||
serverSlots[serverSlotIndex].sockLen = socklen; // XXX
|
/* threadStatus = pthread_create(&serverSlots[serverSlotIndex].id, */
|
||||||
serverSlots[serverSlotIndex].sockfd = connfd;
|
/* NULL, */
|
||||||
serverSlots[serverSlotIndex].associatedServer = args;
|
/* server_communication_instance, */
|
||||||
|
/* (void*)&serverSlots[serverSlotIndex]); */
|
||||||
|
/* if(threadStatus != 0) { */
|
||||||
|
/* printErr("Error from pthread: %d (%s)\n", */
|
||||||
|
/* threadStatus, strerror(errno)); */
|
||||||
|
/* args->returnValue = 1; */
|
||||||
|
/* goto serverExiting; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
// Create thread
|
/* serverSlotIndex++; */
|
||||||
threadStatus = pthread_create(&serverSlots[serverSlotIndex].id,
|
/* //printLog("Accepted connection. Server will now listen...\n"); */
|
||||||
NULL,
|
/* } */
|
||||||
serverCommunicationInstance,
|
/* } */
|
||||||
(void*)&serverSlots[serverSlotIndex]);
|
|
||||||
if(threadStatus != 0) {
|
|
||||||
printErr("Error from pthread: %d (%s)\n",
|
|
||||||
threadStatus, strerror(errno));
|
|
||||||
args->returnValue = 1;
|
|
||||||
goto serverExiting;
|
|
||||||
}
|
|
||||||
|
|
||||||
serverSlotIndex++;
|
/* serverExiting: */
|
||||||
//printLog("Accepted connection. Server will now listen...\n");
|
/* for (int i; i < serverSlotIndex; i++) { */
|
||||||
}
|
/* serverSlots[i].pleaseStop = true; */
|
||||||
}
|
/* usleep(10000); */
|
||||||
|
/* pthread_cancel(serverSlots[i].id); */
|
||||||
serverExiting:
|
/* pthread_join(serverSlots[i].id, NULL); */
|
||||||
for (int i; i < serverSlotIndex; i++) {
|
/* } */
|
||||||
serverSlots[i].pleaseStop = true;
|
/* close(args->sockfd); */
|
||||||
usleep(10000);
|
/* printLog("Server #%lu offline\n", args->id); */
|
||||||
pthread_cancel(serverSlots[i].id);
|
/* return NULL; */
|
||||||
pthread_join(serverSlots[i].id, NULL);
|
/* } */
|
||||||
}
|
|
||||||
close(args->sockfd);
|
|
||||||
printLog("Server #%lu offline\n", args->id);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,26 +20,9 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
|
#include "../include/base.h"
|
||||||
#include "../include/supervisor.h"
|
#include "../include/supervisor.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
BIN
src/tests/xml
BIN
src/tests/xml
Binary file not shown.
46
src/worker.c
46
src/worker.c
|
@ -20,44 +20,24 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
//=-------------------------------------------------------------------------=//
|
//=-------------------------------------------------------------------------=//
|
||||||
|
|
||||||
|
#include "../include/base.h"
|
||||||
#include "../include/worker.h"
|
#include "../include/worker.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *WorkerMain(void *worker);
|
double truc;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
//
|
||||||
|
//
|
||||||
// -------------------------------------------------------------------------- //
|
//
|
||||||
// Worker init function //
|
//
|
||||||
// -------------------------------------------------------------------------- //
|
void worker_start(struct worker_t *self, struct scheduler_t *scheduler)
|
||||||
void WorkerInit(Worker_t *worker)
|
|
||||||
{
|
{
|
||||||
if (pthread_create(&worker->id, NULL, WorkerMain, worker)) {
|
// Locking ressources
|
||||||
printLog("Worker #%lu can't be initialized!\n", worker->id);
|
#pragma omp critical
|
||||||
return;
|
{
|
||||||
|
scheduler->n_workers++;
|
||||||
|
//XXX lock space units
|
||||||
}
|
}
|
||||||
}
|
self->status = WORKER_NORMAL_EXIT;
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue