Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2012-01-25 10:37:37 +0000
committerThomas Schuetz2012-01-25 10:37:37 +0000
commit8e3702cf33a4be4974ed583fc15f35abfa0f0853 (patch)
tree7ed17fff828399aede256a521016c03c37a80716 /runtime
parent749b13f65870f2cbdc3ae89c90b432966300d235 (diff)
parent4cf0af1ebfd6c8c9f9122da470dc8e21f721fbfa (diff)
downloadorg.eclipse.etrice-8e3702cf33a4be4974ed583fc15f35abfa0f0853.tar.gz
org.eclipse.etrice-8e3702cf33a4be4974ed583fc15f35abfa0f0853.tar.xz
org.eclipse.etrice-8e3702cf33a4be4974ed583fc15f35abfa0f0853.zip
Merge branch 'master' of ssh://git.eclipse.org/gitroot/etrice/org.eclipse.etrice
Conflicts: plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/ProcedureHelpers.java runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketConfiguration.java runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketData.java runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/ALogService.java runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/InternalLogData.java runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/Log.java
Diffstat (limited to 'runtime')
-rw-r--r--runtime/org.eclipse.etrice.modellib/jgen_modellib.launch12
-rw-r--r--runtime/org.eclipse.etrice.modellib/models/ALogService.room9
-rw-r--r--runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketConfiguration.java81
-rw-r--r--runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketData.java51
-rw-r--r--runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/ALogService.java279
-rw-r--r--runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/InternalLogData.java61
-rw-r--r--runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/Log.java235
7 files changed, 725 insertions, 3 deletions
diff --git a/runtime/org.eclipse.etrice.modellib/jgen_modellib.launch b/runtime/org.eclipse.etrice.modellib/jgen_modellib.launch
new file mode 100644
index 000000000..5074d0e3f
--- /dev/null
+++ b/runtime/org.eclipse.etrice.modellib/jgen_modellib.launch
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.etrice.generator.java.Main"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="${workspace_loc:org.eclipse.etrice.modellib}/models/ALogService.room&#13;&#10;${workspace_loc:org.eclipse.etrice.modellib}/models/Socket.room&#13;&#10;${workspace_loc:org.eclipse.etrice.modellib}/models/TimingService.room&#13;&#10;-lib"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.etrice.generator.java"/>
+</launchConfiguration>
diff --git a/runtime/org.eclipse.etrice.modellib/models/ALogService.room b/runtime/org.eclipse.etrice.modellib/models/ALogService.room
index 3a946c1ce..d6f91e3c9 100644
--- a/runtime/org.eclipse.etrice.modellib/models/ALogService.room
+++ b/runtime/org.eclipse.etrice.modellib/models/ALogService.room
@@ -72,6 +72,12 @@ RoomModel room.basic.service.logging {
}
ProtocolClass Log {
+ usercode2 {
+ "public static final int LOG_LEVEL_LOW = 1;"
+ "public static final int LOG_LEVEL_MEDIUM = 2;"
+ "public static final int LOG_LEVEL_HIGH = 3;"
+ }
+
incoming {
Message open(fileName: string)
Message close()
@@ -80,9 +86,6 @@ RoomModel room.basic.service.logging {
conjugate PortClass {
usercode {
- "public static final int LOG_LEVEL_LOW = 1;"
- "public static final int LOG_LEVEL_MEDIUM = 2;"
- "public static final int LOG_LEVEL_HIGH = 3;"
"static int logLevel=0;"
"InternalLogData d = new InternalLogData();"
}
diff --git a/runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketConfiguration.java b/runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketConfiguration.java
new file mode 100644
index 000000000..cb7e3c3ae
--- /dev/null
+++ b/runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketConfiguration.java
@@ -0,0 +1,81 @@
+package org.eclipse.etrice.modellib.Socket;
+
+
+
+
+public class DSocketConfiguration {
+
+
+ //--------------------- attributes
+ protected String serverName;
+ protected int portNumber;
+ protected int protocol;
+ protected boolean checkCookie;
+ protected int mode;
+
+ //--------------------- attribute setters and getters
+ public void setServerName (String serverName) {
+ this.serverName = serverName;
+ }
+ public String getServerName () {
+ return this.serverName;
+ }
+ public void setPortNumber (int portNumber) {
+ this.portNumber = portNumber;
+ }
+ public int getPortNumber () {
+ return this.portNumber;
+ }
+ public void setProtocol (int protocol) {
+ this.protocol = protocol;
+ }
+ public int getProtocol () {
+ return this.protocol;
+ }
+ public void setCheckCookie (boolean checkCookie) {
+ this.checkCookie = checkCookie;
+ }
+ public boolean getCheckCookie () {
+ return this.checkCookie;
+ }
+ public void setMode (int mode) {
+ this.mode = mode;
+ }
+ public int getMode () {
+ return this.mode;
+ }
+
+ //--------------------- operations
+
+ // default constructor
+ public DSocketConfiguration() {
+ super();
+ // initialize attributes
+ serverName = "";
+ portNumber = 0;
+ protocol = 0;
+ checkCookie = false;
+ mode = 0;
+ }
+
+ // constructor using fields
+ public DSocketConfiguration(String serverName, int portNumber, int protocol, boolean checkCookie, int mode) {
+ super();
+ this.serverName = serverName;
+ this.portNumber = portNumber;
+ this.protocol = protocol;
+ this.checkCookie = checkCookie;
+ this.mode = mode;
+ }
+
+ // deep copy
+ public DSocketConfiguration deepCopy() {
+ DSocketConfiguration copy = new DSocketConfiguration();
+ copy.serverName = serverName;
+ copy.portNumber = portNumber;
+ copy.protocol = protocol;
+ copy.checkCookie = checkCookie;
+ copy.mode = mode;
+ return copy;
+ }
+};
diff --git a/runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketData.java b/runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketData.java
new file mode 100644
index 000000000..f4c37c67d
--- /dev/null
+++ b/runtime/org.eclipse.etrice.modellib/src-gen/org/eclipse/etrice/modellib/Socket/DSocketData.java
@@ -0,0 +1,51 @@
+package org.eclipse.etrice.modellib.Socket;
+
+
+
+
+public class DSocketData {
+
+
+ //--------------------- attributes
+ protected int size;
+ protected String data;
+
+ //--------------------- attribute setters and getters
+ public void setSize (int size) {
+ this.size = size;
+ }
+ public int getSize () {
+ return this.size;
+ }
+ public void setData (String data) {
+ this.data = data;
+ }
+ public String getData () {
+ return this.data;
+ }
+
+ //--------------------- operations
+
+ // default constructor
+ public DSocketData() {
+ super();
+ // initialize attributes
+ size = 0;
+ data = "";
+ }
+
+ // constructor using fields
+ public DSocketData(int size, String data) {
+ super();
+ this.size = size;
+ this.data = data;
+ }
+
+ // deep copy
+ public DSocketData deepCopy() {
+ DSocketData copy = new DSocketData();
+ copy.size = size;
+ copy.data = data;
+ return copy;
+ }
+};
diff --git a/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/ALogService.java b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/ALogService.java
new file mode 100644
index 000000000..4f148d217
--- /dev/null
+++ b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/ALogService.java
@@ -0,0 +1,279 @@
+package room.basic.service.logging;
+
+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.logging.Log.*;
+
+//--------------------- begin user code
+ import java.io.*;
+ import java.util.*;
+//--------------------- end user code
+
+
+public class ALogService extends ActorClassBase {
+
+ //--------------------- begin user code
+ FileOutputStream file = null;
+ PrintStream p = null;
+ static long tStart = System.currentTimeMillis();
+ //--------------------- end user code
+
+ //--------------------- ports
+ //--------------------- saps
+ //--------------------- services
+ protected LogPortRepl log = null;
+
+ //--------------------- interface item IDs
+ protected static final int IFITEM_log = 1;
+
+ //--------------------- attributes
+ //--------------------- operations
+ public void destroyUser() {
+ if (p!= null) {
+ p.flush();
+ p.close();
+ p=null;
+ }
+ }
+
+ //--------------------- construction
+ public ALogService(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
+ super(parent, name, port_addr[0][0], peer_addr[0][0]);
+ setClassName("ALogService");
+
+ // initialize attributes
+
+ // own ports
+ // own saps
+ // own service implementations
+ log = new LogPortRepl(this, "log", IFITEM_log, port_addr[IFITEM_log], peer_addr[IFITEM_log]);
+ }
+
+
+ //--------------------- 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_closed = 2;
+ protected static final int STATE_opened = 3;
+ protected static final String stateStrings[] = {"<no state>","<top>","closed",
+ "opened"
+ };
+
+ // 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__closed = 1;
+ protected static final int CHAIN_TRANS_closed_TO_opened_BY_openlog = 2;
+ protected static final int CHAIN_TRANS_opened_TO_closed_BY_closelog = 3;
+ protected static final int CHAIN_TRANS_opened_TO_opened_BY_internalLoglog_tr1 = 4;
+
+ // triggers for FSM
+ protected static final int TRIG_log__close = IFITEM_log + EVT_SHIFT*Log.IN_close;
+ protected static final int TRIG_log__internalLog = IFITEM_log + EVT_SHIFT*Log.IN_internalLog;
+ protected static final int TRIG_log__open = IFITEM_log + EVT_SHIFT*Log.IN_open;
+
+ // 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_closed:
+ switch(trigger) {
+ case TRIG_log__open:
+ {
+ chain = CHAIN_TRANS_closed_TO_opened_BY_openlog;
+ catching_state = STATE_TOP;
+ }
+ break;
+ }
+ break;
+ case STATE_opened:
+ switch(trigger) {
+ case TRIG_log__close:
+ {
+ chain = CHAIN_TRANS_opened_TO_closed_BY_closelog;
+ catching_state = STATE_TOP;
+ }
+ break;
+ case TRIG_log__internalLog:
+ {
+ chain = CHAIN_TRANS_opened_TO_opened_BY_internalLoglog_tr1;
+ 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__closed;
+ 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_closed:
+ history[STATE_TOP] = STATE_closed;
+ current = STATE_TOP;
+ break;
+ case STATE_opened:
+ history[STATE_TOP] = STATE_opened;
+ 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__closed:
+ {
+ return STATE_closed;
+ }
+ case CHAIN_TRANS_closed_TO_opened_BY_openlog:
+ {
+ String fileName = (String) generic_data;
+ action_TRANS_closed_TO_opened_BY_openlog(ifitem, fileName);
+ return STATE_opened;
+ }
+ case CHAIN_TRANS_opened_TO_closed_BY_closelog:
+ {
+ action_TRANS_opened_TO_closed_BY_closelog(ifitem);
+ return STATE_closed;
+ }
+ case CHAIN_TRANS_opened_TO_opened_BY_internalLoglog_tr1:
+ {
+ InternalLogData data = (InternalLogData) generic_data;
+ action_TRANS_opened_TO_opened_BY_internalLoglog_tr1(ifitem, data);
+ return STATE_opened;
+ }
+ }
+ 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_closed:
+ // in leaf state: return state id
+ return STATE_closed;
+ case STATE_opened:
+ // in leaf state: return state id
+ return STATE_opened;
+ 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_closed_TO_opened_BY_openlog(InterfaceItemBase ifitem, String fileName) {
+ Date d=new Date(tStart);
+ try{
+ file=new FileOutputStream(fileName);
+ p=new PrintStream(file);
+ p.println("Log opened at "+ d.toString());
+ p.println("--------------------------------------------------");
+ } catch (Exception e){
+ System.out.println("Log file not opened !");
+ }
+ }
+ protected void action_TRANS_opened_TO_closed_BY_closelog(InterfaceItemBase ifitem) {
+ p.flush();
+ p.close();
+ p=null;
+ }
+ protected void action_TRANS_opened_TO_opened_BY_internalLoglog_tr1(InterfaceItemBase ifitem, InternalLogData data) {
+ p.println("Timestamp: " + Long.toString(data.timeStamp-tStart) + "ms");
+ p.println("SenderInstance: "+ data.sender);
+ p.println("UserString: " + data.userString);
+ p.println("--------------------------------------------------");
+ System.out.printf(data.userString);
+ }
+
+ //******************************************
+ // END of generated code for FSM
+ //******************************************
+};
diff --git a/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/InternalLogData.java b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/InternalLogData.java
new file mode 100644
index 000000000..3a7968a26
--- /dev/null
+++ b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/InternalLogData.java
@@ -0,0 +1,61 @@
+package room.basic.service.logging;
+
+
+
+
+public class InternalLogData {
+
+
+ //--------------------- attributes
+ protected String userString;
+ protected String sender;
+ protected long timeStamp;
+
+ //--------------------- attribute setters and getters
+ public void setUserString (String userString) {
+ this.userString = userString;
+ }
+ public String getUserString () {
+ return this.userString;
+ }
+ public void setSender (String sender) {
+ this.sender = sender;
+ }
+ public String getSender () {
+ return this.sender;
+ }
+ public void setTimeStamp (long timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+ public long getTimeStamp () {
+ return this.timeStamp;
+ }
+
+ //--------------------- operations
+
+ // default constructor
+ public InternalLogData() {
+ super();
+ // initialize attributes
+ userString = "";
+ sender = "";
+ timeStamp = 0;
+ }
+
+ // constructor using fields
+ public InternalLogData(String userString, String sender, long timeStamp) {
+ super();
+ this.userString = userString;
+ this.sender = sender;
+ this.timeStamp = timeStamp;
+ }
+
+ // deep copy
+ public InternalLogData deepCopy() {
+ InternalLogData copy = new InternalLogData();
+ copy.userString = userString;
+ copy.sender = sender;
+ copy.timeStamp = timeStamp;
+ return copy;
+ }
+};
diff --git a/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/Log.java b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/Log.java
new file mode 100644
index 000000000..538f56e52
--- /dev/null
+++ b/runtime/org.eclipse.etrice.modellib/src-gen/room/basic/service/logging/Log.java
@@ -0,0 +1,235 @@
+package room.basic.service.logging;
+
+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;
+
+
+
+public class Log {
+ // 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
+ //IDs for incoming messages
+ public static final int IN_open = 1;
+ public static final int IN_close = 2;
+ public static final int IN_internalLog = 3;
+ //error if msgID >= MSG_MAX
+ public static final int MSG_MAX = 4;
+
+
+ private static String messageStrings[] = {"MIN", "open","close","internalLog","MAX"};
+
+ public String getMessageString(int msg_id) {
+ if (msg_id<MSG_MIN || 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 LogPort extends PortBase {
+ // constructors
+ public LogPort(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
+ super(actor, name, localId, 0, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+ public LogPort(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()]);
+ }
+ if (msg instanceof EventWithDataMessage)
+ getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());
+ else
+ getActor().receiveEvent(this, msg.getEvtId(), null);
+ }
+ }
+
+
+ // sent messages
+ }
+
+ // replicated port class
+ static public class LogPortRepl {
+ private ArrayList<LogPort> ports;
+ private int replication;
+
+ public LogPortRepl(IEventReceiver actor, String name, int localId, Address[] addr,
+ Address[] peerAddress) {
+ replication = addr.length;
+ ports = new ArrayList<Log.LogPort>(replication);
+ for (int i=0; i<replication; ++i) {
+ ports.add(new LogPort(
+ actor, name+i, localId, i, addr[i], peerAddress[i]));
+ }
+ }
+
+ public int getReplication() {
+ return replication;
+ }
+
+ public int getIndexOf(InterfaceItemBase ifitem){
+ return ifitem.getIdx();
+ }
+
+ public LogPort get(int i) {
+ return ports.get(i);
+ }
+
+ // outgoing messages
+ }
+
+
+ // port class
+ static public class LogConjPort extends PortBase {
+ //--------------------- begin user code
+ public static final int LOG_LEVEL_LOW = 1;
+ public static final int LOG_LEVEL_MEDIUM = 2;
+ public static final int LOG_LEVEL_HIGH = 3;
+ static int logLevel=0;
+ InternalLogData d = new InternalLogData();
+ //--------------------- end user code
+ // constructors
+ public LogConjPort(IEventReceiver actor, String name, int localId, Address addr, Address peerAddress) {
+ super(actor, name, localId, 0, addr, peerAddress);
+ DebuggingService.getInstance().addPortInstance(this);
+ }
+ public LogConjPort(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()]);
+ }
+ if (msg instanceof EventWithDataMessage)
+ getActor().receiveEvent(this, msg.getEvtId(), ((EventWithDataMessage)msg).getData());
+ else
+ getActor().receiveEvent(this, msg.getEvtId(), null);
+ }
+ }
+
+ //--------------------- attributes
+ //--------------------- operations
+ public void setLogLevel(int l) {
+ logLevel=l;
+ if (logLevel > LOG_LEVEL_HIGH) logLevel=LOG_LEVEL_HIGH;
+ }
+ public void log(int logLevel, String userString) {
+ long s;
+ if (logLevel>this.logLevel){
+ d.userString=userString;
+ d.timeStamp=System.currentTimeMillis();
+ d.sender=getInstancePath();
+ if (getPeerAddress()!=null)
+ getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), IN_internalLog, d));
+ }
+ }
+
+ // sent messages
+ public void open(String fileName) {
+ if (messageStrings[ IN_open] != "timerTick"){
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_open]);
+ }
+ if (getPeerAddress()!=null)
+ getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), IN_open, fileName));
+ }
+ public void close() {
+ if (messageStrings[ IN_close] != "timerTick"){
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_close]);
+ }
+ if (getPeerAddress()!=null)
+ getPeerMsgReceiver().receive(new EventMessage(getPeerAddress(), IN_close));
+ }
+ private void internalLog(InternalLogData data) {
+ if (messageStrings[ IN_internalLog] != "timerTick"){
+ // TODOTS: model switch for activation
+ DebuggingService.getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(), messageStrings[IN_internalLog]);
+ }
+ if (getPeerAddress()!=null)
+ getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), IN_internalLog, data.deepCopy()));
+ }
+ public void internalLog(String userString, String sender, long timeStamp) {
+ internalLog(new InternalLogData(userString, sender, timeStamp));
+ }
+ }
+
+ // replicated port class
+ static public class LogConjPortRepl {
+ private ArrayList<LogConjPort> ports;
+ private int replication;
+
+ public LogConjPortRepl(IEventReceiver actor, String name, int localId, Address[] addr,
+ Address[] peerAddress) {
+ replication = addr.length;
+ ports = new ArrayList<Log.LogConjPort>(replication);
+ for (int i=0; i<replication; ++i) {
+ ports.add(new LogConjPort(
+ actor, name+i, localId, i, addr[i], peerAddress[i]));
+ }
+ }
+
+ public int getReplication() {
+ return replication;
+ }
+
+ public int getIndexOf(InterfaceItemBase ifitem){
+ return ifitem.getIdx();
+ }
+
+ public LogConjPort get(int i) {
+ return ports.get(i);
+ }
+
+ // incoming messages
+ public void open(String fileName){
+ for (int i=0; i<replication; ++i) {
+ ports.get(i).open( fileName);
+ }
+ }
+ public void close(){
+ for (int i=0; i<replication; ++i) {
+ ports.get(i).close();
+ }
+ }
+ private void internalLog(InternalLogData data){
+ for (int i=0; i<replication; ++i) {
+ ports.get(i).internalLog( data);
+ }
+ }
+ }
+
+}

Back to the top