Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-02-20 09:32:09 +0000
committerHenrik Rentz-Reichert2012-02-20 09:32:09 +0000
commitc4a795f431f8ee844b48a56016a0a9ab02ad4dd3 (patch)
treec823dbf412cca7e9b207bb27078225df11c5d1a9 /runtime
parent90088f94927e0583d8d00bc824e92addd72184bf (diff)
downloadorg.eclipse.etrice-c4a795f431f8ee844b48a56016a0a9ab02ad4dd3.tar.gz
org.eclipse.etrice-c4a795f431f8ee844b48a56016a0a9ab02ad4dd3.tar.xz
org.eclipse.etrice-c4a795f431f8ee844b48a56016a0a9ab02ad4dd3.zip
[generator, generator.c, generator.java, runtime.c, runtime.java] unified code generation for Java and C including state machine generation
Diffstat (limited to 'runtime')
-rw-r--r--runtime/org.eclipse.etrice.modellib/models/TimingService.room2
-rw-r--r--runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/ATimingService.java199
-rw-r--r--runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimeout.java19
-rw-r--r--runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimer.java19
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.abin129984 -> 144124 bytes
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etActor.c18
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etActor.h24
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h1
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etMessageReceiver.h2
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/etPort.h2
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java2
11 files changed, 158 insertions, 130 deletions
diff --git a/runtime/org.eclipse.etrice.modellib/models/TimingService.room b/runtime/org.eclipse.etrice.modellib/models/TimingService.room
index 2498d0947..8fccf01e5 100644
--- a/runtime/org.eclipse.etrice.modellib/models/TimingService.room
+++ b/runtime/org.eclipse.etrice.modellib/models/TimingService.room
@@ -40,7 +40,7 @@ RoomModel room.basic.service.timing {
action {
"// start timeout"
"taskCount++;"
- "if (taskCount>PURGE_LIMIT) timerService.purge();"
+ "if (taskCount>PURGE_LIMIT) timerService.purge();"
"timerService.schedule(((PTimeoutPort)ifitem).getTask(), time_ms);"
}
}
diff --git a/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/ATimingService.java b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/ATimingService.java
index 2f23163f0..f30bfda23 100644
--- a/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/ATimingService.java
+++ b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/ATimingService.java
@@ -32,9 +32,9 @@ public class ATimingService extends ActorClassBase {
protected PTimeoutPortRepl timeout = null;
//--------------------- interface item IDs
- protected static final int IFITEM_timer = 1;
- protected static final int IFITEM_timeout = 2;
-
+ public static final int IFITEM_timer = 1;
+ public static final int IFITEM_timeout = 2;
+
//--------------------- attributes
//--------------------- operations
public void stop() {
@@ -72,100 +72,58 @@ public class ATimingService extends ActorClassBase {
destroyUser();
}
- //******************************************
- // START of generated code for FSM
- //******************************************
- // State IDs for FSM
- protected static final int STATE_Operational = 2;
- protected static final String stateStrings[] = {"<no state>","<top>","Operational"
- };
+ /* state IDs */
+ public static final int STATE_Operational = 2;
- // 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};
+ /* transition chains */
+ public static final int CHAIN_TRANS_INITIAL_TO__Operational = 1;
+ public static final int CHAIN_TRANS_Operational_TO_Operational_BY_Killtimeout_tr2 = 2;
+ public static final int CHAIN_TRANS_Operational_TO_Operational_BY_Killtimer_tr4 = 3;
+ public static final int CHAIN_TRANS_Operational_TO_Operational_BY_Starttimeout_tr1 = 4;
+ public static final int CHAIN_TRANS_Operational_TO_Operational_BY_Starttimer_tr3 = 5;
- // transition chains
- protected static final int CHAIN_TRANS_INITIAL_TO__Operational = 1;
- protected static final int CHAIN_TRANS_Operational_TO_Operational_BY_Killtimeout_tr2 = 2;
- protected static final int CHAIN_TRANS_Operational_TO_Operational_BY_Killtimer_tr4 = 3;
- protected static final int CHAIN_TRANS_Operational_TO_Operational_BY_Starttimeout_tr1 = 4;
- protected static final int CHAIN_TRANS_Operational_TO_Operational_BY_Starttimer_tr3 = 5;
+ /* triggers */
+ public static final int TRIG_timeout__Kill = IFITEM_timeout + EVT_SHIFT*PTimeout.IN_Kill;
+ public static final int TRIG_timeout__Start = IFITEM_timeout + EVT_SHIFT*PTimeout.IN_Start;
+ public static final int TRIG_timer__Kill = IFITEM_timer + EVT_SHIFT*PTimer.IN_Kill;
+ public static final int TRIG_timer__Start = IFITEM_timer + EVT_SHIFT*PTimer.IN_Start;
- // triggers for FSM
- protected static final int TRIG_timeout__Kill = IFITEM_timeout + EVT_SHIFT*PTimeout.IN_Kill;
- protected static final int TRIG_timeout__Start = IFITEM_timeout + EVT_SHIFT*PTimeout.IN_Start;
- protected static final int TRIG_timer__Kill = IFITEM_timer + EVT_SHIFT*PTimer.IN_Kill;
- protected static final int TRIG_timer__Start = IFITEM_timer + EVT_SHIFT*PTimer.IN_Start;
+ // state names
+ protected static final String stateStrings[] = {"<no state>","<top>","Operational"
+ };
- // 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_Operational:
- switch(trigger) {
- case TRIG_timeout__Start:
- {
- chain = CHAIN_TRANS_Operational_TO_Operational_BY_Starttimeout_tr1;
- catching_state = STATE_TOP;
- }
- break;
- case TRIG_timeout__Kill:
- {
- chain = CHAIN_TRANS_Operational_TO_Operational_BY_Killtimeout_tr2;
- catching_state = STATE_TOP;
- }
- break;
- case TRIG_timer__Start:
- {
- chain = CHAIN_TRANS_Operational_TO_Operational_BY_Starttimer_tr3;
- catching_state = STATE_TOP;
- }
- break;
- case TRIG_timer__Kill:
- {
- chain = CHAIN_TRANS_Operational_TO_Operational_BY_Killtimer_tr4;
- catching_state = STATE_TOP;
- }
- break;
- }
- 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);
- }
- }
+ // history
+ protected int history[] = {NO_STATE,NO_STATE,NO_STATE};
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__Operational;
- int next = executeTransitionChain(chain, null, null);
- next = enterHistory(next, false, false);
- setState(next);
+ //*** Entry and Exit Codes
+ protected void entry_Operational() {
+ // prepare
+ }
+
+ //*** Action Codes
+ protected void action_TRANS_INITIAL_TO__Operational() {
+ timerService = new Timer();
+ }
+ protected void action_TRANS_Operational_TO_Operational_BY_Starttimeout_tr1(InterfaceItemBase ifitem, int time_ms) {
+ // start timeout
+ taskCount++;
+ if (taskCount>PURGE_LIMIT) timerService.purge();
+ timerService.schedule(((PTimeoutPort)ifitem).getTask(), time_ms);
+ }
+ protected void action_TRANS_Operational_TO_Operational_BY_Starttimer_tr3(InterfaceItemBase ifitem, int time_ms) {
+ // start timer
+ taskCount++;
+ if (taskCount>PURGE_LIMIT) timerService.purge();
+ timerService.scheduleAtFixedRate(((PTimerPort)ifitem).getTask(), time_ms, time_ms);
}
/**
@@ -179,12 +137,13 @@ public class ATimingService extends ActorClassBase {
while (current!=to) {
switch (current) {
case STATE_Operational:
- history[STATE_TOP] = STATE_Operational;
+ this.history[STATE_TOP] = STATE_Operational;
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
@@ -222,6 +181,7 @@ public class ATimingService extends ActorClassBase {
}
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
@@ -236,7 +196,7 @@ public class ATimingService extends ActorClassBase {
// in leaf state: return state id
return STATE_Operational;
case STATE_TOP:
- state = history[STATE_TOP];
+ state = this.history[STATE_TOP];
break;
}
skip_entry = false;
@@ -244,26 +204,59 @@ public class ATimingService extends ActorClassBase {
//return NO_STATE; // required by CDT but detected as unreachable by JDT because of while (true)
}
- //*** Entry and Exit Codes
- protected void entry_Operational() {
- // prepare
+ public void executeInitTransition() {
+ int chain = CHAIN_TRANS_INITIAL_TO__Operational;
+ int next = executeTransitionChain(chain, null, null);
+ next = enterHistory(next, false, false);
+ setState(next);
}
- //*** Action Codes
- protected void action_TRANS_INITIAL_TO__Operational() {
- timerService = new Timer();
- }
- protected void action_TRANS_Operational_TO_Operational_BY_Starttimeout_tr1(InterfaceItemBase ifitem, int time_ms) {
- // start timeout
- taskCount++;
- if (taskCount>PURGE_LIMIT) timerService.purge();
- timerService.schedule(((PTimeoutPort)ifitem).getTask(), time_ms);
- }
- protected void action_TRANS_Operational_TO_Operational_BY_Starttimer_tr3(InterfaceItemBase ifitem, int time_ms) {
- // start timer
- taskCount++;
- if (taskCount>PURGE_LIMIT) timerService.purge();
- timerService.scheduleAtFixedRate(((PTimerPort)ifitem).getTask(), time_ms, time_ms);
+ /* receiveEvent contains the main implementation of the FSM */
+ 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 (this.state) {
+ case STATE_Operational:
+ switch(trigger) {
+ case TRIG_timeout__Start:
+ {
+ chain = CHAIN_TRANS_Operational_TO_Operational_BY_Starttimeout_tr1;
+ catching_state = STATE_TOP;
+ }
+ break;
+ case TRIG_timeout__Kill:
+ {
+ chain = CHAIN_TRANS_Operational_TO_Operational_BY_Killtimeout_tr2;
+ catching_state = STATE_TOP;
+ }
+ break;
+ case TRIG_timer__Start:
+ {
+ chain = CHAIN_TRANS_Operational_TO_Operational_BY_Starttimer_tr3;
+ catching_state = STATE_TOP;
+ }
+ break;
+ case TRIG_timer__Kill:
+ {
+ chain = CHAIN_TRANS_Operational_TO_Operational_BY_Killtimer_tr4;
+ catching_state = STATE_TOP;
+ }
+ break;
+ }
+ break;
+ }
+ }
+ if (chain != NOT_CAUGHT) {
+ exitTo(this.state, catching_state, is_handler);
+ int next = executeTransitionChain(chain, ifitem, generic_data);
+ next = enterHistory(next, is_handler, skip_entry);
+ setState(next);
+ }
}
//******************************************
diff --git a/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimeout.java b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimeout.java
index 1df8619e3..3f06d4ae0 100644
--- a/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimeout.java
+++ b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimeout.java
@@ -14,16 +14,11 @@ import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
public class PTimeout {
// message IDs
- // TODO: separate class for message IDs: class MSG{public static volatile int MSG_MIN = 0; ...} -> better structure
- // error if msgID <= MSG_MIN
- public static final int MSG_MIN = 0;
- //IDs for outgoing messages
+ public static final int MSG_MIN = 0;
public static final int OUT_timeoutTick = 1;
- //IDs for incoming messages
public static final int IN_Start = 2;
public static final int IN_Kill = 3;
- //error if msgID >= MSG_MAX
- public static final int MSG_MAX = 4;
+ public static final int MSG_MAX = 4;
//--------------------- begin user code
static protected class FireTimeoutTask extends TimerTask {
@@ -137,11 +132,11 @@ public class PTimeout {
//--------------------- operations
public void timeout(Integer id) {
//regular PortClass Operation timeout
- DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
- getPeerAddress(), messageStrings[OUT_timeoutTick]);
-
- getPeerMsgReceiver().receive(
- new EventWithDataMessage(getPeerAddress(), OUT_timeoutTick, id));
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(), messageStrings[OUT_timeoutTick]);
+
+ getPeerMsgReceiver().receive(
+ new EventWithDataMessage(getPeerAddress(), OUT_timeoutTick, id));
}
// sent messages
diff --git a/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimer.java b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimer.java
index 426cafb1f..aaa64e4bc 100644
--- a/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimer.java
+++ b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimer.java
@@ -14,16 +14,11 @@ import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
public class PTimer {
// message IDs
- // TODO: separate class for message IDs: class MSG{public static volatile int MSG_MIN = 0; ...} -> better structure
- // error if msgID <= MSG_MIN
- public static final int MSG_MIN = 0;
- //IDs for outgoing messages
+ public static final int MSG_MIN = 0;
public static final int OUT_timerTick = 1;
- //IDs for incoming messages
public static final int IN_Start = 2;
public static final int IN_Kill = 3;
- //error if msgID >= MSG_MAX
- public static final int MSG_MAX = 4;
+ public static final int MSG_MAX = 4;
//--------------------- begin user code
static protected class FireTimerTask extends TimerTask {
@@ -137,11 +132,11 @@ public class PTimer {
//--------------------- operations
public void timer(Integer id) {
//regular PortClass Operation timer
- DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
- getPeerAddress(), messageStrings[OUT_timerTick]);
-
- getPeerMsgReceiver().receive(
- new EventWithDataMessage(getPeerAddress(), OUT_timerTick, id));
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(), messageStrings[OUT_timerTick]);
+
+ getPeerMsgReceiver().receive(
+ new EventWithDataMessage(getPeerAddress(), OUT_timerTick, id));
}
// sent messages
diff --git a/runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.a b/runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.a
index 7ec20988a..6824bf738 100644
--- a/runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.a
+++ b/runtime/org.eclipse.etrice.runtime.c/Debug/liborg.eclipse.etrice.runtime.c.a
Binary files differ
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etActor.c b/runtime/org.eclipse.etrice.runtime.c/src/etActor.c
new file mode 100644
index 000000000..008a6474d
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etActor.c
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#include "etActor.h"
+
+boolean handleSystemEvent(InterfaceItemBase ifitem, int evt, void* generic_data) {
+ /* TODO */
+ return FALSE;
+}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etActor.h b/runtime/org.eclipse.etrice.runtime.c/src/etActor.h
new file mode 100644
index 000000000..5cd70f694
--- /dev/null
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etActor.h
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+#ifndef _ETACTOR_H_
+#define _ETACTOR_H_
+
+#include "etDataTypes.h"
+#include "etPort.h"
+
+#define NOT_CAUGHT 0
+#define EVT_SHIFT 100
+
+boolean handleSystemEvent(InterfaceItemBase ifitem, int evt, void* generic_data);
+
+#endif /* _ETACTOR_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h
index e49ebf53a..bf161f396 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etDatatypes.h
@@ -39,6 +39,7 @@ typedef double float64;
/* boolean datatypes and values */
typedef char bool; /* TODO: bool, Bool, Boolean, and boolean are already defined in some platforms*/
+typedef bool boolean;
#ifndef TRUE
#define TRUE 1
#endif
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etMessageReceiver.h b/runtime/org.eclipse.etrice.runtime.c/src/etMessageReceiver.h
index 4d5c35680..c75686654 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/etMessageReceiver.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etMessageReceiver.h
@@ -17,7 +17,7 @@
#include "etMessage.h"
-typedef void (*etActorReceiveMessage)(void* self, etInt16 localId, const etMessage* msg);
+typedef void (*etActorReceiveMessage)(void* self, void* ifitem, const etMessage* msg);
typedef void (*etDispatcherReceiveMessage)(const etMessage* msg);
#endif /* _ETMESSAGERECEIVER_H_ */
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/etPort.h b/runtime/org.eclipse.etrice.runtime.c/src/etPort.h
index f7b4ea81e..3e7bd617b 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/etPort.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/etPort.h
@@ -33,6 +33,8 @@ typedef struct {
#endif
} etPort;
+typedef etPort* InterfaceItemBase;
+
void etPort_receive(const etPort* self, const etMessage* msg);
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java
index ad67fc2c0..8cef1e8f0 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/ActorClassBase.java
@@ -99,7 +99,7 @@ public abstract class ActorClassBase extends EventReceiver implements IMessageRe
return ownMsgsvc;
}
- protected boolean handleSystemEvent(InterfaceItemBase ifitem, int evt, Object... generic_data){
+ protected boolean handleSystemEvent(InterfaceItemBase ifitem, int evt, Object generic_data){
if (ifitem.getLocalId()!=0){
return false;
}

Back to the top