From 7af3a044a06acac25ee0c27d2f6e8d9f113f3eb3 Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Thu, 10 Mar 2011 20:09:03 +0000 Subject: [PATCH] new header and code files --- executablecode/Makefile | 2 +- executablecode/generated_src/main.c | 5 +++++ executablecode/src/asyncchannel.c | 19 +++++++++++++++++ executablecode/src/asyncchannel.h | 29 +++++++++++++++++++++++++ executablecode/src/message.c | 25 ++++++++++++++++++++++ executablecode/src/message.h | 23 ++++++++++++++++++++ executablecode/src/request.c | 20 +++++++++++++++++ executablecode/src/request.h | 33 +++++++++++++++++++++++++++++ executablecode/src/syncchannel.c | 19 +++++++++++++++++ executablecode/src/syncchannel.h | 19 +++++++++++++++++ 10 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 executablecode/src/asyncchannel.c create mode 100644 executablecode/src/asyncchannel.h create mode 100644 executablecode/src/message.c create mode 100644 executablecode/src/message.h create mode 100644 executablecode/src/request.c create mode 100644 executablecode/src/request.h create mode 100644 executablecode/src/syncchannel.c create mode 100644 executablecode/src/syncchannel.h diff --git a/executablecode/Makefile b/executablecode/Makefile index 2a513488f8..c76b0fa419 100755 --- a/executablecode/Makefile +++ b/executablecode/Makefile @@ -20,7 +20,7 @@ OBJDIR = lib MODULE = run SRCS_generated_DIR = generated_src/ include Makefile.src -SRCS_base = src/transactions.c src/syncchannel.c src/timers.c src/myerrors.c src/debug.c src/storeevents.c +SRCS_base = src/request.c src/message.c src/myerrors.c src/debug.c src/syncchannel.c src/asyncchannel.c SRCS_base_DIR = . SRCS_base_DIRSRC = src/ OBJS_executor = $(SRCS_base:%.c=lib/%.o) diff --git a/executablecode/generated_src/main.c b/executablecode/generated_src/main.c index 13f6f76924..510fee7c6d 100644 --- a/executablecode/generated_src/main.c +++ b/executablecode/generated_src/main.c @@ -4,9 +4,11 @@ #include <stdlib.h> #include "request.h" +#include "syncchannel.h" #include "debug.h" +syncchannel * syncchannels[1]; void *send(void *arg) { @@ -62,6 +64,9 @@ void *receive(void *arg) { int main(int argc, char * argv[]) { + + syncchannels[0] = getNewSyncchannel("outch", "inch"); + pthread_t sender; pthread_t receiver0, receiver1; diff --git a/executablecode/src/asyncchannel.c b/executablecode/src/asyncchannel.c new file mode 100644 index 0000000000..6bc670b17b --- /dev/null +++ b/executablecode/src/asyncchannel.c @@ -0,0 +1,19 @@ +#include <stdlib.h> + +#include "asyncchannel.h" +#include "myerrors.h" + + +asyncchannel *getNewAsyncchannel(char *outname, char *inname, int nbOfParams) { + asyncchannel * asyncch = (asyncchannel *)(malloc(sizeof(struct asyncchannel))); + if (asyncch == NULL) { + criticalError("Allocation of asyncchannel failed"); + } + asyncch->inname = inname; + asyncch->outname = outname; + return asyncch; +} + +void destroyAsyncchannel(asyncchannel *asyncch) { + free(asyncch); +} diff --git a/executablecode/src/asyncchannel.h b/executablecode/src/asyncchannel.h new file mode 100644 index 0000000000..6d0d37bb1f --- /dev/null +++ b/executablecode/src/asyncchannel.h @@ -0,0 +1,29 @@ +#ifndef ASYNCCHANNEL_H +#define ASYNCCHANNEL_H + + +#include "request.h" +#include "message.h" + +struct asyncchannel; + + +struct asyncchannel { + char *outname; + char *inname; + int isInfinite; + int isBlocking; + int maxNbOfMssages; + request* outWaitQueue; + request* inWaitQueue; + setOfMessages *pendingMessages; + int nbOfParams; +}; + +typedef struct asyncchannel asyncchannel; + +asyncchannel *getNewAsyncchannel(char *inname, char *outname, int nbOfParams); +void destroyAsyncchannel(asyncchannel *syncch); + + +#endif diff --git a/executablecode/src/message.c b/executablecode/src/message.c new file mode 100644 index 0000000000..6c7eef7200 --- /dev/null +++ b/executablecode/src/message.c @@ -0,0 +1,25 @@ + +#include <stdlib.h> +#include <unistd.h> + +#include "message.h" +#include "myerrors.h" + + +message *getNewMessage(int nbOfParams, int *params[]) { + int i; + + message *msg = (message *)(malloc(sizeof(struct message) + nbOfParams*sizeof(int *) )); + if (msg == NULL) { + criticalError("Allocation of request failed"); + } + msg->nbOfParams = nbOfParams; + for(i=0; i<nbOfParams; i++) { + msg->params[i] = params[i]; + } + return msg; +} + +void *destroyMessage(message *msg) { + free(msg); +} diff --git a/executablecode/src/message.h b/executablecode/src/message.h new file mode 100644 index 0000000000..f67236fd9d --- /dev/null +++ b/executablecode/src/message.h @@ -0,0 +1,23 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + + +struct message; + +struct setOfMessages { + struct message *head; +}; + +typedef struct setOfMessages setOfMessages; + +struct message { + int nbOfParams; + int *params[]; +}; + +typedef struct message message; + +message * getNewMessage(int nbOfParams, int *params[]); +void *destroyMessage(message *msg); + +#endif diff --git a/executablecode/src/request.c b/executablecode/src/request.c new file mode 100644 index 0000000000..12c38cca93 --- /dev/null +++ b/executablecode/src/request.c @@ -0,0 +1,20 @@ + +#include <stdlib.h> +#include <unistd.h> + +#include "request.h" +#include "myerrors.h" + + +request *getNewRequest(int type) { + request *req = (request *)(malloc(sizeof(struct request))); + if (req == NULL) { + criticalError("Allocation of request failed"); + } + req->type = type; + return req; +} + +void *destroyRequest(request *req) { + free(req); +} diff --git a/executablecode/src/request.h b/executablecode/src/request.h new file mode 100644 index 0000000000..cb4d0d009b --- /dev/null +++ b/executablecode/src/request.h @@ -0,0 +1,33 @@ +#ifndef REQUEST_H +#define REQUEST_H + +#define SYNC_REQUEST 0 +#define SYNC_REQUEST_WITH_DELAY 1 +#define ASYNC_REQUEST 2 +#define ASYNC_REQUEST_WITH_DELAY 3 +#define DELAY 4 + +struct request; + +struct setOfRequests { + struct request *head; +}; + +typedef struct setOfRequests setOfRequests; + +struct request { + int type; + setOfRequests* listOfRequests; + int hasDelay; + long delay; + int delayElapsed; + int nbOfParams; + int *params[]; +}; + +typedef struct request request; + +request * getNewRequest(int type); +void *destroyRequest(request *req); + +#endif diff --git a/executablecode/src/syncchannel.c b/executablecode/src/syncchannel.c new file mode 100644 index 0000000000..e345e7c1da --- /dev/null +++ b/executablecode/src/syncchannel.c @@ -0,0 +1,19 @@ +#include <stdlib.h> + +#include "syncchannel.h" +#include "myerrors.h" + + +syncchannel *getNewSyncchannel(char *outname, char *inname) { + syncchannel * syncch = (syncchannel *)(malloc(sizeof(struct syncchannel))); + if (syncch == NULL) { + criticalError("Allocation of request failed"); + } + syncch->inname = inname; + syncch->outname = outname; + return syncch; +} + +void destroySyncchannel(syncchannel *syncch) { + free(syncch); +} diff --git a/executablecode/src/syncchannel.h b/executablecode/src/syncchannel.h new file mode 100644 index 0000000000..b9d9baea40 --- /dev/null +++ b/executablecode/src/syncchannel.h @@ -0,0 +1,19 @@ +#ifndef SYNCCHANNEL_H +#define SYNCCHANNEL_H + + +#include "request.h" + +struct syncchannel { + char *outname; + char *inname; + request* inWaitQueue; + request* outWaitQueue; +}; + +typedef struct syncchannel syncchannel; + +syncchannel *getNewSyncchannel(char *inname, char *outname); +void destroySyncchannel(syncchannel *syncch); + +#endif -- GitLab