diff options
author | tjung | 2012-01-02 13:22:51 +0000 |
---|---|---|
committer | tjung | 2012-01-02 13:22:51 +0000 |
commit | e19e876c6c2d3be75dcfca7fc57f179191aedb3c (patch) | |
tree | 91c7d8bad42b853bd802b171bff828c85235f43f | |
parent | c79f92e56625e20d78899a236102fe31ef4a8783 (diff) | |
download | org.eclipse.etrice-e19e876c6c2d3be75dcfca7fc57f179191aedb3c.tar.gz org.eclipse.etrice-e19e876c6c2d3be75dcfca7fc57f179191aedb3c.tar.xz org.eclipse.etrice-e19e876c6c2d3be75dcfca7fc57f179191aedb3c.zip |
ALogService added
-rw-r--r-- | runtime/org.eclipse.etrice.modellib/models/ALogService.room | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/runtime/org.eclipse.etrice.modellib/models/ALogService.room b/runtime/org.eclipse.etrice.modellib/models/ALogService.room new file mode 100644 index 000000000..bf666eea7 --- /dev/null +++ b/runtime/org.eclipse.etrice.modellib/models/ALogService.room @@ -0,0 +1,115 @@ +RoomModel ALogService { + + ActorClass ALogService { + Interface { + SPP log: Log + } + Structure { + usercode1 { + "import java.io.*;" + "import java.util.*;" + } + usercode2 { + "FileOutputStream file = null;" + "PrintStream p = null;" + "static long tStart = System.currentTimeMillis();" + } ServiceImplementation of log + } + Behavior { + Operation destroyUser() { + "if (p!= null) {" + "p.flush();" + "p.close();" + "p=null;" + "}" + } + StateMachine { + Transition init: initial -> closed { } + Transition open: closed -> opened { + triggers { + <open: log> + } + action { + "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 !\");" + "}" + } + } + Transition tr0: opened -> closed { + triggers { + <close: log> + } + action { + "p.flush();" + "p.close();" + "p=null;" + } + } + Transition tr1: opened -> opened { + triggers { + <internalLog: log> + } + action { + "long s = Long.valueOf(data.timeStamp);" + "p.println(\"Timestamp: \" + Long.toString(s-tStart) + \"ms\");" + "p.println(\"SenderInstance: \"+ data.sender);" + "p.println(\"UserString: \" + data.userString);" + "p.println(\"--------------------------------------------------\");" + "System.out.printf(data.userString);" + } + } + State closed + State opened + } + } + } + + ProtocolClass Log { + incoming { + Message open(fileName: string) + Message setLogLevel(l: int32) + Message close() + Message internalLog(data: InternalLogData) + } + outgoing { } 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();" + } + handle setLogLevel { + "logLevel=l;" + "if (logLevel > LOG_LEVEL_HIGH) logLevel=LOG_LEVEL_HIGH;" + } + handle internalLog{ + "System.out.printf(\"\\ndonīt use the internalLog messages !\\n\");" + } + Operation log(logLevel:int32, userString:string){ + "long s;" + "if (logLevel>this.logLevel){" + "d.userString=userString;" + "s=System.currentTimeMillis();" + "d.timeStamp=Long.toString(s);" + "d.sender=getInstancePath();" + "if (getPeerAddress()!=null)" + "getPeerMsgReceiver().receive(new EventWithDataMessage(getPeerAddress(), IN_internalLog, d));" + "}" + } + } + } + + DataClass InternalLogData { + Attribute timeStamp:string + Attribute sender: string + Attribute userString: string + } + +}
\ No newline at end of file |