Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2012-01-02 17:40:00 -0500
committerThomas Schuetz2012-01-02 17:40:00 -0500
commitdf35a49da5a4aadb7875e37d938afc605251868d (patch)
treec3fdd54a5728aa862d6f74522799f598f3333d72 /examples/org.eclipse.etrice.generator.c.reference
parentc79f92e56625e20d78899a236102fe31ef4a8783 (diff)
downloadorg.eclipse.etrice-df35a49da5a4aadb7875e37d938afc605251868d.tar.gz
org.eclipse.etrice-df35a49da5a4aadb7875e37d938afc605251868d.tar.xz
org.eclipse.etrice-df35a49da5a4aadb7875e37d938afc605251868d.zip
[generator.c.reference] first version of runtime messaging for C, cleaned up unneeded "interface for port class" in Java ProtocolClass Generator, regenerated integration.tests
Diffstat (limited to 'examples/org.eclipse.etrice.generator.c.reference')
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/.cproject16
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/model/cGenRef.room22
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/report.xml9
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Broadcast.c2
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Broadcast.h333
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/CommunicationProtocol.c1
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/CommunicationProtocol.h46
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Receiver.c2
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Receiver.h219
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Sender.c2
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Sender.h215
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/DataClass.h17
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/SSRunner.c30
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessage.c21
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessage.h26
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageQueue.c79
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageQueue.h45
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageService.c60
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageService.h44
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/runtime/RUnit.c7
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/test/TestMessage.c47
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/test/TestMessage.h20
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageQueue.c99
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageQueue.h18
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageService.c114
-rw-r--r--examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageService.h21
26 files changed, 642 insertions, 873 deletions
diff --git a/examples/org.eclipse.etrice.generator.c.reference/.cproject b/examples/org.eclipse.etrice.generator.c.reference/.cproject
index bf8fcd9f5..8e525ab41 100644
--- a/examples/org.eclipse.etrice.generator.c.reference/.cproject
+++ b/examples/org.eclipse.etrice.generator.c.reference/.cproject
@@ -20,7 +20,7 @@
<targetPlatform id="cdt.managedbuild.target.gnu.platform.mingw.exe.debug.1377401325" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.mingw.exe.debug"/>
<builder buildPath="${workspace_loc:/org.eclipse.etrice.generator.c.reference/Debug}" id="cdt.managedbuild.tool.gnu.builder.mingw.base.1914462916" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base"/>
<tool id="cdt.managedbuild.tool.gnu.assembler.mingw.exe.debug.2128193487" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.exe.debug">
- <option id="gnu.both.asm.option.include.paths.646571697" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath"/>
+ <option id="gnu.both.asm.option.include.paths.646571697" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths"/>
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1636502349" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.1852443642" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
@@ -37,8 +37,8 @@
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.215126527" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug.2141539090" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug">
- <option id="gnu.c.link.option.libs.1886054812" name="Libraries (-l)" superClass="gnu.c.link.option.libs" valueType="libs"/>
- <option id="gnu.c.link.option.paths.1410926104" name="Library search path (-L)" superClass="gnu.c.link.option.paths" valueType="libPaths"/>
+ <option id="gnu.c.link.option.libs.1886054812" name="Libraries (-l)" superClass="gnu.c.link.option.libs"/>
+ <option id="gnu.c.link.option.paths.1410926104" name="Library search path (-L)" superClass="gnu.c.link.option.paths"/>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1941302758" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@@ -48,8 +48,8 @@
</toolChain>
</folderInfo>
<sourceEntries>
- <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="src|src-gen" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
+ <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src-gen"/>
</sourceEntries>
</configuration>
@@ -88,12 +88,12 @@
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.1378403430" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.mingw.exe.release.option.optimization.level.554911279" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.release.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.mingw.exe.release.option.debugging.level.331396171" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
- <option id="gnu.c.compiler.option.include.paths.1226733508" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath"/>
+ <option id="gnu.c.compiler.option.include.paths.1226733508" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.156681579" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.release.1192709765" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.release">
- <option id="gnu.c.link.option.libs.2121552378" name="Libraries (-l)" superClass="gnu.c.link.option.libs" valueType="libs"/>
- <option id="gnu.c.link.option.paths.1610581119" name="Library search path (-L)" superClass="gnu.c.link.option.paths" valueType="libPaths"/>
+ <option id="gnu.c.link.option.libs.2121552378" name="Libraries (-l)" superClass="gnu.c.link.option.libs"/>
+ <option id="gnu.c.link.option.paths.1610581119" name="Library search path (-L)" superClass="gnu.c.link.option.paths"/>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1107454825" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@@ -103,9 +103,9 @@
</toolChain>
</folderInfo>
<sourceEntries>
- <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src-gen"/>
<entry excluding="src|src-gen" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
+ <entry excluding="runtime/RMessageQueue.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
</sourceEntries>
</configuration>
</storageModule>
diff --git a/examples/org.eclipse.etrice.generator.c.reference/model/cGenRef.room b/examples/org.eclipse.etrice.generator.c.reference/model/cGenRef.room
index 87d9b5f24..6ecd60223 100644
--- a/examples/org.eclipse.etrice.generator.c.reference/model/cGenRef.room
+++ b/examples/org.eclipse.etrice.generator.c.reference/model/cGenRef.room
@@ -1,5 +1,17 @@
RoomModel cGenRef {
+ ProtocolClass CommunicationProtocol {
+ incoming {
+ Message sendData(data: int32)
+ Message sendData2(data: DataClass1)
+
+ }
+ outgoing {
+ Message receivedData()
+ }
+ }
+
+
DataClass DataClass1 {
usercode1 {"// usercode1"}
usercode2 {"// usercode2"}
@@ -162,15 +174,5 @@ RoomModel cGenRef {
}
}
- ProtocolClass CommunicationProtocol {
- incoming {
- Message sendData(data: int32)
- Message sendData2(data: DataClass1)
-
- }
- outgoing {
- Message receivedData()
- }
- }
} \ No newline at end of file
diff --git a/examples/org.eclipse.etrice.generator.c.reference/report.xml b/examples/org.eclipse.etrice.generator.c.reference/report.xml
deleted file mode 100644
index 72be9bcea..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/report.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<testsuite name="testGeneratedDataClass" tests="0" failures="0" errors="0" time="0">
- <testcase name="Attr1" classname="none" time="0.0000"/>
- <testcase name="ComplexAttr.Attr1" classname="none" time="0.0000"/>
- <testcase name="ComplexAttr.Attr2" classname="none" time="0.0000"/>
- <testcase name="ComplexAttr.Attr3" classname="none" time="0.0000"/>
- <testcase name="Attr3" classname="none" time="0.0000"/>
- <testcase name="Operation DataClass1_MultiplyWithAttr1" classname="none" time="0.0000"/>
- <testcase name="Operation DataClass1_MultiplyWithAttr3" classname="none" time="0.0000"/>
-</testsuite>
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Broadcast.c b/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Broadcast.c
deleted file mode 100644
index abb345c93..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Broadcast.c
+++ /dev/null
@@ -1,2 +0,0 @@
-#include "Broadcast.h"
-
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Broadcast.h b/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Broadcast.h
deleted file mode 100644
index 57236b772..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Broadcast.h
+++ /dev/null
@@ -1,333 +0,0 @@
-#ifndef _Broadcast_H_
-#define _Broadcast_H_
-
-#include "datatypes.h"
-
-package cGenRef;
-
-
-
-
-#include "CommunicationProtocol.h"
-
-
-
-public class Broadcast extends ActorClassBase {
-
-
- //--------------------- ports
- protected CommunicationProtocolPort dataIn = null;
- protected CommunicationProtocolConjPortRepl dataOut = null;
- //--------------------- saps
- //--------------------- services
-
- //--------------------- interface item IDs
- protected static final int IFITEM_dataIn = 1;
- protected static final int IFITEM_dataOut = 2;
-
- //--------------------- attributes
- //--------------------- operations
-
- //--------------------- construction
- public Broadcast(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
- super(parent, name, port_addr[0][0], peer_addr[0][0]);
- setClassName("Broadcast");
-
- // initialize attributes
-
- // own ports
- dataIn = new CommunicationProtocolPort(this, "dataIn", IFITEM_dataIn, 0, port_addr[IFITEM_dataIn][0], peer_addr[IFITEM_dataIn][0]);
- dataOut = new CommunicationProtocolConjPortRepl(this, "dataOut", IFITEM_dataOut, port_addr[IFITEM_dataOut], peer_addr[IFITEM_dataOut]);
- // own saps
- // own service implementations
- }
-
-
- //--------------------- lifecycle functions
- public void init(){
- initUser();
- }
-
- public void start(){
- startUser();
- }
-
- public void stop(){
- stopUser();
- }
-
- public void destroy(){
- destroyUser();
- }
-
- //******************************************
- // START of generated code for FSM
- //******************************************
-
- // State IDs for FSM
- protected static final int STATE_Idle = 2;
- protected static final int STATE_Sending = 3;
- protected static final int STATE_Sending_WaitingForReceived = 4;
- protected static final int STATE_Sending_ReceivedOne = 5;
- protected static final int STATE_Sending_ReceivedTheOther = 6;
- protected static final int STATE_ReceivedBoth = 7;
- protected static final String stateStrings[] = {"<no state>","<top>","Idle",
- "Sending",
- "Sending_WaitingForReceived",
- "Sending_ReceivedOne",
- "Sending_ReceivedTheOther",
- "ReceivedBoth"
- };
-
- // history
- // TODOHRR: history defined in ActorClassBase, init in constructor
- // history = new int[5];
- // for (int i = 0; i < history.length; i++) {
- // history[i] = NO_STATE;
- // }
- protected int history[] = {NO_STATE,NO_STATE,NO_STATE,NO_STATE,NO_STATE,NO_STATE,NO_STATE,NO_STATE};
-
- // transition chains
- protected static final int CHAIN_Sending_TRANS_ReceivedOne_TO_tp1_BY_receivedDatadataOut = 1;
- protected static final int CHAIN_Sending_TRANS_ReceivedTheOther_TO_tp1_BY_receivedDatadataOut = 2;
- protected static final int CHAIN_Sending_TRANS_WaitingForReceived_TO_ReceivedOne_BY_receivedDatadataOut = 3;
- protected static final int CHAIN_Sending_TRANS_WaitingForReceived_TO_ReceivedTheOther_BY_receivedDatadataOut = 4;
- protected static final int CHAIN_TRANS_INITIAL_TO__Idle = 5;
- protected static final int CHAIN_TRANS_Idle_TO_Sending_tp0_BY_sendDatadataIn = 6;
-
- // triggers for FSM
- protected static final int TRIG_dataIn__sendData = IFITEM_dataIn + EVT_SHIFT*CommunicationProtocol.IN_sendData;
- protected static final int TRIG_dataOut__receivedData = IFITEM_dataOut + EVT_SHIFT*CommunicationProtocol.OUT_receivedData;
-
- // receiveEvent contains the main implementation of the FSM
- @Override
- public void receiveEvent(InterfaceItemBase ifitem, int evt, Object generic_data) {
- int trigger = ifitem.getLocalId() + EVT_SHIFT*evt;
- int chain = NOT_CAUGHT;
- int catching_state = NO_STATE;
- boolean is_handler = false;
- boolean skip_entry = false;
-
- if (!handleSystemEvent(ifitem, evt, generic_data)) {
- switch (state) {
- case STATE_Idle:
- switch(trigger) {
- case TRIG_dataIn__sendData:
- {
- chain = CHAIN_TRANS_Idle_TO_Sending_tp0_BY_sendDatadataIn;
- catching_state = STATE_TOP;
- }
- break;
- }
- break;
- case STATE_Sending_WaitingForReceived:
- switch(trigger) {
- case TRIG_dataOut__receivedData:
- {
- if (true
- )
- {
- chain = CHAIN_Sending_TRANS_WaitingForReceived_TO_ReceivedOne_BY_receivedDatadataOut;
- catching_state = STATE_Sending;
- } else
- if (false
- )
- {
- chain = CHAIN_Sending_TRANS_WaitingForReceived_TO_ReceivedTheOther_BY_receivedDatadataOut;
- catching_state = STATE_Sending;
- }
- }
- break;
- }
- break;
- case STATE_Sending_ReceivedOne:
- switch(trigger) {
- case TRIG_dataOut__receivedData:
- {
- if (true
- )
- {
- chain = CHAIN_Sending_TRANS_ReceivedOne_TO_tp1_BY_receivedDatadataOut;
- catching_state = STATE_Sending;
- }
- }
- break;
- }
- break;
- case STATE_Sending_ReceivedTheOther:
- switch(trigger) {
- case TRIG_dataOut__receivedData:
- {
- if (false
- )
- {
- chain = CHAIN_Sending_TRANS_ReceivedTheOther_TO_tp1_BY_receivedDatadataOut;
- catching_state = STATE_Sending;
- }
- }
- break;
- }
- break;
- case STATE_ReceivedBoth:
- break;
- }
- }
- if (chain != NOT_CAUGHT) {
- exitTo(state, catching_state, is_handler);
- int next = executeTransitionChain(chain, ifitem, generic_data);
- next = enterHistory(next, is_handler, skip_entry);
- setState(next);
- }
- }
-
- private void setState(int new_state) {
- DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);
- if (stateStrings[new_state]!="Idle") {
- // TODOTS: model switch for activation
- System.out.println(getInstancePath() + " -> " + stateStrings[new_state]);
- }
- this.state = new_state;
- }
-
- @Override
- public void executeInitTransition() {
- int chain = CHAIN_TRANS_INITIAL_TO__Idle;
- int next = executeTransitionChain(chain, null, null);
- next = enterHistory(next, false, false);
- setState(next);
- }
-
- /**
- * calls exit codes while exiting from the current state to one of its
- * parent states while remembering the history
- * @param current - the current state
- * @param to - the final parent state
- * @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)
- */
- private void exitTo(int current, int to, boolean handler) {
- while (current!=to) {
- switch (current) {
- case STATE_Idle:
- history[STATE_TOP] = STATE_Idle;
- current = STATE_TOP;
- break;
- case STATE_Sending:
- history[STATE_TOP] = STATE_Sending;
- current = STATE_TOP;
- break;
- case STATE_Sending_WaitingForReceived:
- history[STATE_Sending] = STATE_Sending_WaitingForReceived;
- current = STATE_Sending;
- break;
- case STATE_Sending_ReceivedOne:
- history[STATE_Sending] = STATE_Sending_ReceivedOne;
- current = STATE_Sending;
- break;
- case STATE_Sending_ReceivedTheOther:
- history[STATE_Sending] = STATE_Sending_ReceivedTheOther;
- current = STATE_Sending;
- break;
- case STATE_ReceivedBoth:
- history[STATE_TOP] = STATE_ReceivedBoth;
- current = STATE_TOP;
- break;
- }
- }
- }
- /**
- * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data
- * matching the trigger of this chain. The ID of the final state is returned
- * @param chain - the chain ID
- * @param generic_data - the generic data pointer
- * @return the ID of the final state
- */
- private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) {
- switch (chain) {
- case CHAIN_TRANS_INITIAL_TO__Idle:
- {
- return STATE_Idle;
- }
- case CHAIN_TRANS_Idle_TO_Sending_tp0_BY_sendDatadataIn:
- {
- int data = (Integer) generic_data;
- action_TRANS_Idle_TO_Sending_tp0_BY_sendDatadataIn(ifitem, data);
- return STATE_Sending_WaitingForReceived;
- }
- case CHAIN_Sending_TRANS_WaitingForReceived_TO_ReceivedOne_BY_receivedDatadataOut:
- {
- return STATE_Sending_ReceivedOne;
- }
- case CHAIN_Sending_TRANS_WaitingForReceived_TO_ReceivedTheOther_BY_receivedDatadataOut:
- {
- return STATE_Sending_ReceivedTheOther;
- }
- case CHAIN_Sending_TRANS_ReceivedOne_TO_tp1_BY_receivedDatadataOut:
- {
- action_TRANS_Sending_tp1_TO_ReceivedBoth(ifitem);
- return STATE_ReceivedBoth;
- }
- case CHAIN_Sending_TRANS_ReceivedTheOther_TO_tp1_BY_receivedDatadataOut:
- {
- action_TRANS_Sending_tp1_TO_ReceivedBoth(ifitem);
- return STATE_ReceivedBoth;
- }
- }
- return NO_STATE;
- }
- /**
- * calls entry codes while entering a state's history. The ID of the final leaf state is returned
- * @param state - the state which is entered
- * @param handler - entry code is executed if not handler
- * @return - the ID of the final leaf state
- */
- private int enterHistory(int state, boolean handler, boolean skip_entry) {
- while (true) {
- switch (state) {
- case STATE_Idle:
- // in leaf state: return state id
- return STATE_Idle;
- case STATE_Sending:
- // state has a sub graph
- // without init transition
- state = history[STATE_Sending];
- break;
- case STATE_Sending_WaitingForReceived:
- // in leaf state: return state id
- return STATE_Sending_WaitingForReceived;
- case STATE_Sending_ReceivedOne:
- // in leaf state: return state id
- return STATE_Sending_ReceivedOne;
- case STATE_Sending_ReceivedTheOther:
- // in leaf state: return state id
- return STATE_Sending_ReceivedTheOther;
- case STATE_ReceivedBoth:
- // in leaf state: return state id
- return STATE_ReceivedBoth;
- case STATE_TOP:
- state = history[STATE_TOP];
- break;
- }
- skip_entry = false;
- }
- //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)
- }
-
- //*** Entry and Exit Codes
-
- //*** Action Codes
- protected void action_TRANS_Idle_TO_Sending_tp0_BY_sendDatadataIn(InterfaceItemBase ifitem, int data) {
- //dataOut.get(0).sendData(data);
- //dataOut.get(1).sendData(data);
- dataOut.sendData(data);
- }
- protected void action_TRANS_Sending_tp1_TO_ReceivedBoth(InterfaceItemBase ifitem) {
- dataIn.receivedData();
- }
-
- //******************************************
- // END of generated code for FSM
- //******************************************
-};
-
-#endif /* _Broadcast_H_ */
-
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/CommunicationProtocol.c b/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/CommunicationProtocol.c
deleted file mode 100644
index d819ff9eb..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/CommunicationProtocol.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "CommunicationProtocol.h"
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/CommunicationProtocol.h b/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/CommunicationProtocol.h
deleted file mode 100644
index c90a0ce16..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/CommunicationProtocol.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef _CommunicationProtocol_H_
-#define _CommunicationProtocol_H_
-
-#include "datatypes.h"
-
-
-
-#include "CommunicationProtocol.h"
-
-typedef struct {
-
-
-} CommunicationProtocol;
-
-/* message IDs */
-enum {
- MSG_CommunicationProtocol_MIN = 0,
- /* IDs for outgoing messages */
- OUT_CommunicationProtocol_receivedData = 1,
- /* IDs for incoming messages */
- IN_CommunicationProtocol_sendData = 2,
- IN_CommunicationProtocol_sendData2 = 3,
- /* error if msgID >= MSG_MAX */
- MSG_CommunicationProtocol_MAX = 4
-};
-
-
-/* message names as strings for debugging (generate MSC) */
-/* TODO: make this optional or different for smaller footprint */
-static char CommunicationProtocol_messageStrings[][] = {"MIN", "receivedData","sendData", "sendData2", "MAX"};
-
-char* CommunicationProtocol_getMessageString(int msg_id) {
- if (msg_id<MSG_CommunicationProtocol_MIN || msg_id>MSG_CommunicationProtocol_MAX+1){
- /* id out of range */
- return "Message ID out of range";
- }
- else{
- return CommunicationProtocol_messageStrings[msg_id];
- }
-}
-
-
-
-
-#endif /* _CommunicationProtocol_H_ */
-
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Receiver.c b/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Receiver.c
deleted file mode 100644
index 041300249..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Receiver.c
+++ /dev/null
@@ -1,2 +0,0 @@
-#include "Receiver.h"
-
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Receiver.h b/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Receiver.h
deleted file mode 100644
index 198bb3cf8..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Receiver.h
+++ /dev/null
@@ -1,219 +0,0 @@
-#ifndef _Receiver_H_
-#define _Receiver_H_
-
-#include "datatypes.h"
-
-package cGenRef;
-
-
-
-#include "DataClass1.h"
-
-#include "CommunicationProtocol.h"
-
-
-
-public class Receiver extends ActorClassBase {
-
-
- //--------------------- ports
- protected CommunicationProtocolPort dataIn = null;
- //--------------------- saps
- //--------------------- services
-
- //--------------------- interface item IDs
- protected static final int IFITEM_dataIn = 1;
-
- //--------------------- attributes
- DataClass1 attr1;
- //--------------------- operations
-
- //--------------------- construction
- public Receiver(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
- super(parent, name, port_addr[0][0], peer_addr[0][0]);
- setClassName("Receiver");
-
- // initialize attributes
- attr1 = new DataClass1();
-
- // own ports
- dataIn = new CommunicationProtocolPort(this, "dataIn", IFITEM_dataIn, 0, port_addr[IFITEM_dataIn][0], peer_addr[IFITEM_dataIn][0]);
- // own saps
- // own service implementations
- }
-
-
- //--------------------- lifecycle functions
- public void init(){
- initUser();
- }
-
- public void start(){
- startUser();
- }
-
- public void stop(){
- stopUser();
- }
-
- public void destroy(){
- destroyUser();
- }
-
- //******************************************
- // START of generated code for FSM
- //******************************************
-
- // State IDs for FSM
- protected static final int STATE_Idle = 2;
- protected static final int STATE_DataReceived = 3;
- protected static final String stateStrings[] = {"<no state>","<top>","Idle",
- "DataReceived"
- };
-
- // history
- // TODOHRR: history defined in ActorClassBase, init in constructor
- // history = new int[5];
- // for (int i = 0; i < history.length; i++) {
- // history[i] = NO_STATE;
- // }
- protected int history[] = {NO_STATE,NO_STATE,NO_STATE,NO_STATE};
-
- // transition chains
- protected static final int CHAIN_TRANS_INITIAL_TO__Idle = 1;
- protected static final int CHAIN_TRANS_Idle_TO_DataReceived_BY_sendDatadataIn = 2;
-
- // triggers for FSM
- protected static final int TRIG_dataIn__sendData = IFITEM_dataIn + EVT_SHIFT*CommunicationProtocol.IN_sendData;
-
- // receiveEvent contains the main implementation of the FSM
- @Override
- public void receiveEvent(InterfaceItemBase ifitem, int evt, Object generic_data) {
- int trigger = ifitem.getLocalId() + EVT_SHIFT*evt;
- int chain = NOT_CAUGHT;
- int catching_state = NO_STATE;
- boolean is_handler = false;
- boolean skip_entry = false;
-
- if (!handleSystemEvent(ifitem, evt, generic_data)) {
- switch (state) {
- case STATE_Idle:
- switch(trigger) {
- case TRIG_dataIn__sendData:
- {
- chain = CHAIN_TRANS_Idle_TO_DataReceived_BY_sendDatadataIn;
- catching_state = STATE_TOP;
- }
- break;
- }
- break;
- case STATE_DataReceived:
- break;
- }
- }
- if (chain != NOT_CAUGHT) {
- exitTo(state, catching_state, is_handler);
- int next = executeTransitionChain(chain, ifitem, generic_data);
- next = enterHistory(next, is_handler, skip_entry);
- setState(next);
- }
- }
-
- private void setState(int new_state) {
- DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);
- if (stateStrings[new_state]!="Idle") {
- // TODOTS: model switch for activation
- System.out.println(getInstancePath() + " -> " + stateStrings[new_state]);
- }
- this.state = new_state;
- }
-
- @Override
- public void executeInitTransition() {
- int chain = CHAIN_TRANS_INITIAL_TO__Idle;
- int next = executeTransitionChain(chain, null, null);
- next = enterHistory(next, false, false);
- setState(next);
- }
-
- /**
- * calls exit codes while exiting from the current state to one of its
- * parent states while remembering the history
- * @param current - the current state
- * @param to - the final parent state
- * @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)
- */
- private void exitTo(int current, int to, boolean handler) {
- while (current!=to) {
- switch (current) {
- case STATE_Idle:
- history[STATE_TOP] = STATE_Idle;
- current = STATE_TOP;
- break;
- case STATE_DataReceived:
- history[STATE_TOP] = STATE_DataReceived;
- current = STATE_TOP;
- break;
- }
- }
- }
- /**
- * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data
- * matching the trigger of this chain. The ID of the final state is returned
- * @param chain - the chain ID
- * @param generic_data - the generic data pointer
- * @return the ID of the final state
- */
- private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) {
- switch (chain) {
- case CHAIN_TRANS_INITIAL_TO__Idle:
- {
- return STATE_Idle;
- }
- case CHAIN_TRANS_Idle_TO_DataReceived_BY_sendDatadataIn:
- {
- int data = (Integer) generic_data;
- action_TRANS_Idle_TO_DataReceived_BY_sendDatadataIn(ifitem, data);
- return STATE_DataReceived;
- }
- }
- return NO_STATE;
- }
- /**
- * calls entry codes while entering a state's history. The ID of the final leaf state is returned
- * @param state - the state which is entered
- * @param handler - entry code is executed if not handler
- * @return - the ID of the final leaf state
- */
- private int enterHistory(int state, boolean handler, boolean skip_entry) {
- while (true) {
- switch (state) {
- case STATE_Idle:
- // in leaf state: return state id
- return STATE_Idle;
- case STATE_DataReceived:
- // in leaf state: return state id
- return STATE_DataReceived;
- case STATE_TOP:
- state = history[STATE_TOP];
- break;
- }
- skip_entry = false;
- }
- //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)
- }
-
- //*** Entry and Exit Codes
-
- //*** Action Codes
- protected void action_TRANS_Idle_TO_DataReceived_BY_sendDatadataIn(InterfaceItemBase ifitem, int data) {
- dataIn.receivedData();
- }
-
- //******************************************
- // END of generated code for FSM
- //******************************************
-};
-
-#endif /* _Receiver_H_ */
-
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Sender.c b/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Sender.c
deleted file mode 100644
index a7c1e7190..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Sender.c
+++ /dev/null
@@ -1,2 +0,0 @@
-#include "Sender.h"
-
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Sender.h b/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Sender.h
deleted file mode 100644
index 8c93be918..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/src-gen/cGenRef/Sender.h
+++ /dev/null
@@ -1,215 +0,0 @@
-#ifndef _Sender_H_
-#define _Sender_H_
-
-#include "datatypes.h"
-
-package cGenRef;
-
-
-
-
-#include "CommunicationProtocol.h"
-
-
-
-public class Sender extends ActorClassBase {
-
-
- //--------------------- ports
- protected CommunicationProtocolConjPort dataOut = null;
- //--------------------- saps
- //--------------------- services
-
- //--------------------- interface item IDs
- protected static final int IFITEM_dataOut = 1;
-
- //--------------------- attributes
- //--------------------- operations
-
- //--------------------- construction
- public Sender(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
- super(parent, name, port_addr[0][0], peer_addr[0][0]);
- setClassName("Sender");
-
- // initialize attributes
-
- // own ports
- dataOut = new CommunicationProtocolConjPort(this, "dataOut", IFITEM_dataOut, 0, port_addr[IFITEM_dataOut][0], peer_addr[IFITEM_dataOut][0]);
- // own saps
- // own service implementations
- }
-
-
- //--------------------- lifecycle functions
- public void init(){
- initUser();
- }
-
- public void start(){
- startUser();
- }
-
- public void stop(){
- stopUser();
- }
-
- public void destroy(){
- destroyUser();
- }
-
- //******************************************
- // START of generated code for FSM
- //******************************************
-
- // State IDs for FSM
- protected static final int STATE_SendingData = 2;
- protected static final int STATE_Done = 3;
- protected static final String stateStrings[] = {"<no state>","<top>","SendingData",
- "Done"
- };
-
- // history
- // TODOHRR: history defined in ActorClassBase, init in constructor
- // history = new int[5];
- // for (int i = 0; i < history.length; i++) {
- // history[i] = NO_STATE;
- // }
- protected int history[] = {NO_STATE,NO_STATE,NO_STATE,NO_STATE};
-
- // transition chains
- protected static final int CHAIN_TRANS_INITIAL_TO__SendingData = 1;
- protected static final int CHAIN_TRANS_SendingData_TO_Done_BY_receivedDatadataOut = 2;
-
- // triggers for FSM
- protected static final int TRIG_dataOut__receivedData = IFITEM_dataOut + EVT_SHIFT*CommunicationProtocol.OUT_receivedData;
-
- // receiveEvent contains the main implementation of the FSM
- @Override
- public void receiveEvent(InterfaceItemBase ifitem, int evt, Object generic_data) {
- int trigger = ifitem.getLocalId() + EVT_SHIFT*evt;
- int chain = NOT_CAUGHT;
- int catching_state = NO_STATE;
- boolean is_handler = false;
- boolean skip_entry = false;
-
- if (!handleSystemEvent(ifitem, evt, generic_data)) {
- switch (state) {
- case STATE_SendingData:
- switch(trigger) {
- case TRIG_dataOut__receivedData:
- {
- chain = CHAIN_TRANS_SendingData_TO_Done_BY_receivedDatadataOut;
- catching_state = STATE_TOP;
- }
- break;
- }
- break;
- case STATE_Done:
- break;
- }
- }
- if (chain != NOT_CAUGHT) {
- exitTo(state, catching_state, is_handler);
- int next = executeTransitionChain(chain, ifitem, generic_data);
- next = enterHistory(next, is_handler, skip_entry);
- setState(next);
- }
- }
-
- private void setState(int new_state) {
- DebuggingService.getInstance().addActorState(this,stateStrings[new_state]);
- if (stateStrings[new_state]!="Idle") {
- // TODOTS: model switch for activation
- System.out.println(getInstancePath() + " -> " + stateStrings[new_state]);
- }
- this.state = new_state;
- }
-
- @Override
- public void executeInitTransition() {
- int chain = CHAIN_TRANS_INITIAL_TO__SendingData;
- int next = executeTransitionChain(chain, null, null);
- next = enterHistory(next, false, false);
- setState(next);
- }
-
- /**
- * calls exit codes while exiting from the current state to one of its
- * parent states while remembering the history
- * @param current - the current state
- * @param to - the final parent state
- * @param handler - entry and exit codes are called only if not handler (for handler TransitionPoints)
- */
- private void exitTo(int current, int to, boolean handler) {
- while (current!=to) {
- switch (current) {
- case STATE_SendingData:
- history[STATE_TOP] = STATE_SendingData;
- current = STATE_TOP;
- break;
- case STATE_Done:
- history[STATE_TOP] = STATE_Done;
- current = STATE_TOP;
- break;
- }
- }
- }
- /**
- * calls action, entry and exit codes along a transition chain. The generic data are cast to typed data
- * matching the trigger of this chain. The ID of the final state is returned
- * @param chain - the chain ID
- * @param generic_data - the generic data pointer
- * @return the ID of the final state
- */
- private int executeTransitionChain(int chain, InterfaceItemBase ifitem, Object generic_data) {
- switch (chain) {
- case CHAIN_TRANS_INITIAL_TO__SendingData:
- {
- return STATE_SendingData;
- }
- case CHAIN_TRANS_SendingData_TO_Done_BY_receivedDatadataOut:
- {
- return STATE_Done;
- }
- }
- return NO_STATE;
- }
- /**
- * calls entry codes while entering a state's history. The ID of the final leaf state is returned
- * @param state - the state which is entered
- * @param handler - entry code is executed if not handler
- * @return - the ID of the final leaf state
- */
- private int enterHistory(int state, boolean handler, boolean skip_entry) {
- while (true) {
- switch (state) {
- case STATE_SendingData:
- if (!(skip_entry || handler)) entry_SendingData();
- // in leaf state: return state id
- return STATE_SendingData;
- case STATE_Done:
- // in leaf state: return state id
- return STATE_Done;
- case STATE_TOP:
- state = history[STATE_TOP];
- break;
- }
- skip_entry = false;
- }
- //return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)
- }
-
- //*** Entry and Exit Codes
- protected void entry_SendingData() {
- dataOut.sendData(1234);
- }
-
- //*** Action Codes
-
- //******************************************
- // END of generated code for FSM
- //******************************************
-};
-
-#endif /* _Sender_H_ */
-
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/DataClass.h b/examples/org.eclipse.etrice.generator.c.reference/src/DataClass.h
deleted file mode 100644
index 196481c0e..000000000
--- a/examples/org.eclipse.etrice.generator.c.reference/src/DataClass.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * DataClass.h
- *
- * Created on: 22.12.2011
- * Author: tschuetz
- */
-
-#ifndef DATACLASS_H_
-#define DATACLASS_H_
-
-
-
-struct DataClass {
- int att1;
-};
-
-#endif /* DATACLASS_H_ */
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/SSRunner.c b/examples/org.eclipse.etrice.generator.c.reference/src/SSRunner.c
index 72b9f8564..8f99b462a 100644
--- a/examples/org.eclipse.etrice.generator.c.reference/src/SSRunner.c
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/SSRunner.c
@@ -1,19 +1,29 @@
-/*
- * SSRunner.c
+/*******************************************************************************
+ * Copyright (c) 2011 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
*
- * Created on: 21.12.2011
- * Author: tschuetz
- */
+ * CONTRIBUTORS:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
#include <stdio.h>
#include "../src-gen/cGenRef/DataClass1.h"
#include "RUnit.h"
+#include "RMessage.h"
+#include "test/TestMessage.h"
+#include "test/TestRMessageQueue.h"
+#include "test/TestRMessageService.h"
+
-void testDataClassDeepCopy(void);
+void runTestCases(void);
int main(void){
- testDataClassDeepCopy();
+ runTestCases();
return 0;
}
@@ -41,4 +51,10 @@ void testDataClassDeepCopy(void){
RUnit_close();
}
+void runTestCases(void){
+ testDataClassDeepCopy();
+ TestMessage_runSuite();
+ TestMessageQueue_runSuite();
+ TestRMessageService_runSuite();
+}
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessage.c b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessage.c
new file mode 100644
index 000000000..9e67a84c2
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessage.c
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "RMessage.h"
+
+#include <stddef.h>
+
+void RMessage_init(RMessage* self){
+ self->next = NULL;
+ self->address = 0;
+ self->evtID = 0;
+}
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessage.h b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessage.h
new file mode 100644
index 000000000..dd6927662
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessage.h
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef RMESSAGE_H_
+#define RMESSAGE_H_
+
+#include "datatypes.h"
+
+typedef struct RMessage{
+ struct RMessage* next;
+ int16 address;
+ int16 evtID;
+} RMessage;
+
+void RMessage_init(RMessage* self);
+
+#endif /* RMESSAGE_H_ */
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageQueue.c b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageQueue.c
new file mode 100644
index 000000000..0c28cdec9
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageQueue.c
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "RMessageQueue.h"
+
+void RMessageQueue_init(RMessageQueue* self){
+ self->first = NULL;
+ self->last = NULL;
+ self->highWaterMark = 0;
+ self->size = 0;
+}
+
+
+void RMessageQueue_push(RMessageQueue* self, RMessage* msg){
+ // TODO: optimize queue for concurrent push / pop
+ if (self->first == NULL) {
+ /*no message in queue*/
+ self->first = self->last = msg;
+ }
+ else {
+ /*at least one message in queue*/
+ self->last->next = msg;
+ self->last = msg;
+ }
+ msg->next = NULL; /*TODO: optimization: this line could be removed if we assume that all messages are initialized*/
+
+ if (++self->size > self->highWaterMark)
+ self->highWaterMark++;
+}
+
+RMessage* RMessageQueue_pop(RMessageQueue* self){
+ RMessage* pop_msg = self->first;
+ if(self->first == NULL){
+ /*no message in queue*/
+ return NULL;
+ }
+ if (self->first->next==NULL){
+ /*only one message in queue*/
+ self->first = self->last = NULL;
+ }
+ else {
+ /*more than one message in queue -> set first to nex message*/
+ self->first = self->first->next;
+ }
+
+ pop_msg->next=NULL;
+ self->size--;
+
+ return pop_msg;
+}
+
+int16 RMessageQueue_getSize(RMessageQueue* self) {
+ return self->size;
+}
+
+RMessage* RMessageQueue_getFirst(RMessageQueue* self){
+ return self->first;
+}
+
+RMessage* RMessageQueue_getLast(RMessageQueue* self){
+ return self->last;
+}
+
+boool RMessageQueue_isNotEmpty(RMessageQueue* self){
+ return self->last != NULL;
+}
+
+int16 RMessageQueue_getHightWaterMark(RMessageQueue* self) {
+ return self->highWaterMark;
+}
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageQueue.h b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageQueue.h
new file mode 100644
index 000000000..b2326eec8
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageQueue.h
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef _RMESSAGEQUEUE_H_
+#define _RMESSAGEQUEUE_H_
+
+#include "RMessage.h"
+#include <stddef.h>
+
+typedef struct RMessageQueue {
+ RMessage* first;
+ RMessage* last;
+ int16 highWaterMark;
+ int16 size;
+
+} RMessageQueue;
+
+void RMessageQueue_init(RMessageQueue* self);
+
+void RMessageQueue_push(RMessageQueue* self, RMessage* msg);
+
+RMessage* RMessageQueue_pop(RMessageQueue* self);
+
+int16 RMessageQueue_getSize(RMessageQueue* self);
+
+RMessage* RMessageQueue_getFirst(RMessageQueue* self);
+
+RMessage* RMessageQueue_getLast(RMessageQueue* self);
+
+boool RMessageQueue_isNotEmpty(RMessageQueue* self);
+
+int16 RMessageQueue_getHightWaterMark(RMessageQueue* self);
+
+
+
+#endif /* _RMESSAGEQUEUE_H_ */
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageService.c b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageService.c
new file mode 100644
index 000000000..2fe28406c
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageService.c
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+
+#include "RMessageService.h"
+
+void RMessageService_init(RMessageService* self, uint8* buffer, uint16 maxBlocks, uint16 blockSize){
+ self->messageBuffer.buffer = buffer;
+ self->messageBuffer.maxBlocks = maxBlocks;
+ self->messageBuffer.blockSize = blockSize;
+ RMessageQueue_init(&self->messagePool);
+ RMessageQueue_init(&self->messageQueue);
+
+ RMessageService_initMessagePool(self);
+}
+
+/*
+ * initialize message pool with block buffer
+ * all blocks are added to pool
+ */
+void RMessageService_initMessagePool(RMessageService* self){
+ int i;
+
+ for (i=0; i<self->messageBuffer.maxBlocks; i++){
+ RMessage* block = (RMessage*) &self->messageBuffer.buffer[i*self->messageBuffer.blockSize];
+ RMessageQueue_push(&self->messagePool, block);
+ }
+}
+
+void RMessageService_pushMessage(RMessageService* self, RMessage* msg){
+ RMessageQueue_push(&self->messageQueue, msg);
+
+}
+
+RMessage* RMessageService_popMessage(RMessageService* self){
+ return RMessageQueue_pop(&self->messageQueue);
+}
+
+
+RMessage* RMessageService_getMessageBuffer(RMessageService* self, int16 size){
+ if (size<=self->messageBuffer.blockSize){
+ if (self->messagePool.size>0){
+ return RMessageQueue_pop(&self->messagePool);
+ }
+ }
+ return NULL;
+}
+
+void RMessageService_returnMessageBuffer(RMessageService* self, RMessage* buffer){
+ RMessageQueue_push(&self->messagePool, buffer);
+}
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageService.h b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageService.h
new file mode 100644
index 000000000..fae4e33bb
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RMessageService.h
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef RMESSAGESERVICE_H_
+#define RMESSAGESERVICE_H_
+
+#include <stddef.h>
+#include "datatypes.h"
+#include "RMessageQueue.h"
+
+
+typedef struct RBuffer{
+ uint8 *buffer;
+ uint16 maxBlocks;
+ uint16 blockSize;
+} RBuffer;
+
+typedef struct RMessageService {
+ RMessageQueue messageQueue;
+ RMessageQueue messagePool;
+ RBuffer messageBuffer;
+} RMessageService;
+
+void RMessageService_init(RMessageService* self, uint8* buffer, uint16 maxBlocks, uint16 blockSize);
+
+void RMessageService_initMessagePool(RMessageService* self);
+
+void RMessageService_pushMessage(RMessageService* self, RMessage* msg);
+RMessage* RMessageService_popMessage(RMessageService* self);
+
+
+RMessage* RMessageService_getMessageBuffer(RMessageService* self, int16 size);
+void RMessageService_returnMessageBuffer(RMessageService* self, RMessage* buffer);
+
+#endif /* RMESSAGESERVICE_H_ */
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RUnit.c b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RUnit.c
index 655e84d43..0ab3e7dce 100644
--- a/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RUnit.c
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/runtime/RUnit.c
@@ -16,10 +16,13 @@
void RUnit_open(const char *testSuiteName) {
RUnit_passCount = 0;
RUnit_failCount = 0;
- printf("************* TEST START **************\n");
+ printf("************* TEST START (%s) **************\n", testSuiteName);
+
+ char filename[256];
+ sprintf(filename, "%s.xml", testSuiteName);
if (RUnit_reportfile == NULL) {
- RUnit_reportfile = fopen("report.xml", "w+");
+ RUnit_reportfile = fopen(filename, "w+");
if (RUnit_reportfile != NULL) {
fprintf(
RUnit_reportfile,
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/test/TestMessage.c b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestMessage.c
new file mode 100644
index 000000000..848bbe94c
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestMessage.c
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "TestMessage.h"
+
+#include <stddef.h>
+#include "RUnit.h"
+#include "RMessage.h"
+
+
+
+void TestMessage_testBasicMessage(void){
+
+ RMessage msg1 = {(RMessage*)1234567, 123,456,};
+ RMessage msg2 = {NULL, 222,333};
+
+ // basic checks -> detects structure changes that would cause problems for generated code
+ EXPECT_EQUAL_INT("Message.next", 1234567,msg1.next);
+ EXPECT_EQUAL_INT("Message.address", 123,msg1.address);
+ EXPECT_EQUAL_INT("Message.evtID", 456,msg1.evtID);
+
+ // build pointer ring
+ msg1.next = &msg2;
+ msg2.next = &msg1;
+
+ EXPECT_EQUAL_INT("msg1.NextMsg", msg2.evtID, msg1.next->evtID);
+ EXPECT_EQUAL_INT("msg2.NextMsg", msg1.evtID, msg2.next->evtID);
+
+
+}
+
+
+void TestMessage_runSuite(void){
+ RUnit_open("testMessage");
+ TestMessage_testBasicMessage();
+ RUnit_close();
+}
+
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/test/TestMessage.h b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestMessage.h
new file mode 100644
index 000000000..8a898e137
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestMessage.h
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef TESTMESSAGE_H_
+#define TESTMESSAGE_H_
+
+
+void TestMessage_runSuite(void);
+
+
+#endif /* TESTMESSAGE_H_ */
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageQueue.c b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageQueue.c
new file mode 100644
index 000000000..1bc7b2772
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageQueue.c
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "TestRMessageQueue.h"
+#include "RUnit.h"
+#include "RMessageQueue.h"
+
+void testPushPop(void){
+ RMessage msg1 = {NULL, 123, 456};
+ RMessage msg2 = {NULL, 222, 333};
+
+ RMessageQueue queue1;
+ RMessageQueue_init(&queue1);
+
+ RMessageQueue_push(&queue1, &msg1);
+ RMessageQueue_push(&queue1, &msg2);
+
+ EXPECT_EQUAL_INT("RMessageQueue.size before", 2,queue1.size);
+ EXPECT_EQUAL_INT("RMessageQueue.highWaterMark before", 2,queue1.highWaterMark);
+
+ RMessage* rcvMsg1 = RMessageQueue_pop(&queue1);
+ RMessage* rcvMsg2 = RMessageQueue_pop(&queue1);
+
+ EXPECT_EQUAL_INT("RMessageQueue.size after", 0,queue1.size);
+ EXPECT_EQUAL_INT("RMessageQueue.highWaterMark after", 2,queue1.highWaterMark);
+
+ EXPECT_EQUAL_INT("rcvMsg1->address", 123, rcvMsg1->address);
+ EXPECT_EQUAL_INT("rcvMsg1->evtID", 456, rcvMsg1->evtID);
+ EXPECT_EQUAL_INT("rcvMsg1->next", NULL, rcvMsg1->next);
+
+ EXPECT_EQUAL_INT("rcvMsg2->address", 222, rcvMsg2->address);
+ EXPECT_EQUAL_INT("rcvMsg2->evtID", 333, rcvMsg2->evtID);
+ EXPECT_EQUAL_INT("rcvMsg2->next", NULL, rcvMsg2->next);
+
+ EXPECT_EQUAL_INT("RMessageQueue->first", NULL, queue1.first);
+ EXPECT_EQUAL_INT("RMessageQueue->last", NULL, queue1.last);
+
+ RMessage* rcvMsg3 = RMessageQueue_pop(&queue1);
+ EXPECT_EQUAL_INT("RMessageQueue_pop if empty", NULL, rcvMsg3);
+
+}
+
+#define MAX 1000
+
+void testMassiveMessaging(void){
+ RMessage msgArray[MAX];
+ printf("sizeof(RMessage):%d\n", sizeof(RMessage));
+ printf("size(msgArray):%d\n", sizeof(msgArray));
+
+ RMessageQueue queue1;
+ RMessageQueue_init(&queue1);
+
+ int i;
+ for(i=0; i<MAX; i++){
+ //RMessage_init(&msgArray[i]);
+ msgArray[i].address = i;
+ msgArray[i].evtID = i;
+ }
+
+ int j;
+ for(j=0; j<3; j++){
+ for (i=0; i<MAX; i++){
+ RMessageQueue_push(&queue1, &(msgArray[i]));
+ }
+ for (i=0; i<MAX; i++){
+ RMessage* msg = RMessageQueue_pop(&queue1);
+ // EXPECTS are hidden to avoid too many testcases in log
+ if (msg == NULL){
+ EXPECT_FALSE("msg == NULL", TRUE);
+ break;
+ }
+ if (msg->address != msg->evtID){
+ EXPECT_FALSE("msg->address != msg->evtID", TRUE);
+ break;
+ }
+ if (msg->address != i){
+ EXPECT_FALSE("msg->address != i", TRUE);
+ break;
+ }
+ }
+ EXPECT_EQUAL_INT("i==MAX", MAX, i);
+ }
+}
+
+void TestMessageQueue_runSuite(void){
+ RUnit_open("TestRMessageQueue");
+ testPushPop();
+ testMassiveMessaging();
+ RUnit_close();
+}
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageQueue.h b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageQueue.h
new file mode 100644
index 000000000..5c3b51eaa
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageQueue.h
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef TESTRMESSAGEQUEUE_H_
+#define TESTRMESSAGEQUEUE_H_
+
+void TestMessageQueue_runSuite(void);
+
+#endif /* TESTRMESSAGEQUEUE_H_ */
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageService.c b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageService.c
new file mode 100644
index 000000000..e11e3c556
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageService.c
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "TestRMessageService.h"
+#include "RUnit.h"
+#include "RMessageService.h"
+
+
+void testRMessageService_init(void){
+ RMessageService msgService;
+ int16 max = 6;
+ int16 blockSize = 32;
+
+ uint8 msgBuffer[max*blockSize];
+
+ RMessageService_init(&msgService, msgBuffer, max, blockSize);
+
+ EXPECT_EQUAL_INT("msgService.messagePool.first", msgBuffer, msgService.messagePool.first);
+ EXPECT_EQUAL_INT("msgService.messagePool in between", &msgBuffer[3*blockSize], msgService.messagePool.first->next->next->next);
+ EXPECT_EQUAL_INT("msgService.messagePool.last(1)", &msgBuffer[5*blockSize], msgService.messagePool.first->next->next->next->next->next);
+ EXPECT_EQUAL_INT("msgService.messagePool.last(2)", &msgBuffer[5*blockSize], msgService.messagePool.last);
+ EXPECT_EQUAL_INT("msgService.messagePool.last.next", NULL, msgService.messagePool.last->next);
+
+
+}
+
+void testRMessageService_GetPushPopReturn(void){
+ RMessageService msgService;
+ int16 max = 6;
+ int16 blockSize = 32;
+ uint8 msgBuffer[max*blockSize];
+
+ RMessageService_init(&msgService, msgBuffer, max, blockSize);
+
+ // get messages from pool
+ RMessage* msg1 = RMessageService_getMessageBuffer(&msgService, sizeof(RMessage));
+ RMessage* msg2 = RMessageService_getMessageBuffer(&msgService, sizeof(RMessage));
+
+ EXPECT_EQUAL_INT("msgService.messagePool.size", 4, msgService.messagePool.size);
+
+ // define content
+ msg1->address = 11;
+ msg1->evtID = 111;
+ msg2->address = 22;
+ msg2->evtID = 222;
+
+ // push messages to queue
+ RMessageService_pushMessage(&msgService, msg2);
+ RMessageService_pushMessage(&msgService, msg1);
+
+ EXPECT_EQUAL_INT("msgService.messageQueue.size", 2, msgService.messageQueue.size);
+
+ // pop messages from queue
+ RMessage* rcvMsg1 = RMessageService_popMessage(&msgService);
+ RMessage* rcvMsg2 = RMessageService_popMessage(&msgService);
+
+ EXPECT_EQUAL_INT("msgService.messageQueue.size",0, msgService.messageQueue.size);
+
+
+ EXPECT_EQUAL_INT("msgService.popMessage", 22, rcvMsg1->address);
+ EXPECT_EQUAL_INT("msgService.popMessage", 222, rcvMsg1->evtID);
+ EXPECT_EQUAL_INT("msgService.popMessage", 11, rcvMsg2->address);
+ EXPECT_EQUAL_INT("msgService.popMessage", 111, rcvMsg2->evtID);
+
+ RMessageService_returnMessageBuffer(&msgService, rcvMsg1);
+ RMessageService_returnMessageBuffer(&msgService, rcvMsg2);
+
+ EXPECT_EQUAL_INT("msgService.messagePool.size", 6, msgService.messagePool.size);
+
+}
+
+void testRMessageService_GetReturn(void){
+ RMessageService msgService;
+ int16 max = 2;
+ int16 blockSize = 32;
+ uint8 msgBuffer[max*blockSize];
+
+ RMessageService_init(&msgService, msgBuffer, max, blockSize);
+
+ // get on message too much from pool
+ RMessage* msg1 = RMessageService_getMessageBuffer(&msgService, sizeof(RMessage));
+ RMessage* msg2 = RMessageService_getMessageBuffer(&msgService, sizeof(RMessage));
+ RMessage* msg3 = RMessageService_getMessageBuffer(&msgService, sizeof(RMessage));
+ EXPECT_TRUE("msgService getMessageBuffer", msg1!=NULL);
+ EXPECT_TRUE("msgService getMessageBuffer", msg2!=NULL);
+ EXPECT_EQUAL_INT("msgService getMessageBuffer", msg3, NULL);
+
+ // return messages
+ RMessageService_returnMessageBuffer(&msgService, msg1);
+ RMessageService_returnMessageBuffer(&msgService, msg2);
+ EXPECT_EQUAL_INT("msgService.messagePool.size", 2, msgService.messagePool.size);
+
+ // get message bigger than blocksize
+ RMessage* msg4 = RMessageService_getMessageBuffer(&msgService, 33);
+ EXPECT_EQUAL_INT("msgService getMessageBuffer", msg4, NULL);
+
+}
+
+void TestRMessageService_runSuite(void){
+ RUnit_open("TestRMessageService");
+ testRMessageService_init();
+ testRMessageService_GetPushPopReturn();
+ testRMessageService_GetReturn();
+ RUnit_close();
+}
diff --git a/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageService.h b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageService.h
new file mode 100644
index 000000000..981a0484b
--- /dev/null
+++ b/examples/org.eclipse.etrice.generator.c.reference/src/test/TestRMessageService.h
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef TESTRMESSAGESERVICE_H_
+#define TESTRMESSAGESERVICE_H_
+
+#include "RMessageService.h"
+
+void TestRMessageService_runSuite(void);
+
+
+#endif /* TESTRMESSAGESERVICE_H_ */

Back to the top