Progressing into parsing and model file syntax
This commit is contained in:
parent
1342b445af
commit
5ee70f6c44
4
Makefile
4
Makefile
|
@ -121,6 +121,10 @@ 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
|
||||
@valgrind bin/gem-graph-server \
|
||||
-C debian/etc -M debian/var/models -U debian/var/users
|
||||
|
||||
run-both: all
|
||||
@bin/gem-graph-server -C debian/etc -M debian/var/models \
|
||||
-U debian/var/users & sleep 1 && bin/gem-graph-ctl
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
<!-- Model identity informations -->
|
||||
<identity>
|
||||
<name>Modèle de test</name>
|
||||
<author>Adrien Bourmault, Jean Sirmai</author>
|
||||
<author_id>1,2</author_id>
|
||||
<date>1629830000</date> <!--Warning: it's an arbitrary unchecked date...-->
|
||||
<owner>Jean Sirmai</owner>
|
||||
<owner_id>2</owner_id>
|
||||
<date>1629830000</date> <!--Warning: it's an arbitrary unchecked date...-->
|
||||
<version>1.0</version>
|
||||
|
||||
</identity>
|
||||
|
@ -30,7 +30,7 @@
|
|||
<!-- X="00" no boundaries X="||" boundaries west and east X="|0" boundary west only X="0|" boundary east-->
|
||||
<!-- X="|0" indicates that: a particle which moves beyond the east boundary will reenter on the west side-->
|
||||
<!-- X="|0" : no particle can move beyond the west boundary-->
|
||||
|
||||
|
||||
</space>
|
||||
|
||||
</parameters>
|
||||
|
@ -91,26 +91,6 @@
|
|||
|
||||
</transition>
|
||||
|
||||
<transition id="0" date="" author="" probability="1"> <!-- moves a dimer to west-->
|
||||
<if>
|
||||
<arrow x="0" y="0" z="0" site="1" weight="1"/>
|
||||
<arrow x="1" y="0" z="0" site="0" weight="1"/> <!-- a dimer is identified-->
|
||||
<!-- the local space origin is its "east" particule-->
|
||||
<arrow x="-1" y="0" z="0" site="0" weight="0"/> <!-- the west location next this dimer is empty-->
|
||||
<arrow x="-2" y="0" z="0" site="1" weight="0"/> <!-- In this very simple model, I do not need to check this condition-->
|
||||
|
||||
</if>
|
||||
|
||||
<then> <!-- Therefore I can (and I want to) move it to its next west location-->
|
||||
<arrow x="0" y="0" z="0" site="1" weight="0"/>
|
||||
<arrow x="1" y="0" z="0" site="0" weight="0"/> <!-- The identified dimer no more exists ( :-(( -->
|
||||
<arrow x="0" y="0" z="0" site="0" weight="1"/>
|
||||
<arrow x="-1" y="0" z="0" site="1" weight="1"/> <!-- Happily, it is now rebuilt at its west location ( ;-))-->
|
||||
|
||||
</then>
|
||||
|
||||
</transition>
|
||||
|
||||
</transitions>
|
||||
|
||||
<!-- Non context-specific tags -->
|
||||
|
|
|
@ -160,7 +160,8 @@ struct Model_t {
|
|||
int id;
|
||||
bool validated; // true if model has been correctly parsed
|
||||
char *name;
|
||||
char *author;
|
||||
char *owner;
|
||||
char *owner_id;
|
||||
time_t date;
|
||||
char *version;
|
||||
char *filename;
|
||||
|
|
|
@ -26,6 +26,24 @@
|
|||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#define MODEL_STRING_SIZE 48
|
||||
#define MAX_MODEL_NUMBER 1
|
||||
#define MAX_MODEL_NAME_SIZE MODEL_STRING_SIZE
|
||||
#define MAX_MODEL_FILENAME_SIZE MODEL_STRING_SIZE
|
||||
#define MAX_OWNER_NAME_SIZE MODEL_STRING_SIZE
|
||||
#define MAX_VERSION_SIZE MODEL_STRING_SIZE
|
||||
|
||||
#define ARROW_NUMBER 6
|
||||
#define SITE_NUMBER 2
|
||||
#define MAX_CYCLES 10
|
||||
#define MAX_THREAD 0
|
||||
#define XMAX 39
|
||||
#define YMAX 0
|
||||
#define ZMAX 0
|
||||
#define SPACE_SIZE (XMAX+1) * (YMAX+1) * (ZMAX+1)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Model init function (and model discovery) //
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
|
31
src/model.c
31
src/model.c
|
@ -23,24 +23,11 @@
|
|||
#include "../include/parsing.h"
|
||||
#include "../include/arrows.h"
|
||||
#include "../include/scheduler.h"
|
||||
#include "../include/model.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define MAX_MODEL_NUMBER 1
|
||||
#define MAX_MODEL_NAME_SIZE 48
|
||||
#define MAX_MODEL_FILENAME_SIZE 48
|
||||
#define MAX_AUTHOR_NAME_SIZE 48
|
||||
#define MAX_VERSION_SIZE 16
|
||||
#define ARROW_NUMBER 6
|
||||
#define SITE_NUMBER 2
|
||||
#define MAX_CYCLES 10
|
||||
#define MAX_THREAD 0
|
||||
#define XMAX 39
|
||||
#define YMAX 0
|
||||
#define ZMAX 0
|
||||
#define SPACE_SIZE (XMAX+1) * (YMAX+1) * (ZMAX+1)
|
||||
|
||||
static Model_t **loadedModel;
|
||||
static int loadedModelSize; // begins to 1
|
||||
|
||||
|
@ -59,12 +46,12 @@ void printModels(char *buf)
|
|||
sprintf(buf + strlen(buf),"Known models\n");
|
||||
for (int i = 0; i <= knownModelSize-1; i++) {
|
||||
sprintf(buf + strlen(buf), "id: %d, addr: %p, name: %s, date: %lu, "
|
||||
"author: %s\n",
|
||||
"owner: %s\n",
|
||||
knownModel[i]->id,
|
||||
knownModel[i],
|
||||
knownModel[i]->name,
|
||||
knownModel[i]->date,
|
||||
knownModel[i]->author
|
||||
knownModel[i]->owner
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -95,7 +82,7 @@ int ModelLoad(int id)
|
|||
return loadedModelSize;
|
||||
}
|
||||
|
||||
void ModelUnload(int id)
|
||||
int ModelUnload(int id)
|
||||
{
|
||||
// Destroy scheduler
|
||||
SchedDestroy(loadedModel[id-1]->scheduler);
|
||||
|
@ -196,8 +183,8 @@ void ModelAddToKnown(Model_t **newModel) // TODO manage deletion and empty slots
|
|||
knownModel[knownModelSize-1]->filename =
|
||||
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
|
||||
|
||||
knownModel[knownModelSize-1]->author =
|
||||
(char *) calloc(1, sizeof(char) * MAX_AUTHOR_NAME_SIZE);
|
||||
knownModel[knownModelSize-1]->owner =
|
||||
(char *) calloc(1, sizeof(char) * MAX_OWNER_NAME_SIZE);
|
||||
|
||||
knownModel[knownModelSize-1]->version =
|
||||
(char *) calloc(1, sizeof(char) * MAX_VERSION_SIZE);
|
||||
|
@ -219,8 +206,8 @@ void ModelDelete(int id) //XXX
|
|||
free(knownModel[id-1]->filename);
|
||||
knownModel[id-1]->filename = NULL;
|
||||
|
||||
free(knownModel[id-1]->author);
|
||||
knownModel[id-1]->author = NULL;
|
||||
free(knownModel[id-1]->owner);
|
||||
knownModel[id-1]->owner = NULL;
|
||||
|
||||
free(knownModel[id-1]->version);
|
||||
knownModel[id-1]->version = NULL;
|
||||
|
@ -293,7 +280,7 @@ void ModelSystemInit(Parameters_t *parameters)
|
|||
// Ask to parse the new model
|
||||
if (ParseModelXML(newModel) != 0) {
|
||||
ModelDelete(newModel->id);
|
||||
continue;XMAX
|
||||
continue;
|
||||
};
|
||||
|
||||
// Check model is valid and/or parsed
|
||||
|
|
149
src/parsing.c
149
src/parsing.c
|
@ -20,70 +20,134 @@
|
|||
//=-------------------------------------------------------------------------=//
|
||||
|
||||
#include "../include/base.h"
|
||||
#include "../include/model.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <libxml2/libxml/xmlmemory.h>
|
||||
#include <libxml2/libxml/parser.h>
|
||||
#include <libxml/parser.h>
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static int parseIdentityXML(Model_t*, xmlDocPtr, xmlNodePtr);
|
||||
static int parseIdentityNameXML(Model_t*, xmlDocPtr, xmlNodePtr);
|
||||
#define NO_DESTINATION NULL
|
||||
|
||||
// Table of all parsers
|
||||
struct parserTableXML_t {
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
struct ModelParserTableXML_t;
|
||||
|
||||
struct ParserTableXML_t
|
||||
{
|
||||
const xmlChar *tag;
|
||||
int (*execute) (Model_t*, xmlDocPtr, xmlNodePtr);
|
||||
int (*parse) (xmlDoc*,
|
||||
struct ModelParserTableXML_t*,
|
||||
int currentParser,
|
||||
xmlNode*);
|
||||
void *destination;
|
||||
} typedef ParserTableXML_t;
|
||||
|
||||
static ParserTableXML_t toplevelParserTableXML[] =
|
||||
struct ModelParserTableXML_t
|
||||
{
|
||||
{(const xmlChar *)"identity", parseIdentityXML},
|
||||
};
|
||||
|
||||
static ParserTableXML_t identityParserTableXML[] =
|
||||
{
|
||||
{(const xmlChar *)"name", parseIdentityChildren},
|
||||
{(const xmlChar *)"author", parseIdentityChildren},
|
||||
{(const xmlChar *)"author_id", parseIdentityChildren},
|
||||
{(const xmlChar *)"date", parseIdentityChildren},
|
||||
{(const xmlChar *)"version", parseIdentityChildren},
|
||||
};
|
||||
size_t len;
|
||||
ParserTableXML_t *table;
|
||||
} typedef ModelParserTableXML_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static int parseIdentityNameXML (Model_t *model, xmlDocPtr doc,
|
||||
xmlNodePtr currentNode)
|
||||
int parseParentFieldXML(xmlDocPtr,
|
||||
ModelParserTableXML_t*,
|
||||
int,
|
||||
xmlNodePtr);
|
||||
|
||||
int parseTextField(xmlDocPtr,
|
||||
ModelParserTableXML_t*,
|
||||
int,
|
||||
xmlNodePtr);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Parsing NOTHING //
|
||||
// -------------------------------------------------------------------------- //
|
||||
int parseStubFieldXML (xmlDocPtr doc,
|
||||
ModelParserTableXML_t *ModelTable,
|
||||
int currentParser,
|
||||
xmlNodePtr currentNode)
|
||||
{
|
||||
xmlChar *key;
|
||||
key = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
|
||||
printLog("key: %s\n", key);
|
||||
xmlFree(key);
|
||||
xmlChar *content;
|
||||
content = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
|
||||
|
||||
printLog("%s (stub): %s\n",
|
||||
ModelTable->table[currentParser].tag,
|
||||
content);
|
||||
|
||||
xmlFree(content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parseIdentityXML (Model_t *model, xmlDocPtr doc,
|
||||
xmlNodePtr currentNode)
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Parsing a text field //
|
||||
// -------------------------------------------------------------------------- //
|
||||
int parseTextFieldXML (xmlDocPtr doc,
|
||||
ModelParserTableXML_t *ModelTable,
|
||||
int currentParser,
|
||||
xmlNodePtr currentNode)
|
||||
{
|
||||
xmlChar *key;
|
||||
currentNode = currentNode->xmlChildrenNode;
|
||||
while (currentNode != NULL) {
|
||||
for (int i = 0; i < LEN(identityParserTableXML); i++) {
|
||||
xmlChar *content;
|
||||
content = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
|
||||
|
||||
printLog("%s: %s\n", ModelTable->table[currentParser].tag,
|
||||
content);
|
||||
|
||||
strncpy((char *)ModelTable->table[currentParser].destination,
|
||||
(char *)content, MODEL_STRING_SIZE);
|
||||
xmlFree(content);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parseParentFieldXML (xmlDocPtr doc,
|
||||
ModelParserTableXML_t *ModelTable,
|
||||
int currentParser,
|
||||
xmlNodePtr currentNode)
|
||||
{
|
||||
currentNode = currentNode->xmlChildrenNode;
|
||||
while (currentNode != NULL) {
|
||||
for (int i = 0; i < ModelTable->len; i++) {
|
||||
if ((!xmlStrcmp(currentNode->name,
|
||||
identityParserTableXML[i].tag))) {
|
||||
identityParserTableXML[i].execute(model,
|
||||
doc,
|
||||
currentNode);
|
||||
ModelTable->table[i].tag))) {
|
||||
ModelTable->table[i].parse(doc,
|
||||
ModelTable,
|
||||
i,
|
||||
currentNode);
|
||||
}
|
||||
}
|
||||
currentNode = currentNode->next;
|
||||
}
|
||||
currentNode = currentNode->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ParseModelXML(Model_t *model)
|
||||
{
|
||||
ParserTableXML_t table[] =
|
||||
{
|
||||
{(const xmlChar *)"identity", parseParentFieldXML,
|
||||
model},
|
||||
{(const xmlChar *)"name", parseTextFieldXML,
|
||||
model->name},
|
||||
{(const xmlChar *)"owner", parseTextFieldXML,
|
||||
model->owner},
|
||||
{(const xmlChar *)"owner_id", parseStubFieldXML,
|
||||
model->owner_id},
|
||||
{(const xmlChar *)"date", parseStubFieldXML,
|
||||
model->date},
|
||||
{(const xmlChar *)"version", parseTextFieldXML,
|
||||
model->version},
|
||||
};
|
||||
|
||||
ModelParserTableXML_t modelParserTable =
|
||||
{
|
||||
LEN(table),
|
||||
&table[0]
|
||||
};
|
||||
|
||||
printLog("Parsing model %s\n", model->name);
|
||||
xmlDocPtr xmlDocument;
|
||||
xmlNodePtr currentNode;
|
||||
|
@ -114,12 +178,13 @@ int ParseModelXML(Model_t *model)
|
|||
|
||||
currentNode = currentNode->xmlChildrenNode;
|
||||
while (currentNode != NULL) {
|
||||
for (int i = 0; i < LEN(toplevelParserTableXML); i++) {
|
||||
for (int i = 0; i < modelParserTable.len; i++) {
|
||||
if ((!xmlStrcmp(currentNode->name,
|
||||
toplevelParserTableXML[i].tag))) {
|
||||
toplevelParserTableXML[i].execute(model,
|
||||
xmlDocument,
|
||||
currentNode);
|
||||
modelParserTable.table[i].tag))) {
|
||||
modelParserTable.table[i].parse(xmlDocument,
|
||||
&modelParserTable,
|
||||
i,
|
||||
currentNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue