summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Karlitschek2012-08-24 05:50:30 (EDT)
committerPeter Karlitschek2012-08-24 05:50:30 (EDT)
commita7b552130d968124bbb54c5a80b2fb0fec431e91 (patch)
treee539c41534d09c9b99e5caacd30c29fd425e5c5c
parent679e0c2c17c0044448910fcf16359fd9d38693da (diff)
downloadorg.eclipse.etrice-a7b552130d968124bbb54c5a80b2fb0fec431e91.zip
org.eclipse.etrice-a7b552130d968124bbb54c5a80b2fb0fec431e91.tar.gz
org.eclipse.etrice-a7b552130d968124bbb54c5a80b2fb0fec431e91.tar.bz2
cpp runtime continuedrefs/changes/28/8128/1
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCFilter.cpp43
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCFilter.h43
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.cpp96
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.h63
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageReceiver.h42
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IRTObject.cpp16
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IRTObject.h28
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp72
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.h41
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageSeQueue.cpp59
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageSeQueue.h44
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp97
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h68
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp21
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h125
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTObject.cpp54
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTObject.h36
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTServices.cpp39
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTServices.h44
19 files changed, 1031 insertions, 0 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCFilter.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCFilter.cpp
new file mode 100644
index 0000000..b50cc8e
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCFilter.cpp
@@ -0,0 +1,43 @@
+/*
+ * MSCFilter.cpp
+ *
+ * Created on: 16.08.2012
+ * Author: karlitsc
+ */
+
+#include "MSCFilter.h"
+
+namespace etRuntime {
+
+MSCFilter::MSCFilter() :
+ filterList() {
+}
+MSCFilter::~MSCFilter() {
+}
+
+void MSCFilter::addFilter(FilterItem filter) {
+ filterList.push_back(filter);
+}
+
+bool MSCFilter::applyTo(std::string text) {
+ if (filterList.empty())
+ return true; // no filters -> all messages will be logged
+ std::list<FilterItem>::iterator it = filterList.begin();
+ for ( ; it != filterList.end(); ++it) {
+ if (text.compare((*it).filter) == 0)
+ return !(*it).exclude;
+ }
+ return false;
+}
+
+std::string MSCFilter::reduceString(std::string string) {
+ if (filterList.size() == 1)
+ //TODO: filtering with regular expression
+ // return string.replaceFirst(filterList.front().filter, "");
+ return string;
+ else
+ return string;
+}
+
+} /* namespace etRuntime */
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCFilter.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCFilter.h
new file mode 100644
index 0000000..c1e34c4
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCFilter.h
@@ -0,0 +1,43 @@
+/*
+ * MSCFilter.h
+ *
+ * Created on: 16.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef MSCFILTER_H_
+#define MSCFILTER_H_
+
+#include <list>
+#include <string>
+
+namespace etRuntime {
+
+class MSCFilter {
+public:
+ class FilterItem{
+ public:
+ FilterItem(std::string filter_, bool exclude_)
+ : exclude(exclude_),
+ filter(filter_)
+ {};
+ bool exclude;
+ std::string filter;
+ private:
+ FilterItem();
+ };
+
+ MSCFilter();
+ virtual ~MSCFilter();
+
+ void addFilter(FilterItem filter);
+ bool applyTo(std::string text);
+ std::string reduceString(std::string string);
+
+private:
+ std::list<FilterItem> filterList;
+
+};
+
+} /* namespace etRuntime */
+#endif /* MSCFILTER_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.cpp
new file mode 100644
index 0000000..2208db4
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.cpp
@@ -0,0 +1,96 @@
+/*
+ * MSCLogger.cpp
+ *
+ * Created on: 16.08.2012
+ * Author: karlitsc
+ */
+
+#include "MSCLogger.h"
+
+namespace etRuntime {
+
+MSCLogger::MSCLogger()
+: commandList(),
+ filter(0),
+ path(),
+ msc_name(),
+is_open(false)
+{
+}
+
+MSCLogger::~MSCLogger() {
+ delete filter;
+ filter = 0;
+}
+
+void MSCLogger::setMSC(std::string msc_name_, std::string path_) {
+ msc_name = msc_name_;
+ path = path_;
+ delete filter;
+ filter = new MSCFilter();
+}
+
+void MSCLogger::addMessageAsyncOut(std::string source, std::string target,
+ std::string message) {
+ createLine(source, " >-- ", target, message);
+}
+
+void MSCLogger::addMessageAsyncIn(std::string source, std::string target,
+ std::string message) {
+ createLine(source, " --> ", target, message);
+}
+
+void MSCLogger::addMessageSyncCall(std::string source, std::string target,
+ std::string message) {
+ createLine(source, " ==> ", target, message);
+}
+
+void MSCLogger::addMessageSyncReturn(std::string source, std::string target,
+ std::string message) {
+ createLine(source, " <== ", target, message);
+}
+
+void MSCLogger::addActorState(std::string actor, std::string state) {
+ if (filter->applyTo(actor))
+ getCommandList().push_back("\t" + filter->reduceString(actor) + " >>> " + state);
+}
+
+void MSCLogger::createLine(std::string source, std::string mid, std::string target, std::string message) {
+ if (filter->applyTo(source) && filter->applyTo(target)) {
+ getCommandList().push_back( "\t"+filter->reduceString(source)+mid+filter->reduceString(target)+ " " + message);
+ }
+}
+
+void MSCLogger::close() {
+ if (is_open) {
+// try {
+ //TODO: error handling
+ // Create file
+ std::ofstream myfile;
+ myfile.open (std::string("tmp/log/" + path + msc_name + ".seq").c_str(), std::ios::out);
+ if (myfile.is_open()) { /* ok, proceed with output */
+ saveMSCforTrace2UML(myfile);
+ myfile.close();
+ }
+// };
+ }
+ is_open = false;
+}
+
+void MSCLogger::saveMSCforTrace2UML(std::ofstream& out) {
+ //try {
+ //TODO: errorhandling
+ out << "#generated MSC for Trace2UML";
+ out << std::endl ;
+ std::list<std::string>::iterator it = getCommandList().begin();
+ for ( ; it != getCommandList().end(); ++it) {
+ out << *it << std::endl;
+ }
+// } catch (IOException e) {
+// System.err.println("Error: " + e.getMessage());
+// }
+
+}
+
+
+}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.h
new file mode 100644
index 0000000..330dc80
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/MSCLogger.h
@@ -0,0 +1,63 @@
+/*
+ * MSCLogger.h
+ *
+ * Created on: 16.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef MSCLOGGER_H_
+#define MSCLOGGER_H_
+
+#include <string>
+#include <list>
+#include <iostream>
+#include <fstream>
+#include "MSCFilter.h"
+
+namespace etRuntime {
+
+class MSCLogger {
+public:
+ MSCLogger();
+ virtual ~MSCLogger();
+
+ void setMSC(std::string msc_name_, std::string path_);
+
+ //TODO synchronized
+ void open() {is_open = true; };
+ //TODO synchronized
+ void addMessageAsyncOut(std::string source, std::string target, std::string message);
+ //TODO synchronized
+ void addMessageAsyncIn(std::string source, std::string target, std::string message);
+ //TODO synchronized
+ void addMessageSyncCall(std::string source, std::string target, std::string message);
+ //TODO synchronized
+ void addMessageSyncReturn(std::string source, std::string target, std::string message);
+ //TODO synchronized
+ void addActorState(std::string actor, std::string state);
+ //TODO synchronized
+ void close();
+
+ std::list<std::string> getCommandList() { return commandList; };
+ MSCFilter* getMSCFilter(){ return filter; };
+
+private:
+ void createLine(std::string source, std::string mid, std::string target, std::string message);
+ void saveMSCforTrace2UML(std::ofstream& out);
+
+ std::list<std::string> commandList;
+ MSCFilter* filter;
+
+ std::string path;
+ std::string msc_name ;
+ bool is_open;
+
+ MSCLogger(const MSCLogger& right);
+ MSCLogger& operator=(const MSCLogger& right);
+
+
+};
+
+
+} /* namespace etRuntime */
+#endif /* MSCLOGGER_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageReceiver.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageReceiver.h
new file mode 100644
index 0000000..191b51d
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/AbstractMessageReceiver.h
@@ -0,0 +1,42 @@
+/*
+ * AbstractMessageReceiver.h
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef ABSTRACTMESSAGERECEIVER_H_
+#define ABSTRACTMESSAGERECEIVER_H_
+
+#include "common/messaging/Address.h"
+#include "common/messaging/IMessageReceiver.h"
+#include "common/messaging/RTObject.h"
+#include <string>
+
+namespace etRuntime {
+
+class AbstractMessageReceiver: public RTObject, public IMessageReceiver {
+
+public:
+ Address getAddress() const {
+ return address_;
+ }
+ virtual ~AbstractMessageReceiver();
+
+protected:
+ AbstractMessageReceiver(IRTObject* parent, Address address, std::string name) :
+ RTObject(parent, name), IMessageReceiver(), address_(address) {
+
+ }
+
+private:
+ Address address_;
+
+ AbstractMessageReceiver();
+ AbstractMessageReceiver(const AbstractMessageReceiver& right);
+ AbstractMessageReceiver& operator=(const AbstractMessageReceiver& right);
+};
+
+
+}
+#endif /* ABSTRACTMESSAGERECEIVER_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IRTObject.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IRTObject.cpp
new file mode 100644
index 0000000..158cb2a
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IRTObject.cpp
@@ -0,0 +1,16 @@
+/*
+ * IRTObject.cpp
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+
+#include "IRTObject.h"
+
+namespace etRuntime {
+
+const std::string IRTObject::NO_NAME = "<no name>";
+
+}
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IRTObject.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IRTObject.h
new file mode 100644
index 0000000..6f242a5
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/IRTObject.h
@@ -0,0 +1,28 @@
+/*
+ * IRTObject.h
+ *
+ * Created on: 16.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef IRTOBJECT_H_
+#define IRTOBJECT_H_
+
+#include <string>
+
+namespace etRuntime {
+
+class IRTObject {
+
+public:
+ static const char PATH_DELIM = '/';
+ static const char PATHNAME_DELIM = '_';
+ static const std::string NO_NAME;
+
+ std::string getInstancePath();
+ std::string getInstancePathName();
+};
+
+}
+
+#endif /* IRTOBJECT_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
new file mode 100644
index 0000000..7b38e04
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp
@@ -0,0 +1,72 @@
+/*
+ * MessageDispatcher.cpp
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#include "MessageDispatcher.h"
+
+namespace etRuntime {
+
+
+MessageDispatcher::~MessageDispatcher() {
+}
+
+MessageDispatcher::MessageDispatcher(IRTObject* parent, Address addr, std::string name)
+: RTObject(parent, name) ,
+ IMessageReceiver(),
+ m_local_map(),
+ m_thread_map(),
+ m_node_map(),
+ m_address(addr)
+{};
+
+void MessageDispatcher::addMessageReceiver(IMessageReceiver& receiver){
+if (! receiver.getAddress().isValid() )
+ return;
+
+// TODO: does only work same thread (else)
+if (receiver.getAddress().m_nodeID != m_address.m_nodeID){
+ m_node_map[receiver.getAddress().m_objectID] = &receiver;
+}
+else if(receiver.getAddress().m_threadID != m_address.m_threadID){
+ m_thread_map[receiver.getAddress().m_threadID] = &receiver;
+}
+else {
+ m_local_map[receiver.getAddress().m_objectID] = &receiver;
+}
+};
+
+void MessageDispatcher::receive(Message* msg) {
+// TODO: does only work same thread (else)
+ //TODO: assert msg != 0
+IMessageReceiver* receiver = 0;
+std::map<int, IMessageReceiver*>::iterator it;
+if (msg->getAddress().m_nodeID != m_address.m_nodeID){
+ it = m_node_map.find(msg->getAddress().m_objectID);
+ if (it != m_node_map.end() ) {
+ receiver = (*it).second;
+ }
+}
+else if(msg->getAddress().m_threadID != m_address.m_threadID){
+ it = m_thread_map.find(msg->getAddress().m_objectID);
+ if (it != m_thread_map.end() ) {
+ receiver = (*it).second;
+ }
+}
+else {
+ // Same node, same thread -> local call Dispatch Map
+ it = m_local_map.find(msg->getAddress().m_objectID);
+ if (it != m_local_map.end() ) {
+ receiver = (*it).second;
+ }
+}
+if (receiver!=0)
+{
+ receiver->receive(msg);
+ // TODO: error handling for not found addresses
+}
+}
+} /* namespace etRuntime */
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.h
new file mode 100644
index 0000000..a18c718
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.h
@@ -0,0 +1,41 @@
+/*
+ * MessageDispatcher.h
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef MESSAGEDISPATCHER_H_
+#define MESSAGEDISPATCHER_H_
+
+#include "common/messaging/IMessageReceiver.h"
+#include "common/messaging/IRTObject.h"
+#include "common/messaging/RTObject.h"
+#include <map>
+#include <string>
+
+namespace etRuntime {
+
+class MessageDispatcher : public RTObject, public IMessageReceiver {
+public:
+ virtual ~MessageDispatcher();
+ MessageDispatcher(IRTObject* parent, Address addr, std::string name);
+ void addMessageReceiver(IMessageReceiver& receiver);
+ void receive(Message* msg);
+ Address getAddress() { return m_address; };
+
+private:
+ std::map<int, IMessageReceiver*> m_local_map;
+ std::map<int, IMessageReceiver*> m_thread_map;
+ std::map<int, IMessageReceiver*> m_node_map;
+ Address m_address;
+
+ MessageDispatcher();
+ MessageDispatcher(const MessageDispatcher& right);
+ MessageDispatcher& operator=(const MessageDispatcher& right);
+};
+
+} /* namespace etRuntime */
+#endif /* MESSAGEDISPATCHER_H_ */
+
+
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageSeQueue.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageSeQueue.cpp
new file mode 100644
index 0000000..632464f
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageSeQueue.cpp
@@ -0,0 +1,59 @@
+/*
+ * MessageSeQueue.cpp
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#include "MessageSeQueue.h"
+
+namespace etRuntime {
+
+
+MessageSeQueue::~MessageSeQueue() {
+ m_first = 0;
+ m_last = 0;
+}
+
+MessageSeQueue::MessageSeQueue(IRTObject* parent, std::string name)
+ : RTObject(parent, name),
+ m_first(0),
+ m_last(0),
+ m_highWaterMark(0),
+ m_size(0)
+{
+}
+
+void MessageSeQueue::push(Message* msg) {
+ // TODO: optimize queue for concurrent push / pop
+ if (m_first == 0) {
+ m_first = m_last = msg;
+ } else {
+ m_last->setNext(msg);
+ m_last = msg;
+ }
+ if (++m_size > m_highWaterMark)
+ m_highWaterMark++;
+
+}
+
+Message* MessageSeQueue::pop() {
+ // TODO: optimize queue for concurrent push / pop
+ Message* pop_msg = m_first;
+ if (m_first == 0) {
+ return m_first;
+ }
+ if (m_first->getNext() == 0) {
+ m_first = m_last = 0;
+ } else {
+ m_first = m_first->getNext();
+ }
+
+ pop_msg->setNext(0);
+ m_size--;
+
+ return pop_msg;
+}
+
+
+} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageSeQueue.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageSeQueue.h
new file mode 100644
index 0000000..d99acda
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageSeQueue.h
@@ -0,0 +1,44 @@
+/*
+ * MessageSeQueue.h
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef MESSAGESEQUEUE_H_
+#define MESSAGESEQUEUE_H_
+
+#include "common/messaging/RTObject.h"
+#include <string>
+#include "common/messaging/Message.h"
+
+namespace etRuntime {
+
+class MessageSeQueue: public RTObject {
+public:
+ MessageSeQueue(IRTObject* parent, std::string name);
+ virtual ~MessageSeQueue();
+
+ void push(Message* msg);
+ Message* pop();
+
+ long getSize() const {return m_size; }
+ Message* getFirst() const {return m_first; }
+ Message* getLast() const { return m_last; }
+ boolean isNotEmpty() const { return m_last != 0; }
+ long getHightWaterMark() const { return m_highWaterMark; }
+
+private:
+ Message* m_first;
+ Message* m_last;
+ long m_highWaterMark;
+ long m_size;
+
+ MessageSeQueue();
+ MessageSeQueue(const MessageSeQueue& right);
+ MessageSeQueue& operator=(const MessageSeQueue& right);
+
+};
+
+} /* namespace etRuntime */
+#endif /* MESSAGESEQUEUE_H_ */
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
new file mode 100644
index 0000000..5e01704
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp
@@ -0,0 +1,97 @@
+/*
+ * MessageService.cpp
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#include "MessageService.h"
+
+namespace etRuntime {
+
+MessageService::MessageService(IRTObject* parent, Address addr, std::string name, int priority)
+ : // super("MessageService "+name),
+ IMessageReceiver(),
+ m_parent(parent),
+ m_name(name),
+ m_running(false),
+ m_messageQueue(this, "Queue"),
+ m_messageDispatcher( this,
+ Address(addr.m_nodeID, addr.m_threadID, addr.m_objectID + 1),
+ "Dispatcher"),
+ m_address(addr),
+ m_lastMessageTimestamp(0) {
+
+ // check and set priority
+// assert priority >= Thread.MIN_PRIORITY : ("priority smaller than Thread.MIN_PRIORITY (1)");
+// assert priority <= Thread.MAX_PRIORITY : ("priority bigger than Thread.MAX_PRIORITY (10)");
+// this.setPriority(priority);
+
+}
+
+MessageService::~MessageService() {
+ m_parent = 0;
+}
+
+void MessageService::run() {
+ m_running = true;
+ while (m_running) {
+ pollOneMessage();
+ }
+}
+
+//TODO: synchronized
+void MessageService::receive(Message* msg) {
+ if (msg != 0) {
+ m_messageQueue.push(msg);
+ //TODO
+ //notifyAll(); // wake up thread to compute message
+ }
+}
+
+std::string MessageService::getInstancePath() {
+ std::string path = PATH_DELIM + m_name;
+
+ if (m_parent != 0)
+ path = m_parent->getInstancePath() + path;
+
+ return path;
+}
+
+std::string MessageService::getInstancePathName() {
+ std::string path = PATHNAME_DELIM + m_name;
+
+ if (m_parent != 0)
+ path = m_parent->getInstancePathName() + path;
+
+ return path;
+}
+
+// TODO: synchronized
+void MessageService::terminate() {
+ if (m_running) {
+ m_running = false;
+ //TODO:
+ // notifyAll();
+ }
+}
+//TODO: synchronized
+void MessageService::pollOneMessage() {
+ Message* msg = m_messageQueue.pop(); // get next Message from Queue
+ if (msg == 0) {
+ //TODO:
+ // no message in queue -> wait till Thread is notified
+// try {
+// wait();
+// } catch (InterruptedException e) {
+// }
+ } else {
+ //TODO: set timestamp
+ // m_lastMessageTimestamp = System.currentTimeMillis();
+ m_messageDispatcher.receive(msg);
+ }
+
+}
+
+
+} /* namespace etRuntime */
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
new file mode 100644
index 0000000..9f87095
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h
@@ -0,0 +1,68 @@
+/*
+ * MessageService.h
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef MESSAGESERVICE_H_
+#define MESSAGESERVICE_H_
+
+#include <string>
+#include "common/messaging/MessageDispatcher.h"
+#include "common/messaging/Address.h"
+#include "MessageSeQueue.h"
+
+namespace etRuntime {
+
+//TODO: implementation missing yet for threads
+
+class MessageService: public IMessageReceiver {
+public:
+ virtual ~MessageService();
+
+ MessageService(IRTObject* parent, Address addr, std::string name, int priority = 0);
+
+ Address getAddress() { return m_address; } ;
+
+ void run();
+
+ //TODO: synchronized
+ void receive(Message* msg);
+ //TODO: synchronized
+ MessageDispatcher& getMessageDispatcher() { return m_messageDispatcher; }
+ std::string getInstancePath();
+ std::string getInstancePathName();
+
+ //TODO: synchronized
+ void terminate();
+
+ // protected methods for sole use by test cases
+protected:
+ MessageSeQueue& getMessageQueue() { return m_messageQueue; }
+ //TODO: synchronized
+ long getLastMessageTimestamp() { return m_lastMessageTimestamp; }
+
+private:
+ //TODO: synchronized
+ void pollOneMessage();
+
+ IRTObject* m_parent;
+ std::string m_name;
+ boolean m_running;
+
+ // TODO: add internal message queue for less locks (faster thread internal
+ // messaging)
+ MessageSeQueue m_messageQueue;
+ MessageDispatcher m_messageDispatcher;
+ Address m_address;
+ long m_lastMessageTimestamp;
+
+ MessageService();
+ MessageService(const MessageService& right);
+ MessageService& operator=(const MessageService& right);
+
+};
+
+} /* namespace etRuntime */
+#endif /* MESSAGESERVICE_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp
new file mode 100644
index 0000000..b06ffdb
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp
@@ -0,0 +1,21 @@
+/*
+ * MessageServiceController.cpp
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#include "MessageServiceController.h"
+
+namespace etRuntime {
+
+MessageServiceController::MessageServiceController() {
+ // TODO Auto-generated constructor stub
+
+}
+
+MessageServiceController::~MessageServiceController() {
+ // TODO Auto-generated destructor stub
+}
+
+} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h
new file mode 100644
index 0000000..5d0b8bb
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h
@@ -0,0 +1,125 @@
+/*
+ * MessageServiceController.h
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef MESSAGESERVICECONTROLLER_H_
+#define MESSAGESERVICECONTROLLER_H_
+
+#include "common/messaging/MessageService.h"
+#include <list>
+#include <string>
+#include <iostream>
+
+namespace etRuntime {
+
+class MessageServiceController {
+public:
+ virtual ~MessageServiceController();
+
+ MessageServiceController(/*IRTObject parent*/)
+ : m_messageServiceList(),
+ m_running(false) {
+ // TODO: Who is parent of MessageServices and Controller?
+ // this.parent = parent;
+ }
+
+ void addMsgSvc(MessageService msgSvc) {
+ // TODOTS: Who is parent of MessageServices ?
+ //TODO assert
+ //assert(msgSvc.getAddress().m_threadID == m_messageServiceList.size());
+ m_messageServiceList.push_back(msgSvc);
+ }
+
+ MessageService getMsgSvc(int threadID) {
+ //TODO
+ //assert(threadID < m_messageServiceList.size());
+ return m_messageServiceList.get(threadID);
+ }
+
+ //the connectAll method connects all messageServices
+ //it is included for test purposes
+ //currently it is not called
+ void connectAll() {
+ for (size_t i = 0; i < m_messageServiceList.size(); i++) {
+ MessageDispatcher& dispatcher = getMsgSvc(i).getMessageDispatcher();
+ for (int j = 0; j < m_messageServiceList.size(); j++) {
+ if (i != j) {
+ dispatcher.addMessageReceiver(RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(j));
+ }
+ }
+ }
+ }
+
+ void start() {
+ // start all message services
+ for (MessageService msgSvc : m_messageServiceList) {
+ msgSvc.start();
+ // TODOTS: start in order of priorities
+ }
+ m_running = true;
+ }
+
+ void stop() {
+ //dumpThreads("org.eclipse.etrice.runtime.java.messaging.MessageServiceController.stop()");
+ terminate();
+ waitTerminate();
+ }
+
+ /**
+ * waitTerminate waits blocking for all MessageServices to terminate
+ * ! not threadsafe !
+ */
+public:
+ void waitTerminate() {
+ for (MessageService msgSvc : m_messageServiceList) {
+ try {
+ msgSvc.join();
+ } catch (InterruptedException e1) {
+ }
+ }
+ }
+
+protected:
+ void dumpThreads(std::string msg) {
+ std::cout << "<<< begin dump threads <<<" << std::endl;
+ std::cout << "=== " << msg << std::endl;
+ //TODO dump stack traces
+// Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
+// for (Thread thread : traces.keySet()) {
+// std::cout << "thread " << thread.getName() << std::endl;
+// StackTraceElement[] elements = traces.get(thread);
+// int n = 2;
+// if (elements.length < n)
+// n = elements.length;
+// for (int i = 0; i < n; i++) {
+// std::cout << " " << elements[i].toString() << std::endl;
+// }
+// }
+ std::cout <<(">>> end dump threads >>>");
+ }
+
+private:
+ void terminate() {
+ if (!m_running) {
+ return;
+ }
+ m_running = false;
+
+ // terminate all message services
+ for (MessageService msgSvc : m_messageServiceList) {
+ msgSvc.terminate();
+ // TODOTS: stop in order of priorities
+ }
+ }
+
+ std::list<MessageService> m_messageServiceList;
+ // IRTObject parent = null;
+ bool m_running;
+
+};
+
+} /* namespace etRuntime */
+#endif /* MESSAGESERVICECONTROLLER_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTObject.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTObject.cpp
new file mode 100644
index 0000000..f49c876
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTObject.cpp
@@ -0,0 +1,54 @@
+/*
+ * RTObject.cpp
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#include "RTObject.h"
+
+namespace etRuntime {
+
+RTObject::RTObject() :
+ IRTObject(), m_parent(0), m_name(NO_NAME) {
+}
+;
+
+RTObject::RTObject(IRTObject* parent, std::string name) :
+ IRTObject(), m_parent(parent), m_name(name) {
+}
+
+RTObject::RTObject(const RTObject & right) :
+ m_parent(right.m_parent),
+ m_name(right.m_name)
+{
+};
+
+RTObject & RTObject::operator = (RTObject right) {
+ std::swap(right, *this);
+ return *this;
+}
+
+RTObject::~RTObject() {
+ m_parent = 0;
+}
+
+std::string RTObject::getInstancePath() {
+ std::string path = PATH_DELIM + m_name;
+
+ if (m_parent != 0)
+ path = m_parent->getInstancePath() + path;
+
+ return path;
+}
+
+std::string RTObject::getInstancePathName() {
+ std::string path = PATHNAME_DELIM + m_name;
+
+ if (m_parent != 0)
+ path = m_parent->getInstancePathName() + path;
+
+ return path;
+}
+
+} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTObject.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTObject.h
new file mode 100644
index 0000000..3c555ec
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTObject.h
@@ -0,0 +1,36 @@
+/*
+ * RTObject.h
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef RTOBJECT_H_
+#define RTOBJECT_H_
+
+#include <string>
+#include "common/messaging/IRTObject.h"
+
+namespace etRuntime {
+
+class RTObject : public IRTObject{
+public:
+ RTObject();
+ RTObject(IRTObject* parent, std::string name);
+ RTObject(const RTObject & right);
+ RTObject & operator = (RTObject right);
+
+ virtual ~RTObject();
+
+ IRTObject* getParent() { return m_parent; };
+ std::string getInstancePath();
+ std::string getInstancePathName();
+
+private:
+ IRTObject* m_parent;
+ std::string m_name;
+
+};
+
+} /* namespace etRuntime */
+#endif /* RTOBJECT_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTServices.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTServices.cpp
new file mode 100644
index 0000000..09e966b
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTServices.cpp
@@ -0,0 +1,39 @@
+/*
+ * RTServices.cpp
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#include "RTServices.h"
+
+namespace etRuntime {
+
+RTServices* RTServices::s_instance = 0;
+
+RTServices::RTServices()
+ : m_subSystem(0),
+ m_messageServiceController( new MessageServiceController())
+{
+}
+
+RTServices::~RTServices() {
+ // TODO Auto-generated destructor stub
+}
+
+void RTServices::destroy() {
+ // TODO: also clean up all sub elements
+ m_subSystem = 0;
+ m_messageServiceController = 0;
+ //TODO is delete necessary here??
+ //delete s_instance;
+ s_instance = 0;
+}
+
+MessageServiceController& RTServices::getMsgSvcCtrl() {
+ //TODO
+ //assert(m_messageServiceController != 0);
+ return *m_messageServiceController;
+}
+
+} /* namespace etRuntime */
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTServices.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTServices.h
new file mode 100644
index 0000000..7c2a9d0
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTServices.h
@@ -0,0 +1,44 @@
+/*
+ * RTServices.h
+ *
+ * Created on: 22.08.2012
+ * Author: karlitsc
+ */
+
+#ifndef RTSERVICES_H_
+#define RTSERVICES_H_
+#include "common/messaging/MessageServiceController.h"
+
+namespace etRuntime {
+
+class SubSystemClassBase;
+
+
+class RTServices {
+public:
+ virtual ~RTServices();
+
+ static RTServices& getInstance() {
+ if (s_instance == 0) {
+ s_instance = new RTServices();
+ }
+ return *s_instance;
+ }
+
+ void destroy();
+ MessageServiceController& getMsgSvcCtrl();
+ SubSystemClassBase* getSubSystem() { return m_subSystem; };
+ void setSubSystem(SubSystemClassBase* subSystem) { m_subSystem = subSystem; };
+
+private:
+ static RTServices* s_instance;
+
+ SubSystemClassBase* m_subSystem;
+ MessageServiceController* m_messageServiceController;
+
+ RTServices();
+
+};
+
+} /* namespace etRuntime */
+#endif /* RTSERVICES_H_ */