Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2016-10-26 14:36:33 +0000
committerHenrik Rentz-Reichert2016-11-07 08:47:26 +0000
commitcfec11455b4c5d2580af682a7712b55095a53bba (patch)
tree801787f79039398681c120398f591cd1a14aa359 /runtime
parenta488ef8e6dd1be4f685c8284c4a2f45aa1cc21ef (diff)
downloadorg.eclipse.etrice-cfec11455b4c5d2580af682a7712b55095a53bba.tar.gz
org.eclipse.etrice-cfec11455b4c5d2580af682a7712b55095a53bba.tar.xz
org.eclipse.etrice-cfec11455b4c5d2580af682a7712b55095a53bba.zip
Refactored messaging to static message allocation
[runtime.cpp] Added StaticMessageMemory and IMemory class for static messaging. [generator.cpp] Adjusted generator to static messaging. [runtime.cpp.tests] Adjusted test cases to fit the runtime changes and added testcase for the StaticMessageMemory. [ui.runtime] updated zipped contents Change-Id: I92adb0c610555b0b954365611714a5a6f873605c
Diffstat (limited to 'runtime')
-rw-r--r--runtime/org.eclipse.etrice.modellib.cpp/model/GenericPhysical.etphys6
-rw-r--r--runtime/org.eclipse.etrice.modellib.cpp/model/TimingService.room22
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageService.cpp59
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageService.h66
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IMessageMemory.h34
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IMessageService.h3
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.cpp16
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.h17
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp6
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp72
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h23
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.cpp45
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.h45
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ReplicatedActorClassBase.cpp8
14 files changed, 228 insertions, 194 deletions
diff --git a/runtime/org.eclipse.etrice.modellib.cpp/model/GenericPhysical.etphys b/runtime/org.eclipse.etrice.modellib.cpp/model/GenericPhysical.etphys
index 27f442b9c..caec2ba71 100644
--- a/runtime/org.eclipse.etrice.modellib.cpp/model/GenericPhysical.etphys
+++ b/runtime/org.eclipse.etrice.modellib.cpp/model/GenericPhysical.etphys
@@ -14,7 +14,7 @@ PhysicalModel room.generic.physical {
interval = 100ms
prio = 0
stacksize = 1024
- msgblocksize = 64
+ msgblocksize = 128
msgpoolsize = 100
}
@@ -22,7 +22,7 @@ PhysicalModel room.generic.physical {
execmode = blocked
prio = 0
stacksize = 1024
- msgblocksize = 64
+ msgblocksize = 128
msgpoolsize = 100
}
@@ -31,7 +31,7 @@ PhysicalModel room.generic.physical {
interval = 100ms
prio = 0
stacksize = 1024
- msgblocksize = 64
+ msgblocksize = 128
msgpoolsize = 100
}
}
diff --git a/runtime/org.eclipse.etrice.modellib.cpp/model/TimingService.room b/runtime/org.eclipse.etrice.modellib.cpp/model/TimingService.room
index 4229d72c8..c1e56cd71 100644
--- a/runtime/org.eclipse.etrice.modellib.cpp/model/TimingService.room
+++ b/runtime/org.eclipse.etrice.modellib.cpp/model/TimingService.room
@@ -248,13 +248,7 @@ RoomModel room.basic.service.timing {
incoming startTimer {
"if (status==0){
status=ET_TIMER_RUNNING | ET_TIMER_PERIODIC;
- DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- PTimer::getMessageString(PTimer::IN_startTimer));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(),PTimer::IN_startTimer,
- &time,
- sizeof(uint32)));
- }
+ startTimer_impl(time);
}
"
}
@@ -262,13 +256,7 @@ RoomModel room.basic.service.timing {
incoming startTimeout {
"if (status==0){
status = ET_TIMER_RUNNING;
- DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- PTimer::getMessageString(PTimer::IN_startTimeout));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(),PTimer::IN_startTimeout,
- &time,
- sizeof(uint32)));
- }
+ startTimeout_impl(time);
}
"
}
@@ -291,11 +279,7 @@ RoomModel room.basic.service.timing {
"
if (status!=0){
status=0;
- DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- PTimer::getMessageString(PTimer::IN_kill));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(),PTimer::IN_kill));
- }
+ kill_impl();
}
"
}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageService.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageService.cpp
deleted file mode 100644
index a52351d1b..000000000
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageService.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Juergen Haug (initial contribution)
- *
- *******************************************************************************/
-
-#include "common/messaging/AbstractMessageService.h"
-#include <string>
-
-namespace etRuntime {
-
-AbstractMessageService::AbstractMessageService(IRTObject* parent, const std::string& name, int node, int thread) :
- RTObject(parent, name),
- m_address(node, thread, 0),
- m_messageQueue(this, "Queue"),
- m_messageDispatcher(this, m_address.createInc(), "Dispatcher") {
-}
-
-Address AbstractMessageService::getFreeAddress() {
- return m_messageDispatcher.getFreeAddress();
-}
-
-void AbstractMessageService::freeAddress(const Address& addr) {
- m_messageDispatcher.freeAddress(addr);
-}
-
-void AbstractMessageService::addMessageReceiver(IMessageReceiver& receiver) {
- m_messageDispatcher.addMessageReceiver(receiver);
-}
-
-void AbstractMessageService::removeMessageReceiver(IMessageReceiver& receiver) {
- m_messageDispatcher.removeMessageReceiver(receiver);
-}
-
-void AbstractMessageService::addPollingMessageReceiver(IMessageReceiver& receiver) {
- m_messageDispatcher.addPollingMessageReceiver(receiver);
-}
-
-void AbstractMessageService::removePollingMessageReceiver(IMessageReceiver& receiver) {
- m_messageDispatcher.removePollingMessageReceiver(receiver);
-}
-
-void AbstractMessageService::receive(const Message* msg) {
- if (msg != 0) {
- m_messageQueue.push(const_cast<Message*>(msg));
- }
-}
-
-std::string AbstractMessageService::toString() const {
- return getName() + " " + getAddress().toID();
-}
-
-}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageService.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageService.h
deleted file mode 100644
index 08032faf6..000000000
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageService.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * CONTRIBUTORS:
- * Juergen Haug (initial contribution)
- *
- *******************************************************************************/
-#ifndef SRC_COMMON_MESSAGING_ABSTRACTMESSAGESERVICE_H_
-#define SRC_COMMON_MESSAGING_ABSTRACTMESSAGESERVICE_H_
-
-#include "common/messaging/Address.h"
-#include "common/messaging/IMessageService.h"
-#include "common/messaging/MessageDispatcher.h"
-#include "common/messaging/MessageSeQueue.h"
-#include <string>
-
-namespace etRuntime {
-
-class AbstractMessageService: public RTObject, public IMessageService {
-
-public:
- virtual ~AbstractMessageService() {}
-
- virtual const Address& getAddress() const { return m_address; }
-
- virtual Address getFreeAddress();
-
- virtual void freeAddress(const Address& addr);
-
- virtual void addMessageReceiver(IMessageReceiver& receiver);
- virtual void removeMessageReceiver(IMessageReceiver& receiver);
-
- virtual void addPollingMessageReceiver(IMessageReceiver& receiver);
- virtual void removePollingMessageReceiver(IMessageReceiver& receiver);
- virtual void receive(const Message* msg);
-
-protected:
- AbstractMessageService(IRTObject* parent, const std::string& name, int node, int thread);
-
- MessageSeQueue& getMessageQueue() {
- return m_messageQueue;
- }
- MessageDispatcher& getMessageDispatcher() {
- return m_messageDispatcher;
- }
-
- std::string toString() const;
-
-private:
- // TODO: add internal message queue for less locks (faster thread internal
- // messaging)
- Address m_address;
- MessageSeQueue m_messageQueue;
- MessageDispatcher m_messageDispatcher;
-
- AbstractMessageService();
- AbstractMessageService(AbstractMessageService const&);
- AbstractMessageService& operator=(AbstractMessageService const&);
-};
-
-}
-#endif /* SRC_COMMON_MESSAGING_ABSTRACTMESSAGESERVICE_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IMessageMemory.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IMessageMemory.h
new file mode 100644
index 000000000..78656443a
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IMessageMemory.h
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2016 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Jan Belle (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef SRC_COMMON_MESSAGING_IMESSAGEMEMORY_H_
+#define SRC_COMMON_MESSAGING_IMESSAGEMEMORY_H_
+
+#include "common/messaging/Message.h"
+#include "common/messaging/IRTObject.h"
+
+namespace etRuntime {
+
+class IMessageMemory : virtual IRTObject {
+public:
+ virtual ~IMessageMemory() {}
+
+ // returns a buffer of the specified size in bytes
+ // use the placement constructor to create objects and call the destructor explicitly
+ virtual Message* getMessageBuffer(size_t size) = 0;
+ // frees the buffer
+ virtual void returnMessageBuffer(const Message* buffer) = 0;
+};
+
+} /* namespace etRuntime */
+
+#endif /* SRC_COMMON_MESSAGING_IMESSAGEMEMORY_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IMessageService.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IMessageService.h
index 145d767d7..a2871c0f4 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IMessageService.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IMessageService.h
@@ -39,6 +39,9 @@ public:
virtual void addPollingMessageReceiver(IMessageReceiver& receiver) = 0;
virtual void removePollingMessageReceiver(IMessageReceiver& receiver) = 0;
+ virtual Message* getMessageBuffer(int size) = 0;
+ virtual void returnMessageBuffer(const Message* buffer) = 0;
+
// TODO Thread
// void setThread(Thread thread);
//
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.cpp
index d9e5df646..69705f972 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.cpp
@@ -18,20 +18,6 @@
namespace etRuntime {
-Message::Message(const Address& addr, int evtId, const void* dataToCopy, std::size_t dataSize) :
- m_address(addr),
- m_evtId(evtId),
- m_next(0),
- m_dataSize(0),
- m_data(0){
- if(dataToCopy != 0 && dataSize > 0){
- m_data = std::malloc(dataSize);
- if(m_data != 0){
- m_dataSize = dataSize;
- std::memcpy(m_data, dataToCopy, dataSize);
- }
- }
-}
Message::Message(const Address& addr, int evtId, void* dataPtr) :
m_address(addr),
m_evtId(evtId),
@@ -49,8 +35,6 @@ Message::Message(const Address& addr, int evtId) :
Message::~Message() {
m_evtId = 0;
m_next = 0;
- if(m_dataSize > 0)
- std::free(m_data);
m_data = 0;
m_dataSize = 0;
}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.h
index b97802808..e4564c41a 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Message.h
@@ -25,12 +25,10 @@ class Message {
public:
- // Messages with data TODO MessageBuffer
- Message(const Address& addr, int evtId, const void* dataToCopy, std::size_t dataSize);
Message(const Address& addr, int evtId, void* dataPtr);
Message(const Address& addr, int evtId);
- ~Message();
+ virtual ~Message();
const Address& getAddress() const {
return m_address;
@@ -72,5 +70,18 @@ private:
};
+template<class T>
+class DataMessage : public Message {
+public:
+ DataMessage(const Address& addr, int evtId, const T& dataToCopy) :
+ Message(addr, evtId, &m_data), m_data(dataToCopy) {}
+private:
+ T m_data;
+
+ DataMessage(void);
+ DataMessage(DataMessage const&);
+ DataMessage& operator=(DataMessage const&);
+};
+
} /* namespace etRuntime */
#endif /* MESSAGE_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp
index e8035b12a..f5250be98 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp
@@ -12,6 +12,7 @@
#include "common/messaging/Message.h"
#include "common/messaging/MessageDispatcher.h"
+#include "common/messaging/IMessageService.h"
namespace etRuntime {
@@ -82,9 +83,10 @@ void MessageDispatcher::receive(const Message* msg) {
} else if (receiver != 0) {
receiver->receive(msg);
// TODO: error handling for not found addresses
-
- delete msg;
}
+
+ msg->~Message();
+ dynamic_cast<IMessageService*>(getParent())->returnMessageBuffer(msg);
}
std::string MessageDispatcher::toString() const {
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp
index e2d74934c..62d62d66f 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp
@@ -10,7 +10,6 @@
*
*******************************************************************************/
-#include "common/messaging/MessageDispatcher.h"
#include "common/messaging/MessageSeQueue.h"
#include "common/messaging/MessageService.h"
#include "common/messaging/MessageServiceController.h"
@@ -21,12 +20,16 @@
namespace etRuntime {
-MessageService::MessageService(IRTObject* parent, IMessageService::ExecMode mode, int node, int thread, const std::string& name, int priority) :
- AbstractMessageService(parent, name, node, thread),
+MessageService::MessageService(IRTObject* parent, IMessageService::ExecMode mode, int node, int thread, const std::string& name,
+ IMessageMemory* memory, int priority) :
+ RTObject(parent, name),
m_running(false),
m_execMode(mode),
m_lastMessageTimestamp(0),
- m_pollingMessage(getMessageDispatcher().getAddress(), 0) {
+ m_address(node, thread, 0),
+ m_messageQueue(this, "Queue"),
+ m_messageDispatcher(this, m_address.createInc(), "Dispatcher"),
+ m_messageMemory(memory) {
etTime interval;
interval.sec = 0;
@@ -35,12 +38,15 @@ MessageService::MessageService(IRTObject* parent, IMessageService::ExecMode mode
}
MessageService::MessageService(IRTObject* parent, IMessageService::ExecMode mode, etTime interval, int node, int thread,
- const std::string& name, int priority) :
- AbstractMessageService(parent, name, node, thread),
+ const std::string& name, IMessageMemory* memory, int priority) :
+ RTObject(parent, name),
m_running(false),
m_execMode(mode),
m_lastMessageTimestamp(0),
- m_pollingMessage(getMessageDispatcher().getAddress(), 0) {
+ m_address(node, thread, 0),
+ m_messageQueue(this, "Queue"),
+ m_messageDispatcher(this, m_address.createInc(), "Dispatcher"),
+ m_messageMemory(memory) {
MessageService_init(interval, priority);
}
@@ -67,12 +73,18 @@ void MessageService::MessageService_init(etTime interval, int priority) {
}
MessageService::~MessageService() {
+ while(m_messageQueue.getSize() > 0) {
+ const Message* msg = m_messageQueue.pop();
+ msg->~Message();
+ returnMessageBuffer(msg);
+ }
etMutex_destruct(&m_mutex);
etSema_destruct(&m_executionSemaphore);
etThread_destruct(&m_thread);
if (m_execMode == IMessageService::POLLED || m_execMode == IMessageService::MIXED) {
etTimer_destruct(&m_timer);
}
+ delete m_messageMemory;
}
void MessageService::start() {
@@ -86,7 +98,7 @@ void MessageService::start() {
void MessageService::run() {
while (m_running) {
etMutex_enter(&m_mutex);
- const Message* msg = getMessageQueue().pop(); // get next Message from Queue
+ const Message* msg = m_messageQueue.pop(); // get next Message from Queue
etMutex_leave(&m_mutex);
if (msg == 0) {
// no message in queue -> wait till Thread is notified
@@ -94,7 +106,7 @@ void MessageService::run() {
} else {
//TODO: set timestamp
// m_lastMessageTimestamp = System.currentTimeMillis();
- getMessageDispatcher().receive(msg);
+ m_messageDispatcher.receive(msg);
}
}
@@ -103,14 +115,16 @@ void MessageService::run() {
void MessageService::receive(const Message* msg) {
etMutex_enter(&m_mutex);
- AbstractMessageService::receive(msg);
+ if (msg != 0) {
+ m_messageQueue.push(const_cast<Message*>(msg));
+ }
etSema_wakeup(&m_executionSemaphore);
etMutex_leave(&m_mutex);
}
Address MessageService::getFreeAddress() {
etMutex_enter(&m_mutex);
- Address address = AbstractMessageService::getFreeAddress();
+ Address address = m_messageDispatcher.getFreeAddress();
etMutex_leave(&m_mutex);
return address;
@@ -118,34 +132,51 @@ Address MessageService::getFreeAddress() {
void MessageService::freeAddress(const Address& addr) {
etMutex_enter(&m_mutex);
- AbstractMessageService::freeAddress(addr);
+ m_messageDispatcher.freeAddress(addr);
etMutex_leave(&m_mutex);
}
void MessageService::addMessageReceiver(IMessageReceiver& receiver) {
etMutex_enter(&m_mutex);
- AbstractMessageService::addMessageReceiver(receiver);
+ m_messageDispatcher.addMessageReceiver(receiver);
etMutex_leave(&m_mutex);
}
void MessageService::removeMessageReceiver(IMessageReceiver& receiver) {
etMutex_enter(&m_mutex);
- AbstractMessageService::removeMessageReceiver(receiver);
+ m_messageDispatcher.removeMessageReceiver(receiver);
etMutex_leave(&m_mutex);
}
void MessageService::addPollingMessageReceiver(IMessageReceiver& receiver) {
etMutex_enter(&m_mutex);
- AbstractMessageService::addPollingMessageReceiver(receiver);
+ m_messageDispatcher.addPollingMessageReceiver(receiver);
etMutex_leave(&m_mutex);
}
void MessageService::removePollingMessageReceiver(IMessageReceiver& receiver) {
etMutex_enter(&m_mutex);
- AbstractMessageService::removePollingMessageReceiver(receiver);
+ m_messageDispatcher.removePollingMessageReceiver(receiver);
+ etMutex_leave(&m_mutex);
+}
+
+Message* MessageService::getMessageBuffer(int size) {
+ etMutex_enter(&m_mutex);
+ Message* buffer = m_messageMemory->getMessageBuffer(size);
+ etMutex_leave(&m_mutex);
+ return buffer;
+}
+
+void MessageService::returnMessageBuffer(const Message* buffer) {
+ etMutex_enter(&m_mutex);
+ m_messageMemory->returnMessageBuffer(buffer);
etMutex_leave(&m_mutex);
}
+std::string MessageService::toString() const {
+ return getName() + " " + getAddress().toID();
+}
+
void MessageService::terminate() {
if (m_execMode == IMessageService::POLLED || m_execMode == IMessageService::MIXED) {
etTimer_stop(&m_timer);
@@ -160,7 +191,14 @@ void MessageService::terminate() {
// called by osal timer, thread ?
void MessageService::pollingTask() {
if (m_running) {
- receive(&m_pollingMessage);
+ Message* pollingMessage = getMessageBuffer(sizeof(Message));
+ if (pollingMessage) {
+ new (pollingMessage) Message(m_messageDispatcher.getAddress(), 0);
+ receive(pollingMessage);
+ }
+ else {
+ // TODO JB: error handling for pollingMessage == NULL
+ }
}
}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h
index f27ce2e93..388226079 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h
@@ -13,10 +13,11 @@
#ifndef MESSAGESERVICE_H_
#define MESSAGESERVICE_H_
-#include "common/messaging/AbstractMessageService.h"
-
#include "common/messaging/IMessageService.h"
#include "common/messaging/Message.h"
+#include "common/messaging/Address.h"
+#include "common/messaging/StaticMessageMemory.h"
+#include "common/messaging/MessageDispatcher.h"
#include "etDatatypes.h"
#include "osal/etMutex.h"
#include "osal/etSema.h"
@@ -26,7 +27,7 @@
namespace etRuntime {
-class MessageService: public AbstractMessageService {
+class MessageService: public RTObject, public IMessageService {
public:
@@ -34,8 +35,8 @@ public:
POLLED, BLOCKED, MIXED
};
- MessageService(IRTObject* parent, IMessageService::ExecMode mode, int node, int thread, const std::string& name, int priority = 0);
- MessageService(IRTObject* parent, IMessageService::ExecMode mode, etTime interval, int node, int thread, const std::string& name, int priority = 0);
+ MessageService(IRTObject* parent, IMessageService::ExecMode mode, int node, int thread, const std::string& name, IMessageMemory* memory, int priority = 0);
+ MessageService(IRTObject* parent, IMessageService::ExecMode mode, etTime interval, int node, int thread, const std::string& name, IMessageMemory* memory, int priority = 0);
virtual ~MessageService();
void run();
@@ -54,6 +55,12 @@ public:
virtual void removePollingMessageReceiver(IMessageReceiver& receiver);
virtual void receive(const Message* msg);
+ Message* getMessageBuffer(int size);
+ void returnMessageBuffer(const Message* buffer);
+
+ const Address& getAddress(void) const { return m_address; }
+ std::string toString() const;
+
protected:
long getLastMessageTimestamp() const {
@@ -75,13 +82,17 @@ private:
etBool m_running;
IMessageService::ExecMode m_execMode;
long m_lastMessageTimestamp;
- Message m_pollingMessage;
etMutex m_mutex;
etSema m_executionSemaphore;
etThread m_thread;
etTimer m_timer;
+ Address m_address;
+ MessageSeQueue m_messageQueue;
+ MessageDispatcher m_messageDispatcher;
+ IMessageMemory* m_messageMemory;
+
void MessageService_init(etTime interval, int priority); // common ctor
MessageService();
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.cpp
new file mode 100644
index 000000000..c7f73870d
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.cpp
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2016 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Jan Belle (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "common/messaging/StaticMessageMemory.h"
+
+namespace etRuntime {
+
+StaticMessageMemory::StaticMessageMemory(IRTObject* parent, const std::string& name, size_t size, int number) :
+ RTObject(parent, name), m_size(size), m_msgPool(NULL, "memory"), m_buffer(0) {
+ m_buffer = new uint8_t[m_size * number];
+ uint8_t* ptr = m_buffer;
+ for(int i = 0; i < number; ++i) {
+ Message* msg = new (ptr) Message(Address::EMPTY, 0);
+ m_msgPool.push(msg);
+ ptr += m_size;
+ }
+}
+
+StaticMessageMemory::~StaticMessageMemory() {
+ delete[] m_buffer;
+}
+
+Message* StaticMessageMemory::getMessageBuffer(size_t size) {
+ if(size <= m_size && m_msgPool.getSize() > 0) {
+ return const_cast<Message*>(m_msgPool.pop());
+ }
+ else {
+ return 0;
+ }
+}
+
+void StaticMessageMemory::returnMessageBuffer(const Message* buffer) {
+ m_msgPool.push(const_cast<Message*>(buffer));
+}
+
+} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.h
new file mode 100644
index 000000000..56b5eabb1
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.h
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2016 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Jan Belle (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef SRC_COMMON_MESSAGING_STATICMESSAGEMEMORY_H_
+#define SRC_COMMON_MESSAGING_STATICMESSAGEMEMORY_H_
+
+#include "common/messaging/IMessageMemory.h"
+#include "common/messaging/RTObject.h"
+#include "common/messaging/MessageSeQueue.h"
+
+namespace etRuntime {
+
+class StaticMessageMemory : public IMessageMemory, public RTObject {
+public:
+ StaticMessageMemory(IRTObject* parent, const std::string& name, size_t size, int number);
+ virtual ~StaticMessageMemory();
+
+ // returns a buffer of the specified size in bytes
+ Message* getMessageBuffer(size_t size);
+ // frees the buffer
+ void returnMessageBuffer(const Message* buffer);
+
+ // return the size in bytes of one message buffer
+ int getBufferSize(void) { return m_size; }
+ // returns the number of free message buffers
+ int getMessagePoolSize(void) { return m_msgPool.getSize(); }
+
+private:
+ size_t m_size;
+ MessageSeQueue m_msgPool;
+ uint8_t* m_buffer;
+};
+
+} /* namespace etRuntime */
+
+#endif /* SRC_COMMON_MESSAGING_STATICMESSAGEMEMORY_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ReplicatedActorClassBase.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ReplicatedActorClassBase.cpp
index 52be7ecc7..fc9747cc0 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ReplicatedActorClassBase.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ReplicatedActorClassBase.cpp
@@ -19,8 +19,9 @@ ReplicatedActorClassBase::ReplicatedActorClassBase(IRTObject* parent, const std:
}
ReplicatedActorClassBase::~ReplicatedActorClassBase() {
- for(std::vector<ActorClassBase*>::iterator it = m_items.begin(); it != m_items.end(); it++)
+ for(std::vector<ActorClassBase*>::iterator it = m_items.begin(); it != m_items.end(); ++it) {
delete *it;
+ }
}
void ReplicatedActorClassBase::createSubActors(int number) {
@@ -33,12 +34,13 @@ void ReplicatedActorClassBase::createSubActors(int number) {
}
void ReplicatedActorClassBase::initialize() {
- for(std::vector<ActorClassBase*>::iterator it = m_items.begin(); it != m_items.end(); it++)
+ for(std::vector<ActorClassBase*>::iterator it = m_items.begin(); it != m_items.end(); ++it) {
(*it)->initialize();
+ }
}
void ReplicatedActorClassBase::setProbesActive(bool recursive, bool active) {
- for(std::vector<ActorClassBase*>::iterator it = m_items.begin(); it != m_items.end(); it++)
+ for(std::vector<ActorClassBase*>::iterator it = m_items.begin(); it != m_items.end(); ++it)
(*it)->setProbesActive(recursive, active);
}

Back to the top