Renamming/changing vocabulary and signatures
This commit is contained in:
parent
eb3f2c29cf
commit
3b04e4c01b
2
Makefile
2
Makefile
|
@ -27,7 +27,7 @@ INCDIR=include
|
||||||
SRCDIR=src
|
SRCDIR=src
|
||||||
DEBDIR=debian
|
DEBDIR=debian
|
||||||
|
|
||||||
SERVEROBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/localworker.o \
|
SERVEROBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/worker.o \
|
||||||
$(BINDIR)/centers.o $(BINDIR)/cmds.o $(BINDIR)/model.o \
|
$(BINDIR)/centers.o $(BINDIR)/cmds.o $(BINDIR)/model.o \
|
||||||
$(BINDIR)/main.o $(BINDIR)/arrows.o
|
$(BINDIR)/main.o $(BINDIR)/arrows.o
|
||||||
CLIOBJ= $(BINDIR)/cli.o
|
CLIOBJ= $(BINDIR)/cli.o
|
||||||
|
|
|
@ -23,27 +23,29 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline int createArrowLock(ArrowArray_t *arrowArray)
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static inline int ArrowsInitLock(ArrowArray_t *arrowArray)
|
||||||
{
|
{
|
||||||
return pthread_spin_init(&arrowArray->lock, PTHREAD_PROCESS_SHARED);
|
return pthread_spin_init(&arrowArray->lock, PTHREAD_PROCESS_SHARED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int destroyArrowLock(ArrowArray_t *arrowArray)
|
static inline int ArrowsDestroyLock(ArrowArray_t *arrowArray)
|
||||||
{
|
{
|
||||||
return pthread_spin_destroy(&arrowArray->lock);
|
return pthread_spin_destroy(&arrowArray->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int acquireArrowLock(ArrowArray_t *arrowArray)
|
static inline int ArrowsAcquireLock(ArrowArray_t *arrowArray)
|
||||||
{
|
{
|
||||||
return pthread_spin_lock(&arrowArray->lock);
|
return pthread_spin_lock(&arrowArray->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int acquireNonBlockingArrowLock(ArrowArray_t *arrowArray)
|
static inline int ArrowsAcquireNonBlockingLock(ArrowArray_t *arrowArray)
|
||||||
{
|
{
|
||||||
return pthread_spin_trylock(&arrowArray->lock);
|
return pthread_spin_trylock(&arrowArray->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int releaseArrowLock(ArrowArray_t *arrowArray)
|
static inline int ArrowsReleaseLock(ArrowArray_t *arrowArray)
|
||||||
{
|
{
|
||||||
return pthread_spin_unlock(&arrowArray->lock);
|
return pthread_spin_unlock(&arrowArray->lock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,36 +41,36 @@
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
struct {
|
struct IntArray_t {
|
||||||
size_t size;
|
size_t size;
|
||||||
int *space;
|
int *space;
|
||||||
} typedef IntArray_t;
|
} typedef IntArray_t;
|
||||||
|
|
||||||
struct {
|
struct Arrow_t {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int z;
|
int z;
|
||||||
int siteId;
|
int siteId;
|
||||||
} typedef Arrow_t;
|
} typedef Arrow_t;
|
||||||
|
|
||||||
struct {
|
struct ArrowArray_t {
|
||||||
size_t size;
|
size_t size;
|
||||||
pthread_spinlock_t lock;
|
pthread_spinlock_t lock;
|
||||||
Arrow_t *array;
|
Arrow_t *array;
|
||||||
} typedef ArrowArray_t;
|
} typedef ArrowArray_t;
|
||||||
|
|
||||||
struct {
|
struct Site_t {
|
||||||
char *label;
|
char *label;
|
||||||
int nArrow;
|
int nArrow;
|
||||||
} typedef Site_t;
|
} typedef Site_t;
|
||||||
|
|
||||||
struct {
|
struct SpaceUnit_t {
|
||||||
int nSite;
|
int nSite;
|
||||||
char *label;
|
char *label;
|
||||||
Site_t *sites;
|
Site_t *sites;
|
||||||
} typedef SpaceUnit_t;
|
} typedef SpaceUnit_t;
|
||||||
|
|
||||||
struct {
|
struct Space_t {
|
||||||
int xMax;
|
int xMax;
|
||||||
int yMax;
|
int yMax;
|
||||||
int zMax;
|
int zMax;
|
||||||
|
@ -83,7 +83,7 @@ struct {
|
||||||
//
|
//
|
||||||
// Scheduler
|
// Scheduler
|
||||||
//
|
//
|
||||||
struct {
|
struct Scheduler_t {
|
||||||
pthread_t id;
|
pthread_t id;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
Space_t *globalDrawingSpace;
|
Space_t *globalDrawingSpace;
|
||||||
|
@ -107,11 +107,11 @@ struct Center_t {
|
||||||
struct Center_t *prev;
|
struct Center_t *prev;
|
||||||
} typedef Center_t;
|
} typedef Center_t;
|
||||||
|
|
||||||
struct {
|
struct Worker_t {
|
||||||
pthread_t id;
|
pthread_t id;
|
||||||
Center_t *localWorkAreaCenter;
|
Center_t *localWorkAreaCenter;
|
||||||
Space_t *globalDrawingSpace;
|
Space_t *globalDrawingSpace;
|
||||||
IntArray_t *conditionTree;
|
IntArray_t *conditionTree; // XXX
|
||||||
ArrowArray_t *arrowArray;
|
ArrowArray_t *arrowArray;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
bool terminated;
|
bool terminated;
|
||||||
|
@ -123,20 +123,20 @@ struct {
|
||||||
//
|
//
|
||||||
// Server
|
// Server
|
||||||
//
|
//
|
||||||
struct {
|
struct Server_t {
|
||||||
pthread_t id;
|
pthread_t id;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
int returnValue;
|
int returnValue;
|
||||||
int sockfd;
|
int sockfd; // Socket file descriptor
|
||||||
} typedef Server_t;
|
} typedef Server_t;
|
||||||
|
|
||||||
struct {
|
struct ServerCommunication_t {
|
||||||
pthread_t id;
|
pthread_t id;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
Server_t *parent;
|
Server_t *associatedServer;
|
||||||
int sockfd;
|
int sockfd; // Socket file descriptor
|
||||||
struct sockaddr_in clientAddr;
|
struct sockaddr_in clientAddr;
|
||||||
socklen_t socklen;
|
socklen_t sockLen;
|
||||||
} typedef ServerCommunication_t;
|
} typedef ServerCommunication_t;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -144,10 +144,10 @@ struct {
|
||||||
//
|
//
|
||||||
// Supervisor
|
// Supervisor
|
||||||
//
|
//
|
||||||
struct {
|
struct Supervisor_t {
|
||||||
pthread_t id;
|
pthread_t id;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
int *workerCreationOccurency;
|
int *workerCreationOccurency; // XXX ???
|
||||||
} typedef Supervisor_t;
|
} typedef Supervisor_t;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -155,32 +155,35 @@ struct {
|
||||||
//
|
//
|
||||||
// Model
|
// Model
|
||||||
//
|
//
|
||||||
struct {
|
struct Model_t {
|
||||||
|
// Identity
|
||||||
int id;
|
int id;
|
||||||
|
bool validated; // true if model has been correctly parsed
|
||||||
char *name;
|
char *name;
|
||||||
char *author;
|
char *author;
|
||||||
time_t date;
|
time_t date;
|
||||||
char *version;
|
char *version;
|
||||||
char *filename;
|
char *filename;
|
||||||
bool validated;
|
// Parameters
|
||||||
int space_xMax;
|
int space_xMax;
|
||||||
int space_yMax;
|
int space_yMax;
|
||||||
int space_zMax;
|
int space_zMax;
|
||||||
int nmaxThread;
|
int nmaxThread;
|
||||||
int nmaxCycles;
|
int nmaxCycles;
|
||||||
int siteNumber;
|
int siteNumber;
|
||||||
|
// Model instance
|
||||||
bool isRunning;
|
bool isRunning;
|
||||||
Scheduler_t *scheduler;
|
Scheduler_t *scheduler;
|
||||||
Supervisor_t *supervisor;
|
Supervisor_t *supervisor;
|
||||||
} typedef Model_t;
|
} typedef Model_t;
|
||||||
|
|
||||||
struct ModelField_t {
|
struct ModelField_t {
|
||||||
bool mandatory;
|
bool mandatory; // true if field must exist in file
|
||||||
char tag[25];
|
char tag[25]; // XML tag attached to that field
|
||||||
char *value;
|
char *destination; // data destination of that field
|
||||||
size_t valueSize;
|
size_t size; // max size of data allowed
|
||||||
struct ModelField_t *son;
|
struct ModelField_t *son; // son in XML tree
|
||||||
struct ModelField_t *next;
|
struct ModelField_t *next; // brother in XML tree
|
||||||
} typedef ModelField_t;
|
} typedef ModelField_t;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -188,7 +191,7 @@ struct ModelField_t {
|
||||||
//
|
//
|
||||||
// Parameters
|
// Parameters
|
||||||
//
|
//
|
||||||
struct {
|
struct Parameters_t {
|
||||||
char *configDir;
|
char *configDir;
|
||||||
char *modelDir;
|
char *modelDir;
|
||||||
char *userDir;
|
char *userDir;
|
||||||
|
|
|
@ -23,6 +23,14 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Add a center to the center list //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
Center_t *CenterAdd(Center_t *anyCenter, Center_t *newCenter);
|
Center_t *CenterAdd(Center_t *anyCenter, Center_t *newCenter);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Remove a center from the center list //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
void CenterRemove(Center_t *oldCenter);
|
void CenterRemove(Center_t *oldCenter);
|
||||||
|
|
|
@ -23,17 +23,25 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//char *CmdHelp(char **, Server_t *);
|
/* -------------------------------------------------------------------------- */
|
||||||
char *CmdModel(char*, char**, Server_t*);
|
|
||||||
char *CmdShutdown(char*, char**, Server_t*);
|
|
||||||
char *CmdHelp(char*, char**, Server_t*);
|
|
||||||
|
|
||||||
struct {
|
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
|
||||||
|
//
|
||||||
|
char *CmdModel(char*, char**, Server_t*);
|
||||||
|
char *CmdShutdown(char*, char**, Server_t*);
|
||||||
|
char *CmdHelp(char*, char**, Server_t*);
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
Command_t cmdList[] =
|
Command_t cmdList[] =
|
||||||
{
|
{
|
||||||
{"help", CmdHelp, "Help command"},
|
{"help", CmdHelp, "Help command"},
|
||||||
|
|
|
@ -23,20 +23,49 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Model init function (and model discovery) //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
void ModelSystemInit(Parameters_t *parameters);
|
void ModelSystemInit(Parameters_t *parameters);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Model stopping function //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
void ModelSystemDestroy(void);
|
void ModelSystemDestroy(void);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Load a model ready to execute //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
int ModelLoad(int id);
|
int ModelLoad(int id);
|
||||||
|
|
||||||
void ModelCreate(Model_t **newModel);
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Unload a model //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
int ModelUnload(int id);
|
||||||
|
|
||||||
int ModelLoad(int id);
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Add a model to the known model list //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
void ModelAddToKnown(Model_t **newModel);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Print informations about all models (known and loaded) to the client //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
void printModels(char *buf);
|
void printModels(char *buf);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Launch a model execution //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
int ModelRun(int id);
|
int ModelRun(int id);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Stop a model execution //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
int ModelStop(int id);
|
int ModelStop(int id);
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Stop and unload all loaded or running model //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
void ModelShutdown(void);
|
void ModelShutdown(void);
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Scheduler init function //
|
// Scheduler init function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
@ -63,7 +65,6 @@ static inline void SchedDestroy(Scheduler_t *scheduler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Scheduler wait function //
|
// Scheduler wait function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
|
@ -23,18 +23,13 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Server init function //
|
// Server init function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void ServerInit(Server_t *server);
|
void ServerInit(Server_t *server);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
// Server destructor function //
|
|
||||||
// -------------------------------------------------------------------------- //
|
|
||||||
static inline void ServerDestroy(Server_t *server)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Server wait function //
|
// Server wait function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Supervisor init function //
|
// Supervisor init function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
@ -48,12 +50,16 @@
|
||||||
|
|
||||||
#define NON_BLOCKING 1
|
#define NON_BLOCKING 1
|
||||||
|
|
||||||
volatile struct winsize terminalSize;
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
//
|
volatile struct winsize TermWindowSize;
|
||||||
// Get a character code from the keyboard
|
|
||||||
//
|
/* -------------------------------------------------------------------------- */
|
||||||
static inline int getch(bool nonBlocking)
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Get a character code from the keyboard //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
static inline int TermGetch(bool nonBlocking)
|
||||||
{
|
{
|
||||||
int buf = 0;
|
int buf = 0;
|
||||||
// old terminal
|
// old terminal
|
||||||
|
@ -112,62 +118,62 @@ static inline int getch(bool nonBlocking)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
// Get the screen size
|
// Get the screen size //
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void getScreenSize(int signum)
|
static inline void TermGetScreenSize(int signum)
|
||||||
{
|
{
|
||||||
// Get current terminal size
|
// Get current terminal size
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminalSize);
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &TermWindowSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
// Set cursor location
|
// Set cursor location //
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void setCursorLocation(char x, char y)
|
static inline void TermSetCursorLocation(char x, char y)
|
||||||
{
|
{
|
||||||
printf("\x1b[%d;%dH", y, x);
|
printf("\x1b[%d;%dH", y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
// Save cursor location
|
// Save cursor location //
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void saveCursorLocation(void)
|
static inline void TermSaveCursorLocation(void)
|
||||||
{
|
{
|
||||||
printf(C_SAVE_CURSORPOS);
|
printf(C_SAVE_CURSORPOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
// Restore cursor location
|
// Restore cursor location //
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void restoreCursorLocation(void)
|
static inline void TermRestoreCursorLocation(void)
|
||||||
{
|
{
|
||||||
printf(C_RESTORE_CURSORPOS);
|
printf(C_RESTORE_CURSORPOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
// Move cursor location to the right
|
// Move cursor location to the right //
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void moveCursorForward(void)
|
static inline void TermMoveCursorForward(void)
|
||||||
{
|
{
|
||||||
printf(C_CURSORRIGHT);
|
printf(C_CURSORRIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
// Move cursor location to the left
|
// Move cursor location to the left //
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void moveCursorBackward(void)
|
static inline void TermMoveCursorBackward(void)
|
||||||
{
|
{
|
||||||
printf(C_CURSORLEFT);
|
printf(C_CURSORLEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
// Clear screen
|
// Clear screen //
|
||||||
//
|
// -------------------------------------------------------------------------- //
|
||||||
static inline void clearScreen(void)
|
static inline void TermClearScreen(void)
|
||||||
{
|
{
|
||||||
printf(C_CLEARSCREEN);
|
printf(C_CLEARSCREEN);
|
||||||
setCursorLocation(1,1);
|
TermSetCursorLocation(1,1);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Worker init function //
|
// Worker init function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
|
@ -23,15 +23,24 @@
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <libxml2/libxml/xmlmemory.h>
|
#include <libxml2/libxml/xmlmemory.h>
|
||||||
#include <libxml2/libxml/parser.h>
|
#include <libxml2/libxml/parser.h>
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static xmlDocPtr currentDocument = NULL;
|
static xmlDocPtr currentDocument = NULL;
|
||||||
static xmlNodePtr currentDocumentRoot = NULL;
|
static xmlNodePtr currentDocumentRoot = NULL;
|
||||||
|
|
||||||
static inline void openCurrentDocument(const char *filename)
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Open and set a document as current document //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
static inline void XmlSetNewDocument(const char *filename)
|
||||||
{
|
{
|
||||||
currentDocument = xmlParseFile(filename);
|
currentDocument = xmlParseFile(filename);
|
||||||
|
|
||||||
|
@ -53,19 +62,29 @@ static inline void openCurrentDocument(const char *filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void closeCurrentDocument(void)
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Close and unset current document //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
static inline void XmlCloseCurrentDocument(void)
|
||||||
{
|
{
|
||||||
xmlFreeDoc(currentDocument);
|
xmlFreeDoc(currentDocument);
|
||||||
currentDocumentRoot = NULL;
|
currentDocumentRoot = NULL;
|
||||||
currentDocument = NULL;
|
currentDocument = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void resetDocumentRoot(void)
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Reset current working root to document root //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
static inline void XmlResetWorkingRoot(void)
|
||||||
{
|
{
|
||||||
currentDocumentRoot = xmlDocGetRootElement(currentDocument);
|
currentDocumentRoot = xmlDocGetRootElement(currentDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parseTag(const char* tagName, char *destination, char destSize)
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Parse content of a given XML tag //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
static inline int XmlParseTag(const char* tagName, char *destination,
|
||||||
|
char destSize)
|
||||||
{
|
{
|
||||||
char *curString;
|
char *curString;
|
||||||
size_t cursor = 0;
|
size_t cursor = 0;
|
||||||
|
@ -103,7 +122,11 @@ static inline int parseTag(const char* tagName, char *destination, char destSize
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Find a working root for a given tag //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
static inline xmlNodePtr findWorkingRoot(const char *tagName,
|
||||||
|
xmlNodePtr curRoot)
|
||||||
{
|
{
|
||||||
xmlNodePtr cur = curRoot;
|
xmlNodePtr cur = curRoot;
|
||||||
xmlNodePtr recur;
|
xmlNodePtr recur;
|
||||||
|
@ -127,7 +150,11 @@ static inline xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int parseTree(ModelField_t *curTree)
|
// -------------------------------------------------------------------------- //
|
||||||
|
// Parse and validate an XML tree from given structural tree //
|
||||||
|
// and current document //
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
static inline int XmlParseTree(ModelField_t *curTree)
|
||||||
{
|
{
|
||||||
int currentOrSonCorrectlyParsed = 0;
|
int currentOrSonCorrectlyParsed = 0;
|
||||||
int curValueLen;
|
int curValueLen;
|
||||||
|
|
90
src/cli.c
90
src/cli.c
|
@ -47,7 +47,7 @@
|
||||||
//
|
//
|
||||||
// Print monitor screen
|
// Print monitor screen
|
||||||
//
|
//
|
||||||
void decorateMonitor(int signum)
|
void CliDecorateMonitor(int signum)
|
||||||
{
|
{
|
||||||
const char titleText[] = "GEM-GRAPH MONITOR";
|
const char titleText[] = "GEM-GRAPH MONITOR";
|
||||||
const char screenTitleText[] = "Model view";
|
const char screenTitleText[] = "Model view";
|
||||||
|
@ -59,95 +59,95 @@ void decorateMonitor(int signum)
|
||||||
const char infosSchedulerText[] = "Scheduler id";
|
const char infosSchedulerText[] = "Scheduler id";
|
||||||
const char infosScThreadsText[] = "+ threads ";
|
const char infosScThreadsText[] = "+ threads ";
|
||||||
|
|
||||||
getScreenSize(signum);
|
TermTermGetScreenSize(signum);
|
||||||
|
|
||||||
clearScreen();
|
TermTermClearScreen();
|
||||||
|
|
||||||
setCursorLocation(1,1);
|
TermSetCursorLocation(1,1);
|
||||||
printf(C_COLOR_NORMAL C_COLOR_WHITE_ON_BLUE);
|
printf(C_COLOR_NORMAL C_COLOR_WHITE_ON_BLUE);
|
||||||
for (int i = 0; i < terminalSize.ws_col; i++) {
|
for (int i = 0; i < TermWindowSize.ws_col; i++) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
setCursorLocation(1,1);
|
TermSetCursorLocation(1,1);
|
||||||
printf("%s%s",
|
printf("%s%s",
|
||||||
C_COLOR_NORMAL C_COLOR_WHITE_ON_BLUE,
|
C_COLOR_NORMAL C_COLOR_WHITE_ON_BLUE,
|
||||||
titleText
|
titleText
|
||||||
);
|
);
|
||||||
|
|
||||||
setCursorLocation(1,2);
|
TermSetCursorLocation(1,2);
|
||||||
printf(C_COLOR_NORMAL C_COLOR_BLACK_ON_GREEN);
|
printf(C_COLOR_NORMAL C_COLOR_BLACK_ON_GREEN);
|
||||||
for (int i = 0; i < terminalSize.ws_col; i++) {
|
for (int i = 0; i < TermWindowSize.ws_col; i++) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
setCursorLocation(1,2);
|
TermSetCursorLocation(1,2);
|
||||||
printf("%s%s",
|
printf("%s%s",
|
||||||
C_COLOR_NORMAL C_COLOR_BLACK_ON_GREEN,
|
C_COLOR_NORMAL C_COLOR_BLACK_ON_GREEN,
|
||||||
screenTitleText
|
screenTitleText
|
||||||
);
|
);
|
||||||
setCursorLocation(terminalSize.ws_col / 3 * 2, 2);
|
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 2);
|
||||||
printf("%s%s",
|
printf("%s%s",
|
||||||
C_COLOR_NORMAL C_COLOR_BLACK_ON_GREEN,
|
C_COLOR_NORMAL C_COLOR_BLACK_ON_GREEN,
|
||||||
infosTitleText
|
infosTitleText
|
||||||
);
|
);
|
||||||
|
|
||||||
setCursorLocation(terminalSize.ws_col / 3 * 2, 4);
|
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 4);
|
||||||
printf("%s%s%s (void)",
|
printf("%s%s%s (void)",
|
||||||
C_COLOR_NORMAL C_COLOR_BLACK_ON_LIGHTGREY,
|
C_COLOR_NORMAL C_COLOR_BLACK_ON_LIGHTGREY,
|
||||||
infosNameText,
|
infosNameText,
|
||||||
C_COLOR_NORMAL
|
C_COLOR_NORMAL
|
||||||
);
|
);
|
||||||
setCursorLocation(terminalSize.ws_col / 3 * 2, 6);
|
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 6);
|
||||||
printf("%s%s%s (void)",
|
printf("%s%s%s (void)",
|
||||||
C_COLOR_BLACK_ON_GREEN,
|
C_COLOR_BLACK_ON_GREEN,
|
||||||
infosStatusText,
|
infosStatusText,
|
||||||
C_COLOR_NORMAL
|
C_COLOR_NORMAL
|
||||||
);
|
);
|
||||||
setCursorLocation(terminalSize.ws_col / 3 * 2, 8);
|
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 8);
|
||||||
printf("%s%s%s (void)",
|
printf("%s%s%s (void)",
|
||||||
C_COLOR_BLACK_ON_LIGHTGREY,
|
C_COLOR_BLACK_ON_LIGHTGREY,
|
||||||
infosOwnerText,
|
infosOwnerText,
|
||||||
C_COLOR_NORMAL
|
C_COLOR_NORMAL
|
||||||
);
|
);
|
||||||
setCursorLocation(terminalSize.ws_col / 3 * 2, 10);
|
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 10);
|
||||||
printf("%s%s%s (void)",
|
printf("%s%s%s (void)",
|
||||||
C_COLOR_BLACK_ON_GREEN,
|
C_COLOR_BLACK_ON_GREEN,
|
||||||
infosSchedulerText,
|
infosSchedulerText,
|
||||||
C_COLOR_NORMAL
|
C_COLOR_NORMAL
|
||||||
);
|
);
|
||||||
setCursorLocation(terminalSize.ws_col / 3 * 2, 12);
|
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 12);
|
||||||
printf("%s%s%s (void)",
|
printf("%s%s%s (void)",
|
||||||
C_COLOR_BLACK_ON_LIGHTGREY,
|
C_COLOR_BLACK_ON_LIGHTGREY,
|
||||||
infosScThreadsText,
|
infosScThreadsText,
|
||||||
C_COLOR_NORMAL
|
C_COLOR_NORMAL
|
||||||
);
|
);
|
||||||
|
|
||||||
setCursorLocation(1, terminalSize.ws_row - 1);
|
TermSetCursorLocation(1, TermWindowSize.ws_row - 1);
|
||||||
printf(C_COLOR_NORMAL C_COLOR_WHITE_ON_BLUE);
|
printf(C_COLOR_NORMAL C_COLOR_WHITE_ON_BLUE);
|
||||||
for (int i = 0; i < terminalSize.ws_col; i++) {
|
for (int i = 0; i < TermWindowSize.ws_col; i++) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
setCursorLocation(1, terminalSize.ws_row);
|
TermSetCursorLocation(1, TermWindowSize.ws_row);
|
||||||
printf(C_COLOR_NORMAL);
|
printf(C_COLOR_NORMAL);
|
||||||
for (int i = 0; i < terminalSize.ws_col; i++) {
|
for (int i = 0; i < TermWindowSize.ws_col; i++) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
setCursorLocation(1, terminalSize.ws_row);
|
TermSetCursorLocation(1, TermWindowSize.ws_row);
|
||||||
printf("%sQ%s Quit\t%sS%s Start/Stop",
|
printf("%sQ%s Quit\t%sS%s Start/Stop",
|
||||||
C_COLOR_NORMAL C_COLOR_REVERSE,
|
C_COLOR_NORMAL C_COLOR_REVERSE,
|
||||||
C_COLOR_NORMAL,
|
C_COLOR_NORMAL,
|
||||||
C_COLOR_REVERSE,
|
C_COLOR_REVERSE,
|
||||||
C_COLOR_NORMAL);
|
C_COLOR_NORMAL);
|
||||||
|
|
||||||
setCursorLocation(1, 3);
|
TermSetCursorLocation(1, 3);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Monitor mode main loop
|
// Monitor mode main loop
|
||||||
//
|
//
|
||||||
int connectedMonitor(int sockfd)
|
int CliConnectedMonitor(int sockfd)
|
||||||
{
|
{
|
||||||
char sendBuff[SEND_BUFFER_SIZE] = {0};
|
char sendBuff[SEND_BUFFER_SIZE] = {0};
|
||||||
char receiveBuff[RECEIVE_BUFFER_SIZE] = {0};
|
char receiveBuff[RECEIVE_BUFFER_SIZE] = {0};
|
||||||
|
@ -157,15 +157,15 @@ int connectedMonitor(int sockfd)
|
||||||
char curChar;
|
char curChar;
|
||||||
int answerLength;
|
int answerLength;
|
||||||
|
|
||||||
signal(SIGWINCH ,decorateMonitor);
|
signal(SIGWINCH ,CliDecorateMonitor);
|
||||||
decorateMonitor(0);
|
CliDecorateMonitor(0);
|
||||||
|
|
||||||
while (!pleaseStop) {
|
while (!pleaseStop) {
|
||||||
// Zeroing buffer
|
// Zeroing buffer
|
||||||
bzero(sendBuff, sizeof(sendBuff));
|
bzero(sendBuff, sizeof(sendBuff));
|
||||||
|
|
||||||
// Read command from terminal
|
// Read command from terminal
|
||||||
curChar = getch(NON_BLOCKING);
|
curChar = TermGetch(NON_BLOCKING);
|
||||||
|
|
||||||
switch (curChar) {
|
switch (curChar) {
|
||||||
case 'q':
|
case 'q':
|
||||||
|
@ -193,7 +193,7 @@ int connectedMonitor(int sockfd)
|
||||||
/* // Invalid command */
|
/* // Invalid command */
|
||||||
/* } */
|
/* } */
|
||||||
}
|
}
|
||||||
clearScreen();
|
TermClearScreen();
|
||||||
printf("%sEnd of monitoring session\n\e[0m", C_COLOR_YELLOW);
|
printf("%sEnd of monitoring session\n\e[0m", C_COLOR_YELLOW);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -202,7 +202,7 @@ int connectedMonitor(int sockfd)
|
||||||
//
|
//
|
||||||
// Main CLI loop
|
// Main CLI loop
|
||||||
//
|
//
|
||||||
void connectedCommandLine(int sockfd)
|
void CliConnectedCommandLine(int sockfd)
|
||||||
{
|
{
|
||||||
char sendBuff[SEND_BUFFER_SIZE] = {0};
|
char sendBuff[SEND_BUFFER_SIZE] = {0};
|
||||||
char receiveBuff[RECEIVE_BUFFER_SIZE] = {0};
|
char receiveBuff[RECEIVE_BUFFER_SIZE] = {0};
|
||||||
|
@ -230,7 +230,7 @@ void connectedCommandLine(int sockfd)
|
||||||
curPosition = 0;
|
curPosition = 0;
|
||||||
continueReadLine = 1;
|
continueReadLine = 1;
|
||||||
historyModifier = -1;
|
historyModifier = -1;
|
||||||
while (continueReadLine && (curChar = getch(0))) {
|
while (continueReadLine && (curChar = TermGetch(0))) {
|
||||||
|
|
||||||
switch (curChar) {
|
switch (curChar) {
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ void connectedCommandLine(int sockfd)
|
||||||
|
|
||||||
if (curLineLength >= 0) {
|
if (curLineLength >= 0) {
|
||||||
|
|
||||||
saveCursorLocation();
|
TermSaveCursorLocation();
|
||||||
|
|
||||||
memmove(sendBuff + curPosition, sendBuff + curPosition + 1,
|
memmove(sendBuff + curPosition, sendBuff + curPosition + 1,
|
||||||
SEND_BUFFER_SIZE);
|
SEND_BUFFER_SIZE);
|
||||||
|
@ -260,15 +260,15 @@ void connectedCommandLine(int sockfd)
|
||||||
sendBuff
|
sendBuff
|
||||||
);
|
);
|
||||||
|
|
||||||
restoreCursorLocation();
|
TermRestoreCursorLocation();
|
||||||
moveCursorBackward();
|
moveCursorBackward();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_ESCAPE_1:
|
case KEY_ESCAPE_1:
|
||||||
if (getch(0) == KEY_ESCAPE_2) {
|
if (TermGetch(0) == KEY_ESCAPE_2) {
|
||||||
|
|
||||||
switch(getch(0)) {
|
switch(TermGetch(0)) {
|
||||||
|
|
||||||
case KEY_ARROW_UP:
|
case KEY_ARROW_UP:
|
||||||
if (historyIndex <= 0)
|
if (historyIndex <= 0)
|
||||||
|
@ -321,13 +321,13 @@ void connectedCommandLine(int sockfd)
|
||||||
|
|
||||||
case KEY_ARROW_RIGHT:
|
case KEY_ARROW_RIGHT:
|
||||||
if (curPosition < curLineLength) {
|
if (curPosition < curLineLength) {
|
||||||
moveCursorForward();
|
TermMoveCursorForward();
|
||||||
curPosition++;
|
curPosition++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_ESCAPE_3:
|
case KEY_ESCAPE_3:
|
||||||
if (getch(0) == KEY_DELETE) {
|
if (TermGetch(0) == KEY_DELETE) {
|
||||||
if (strlen(sendBuff) == 0)
|
if (strlen(sendBuff) == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ void connectedCommandLine(int sockfd)
|
||||||
|
|
||||||
if (curLineLength >= 0) {
|
if (curLineLength >= 0) {
|
||||||
|
|
||||||
saveCursorLocation();
|
TermSaveCursorLocation();
|
||||||
|
|
||||||
memmove(sendBuff + curPosition, sendBuff + curPosition + 1,
|
memmove(sendBuff + curPosition, sendBuff + curPosition + 1,
|
||||||
SEND_BUFFER_SIZE);
|
SEND_BUFFER_SIZE);
|
||||||
|
@ -348,10 +348,10 @@ void connectedCommandLine(int sockfd)
|
||||||
sendBuff
|
sendBuff
|
||||||
);
|
);
|
||||||
|
|
||||||
restoreCursorLocation();
|
TermRestoreCursorLocation();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
moveCursorForward(); // XXX
|
TermMoveCursorForward(); // XXX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -362,9 +362,9 @@ void connectedCommandLine(int sockfd)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (curLineLength < MIN(SEND_BUFFER_SIZE,
|
if (curLineLength < MIN(SEND_BUFFER_SIZE,
|
||||||
terminalSize.ws_col - promptLength - 3)
|
TermWindowSize.ws_col - promptLength - 3)
|
||||||
&& curChar > 0) {
|
&& curChar > 0) {
|
||||||
saveCursorLocation();
|
TermSaveCursorLocation();
|
||||||
|
|
||||||
memmove(sendBuff + curPosition + 1, sendBuff + curPosition,
|
memmove(sendBuff + curPosition + 1, sendBuff + curPosition,
|
||||||
SEND_BUFFER_SIZE);
|
SEND_BUFFER_SIZE);
|
||||||
|
@ -378,8 +378,8 @@ void connectedCommandLine(int sockfd)
|
||||||
sendBuff
|
sendBuff
|
||||||
);
|
);
|
||||||
|
|
||||||
restoreCursorLocation();
|
TermRestoreCursorLocation();
|
||||||
moveCursorForward();
|
TermMoveCursorForward();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -403,7 +403,7 @@ void connectedCommandLine(int sockfd)
|
||||||
|
|
||||||
// Launch monitor mode if asked
|
// Launch monitor mode if asked
|
||||||
if (strcmp(monitorCommand, sendBuff) == 0) {
|
if (strcmp(monitorCommand, sendBuff) == 0) {
|
||||||
connectedMonitor(sockfd);
|
CliConnectedMonitor(sockfd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,10 +465,10 @@ int main(void)
|
||||||
|
|
||||||
printLog("%sConnected to server!\n\n", C_COLOR_GREEN);
|
printLog("%sConnected to server!\n\n", C_COLOR_GREEN);
|
||||||
|
|
||||||
signal(SIGWINCH, getScreenSize);
|
signal(SIGWINCH, TermGetScreenSize);
|
||||||
getScreenSize(0);
|
TermGetScreenSize(0);
|
||||||
|
|
||||||
connectedCommandLine(sockfd);
|
CliConnectedCommandLine(sockfd);
|
||||||
|
|
||||||
// close the socket
|
// close the socket
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
|
|
|
@ -53,7 +53,7 @@ char *CmdModel(char *buf, char **argv, Server_t *args)
|
||||||
// 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
|
||||||
ModelCreate(&newModel);
|
ModelAddToKnown(&newModel);
|
||||||
|
|
||||||
// TODO modify model according to things in file
|
// TODO modify model according to things in file
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,6 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
// Exiting
|
// Exiting
|
||||||
returnValue |= server->returnValue;
|
returnValue |= server->returnValue;
|
||||||
ServerDestroy(server);
|
|
||||||
ModelSystemDestroy();
|
ModelSystemDestroy();
|
||||||
free(server);
|
free(server);
|
||||||
server = NULL;
|
server = NULL;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
#include "../include/centers.h"
|
#include "../include/centers.h"
|
||||||
#include "../include/localworker.h"
|
#include "../include/worker.h"
|
||||||
#include "../include/arrows.h"
|
#include "../include/arrows.h"
|
||||||
|
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
|
@ -103,7 +103,7 @@ static void *schedulerMain(void *scheduler)
|
||||||
centersList = (Center_t*) calloc(1, sizeof(Center_t));
|
centersList = (Center_t*) calloc(1, sizeof(Center_t));
|
||||||
|
|
||||||
// Initiate the arrowArray lock
|
// Initiate the arrowArray lock
|
||||||
if (err = createArrowLock(args->arrowArray), err != 0) { // TODO destroy this
|
if (err = ArrowsInitLock(args->arrowArray), err != 0) { // TODO destroy this
|
||||||
printLog("Impossible to create the arrow array lock (error %d)\n", err);
|
printLog("Impossible to create the arrow array lock (error %d)\n", err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ static void *schedulerMain(void *scheduler)
|
||||||
workArea = NULL;
|
workArea = NULL;
|
||||||
|
|
||||||
// Acquiring lock to consistently read the arrowArray
|
// Acquiring lock to consistently read the arrowArray
|
||||||
if (acquireNonBlockingArrowLock(args->arrowArray)) {
|
if (ArrowsAcquireNonBlockingLock(args->arrowArray)) {
|
||||||
// Random choice of an arrow
|
// Random choice of an arrow
|
||||||
electedArrow =
|
electedArrow =
|
||||||
&args->arrowArray->array[rand() % args->arrowArray->size];
|
&args->arrowArray->array[rand() % args->arrowArray->size];
|
||||||
|
@ -135,7 +135,7 @@ static void *schedulerMain(void *scheduler)
|
||||||
args->globalDrawingSpace->yMax,
|
args->globalDrawingSpace->yMax,
|
||||||
args->globalDrawingSpace->zMax
|
args->globalDrawingSpace->zMax
|
||||||
);
|
);
|
||||||
releaseArrowLock(args->arrowArray);
|
ArrowsReleaseLock(args->arrowArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a free area exists,
|
// If a free area exists,
|
||||||
|
|
|
@ -58,7 +58,7 @@ void *serverCommunicationInstance(void *server)
|
||||||
inet_ntop(AF_INET,
|
inet_ntop(AF_INET,
|
||||||
&args->clientAddr.sin_addr,
|
&args->clientAddr.sin_addr,
|
||||||
clientIP,
|
clientIP,
|
||||||
args->socklen);
|
args->sockLen);
|
||||||
|
|
||||||
// Get port number from client
|
// Get port number from client
|
||||||
clientPort = ntohs(args->clientAddr.sin_port);
|
clientPort = ntohs(args->clientAddr.sin_port);
|
||||||
|
@ -106,7 +106,7 @@ void *serverCommunicationInstance(void *server)
|
||||||
// Execute command by first arg in cmdList
|
// Execute command by first arg in cmdList
|
||||||
for (int i = 0; i < LEN(cmdList); i++) {
|
for (int i = 0; i < LEN(cmdList); i++) {
|
||||||
if (strcmp(cmdList[i].name, argv[0]) == 0) {
|
if (strcmp(cmdList[i].name, argv[0]) == 0) {
|
||||||
cmdList[i].execute(sendBuff, argv, args->parent);
|
cmdList[i].execute(sendBuff, argv, args->associatedServer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,9 +225,9 @@ static void *serverMain(void *server)
|
||||||
ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread
|
ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread
|
||||||
|
|
||||||
// Populate communicator slot
|
// Populate communicator slot
|
||||||
serverSlots[serverSlotIndex].socklen = socklen; // XXX
|
serverSlots[serverSlotIndex].sockLen = socklen; // XXX
|
||||||
serverSlots[serverSlotIndex].sockfd = connfd;
|
serverSlots[serverSlotIndex].sockfd = connfd;
|
||||||
serverSlots[serverSlotIndex].parent = args;
|
serverSlots[serverSlotIndex].associatedServer = args;
|
||||||
|
|
||||||
// Create thread
|
// Create thread
|
||||||
threadStatus = pthread_create(&serverSlots[serverSlotIndex].id,
|
threadStatus = pthread_create(&serverSlots[serverSlotIndex].id,
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include "../include/base.h"
|
#include "../include/base.h"
|
||||||
|
|
||||||
static void *workerMain(void *worker);
|
static void *WorkerMain(void *worker);
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ static void *workerMain(void *worker);
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
void WorkerInit(Worker_t *worker)
|
void WorkerInit(Worker_t *worker)
|
||||||
{
|
{
|
||||||
if (pthread_create(&worker->id, NULL, workerMain, worker)) {
|
if (pthread_create(&worker->id, NULL, WorkerMain, worker)) {
|
||||||
printLog("Worker #%lu can't be initialized!\n", worker->id);
|
printLog("Worker #%lu can't be initialized!\n", worker->id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ void WorkerInit(Worker_t *worker)
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// Scheduler thread main function //
|
// Scheduler thread main function //
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
static void *workerMain(void *worker)
|
static void *WorkerMain(void *worker)
|
||||||
{
|
{
|
||||||
Worker_t *args;
|
Worker_t *args;
|
||||||
int a = rand()%__INT_MAX__;
|
int a = rand()%__INT_MAX__;
|
Loading…
Reference in New Issue