Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/common/messaging')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c41
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h17
2 files changed, 53 insertions, 5 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
index 3755d2107..59e205e99 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.c
@@ -17,20 +17,55 @@
#include "debugging/etLogger.h"
#include "debugging/etMSCLogger.h"
+
+
+/*
+ * initialize message service with all needed data and initialize message queue and message pool
+ *
+ */
void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher){
ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "init")
+
+ /* copy init data to self */
self->messageBuffer.buffer = buffer;
self->messageBuffer.maxBlocks = maxBlocks;
self->messageBuffer.blockSize = blockSize;
self->msgDispatcher = msgDispatcher;
- etMessageQueue_init(&self->messagePool);
- etMessageQueue_init(&self->messageQueue);
-
+ /* copy init queue and pool */
+ etMessageQueue_init( &(self->messagePool) ); /* the pool is also a queue*/
+ etMessageQueue_init( &(self->messageQueue) );
etMessageService_initMessagePool(self);
+
+ /* init mutexes and semaphores */
+ etMutex_construct( &(self->poolMutex) );
+ etMutex_construct( &(self->queueMutex) );
+ etSema_construct( &(self->executionSemaphore) );
+
ET_MSC_LOGGER_SYNC_EXIT
}
+void etMessageService_start(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "start")
+ etThread_construct( &(self->thread) );
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etMessageService_stop(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "stop")
+ etThread_destruct( &(self->thread) );
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etMessageService_destroy(etMessageService* self){
+ ET_MSC_LOGGER_SYNC_ENTRY("etMessageService", "destroy")
+ etMutex_destruct( &(self->poolMutex) );
+ etMutex_destruct( &(self->queueMutex) );
+ etSema_destruct( &(self->executionSemaphore) );
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+
/*
* initialize message pool with block buffer
* all blocks are added to pool
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h
index 0303bbf0c..f91cb3f82 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/messaging/etMessageService.h
@@ -17,6 +17,8 @@
#include "etDatatypes.h"
#include "messaging/etMessageQueue.h"
#include "messaging/etMessageReceiver.h"
+#include "platform/etPlatform.h"
+
typedef struct etBuffer{
etUInt8 *buffer;
@@ -29,20 +31,31 @@ typedef struct etMessageService {
etMessageQueue messagePool;
etBuffer messageBuffer;
etDispatcherReceiveMessage msgDispatcher;
+ etThread thread;
+ etMutex poolMutex;
+ etMutex queueMutex;
+ etSema executionSemaphore; /* sempahore for waiting and waking up the execution */
} etMessageService;
+
+/* lifecycle functions to startup, execute and shutdown the message service */
void etMessageService_init(etMessageService* self, etUInt8* buffer, etUInt16 maxBlocks, etUInt16 blockSize, etDispatcherReceiveMessage msgDispatcher);
+void etMessageService_start(etMessageService* self);
+void etMessageService_execute(etMessageService* self);
+void etMessageService_stop(etMessageService* self);
+void etMessageService_destroy(etMessageService* self);
+/* initialization of message pool */
void etMessageService_initMessagePool(etMessageService* self);
+/* message queue interface for push and pop messages */
void etMessageService_pushMessage(etMessageService* self, etMessage* msg);
etMessage* etMessageService_popMessage(etMessageService* self);
+/* message pool interface to get and return (push and pop) messages */
etMessage* etMessageService_getMessageBuffer(etMessageService* self, etUInt16 size);
void etMessageService_returnMessageBuffer(etMessageService* self, etMessage* buffer);
-void etMessageService_execute(etMessageService* self);
-
/* functions for debug and service information */
etInt16 etMessageService_getMessagePoolLowWaterMark(etMessageService* self);

Back to the top