Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2017-01-03 19:47:01 +0000
committerJan Belle2017-01-03 19:58:33 +0000
commitff60f646c49bc31680cd2a24446265f94e3c802c (patch)
tree72021e5abed261aa113ef62a92bff0ab3556607b /runtime
parentf6535d3bcaf9be2039d9e4aeb98241165eb74102 (diff)
downloadorg.eclipse.etrice-ff60f646c49bc31680cd2a24446265f94e3c802c.tar.gz
org.eclipse.etrice-ff60f646c49bc31680cd2a24446265f94e3c802c.tar.xz
org.eclipse.etrice-ff60f646c49bc31680cd2a24446265f94e3c802c.zip
[runtime.cpp] Applied generator changes to the SystemServicesProtocol
Added debug code to POSIX TcpService implementation and StaticMessage Memory Change-Id: I65f3b3ee395f6a43b8e38efefa93a8ba2a5fa7c7
Diffstat (limited to 'runtime')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etTcpSockets.c34
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.cpp39
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.h3
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.cpp10
4 files changed, 64 insertions, 22 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etTcpSockets.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etTcpSockets.c
index 000262c20..1337537aa 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etTcpSockets.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etTcpSockets.c
@@ -158,11 +158,15 @@ etSocketError etStartListening(etSocketServerData* data, short port) {
struct sockaddr_in local;
int i;
- if (self==NULL)
+ if (self==NULL) {
+ PRINT_DEBUG("server: SocketServerData is null!")
return ETSOCKET_ERROR;
+ }
- if (self->data.maxConnections>MAX_CONNECTIONS)
+ if (self->data.maxConnections>MAX_CONNECTIONS) {
+ PRINT_DEBUG("server: Max connections reached")
return ETSOCKET_ERROR;
+ }
/* mark all connections unused and set receiver and buffer provider */
for (i=0; i<MAX_CONNECTIONS; ++i) {
@@ -180,13 +184,13 @@ etSocketError etStartListening(etSocketServerData* data, short port) {
self->socket = socket(AF_INET, SOCK_STREAM, 0);
if (self->socket == INVALID_SOCKET) {
- printf("server: ", strerror(errno), "\n");
+ printf("server: %s\n", strerror(errno));
fflush(stdout);
return ETSOCKET_ERROR;
}
if (bind(self->socket, (struct sockaddr*) &local, sizeof(local)) < 0) {
- printf("server: ", strerror(errno), "\n");
+ printf("server: %s\n", strerror(errno));
fflush(stdout);
return ETSOCKET_ERROR;
}
@@ -216,8 +220,10 @@ etSocketError etWriteServerSocket(etSocketServerData* dat, int connection, int s
etSocketServerDataImpl* self = (etSocketServerDataImpl*) dat;
int offset = 0;
- if (connection<0 || connection>MAX_CONNECTIONS || self->connections[connection].socket==INVALID_SOCKET)
+ if (connection<0 || connection>MAX_CONNECTIONS || self->connections[connection].socket==INVALID_SOCKET) {
+ PRINT_DEBUG("server: tried to write on invalid socket\n")
return ETSOCKET_ERROR;
+ }
/* Note: loop required because:
* If no error occurs, send returns the total number of bytes sent, which can be less than the number
@@ -227,8 +233,11 @@ etSocketError etWriteServerSocket(etSocketServerData* dat, int connection, int s
while (size>0) {
int sent = send(self->connections[connection].socket, ((int8*)data)+offset, size, 0);
- if (sent<=0)
+ if (sent<=0) {
+ printf("server error: %s\n", strerror(errno));
+ fflush(stdout);
return ETSOCKET_ERROR;
+ }
offset += sent;
size -= sent;
@@ -290,8 +299,10 @@ etSocketError etConnectServer(etSocketConnectionData* data, const char* addr, sh
host = gethostbyaddr((char *)&a, 4, AF_INET);
}
- if (host == NULL )
+ if (host == NULL ) {
+ PRINT_DEBUG("client: Host is NULL\n")
return ETSOCKET_ERROR;
+ }
memset(&self->address, 0, sizeof(self->address));
memcpy(&(self->address.sin_addr), host->h_addr, host->h_length);
@@ -300,14 +311,14 @@ etSocketError etConnectServer(etSocketConnectionData* data, const char* addr, sh
self->socket = socket(AF_INET, SOCK_STREAM, 0);
if (self->socket==INVALID_SOCKET) {
- printf("client: ", strerror(errno), "\n");
+ printf("client: %s", strerror(errno));
fflush(stdout);
return ETSOCKET_ERROR;
}
PRINT_DEBUG("client: connecting\n")
if (connect(self->socket, (struct sockaddr*)&(self->address), sizeof(self->address)) == INVALID_SOCKET) {
- printf("client: ", strerror(errno), "\n");
+ printf("client: %s\n", strerror(errno));
fflush(stdout);
return ETSOCKET_ERROR;
}
@@ -332,8 +343,11 @@ etSocketError etWriteSocket(etSocketConnectionData* dat, int size, const int8* d
while (size>0) {
int sent = send(self->socket, ((int8*)data)+offset, size, 0);
- if (sent<=0)
+ if (sent<=0) {
+ printf("client: %s\n", strerror(errno));
+ fflush(stdout);
return ETSOCKET_ERROR;
+ }
offset += sent;
size -= sent;
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.cpp
index 0f201c20f..83fa9cd55 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.cpp
@@ -108,24 +108,45 @@ void RTSystemServicesProtocolConjPort::receive(const Message* msg) {
// sent messages
void RTSystemServicesProtocolConjPort::executeInitialTransition() {
+ executeInitialTransition_impl();
+}
+
+void RTSystemServicesProtocolConjPort::executeInitialTransition_impl() {
DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_executeInitialTransition));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(), RTSystemServicesProtocol::IN_executeInitialTransition));
+ RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_executeInitialTransition));
+ if (getPeerAddress().isValid()) {
+ Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message));
+ if (buffer) {
+ getPeerMsgReceiver()->receive(new (buffer) Message(getPeerAddress(), RTSystemServicesProtocol::IN_executeInitialTransition));
+ }
}
}
void RTSystemServicesProtocolConjPort::startDebugging() {
+ startDebugging_impl();
+}
+
+void RTSystemServicesProtocolConjPort::startDebugging_impl() {
DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_startDebugging));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(), RTSystemServicesProtocol::IN_startDebugging));
+ RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_startDebugging));
+ if (getPeerAddress().isValid()) {
+ Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message));
+ if (buffer) {
+ getPeerMsgReceiver()->receive(new (buffer) Message(getPeerAddress(), RTSystemServicesProtocol::IN_startDebugging));
+ }
}
}
void RTSystemServicesProtocolConjPort::stopDebugging() {
+ stopDebugging_impl();
+}
+
+void RTSystemServicesProtocolConjPort::stopDebugging_impl() {
DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_stopDebugging));
- if (getPeerAddress().isValid()){
- getPeerMsgReceiver()->receive(new Message(getPeerAddress(), RTSystemServicesProtocol::IN_stopDebugging));
+ RTSystemServicesProtocol::getMessageString(RTSystemServicesProtocol::IN_stopDebugging));
+ if (getPeerAddress().isValid()) {
+ Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(Message));
+ if (buffer) {
+ getPeerMsgReceiver()->receive(new (buffer) Message(getPeerAddress(), RTSystemServicesProtocol::IN_stopDebugging));
+ }
}
}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.h b/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.h
index 7682e9359..49f575623 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src-gen/common/modelbase/RTSystemServicesProtocol.h
@@ -96,8 +96,11 @@ class RTSystemServicesProtocolConjPort : public etRuntime::PortBase {
// sent messages
public: void executeInitialTransition();
+ private: void executeInitialTransition_impl();
public: void startDebugging();
+ private: void startDebugging_impl();
public: void stopDebugging();
+ private: void stopDebugging_impl();
};
//------------------------------------------------------------------------------------------------------------
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
index c7f73870d..d88f10b86 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/StaticMessageMemory.cpp
@@ -30,12 +30,16 @@ StaticMessageMemory::~StaticMessageMemory() {
}
Message* StaticMessageMemory::getMessageBuffer(size_t size) {
- if(size <= m_size && m_msgPool.getSize() > 0) {
- return const_cast<Message*>(m_msgPool.pop());
+ if(size > m_size) {
+ std::cout << "Could not provide message buffer (message too big)!" << std::endl;
+ }
+ else if(m_msgPool.getSize() <= 0) {
+ std::cout << "Could not provide message buffer (message pool is empty)!" << std::endl;
}
else {
- return 0;
+ return const_cast<Message*>(m_msgPool.pop());
}
+ return NULL;
}
void StaticMessageMemory::returnMessageBuffer(const Message* buffer) {

Back to the top