Header refactor, more XML parsing and stuff

This commit is contained in:
Adrien Bourmault 2021-09-18 01:00:48 +02:00
parent fc10d5de14
commit efb3bfd64c
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
14 changed files with 144 additions and 103 deletions

View File

@ -6,8 +6,9 @@
<!-- Model identity informations -->
<identity>
<name>Modèle de test</name>
<name value="(Trois dimères)"/>
<name>Model created for testing purposes</name>
<name value="(Three dimers)"/>
<owner>Jean Sirmai</owner>
<owner_id>2</owner_id>
<date>1629830000</date> <!--Warning: it's an arbitrary unchecked date...-->
<version>1.0</version>
@ -15,14 +16,14 @@
</identity>
<!-- Model parameters -->
<parameters id="" date="" author="">
<parameters id="test" date="1629830000" author="Jean Sirmai">
<modelization>
<max_thread value="0"/> <!--Why "0" ?-->
<max_cycles value="13"/>
</modelization>
<space>
<space_param>
<dimension value="1"/> <!-- TODO redundancy here: dimension is given by the zero values of z and y-->
<size x="39" y="0" z="0"/> <!-- In this example of random walk, I wish I could see the whole space in a single line of the monitoring CLI-->
<site_multiplicity value="2"/> <!-- Indicates that there are two sites per cell-->
@ -31,13 +32,13 @@
<!-- 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>
</space_param>
</parameters>
<!-- Model objects definition -->
<objects>
<object id="dimer" date="" author="">
<object id="dimer" date="1629830000" author="Jean Sirmai">
<arrow x="0" y="0" z="0" site="0" weight="0"/>
<arrow x="0" y="0" z="0" site="1" weight="1"/>
<arrow x="1" y="0" z="0" site="0" weight="1"/>
@ -51,7 +52,7 @@
</objects>
<!-- Space description (initial state) -->
<space id="" date="" author="">
<space id="test" date="1629830000" author="Jean Sirmai">
<arrow x="0" y="0" z="0" site="1" weight="1"/>
<arrow x="1" y="0" z="0" site="0" weight="1"/>
<arrow x="10" y="0" z="0" site="1" weight="1"/>
@ -63,15 +64,15 @@
</space>
<!-- Saved space description (saved states) -->
<savestates id="" date="" author=""> <!-- TODO or NOT TODO (not today...)-->
<space id="" date="" author="">
<savestates id="test" date="1629830000" author="Jean Sirmai"> <!-- TODO or NOT TODO (not today...)-->
<space id="test" date="1629830000" author="Jean Sirmai">
</space>
</savestates>
<!-- Model transitions definition (rules) -->
<transitions id="" date="" author="">
<transition id="0" date="" author="" probability="1"> <!-- moves a dimer to east-->
<transitions id="test" date="1629830000" author="Jean Sirmai">
<transition id="0" date="1629830000" author="Jean Sirmai" probability="1"> <!-- moves a dimer to east-->
<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-->
@ -94,7 +95,11 @@
</transitions>
<!-- Non context-specific tags -->
<ref id="" date="">https://www.a-lec.org</ref>
<quote id="" date="" author="" lang="">Quote</quote>
<ref id="Best reference!" date="1629830000" author="Jean Sirmai" lang="">
https://www.a-lec.org
</ref>
<quote id="Best quote" date="1629830000" author="Jean Sirmai" lang="">
This is a quote.
</quote>
</gem-graph-model>

View File

