Model create + load cmd
This commit is contained in:
parent
e6ac4a3e91
commit
97868beb39
|
@ -142,6 +142,7 @@ struct {
|
|||
//
|
||||
struct {
|
||||
int id;
|
||||
char *name;
|
||||
int space_xMax;
|
||||
int space_yMax;
|
||||
int space_zMax;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <arpa/inet.h>
|
||||
|
||||
#define SERVER_IP_ADDR "127.0.0.1"
|
||||
#define SERVER_PORT 90190
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
// Socket init function //
|
||||
|
@ -42,7 +43,7 @@ static inline int createSocket(void)
|
|||
static inline int connectSocket(int newSocket)
|
||||
{
|
||||
int effectiveSocket = -1;
|
||||
int serverPort = 90190;
|
||||
int serverPort = SERVER_PORT;
|
||||
struct sockaddr_in remote = {0};
|
||||
|
||||
remote.sin_addr.s_addr = inet_addr(SERVER_IP_ADDR);
|
||||
|
|
15
src/cmds.c
15
src/cmds.c
|
@ -55,7 +55,6 @@ char *CmdModel(char **argv, Server_t *args)
|
|||
}
|
||||
|
||||
if (strncmp(argv[2], "name=", 5) == 0) {
|
||||
// TODO get the model name
|
||||
|
||||
if (strncmp(argv[3], "file=", 5) == 0) {
|
||||
// TODO get the file content (sent by the client) from args
|
||||
|
@ -65,6 +64,8 @@ char *CmdModel(char **argv, Server_t *args)
|
|||
|
||||
// TODO modify model according to things in file
|
||||
|
||||
strcpy(argv[2] + 5, newModel->name);
|
||||
|
||||
strcat(buf, "Model created with id");
|
||||
tempsize = sprintf(temp, " %d\n", newModel->id);
|
||||
strcat(buf, temp);
|
||||
|
@ -84,6 +85,18 @@ char *CmdModel(char **argv, Server_t *args)
|
|||
goto CmdModelEnd;
|
||||
}
|
||||
|
||||
else if (strcmp(argv[1], "load") == 0) {
|
||||
if (!argv[2]) {
|
||||
goto loadEnd;
|
||||
}
|
||||
// TODO get ID
|
||||
loadEnd:
|
||||
// invalid use
|
||||
strcat(buf, "Loads a model structure\n");
|
||||
strcat(buf, "Usage: model load id=ID\n");
|
||||
goto CmdModelEnd;
|
||||
}
|
||||
|
||||
else if (strcmp(argv[1], "delete") == 0) {
|
||||
if (!argv[2]) {
|
||||
goto deleteEnd;
|
||||
|
|
40
src/model.c
40
src/model.c
|
@ -24,6 +24,7 @@
|
|||
#include "../include/scheduler.h"
|
||||
|
||||
#define MAX_MODEL_NUMBER 1
|
||||
#define MAX_MODEL_NAME_SIZE 255
|
||||
#define ARROW_NUMBER 6
|
||||
#define SITE_NUMBER 2
|
||||
#define MAX_CYCLES 10
|
||||
|
@ -46,27 +47,16 @@ static void ModelPrepareArrows(Space_t *globalDrawingSpace,
|
|||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ModelSystemInit(void)
|
||||
{
|
||||
loadedModel = (Model_t**) calloc(MAX_MODEL_NUMBER, sizeof(Model_t*));
|
||||
// XXX read known models from files
|
||||
knownModel = (Model_t**) calloc(MAX_MODEL_NUMBER, sizeof(Model_t));
|
||||
}
|
||||
|
||||
void ModelSystemDestroy(void)
|
||||
{
|
||||
free(loadedModel);
|
||||
free(knownModel);
|
||||
}
|
||||
|
||||
void ModelCreate(Model_t **newModel) // TODO manage deletion and empty slots
|
||||
{
|
||||
knownModel =
|
||||
(Model_t**) realloc(knownModel, ++knownModelIndex * sizeof(Model_t));
|
||||
(Model_t**) realloc(knownModel, ++knownModelIndex * sizeof(Model_t*));
|
||||
knownModel[knownModelIndex] = (Model_t*) calloc(1, sizeof(Model_t));
|
||||
knownModel[knownModelIndex]->id = knownModelIndex;
|
||||
*newModel = knownModel[knownModelIndex];
|
||||
|
||||
knownModel[knownModelIndex]->name =
|
||||
(char *) calloc(1, sizeof(char) * MAX_MODEL_NAME_SIZE);
|
||||
knownModel[knownModelIndex]->space_xMax = XMAX;
|
||||
knownModel[knownModelIndex]->space_yMax = YMAX;
|
||||
knownModel[knownModelIndex]->space_zMax = ZMAX;
|
||||
|
@ -104,6 +94,7 @@ void ModelRun(int id)
|
|||
{
|
||||
// Creating structure for the Scheduler
|
||||
SchedInit(loadedModel[id]->scheduler);
|
||||
printLog("Model %d launched!\n", id);
|
||||
}
|
||||
|
||||
void ModelStop(int id)
|
||||
|
@ -113,9 +104,10 @@ void ModelStop(int id)
|
|||
printLog("Model %d stopped!\n", id);
|
||||
}
|
||||
|
||||
void ModelDelete(Model_t *newModel)
|
||||
void ModelDelete(int id)
|
||||
{
|
||||
return;
|
||||
free(knownModel[id]->name);
|
||||
free(knownModel[id]);
|
||||
}
|
||||
|
||||
void ModelShutdown(void)
|
||||
|
@ -125,6 +117,22 @@ void ModelShutdown(void)
|
|||
}
|
||||
}
|
||||
|
||||
void ModelSystemInit(void)
|
||||
{
|
||||
loadedModel = (Model_t**) calloc(MAX_MODEL_NUMBER, sizeof(Model_t*));
|
||||
// XXX read known models from files
|
||||
knownModel = (Model_t**) calloc(MAX_MODEL_NUMBER, sizeof(Model_t*));
|
||||
}
|
||||
|
||||
void ModelSystemDestroy(void)
|
||||
{
|
||||
for (int i = 0; i < loadedModelIndex; i++) {
|
||||
ModelDelete(i);
|
||||
}
|
||||
free(loadedModel);
|
||||
free(knownModel);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
static void ModelPrepareSpace(Space_t *globalDrawingSpace, Model_t *model)
|
||||
|
|
Loading…
Reference in New Issue