Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-09-14 13:49:30 +0000
committerHenrik Rentz-Reichert2011-09-14 13:49:30 +0000
commitca30194a2188ca91e6edc783615259eeec795adc (patch)
treea1fe99006adfdfaa61569f579ea2cfea10e8ea58
parent1fc4477af26d9bacdf098cae1a96bcf453c06984 (diff)
downloadorg.eclipse.etrice-ca30194a2188ca91e6edc783615259eeec795adc.tar.gz
org.eclipse.etrice-ca30194a2188ca91e6edc783615259eeec795adc.tar.xz
org.eclipse.etrice-ca30194a2188ca91e6edc783615259eeec795adc.zip
[modellib] added generated code
-rw-r--r--modellib/org.eclipse.etrice.modellib/src-gen/readme.txt4
-rw-r--r--modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/ATimingService.java272
-rw-r--r--modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimeout.java337
-rw-r--r--modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimer.java336
4 files changed, 949 insertions, 0 deletions
diff --git a/modellib/org.eclipse.etrice.modellib/src-gen/readme.txt b/modellib/org.eclipse.etrice.modellib/src-gen/readme.txt
new file mode 100644
index 000000000..c3b99d458
--- /dev/null
+++ b/modellib/org.eclipse.etrice.modellib/src-gen/readme.txt
@@ -0,0 +1,4 @@
+This directory is an eTrice code generation target.
+It will be erased every time the generator is executed.
+
+DO NOT PLACE OTHER FILES HERE!
diff --git a/modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/ATimingService.java b/modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/ATimingService.java
new file mode 100644
index 000000000..4f415379b
--- /dev/null
+++ b/modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/ATimingService.java
@@ -0,0 +1,272 @@
+package room.basic.service.timing;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.IRTObject;
+import org.eclipse.etrice.runtime.java.messaging.IMessageReceiver;
+import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;
+import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;
+import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;
+import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
+
+
+import room.basic.service.timing.PTimeout.*;
+import room.basic.service.timing.PTimer.*;
+
+//--------------------- begin user code
+ import java.util.Timer;
+ //--------------------- end user code
+
+
+public class ATimingService extends ActorClassBase {
+
+ //--------------------- begin user code
+ private Timer timerService = null;
+ private int taskCount = 0;
+ private static final int PURGE_LIMIT = 1000;
+ //--------------------- end user code
+
+ //--------------------- ports
+ //--------------------- saps
+ //--------------------- services
+ protected PTimerPortRepl timer = null;
+ protected PTimeoutPortRepl timeout = null;
+
+ //--------------------- interface item IDs
+ protected static final int IFITEM_timer = 1;
+ protected static final int IFITEM_timeout = 2;
+
+ //--------------------- attributes
+ //--------------------- operations
+ public void stop (){
+ System.out.println(toString() + "::stop()");
+ timerService.cancel();
+ timerService = null;
+ }
+
+ //--------------------- construction
+ public ATimingService(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
+ super(parent, name, port_addr[0][0], peer_addr[0][0]);
+ setClassName("ATimingService");
+
+ // initialize attributes
+
+ // own ports
+ // own saps
+ // own service implementations
+ timer = new PTimerPortRepl(this, "timer", IFITEM_timer, port_addr[IFITEM_timer], peer_addr[IFITEM_timer]);
+ timeout = new PTimeoutPortRepl(this, "timeout", IFITEM_timeout, port_addr[IFITEM_timeout], peer_addr[IFITEM_timeout]);
+ }
+
+
+ //--------------------- lifecycle functions
+ public void init(){
+ initUser();
+ }
+
+ public void start(){
+ startUser();
+ }
+
+
+ public void destroy(){
+ 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"
+ };
+
+ // 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
+ 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 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;
+
+ // 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);
+ }
+ }
+
+ 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);
+ }
+
+ /**
+ * 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_Operational:
+ 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
+ * @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__Operational:
+ {
+ action_TRANS_INITIAL_TO__Operational();
+ return STATE_Operational;
+ }
+ case CHAIN_TRANS_Operational_TO_Operational_BY_Starttimeout_tr1:
+ {
+ int time_ms = (Integer) generic_data;
+ action_TRANS_Operational_TO_Operational_BY_Starttimeout_tr1(ifitem, time_ms);
+ return STATE_Operational;
+ }
+ case CHAIN_TRANS_Operational_TO_Operational_BY_Killtimeout_tr2:
+ {
+ return STATE_Operational;
+ }
+ case CHAIN_TRANS_Operational_TO_Operational_BY_Starttimer_tr3:
+ {
+ int time_ms = (Integer) generic_data;
+ action_TRANS_Operational_TO_Operational_BY_Starttimer_tr3(ifitem, time_ms);
+ return STATE_Operational;
+ }
+ case CHAIN_TRANS_Operational_TO_Operational_BY_Killtimer_tr4:
+ {
+ return STATE_Operational;
+ }
+ }
+ 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_Operational:
+ if (!(skip_entry || handler)) entry_Operational();
+ // in leaf state: return state id
+ return STATE_Operational;
+ 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_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);
+ }
+
+ //******************************************
+ // END of generated code for FSM
+ //******************************************
+};
diff --git a/modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimeout.java b/modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimeout.java
new file mode 100644
index 000000000..81cb8ec53
--- /dev/null
+++ b/modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimeout.java
@@ -0,0 +1,337 @@
+package room.basic.service.timing;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+import org.eclipse.etrice.runtime.java.modelbase.*;
+import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
+
+//--------------------- begin user code
+ import java.util.TimerTask;
+ //--------------------- end user code
+
+
+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 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;
+
+ //--------------------- begin user code
+ static protected class FireTimeoutTask extends TimerTask {
+
+ private int time;
+ private int id;
+ private PTimeoutPort port;
+
+ public FireTimeoutTask(int time, int id, PTimeoutPort port) {
+ this.time = time;
+ this.id = id;
+ this.port = port;
+ }
+
+ @Override
+ public void run() {
+ port.timeout(id);
+ }
+
+ public int getTime() {
+ return time;
+ }
+
+ public int getId() {
+ return id;
+ }
+ }
+
+ static protected class TimeoutData {
+ int time;
+ int id;
+ public TimeoutData(int time, int id) {
+ this.time = time;
+ this.id = id;
+ }
+ }
+ //--------------------- end user code
+
+ private static String messageStrings[] = {"MIN", "timeoutTick", "Start","Kill","MAX"};
+
+ public String getMessageString(int msg_id) {
+ if (msg_id<0 || msg_id>MSG_MAX+1){
+ // id out of range
+ return "Message ID out of range";
+ }
+ else{
+ return messageStrings[msg_id];
+ }
+ }
+
+
+ // port class
+ static public class PTimeoutPort extends PortBase {
+ //--------------------- begin user code
+ private FireTimeoutTask task = null;
+
+ public TimerTask getTask() { return task; }
+ //--------------------- end user code
+ // constructors
+ public PTimeoutPort(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
+ super(actor, name, localId, 0, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+ public PTimeoutPort(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) {
+ super(actor, name, localId, idx, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+
+ @Override
+ public void receive(Message m) {
+ if (!(m instanceof EventMessage))
+ return;
+ EventMessage msg = (EventMessage) m;
+ if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
+ System.out.println("unknown");
+ else {
+ if (messageStrings[msg.getEvtId()] != "timerTick"){
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]);
+ }
+ switch (msg.getEvtId()) {
+ case IN_Start:
+ {
+ //regular PortClass handle start
+ EventWithDataMessage dataMsg = (EventWithDataMessage) msg;
+ TimeoutData td = (TimeoutData)dataMsg.getData();
+ task = new FireTimeoutTask(td.time, td.id, this);
+ getActor().receiveEvent(this, IN_Start, td.time);
+ }
+ break;
+ case IN_Kill:
+ {
+ //regular PortClass handle kill
+ EventWithDataMessage dataMsg = (EventWithDataMessage) msg;
+ int id = (Integer)dataMsg.getData();
+ if (task!=null && task.getId()==id) {
+ task.cancel();
+ }
+ }
+ break;
+ default:
+ if (msg instanceof EventWithDataMessage)
+ getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());
+ else
+ getActor().receiveEvent(this, msg.getEvtId(), null);
+ }
+ }
+ }
+
+ //--------------------- attributes
+ //--------------------- 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));
+ }
+
+ // sent messages
+ public void timeoutTick ()
+ {
+ if (messageStrings[ OUT_timeoutTick] != "timerTick"){
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[OUT_timeoutTick]);
+ }
+ if (getPeerAddress()!=null)
+ getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), OUT_timeoutTick));
+ }
+ }
+
+ // replicated port class
+ static public class PTimeoutPortRepl {
+ private ArrayList<PTimeoutPort> ports;
+ private int replication;
+
+ public PTimeoutPortRepl(IEventReceiver actor, String name, int localId, Address[] addr,
+ Address[] peerAddress) {
+ replication = addr.length;
+ ports = new ArrayList<PTimeout.PTimeoutPort>(replication);
+ for (int i=0; i<replication; ++i) {
+ ports.add(new PTimeoutPort(
+ actor, name+i, localId, i, addr[i], peerAddress[i]));
+ }
+ }
+
+ public int getReplication() {
+ return replication;
+ }
+
+ public int getIndexOf(InterfaceItemBase ifitem){
+ return ifitem.getIdx();
+ }
+
+ public PTimeoutPort get(int i) {
+ return ports.get(i);
+ }
+
+ // outgoing messages
+ public void timeoutTick ()
+ {
+ for (int i=0; i<replication; ++i) {
+ ports.get(i).timeoutTick()
+ ;
+ }
+ }
+ }
+
+ // interface for port class
+ public interface IPTimeoutPort{
+ // incoming messages
+ public void Start (int time_ms)
+ ;
+ public void Kill ()
+ ;
+ }
+
+ // port class
+ static public class PTimeoutConjPort extends PortBase {
+ //--------------------- begin user code
+ private int currentId = 0;
+ private boolean active = false;
+ //--------------------- end user code
+ // constructors
+ public PTimeoutConjPort(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
+ super(actor, name, localId, 0, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+ public PTimeoutConjPort(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) {
+ super(actor, name, localId, idx, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+
+ @Override
+ public void receive(Message m) {
+ if (!(m instanceof EventMessage))
+ return;
+ EventMessage msg = (EventMessage) m;
+ if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
+ System.out.println("unknown");
+ else {
+ if (messageStrings[msg.getEvtId()] != "timerTick"){
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]);
+ }
+ switch (msg.getEvtId()) {
+ case OUT_timeoutTick:
+ {
+ //conjugate PortClass handle timeout
+ EventWithDataMessage dataMsg = (EventWithDataMessage) msg;
+ int id = (Integer)dataMsg.getData();
+ if (active && id==currentId) {
+ active = false;
+ getActor().receiveEvent(this, msg.getEvtId(), null);
+ }
+ }
+ break;
+ default:
+ if (msg instanceof EventWithDataMessage)
+ getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());
+ else
+ getActor().receiveEvent(this, msg.getEvtId(), null);
+ }
+ }
+ }
+
+ //--------------------- attributes
+ //--------------------- operations
+
+ // sent messages
+ public void Start (int time_ms)
+ {
+ //conjugate PortClass handle start
+ if (active)
+ return;
+
+ active = true;
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(), messageStrings[IN_Start]);
+
+ getPeerMsgReceiver()
+ .receive(
+ new EventWithDataMessage(getPeerAddress(),
+ IN_Start, new TimeoutData(time_ms, ++currentId)));
+ }
+ public void Kill ()
+ {
+ //conjugate PortClass kill
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(), messageStrings[IN_Kill]);
+
+ if (active) {
+ active = false;
+ getPeerMsgReceiver().receive(
+ new EventWithDataMessage(getPeerAddress(), IN_Kill, new Integer(currentId)));
+ }
+ }
+ }
+
+ // replicated port class
+ static public class PTimeoutConjPortRepl {
+ private ArrayList<PTimeoutConjPort> ports;
+ private int replication;
+
+ public PTimeoutConjPortRepl(IEventReceiver actor, String name, int localId, Address[] addr,
+ Address[] peerAddress) {
+ replication = addr.length;
+ ports = new ArrayList<PTimeout.PTimeoutConjPort>(replication);
+ for (int i=0; i<replication; ++i) {
+ ports.add(new PTimeoutConjPort(
+ actor, name+i, localId, i, addr[i], peerAddress[i]));
+ }
+ }
+
+ public int getReplication() {
+ return replication;
+ }
+
+ public int getIndexOf(InterfaceItemBase ifitem){
+ return ifitem.getIdx();
+ }
+
+ public PTimeoutConjPort get(int i) {
+ return ports.get(i);
+ }
+
+ // incoming messages
+ public void Start (int time_ms)
+ {
+ for (int i=0; i<replication; ++i) {
+ ports.get(i).Start( time_ms)
+ ;
+ }
+ }
+ public void Kill ()
+ {
+ for (int i=0; i<replication; ++i) {
+ ports.get(i).Kill()
+ ;
+ }
+ }
+ }
+
+ // interface for port class
+ public interface IPTimeoutConjPort{
+ // outgoing messages
+ public void timeoutTick ()
+ ;
+ }
+}
diff --git a/modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimer.java b/modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimer.java
new file mode 100644
index 000000000..ad38c6340
--- /dev/null
+++ b/modellib/org.eclipse.etrice.modellib/src-gen/room/basic/service/timing/PTimer.java
@@ -0,0 +1,336 @@
+package room.basic.service.timing;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.runtime.java.messaging.Address;
+import org.eclipse.etrice.runtime.java.messaging.Message;
+import org.eclipse.etrice.runtime.java.modelbase.*;
+import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
+
+//--------------------- begin user code
+ import java.util.TimerTask;
+ //--------------------- end user code
+
+
+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 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;
+
+ //--------------------- begin user code
+ static protected class FireTimerTask extends TimerTask {
+
+ private int time;
+ private int id;
+ private PTimerPort port;
+
+ public FireTimerTask(int time, int id, PTimerPort port) {
+ this.time = time;
+ this.id = id;
+ this.port = port;
+ }
+
+ @Override
+ public void run() {
+ port.timer(id);
+ }
+
+ public int getTime() {
+ return time;
+ }
+
+ public int getId() {
+ return id;
+ }
+ }
+
+ static protected class TimerData {
+ int time;
+ int id;
+ public TimerData(int time, int id) {
+ this.time = time;
+ this.id = id;
+ }
+ }
+ //--------------------- end user code
+
+ private static String messageStrings[] = {"MIN", "timerTick", "Start","Kill","MAX"};
+
+ public String getMessageString(int msg_id) {
+ if (msg_id<0 || msg_id>MSG_MAX+1){
+ // id out of range
+ return "Message ID out of range";
+ }
+ else{
+ return messageStrings[msg_id];
+ }
+ }
+
+
+ // port class
+ static public class PTimerPort extends PortBase {
+ //--------------------- begin user code
+ private FireTimerTask task = null;
+
+ public TimerTask getTask() { return task; }
+ //--------------------- end user code
+ // constructors
+ public PTimerPort(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
+ super(actor, name, localId, 0, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+ public PTimerPort(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) {
+ super(actor, name, localId, idx, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+
+ @Override
+ public void receive(Message m) {
+ if (!(m instanceof EventMessage))
+ return;
+ EventMessage msg = (EventMessage) m;
+ if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
+ System.out.println("unknown");
+ else {
+ if (messageStrings[msg.getEvtId()] != "timerTick"){
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]);
+ }
+ switch (msg.getEvtId()) {
+ case IN_Start:
+ {
+ //regular PortClass handle start
+ EventWithDataMessage dataMsg = (EventWithDataMessage) msg;
+ TimerData td = (TimerData)dataMsg.getData();
+ task = new FireTimerTask(td.time, td.id, this);
+ getActor().receiveEvent(this, IN_Start, td.time);
+ }
+ break;
+ case IN_Kill:
+ {
+ //regular PortClass handle kill
+ EventWithDataMessage dataMsg = (EventWithDataMessage) msg;
+ int id = (Integer)dataMsg.getData();
+ if (task!=null && task.getId()==id) {
+ task.cancel();
+ }
+ }
+ break;
+ default:
+ if (msg instanceof EventWithDataMessage)
+ getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());
+ else
+ getActor().receiveEvent(this, msg.getEvtId(), null);
+ }
+ }
+ }
+
+ //--------------------- attributes
+ //--------------------- 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));
+ }
+
+ // sent messages
+ public void timerTick ()
+ {
+ if (messageStrings[ OUT_timerTick] != "timerTick"){
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[OUT_timerTick]);
+ }
+ if (getPeerAddress()!=null)
+ getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), OUT_timerTick));
+ }
+ }
+
+ // replicated port class
+ static public class PTimerPortRepl {
+ private ArrayList<PTimerPort> ports;
+ private int replication;
+
+ public PTimerPortRepl(IEventReceiver actor, String name, int localId, Address[] addr,
+ Address[] peerAddress) {
+ replication = addr.length;
+ ports = new ArrayList<PTimer.PTimerPort>(replication);
+ for (int i=0; i<replication; ++i) {
+ ports.add(new PTimerPort(
+ actor, name+i, localId, i, addr[i], peerAddress[i]));
+ }
+ }
+
+ public int getReplication() {
+ return replication;
+ }
+
+ public int getIndexOf(InterfaceItemBase ifitem){
+ return ifitem.getIdx();
+ }
+
+ public PTimerPort get(int i) {
+ return ports.get(i);
+ }
+
+ // outgoing messages
+ public void timerTick ()
+ {
+ for (int i=0; i<replication; ++i) {
+ ports.get(i).timerTick()
+ ;
+ }
+ }
+ }
+
+ // interface for port class
+ public interface IPTimerPort{
+ // incoming messages
+ public void Start (int time_ms)
+ ;
+ public void Kill ()
+ ;
+ }
+
+ // port class
+ static public class PTimerConjPort extends PortBase {
+ //--------------------- begin user code
+ private int currentId = 0;
+ private boolean active = false;
+ //--------------------- end user code
+ // constructors
+ public PTimerConjPort(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
+ super(actor, name, localId, 0, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+ public PTimerConjPort(IEventReceiver actor, String name, int localId, int idx, Address addr, Address peerAddress) {
+ super(actor, name, localId, idx, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+
+ @Override
+ public void receive(Message m) {
+ if (!(m instanceof EventMessage))
+ return;
+ EventMessage msg = (EventMessage) m;
+ if (msg.getEvtId() <= 0 || msg.getEvtId() >= MSG_MAX)
+ System.out.println("unknown");
+ else {
+ if (messageStrings[msg.getEvtId()] != "timerTick"){
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), messageStrings[msg.getEvtId()]);
+ }
+ switch (msg.getEvtId()) {
+ case OUT_timerTick:
+ {
+ //conjugate PortClass handle timer
+ EventWithDataMessage dataMsg = (EventWithDataMessage) msg;
+ int id = (Integer)dataMsg.getData();
+ if (active && id==currentId) {
+ getActor().receiveEvent(this, msg.getEvtId(), null);
+ }
+ }
+ break;
+ default:
+ if (msg instanceof EventWithDataMessage)
+ getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());
+ else
+ getActor().receiveEvent(this, msg.getEvtId(), null);
+ }
+ }
+ }
+
+ //--------------------- attributes
+ //--------------------- operations
+
+ // sent messages
+ public void Start (int time_ms)
+ {
+ //conjugate PortClass handle start
+ if (active)
+ return;
+
+ active = true;
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(), messageStrings[IN_Start]);
+
+ getPeerMsgReceiver()
+ .receive(
+ new EventWithDataMessage(getPeerAddress(),
+ IN_Start, new TimerData(time_ms, ++currentId)));
+ }
+ public void Kill ()
+ {
+ //conjugate PortClass kill
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(),
+ getPeerAddress(), messageStrings[IN_Kill]);
+
+ if (active) {
+ active = false;
+ getPeerMsgReceiver().receive(
+ new EventWithDataMessage(getPeerAddress(), IN_Kill, currentId));
+ }
+ }
+ }
+
+ // replicated port class
+ static public class PTimerConjPortRepl {
+ private ArrayList<PTimerConjPort> ports;
+ private int replication;
+
+ public PTimerConjPortRepl(IEventReceiver actor, String name, int localId, Address[] addr,
+ Address[] peerAddress) {
+ replication = addr.length;
+ ports = new ArrayList<PTimer.PTimerConjPort>(replication);
+ for (int i=0; i<replication; ++i) {
+ ports.add(new PTimerConjPort(
+ actor, name+i, localId, i, addr[i], peerAddress[i]));
+ }
+ }
+
+ public int getReplication() {
+ return replication;
+ }
+
+ public int getIndexOf(InterfaceItemBase ifitem){
+ return ifitem.getIdx();
+ }
+
+ public PTimerConjPort get(int i) {
+ return ports.get(i);
+ }
+
+ // incoming messages
+ public void Start (int time_ms)
+ {
+ for (int i=0; i<replication; ++i) {
+ ports.get(i).Start( time_ms)
+ ;
+ }
+ }
+ public void Kill ()
+ {
+ for (int i=0; i<replication; ++i) {
+ ports.get(i).Kill()
+ ;
+ }
+ }
+ }
+
+ // interface for port class
+ public interface IPTimerConjPort{
+ // outgoing messages
+ public void timerTick ()
+ ;
+ }
+}

Back to the top