@ -26,6 +26,11 @@
/* -------------------------------------------------------------------------- */
#define LINE_LENGTH 80
#define LINE_NUMBER 24
/* -------------------------------------------------------------------------- */
struct Command_t {
const char *name;
char* (*execute)(char*, char**, Server_t*);
@ -42,10 +47,3 @@ char *CmdShutdown(char*, char**, Server_t*);
char *CmdHelp(char*, char**, Server_t*);
/* -------------------------------------------------------------------------- */
Command_t cmdList[] =
{
{"help", CmdHelp, "Help command"},
{"model", CmdModel, "Model command"},
{"shutdown", CmdShutdown, "Shutdown command"},
};

View File

@ -24,9 +24,12 @@
#include "../include/base.h"
#endif
#include <dirent.h>
#include <signal.h>
/* -------------------------------------------------------------------------- */
#define MODEL_STRING_SIZE 48
#define MODEL_STRING_SIZE 64
#define MAX_MODEL_NUMBER 1
#define ARROW_NUMBER 6

View File

@ -24,8 +24,46 @@
#include "../include/base.h"
#endif
#include <string.h>
#include <stdlib.h>
#include <libxml/parser.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*);
/* -------------------------------------------------------------------------- */

View File

@ -24,6 +24,8 @@
#include "../include/base.h"
#endif
#include <sys/sysinfo.h>
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //

View File

@ -24,6 +24,13 @@
#include "../include/base.h"
#endif
#include <netdb.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <errno.h>
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //

View File

@ -19,7 +19,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/centers.h"
/* -------------------------------------------------------------------------- */

View File

@ -19,15 +19,12 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/cmds.h"
#include "../include/scheduler.h"
#include "../include/model.h"
#include <sys/socket.h>
#define LINE_LENGTH 80
#define LINE_NUMBER 24
/* -------------------------------------------------------------------------- */
char *CmdModel(char *buf, char **argv, Server_t *args)

View File

@ -19,14 +19,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/model.h"
#include "../include/parsing.h"
#include "../include/arrows.h"
#include "../include/scheduler.h"
#include "../include/model.h"
#include <dirent.h>
#include <signal.h>
static Model_t **loadedModel;
static int loadedModelSize; // begins to 1
@ -37,8 +33,6 @@ static int knownModelSize; // begins to 1
Model_t *lastModel;
Model_t **lastModelAddr;
void ModelSystemDestroy(void);
/* -------------------------------------------------------------------------- */
void printModels(char *buf)

View File

@ -19,51 +19,9 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/parsing.h"
#include "../include/model.h"
#include <string.h>
#include <stdlib.h>
#include <libxml/parser.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);
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Parsing NOTHING (but yeah that prints) //
// -------------------------------------------------------------------------- //
@ -85,11 +43,12 @@ int parseStubFieldXML (xmlDocPtr doc,
// Detect children
if (currentNode->xmlChildrenNode) {
printLog("%s has children\n", ModelTable->table[currentParser].tag);
printLog("%s (stub) has children\n",
ModelTable->table[currentParser].tag);
}
}
printLog("%s: %s\n", ModelTable->table[currentParser].tag,
printLog("%s (stub): %s\n", ModelTable->table[currentParser].tag,
content);
if (!content) {
@ -198,10 +157,48 @@ int parseParentFieldXML (xmlDocPtr doc,
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;
}
printLog("%s parsed\n", ModelTable->table[currentParser].tag);
// -------------------------------------------------------------------------- //
// 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,
@ -226,7 +223,7 @@ int ParseModelXML(Model_t *model)
ParserTableXML_t table[] =
{
// IDENTITY
{(const xmlChar *)"identity", parseParentFieldXML,model},
{(const xmlChar *)"identity", parseParentFieldXML, model},
{(const xmlChar *)"name", parseTextFieldXML, model->name},
{(const xmlChar *)"owner", parseTextFieldXML, model->owner},
@ -237,13 +234,13 @@ int ParseModelXML(Model_t *model)
{(const xmlChar *)"version", parseTextFieldXML, model->version},
// PARAMETERS
{(const xmlChar *)"parameters", parseParentFieldXML, model},
{(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", parseParentFieldXML, model},
{(const xmlChar *)"space_param", parseParentFieldXML, model},
{(const xmlChar *)"dimension", parseStubFieldXML, model},
{(const xmlChar *)"size", parseStubFieldXML, model},
{(const xmlChar *)"site_multiplicity", parseStubFieldXML, model},
@ -253,19 +250,19 @@ int ParseModelXML(Model_t *model)
// OBJECTS
{(const xmlChar *)"objects", parseParentFieldXML, model},
{(const xmlChar *)"object", parseParentFieldXML, model},
{(const xmlChar *)"object", parseParentFieldPropsXML, model},
// SPACE
{(const xmlChar *)"space", parseParentFieldXML, model},
{(const xmlChar *)"space", parseParentFieldPropsXML, model},
// SAVESTATES
{(const xmlChar *)"savestates", parseParentFieldXML, model},
{(const xmlChar *)"savestates", parseParentFieldPropsXML, model},
// TRANSITIONS
{(const xmlChar *)"transitions", parseParentFieldXML, model},
{(const xmlChar *)"transitions", parseParentFieldPropsXML, model},
// TRANSITION
// TODO probability
{(const xmlChar *)"transition", parseParentFieldXML, model},
{(const xmlChar *)"transition", parseParentFieldPropsXML, model},
{(const xmlChar *)"if", parseParentFieldXML, model},
{(const xmlChar *)"then", parseParentFieldXML, model},

View File

@ -19,7 +19,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/scheduler.h"
#include "../include/centers.h"
#include "../include/worker.h"
#include "../include/arrows.h"

View File

@ -19,18 +19,18 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/server.h"
#include "../include/cmds.h"
#include <netdb.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <errno.h>
/* -------------------------------------------------------------------------- */
static Command_t cmdList[] =
{
{"help", CmdHelp, "Help command"},
{"model", CmdModel, "Model command"},
{"shutdown", CmdShutdown, "Shutdown command"},
};
static void *serverMain(void *server);
/* -------------------------------------------------------------------------- */

View File

@ -19,7 +19,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/supervisor.h"
/* -------------------------------------------------------------------------- */

View File

@ -19,7 +19,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/worker.h"
/* -------------------------------------------------------------------------- */