diff --git a/Makefile b/Makefile index b0f0f92..6d48a60 100644 --- a/Makefile +++ b/Makefile @@ -87,11 +87,19 @@ all: dependencies $(BINDIR)/gem-graph-server $(BINDIR)/gem-graph-ctl tests: $(TESTS) # ---- Build debian package -------------------------------------------------- # -$(BINDIR)/gem-graph-server.deb: all +$(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)/Manifest gem-graph-server/DEBIAN/control + 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 \ diff --git a/debian/Manifest b/debian/Manifest deleted file mode 100644 index d7fcae4..0000000 --- a/debian/Manifest +++ /dev/null @@ -1,10 +0,0 @@ -Package: gem-graph-server -Version: 0.0.1 -Section: custom -Priority: optional -Depends: libxml2 -Architecture: amd64 -Essential: no -Installed-Size: 1049 -Maintainer: The Gem-graph Project -Description: The gem-graph computation server diff --git a/include/base.h b/include/base.h index 97ea250..417687f 100644 --- a/include/base.h +++ b/include/base.h @@ -168,3 +168,14 @@ struct { Scheduler_t *scheduler; Supervisor_t *supervisor; } typedef Model_t; + +/* -------------------------------------------------------------------------- */ + +// +// Parameters +// +struct { + char *configDir; + char *modelDir; + char *userDir; +} typedef Parameters_t; diff --git a/include/model.h b/include/model.h index 49a3c02..a42fd6f 100644 --- a/include/model.h +++ b/include/model.h @@ -23,7 +23,7 @@ #include "../include/base.h" #endif -void ModelSystemInit(void); +void ModelSystemInit(Parameters_t *parameters); void ModelSystemDestroy(void); diff --git a/src/cmds.c b/src/cmds.c index b2d82cd..bb76061 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -179,12 +179,12 @@ CmdModelEnd: char *CmdShutdown(char *buf, char **argv, Server_t *args) { - ModelShutdown(); - strcat(buf, "All model shutted down\n"); - args->pleaseStop = true; strcat(buf, "Server stopping\n"); + ModelShutdown(); + strcat(buf, "All model shutted down\n"); + return buf; } diff --git a/src/localworker.c b/src/localworker.c index 1931a2d..958bba6 100644 --- a/src/localworker.c +++ b/src/localworker.c @@ -48,6 +48,7 @@ static void *workerMain(void *worker) printLog("Worker #%lu online\n", args->id); int size = args->globalDrawingSpace->size; + /* In each cell: the West (left) site is 0, the East (right) site is 1 */ for (int orig=0; orig < size; orig++){ int nxt1 = (orig + 1) % size, diff --git a/src/main.c b/src/main.c index 3762f50..e1972a2 100644 --- a/src/main.c +++ b/src/main.c @@ -23,37 +23,66 @@ #include "../include/server.h" #include "../include/model.h" +static Server_t *server; +void SigIntTermHandler(int signum) +{ + server->pleaseStop = true; + printLog("Server stopping\n"); + + ModelShutdown(); + printLog("All model shutted down\n"); +} + + +// TODO parse args to discover : +// - config files directory +// - models & users directories int main(int argc, char **argv) { time_t t; - Server_t *server0; int returnValue = 0; + // Get parameters TODO from args + Parameters_t *parameters = (Parameters_t*) calloc(sizeof(Parameters_t), 1); + + parameters->configDir = (char*) malloc(strlen("../debian/etc")); + strcpy(parameters->configDir, "../debian/etc"); + + parameters->modelDir = (char*) malloc(strlen("../debian/var/models")); + strcpy(parameters->modelDir, "../debian/etc"); + + parameters->userDir = (char*) malloc(strlen("../debian/var/users")); + strcpy(parameters->userDir, "../debian/etc"); + // Go! printLog("Starting gem-graph-server...\n"); + // Register new interrupt handler + signal(SIGINT, SigIntTermHandler); + signal(SIGTERM, SigIntTermHandler); + // Initializing random generator t = time(&t); srand((unsigned) t); - server0 = (Server_t*) calloc(1, sizeof(Server_t)); + server = (Server_t*) calloc(1, sizeof(Server_t)); // Initializing model system - ModelSystemInit(); + ModelSystemInit(parameters); // Launching server - ServerInit(server0); + ServerInit(server); // Waiting for termination - ServerWait(server0); + ServerWait(server); // Exiting - returnValue |= server0->returnValue; - ServerDestroy(server0); + returnValue |= server->returnValue; + ServerDestroy(server); ModelSystemDestroy(); - free(server0); - server0 = NULL; + free(server); + server = NULL; return returnValue; } diff --git a/src/model.c b/src/model.c index 2685dc5..8f093d5 100644 --- a/src/model.c +++ b/src/model.c @@ -182,15 +182,16 @@ void ModelShutdown(void) } } -void ModelSystemInit(void) +void ModelSystemInit(Parameters_t *parameters) { loadedModel = (Model_t**) calloc(1, sizeof(Model_t*)); - // XXX read known models from files knownModel = (Model_t**) calloc(1, sizeof(Model_t*)); knownModelSize = 0; loadedModelSize = 0; + + printLog("Model system initiated with folder : %s\n", parameters->modelDir); } void ModelSystemDestroy(void) diff --git a/src/tests/xml b/src/tests/xml index 04cd32f..b082672 100755 Binary files a/src/tests/xml and b/src/tests/xml differ diff --git a/src/tests/xml.c b/src/tests/xml.c index bcba914..6c5eb80 100644 --- a/src/tests/xml.c +++ b/src/tests/xml.c @@ -8,8 +8,8 @@ void parseStory (xmlDocPtr doc, xmlNodePtr cur) { cur = cur->xmlChildrenNode; while (cur != NULL) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) { - printf("keyword: %s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); + if ((!xmlStrcmp(cur->name, (const xmlChar *)"authors"))) { + printf("%s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); } cur = cur->next; } @@ -41,7 +41,7 @@ static void parseDoc(char *docname) cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){ - parseStory (doc, cur); + parseStory(doc, cur); } cur = cur->next; }