Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.modellib.java/model/TcpService.room')
-rw-r--r--runtime/org.eclipse.etrice.modellib.java/model/TcpService.room406
1 files changed, 196 insertions, 210 deletions
diff --git a/runtime/org.eclipse.etrice.modellib.java/model/TcpService.room b/runtime/org.eclipse.etrice.modellib.java/model/TcpService.room
index 152035ec0..40621266a 100644
--- a/runtime/org.eclipse.etrice.modellib.java/model/TcpService.room
+++ b/runtime/org.eclipse.etrice.modellib.java/model/TcpService.room
@@ -2,96 +2,96 @@ RoomModel room.basic.service.tcp {
import room.basic.types.* from "Types.room"
-
ActorClass ATcpServer {
Interface {
Port ControlPort: PTcpControl
Port PayloadPort: PTcpPayload
}
Structure {
- usercode1 {
- "import java.net.ServerSocket;"
- "import java.net.Socket;"
- "import java.io.*;"
- "import java.util.*;"
- ""
- "class ServerRxThread extends Thread{"
- " private int connectionId;"
- " private Socket sock;"
- " PTcpPayloadPort port;"
- ""
- " public ServerRxThread (int connectionId, PTcpPayloadPort port, Socket sock){"
- " this.sock = sock;"
- " this.connectionId = connectionId;"
- " this.port = port;"
- " }"
- ""
- " public void run(){"
- " try{"
- " InputStream in = sock.getInputStream();"
- " DTcpPayload d = new DTcpPayload();"
- " d.setConnectionId(connectionId);"
- " int c;"
- " while ((c=in.read(d.getData()))!=-1){"
- " d.setLength(c);"
- " port.receive(d); "
- " }"
- " }catch (IOException e){"
- " System.err.println(\"ServerRx: \" + e.toString());"
- " }"
- " }"
- "}"
- ""
- "class ServerAcceptThread extends Thread{"
- " private ServerSocket sock;"
- " private PTcpPayloadPort port;"
- " private ATcpServer parent;"
- " public ServerAcceptThread (PTcpPayloadPort port, ServerSocket sock, ATcpServer parent){"
- " this.sock = sock;"
- " this.port = port;"
- " this.parent = parent;"
- " }"
- " public void run(){"
- " int cnt=0;"
- " try{"
- " while (true){"
- " Socket s = sock.accept();"
- " parent.addOutStreamToHashmap(cnt, s.getOutputStream());"
- " (new ServerRxThread(cnt, port, s)).start();"
- " cnt++;"
- " }"
- " }catch (IOException e){"
- " System.err.println(\"Server Accept: \" + e.toString());"
- " }"
- " }"
- "}"
- " "
- }
- usercode2 {
- "ServerSocket socket = null;"
- "InputStream in = null;"
- "OutputStream out = null;"
- "Hashtable<Integer,OutputStream> outStreams = new Hashtable<Integer,OutputStream>();"
- ""
- "synchronized protected void addOutStreamToHashmap(int cnt, OutputStream out){"
- " outStreams.put(cnt,out);"
- "}"
- ""
- }
+ usercode1 '''
+ import java.net.ServerSocket;
+ import java.net.Socket;
+ import java.io.*;
+ import java.util.*;
+
+ class ServerRxThread extends Thread{
+ private int connectionId;
+ private Socket sock;
+ PTcpPayloadPort port;
+
+ public ServerRxThread (int connectionId, PTcpPayloadPort port, Socket sock){
+ this.sock = sock;
+ this.connectionId = connectionId;
+ this.port = port;
+ }
+
+ public void run(){
+ try{
+ InputStream in = sock.getInputStream();
+ DTcpPayload d = new DTcpPayload();
+ d.setConnectionId(connectionId);
+ int c;
+ while ((c=in.read(d.getData()))!=-1){
+ d.setLength(c);
+ port.receive(d);
+ }
+ }
+ catch (IOException e){
+ System.err.println("ServerRx: " + e.toString());
+ }
+ }
+ }
+
+ class ServerAcceptThread extends Thread{
+ private ServerSocket sock;
+ private PTcpPayloadPort port;
+ private ATcpServer parent;
+ public ServerAcceptThread (PTcpPayloadPort port, ServerSocket sock, ATcpServer parent){
+ this.sock = sock;
+ this.port = port;
+ this.parent = parent;
+ }
+ public void run(){
+ int cnt=0;
+ try{
+ while (true){
+ Socket s = sock.accept();
+ parent.addOutStreamToHashmap(cnt, s.getOutputStream());
+ (new ServerRxThread(cnt, port, s)).start();
+ cnt++;
+ }
+ }
+ catch (IOException e){
+ System.err.println("Server Accept: " + e.toString());
+ }
+ }
+ }
+ '''
+ usercode2 '''
+ ServerSocket socket = null;
+ InputStream in = null;
+ OutputStream out = null;
+ Hashtable<Integer,OutputStream> outStreams = new Hashtable<Integer,OutputStream>();
+
+ synchronized protected void addOutStreamToHashmap(int cnt, OutputStream out){
+ outStreams.put(cnt,out);
+ }
+ '''
external Port ControlPort
external Port PayloadPort
Attribute lastError: int32
Attribute payloadPortReplocation: int32
}
Behavior {
- Operation stopUser() {
- "try{"
- "if(socket != null){"
- "socket.close();"
- "}"
- "}catch(IOException e){"
- "System.err.println(e.toString());}"
- }
+ Operation stopUser() '''
+ try{
+ if (socket != null){
+ socket.close();
+ }
+ }
+ catch (IOException e){
+ System.err.println(e.toString());
+ }'''
StateMachine {
Transition init: initial -> closed {
}
@@ -99,60 +99,56 @@ RoomModel room.basic.service.tcp {
triggers {
<open: ControlPort>
}
- action {
- "lastError=0;"
- "try{"
- "socket = new ServerSocket(transitionData.TcpPort);"
- "(new ServerAcceptThread(PayloadPort, socket, this)).start();"
- "}catch(IOException e){"
- "System.err.println(e.toString());"
- "lastError=1;"
- "}"
- }
+ action '''
+ lastError=0;
+ try{
+ socket = new ServerSocket(transitionData.TcpPort);
+ (new ServerAcceptThread(PayloadPort, socket, this)).start();
+ }
+ catch(IOException e){
+ System.err.println(e.toString());
+ lastError=1;
+ }'''
}
Transition tr1: opened -> closed {
triggers {
<close: ControlPort>
}
- action {
- "try{"
- "\tif(socket!=null){"
- "\t\tsocket.close();"
- "\t\t}"
- "\t}catch(IOException e){"
- "\tSystem.err.println(e.toString());"
- "}"
- }
+ action '''
+ try{
+ if(socket!=null){
+ socket.close();
+ }
+ }
+ catch(IOException e){
+ System.err.println(e.toString());
+ }'''
}
Transition tr2: cp cp0 -> opened {
- action {
- "ControlPort.established();"
- }
+ action '''ControlPort.established();'''
}
Transition socketError: cp cp0 -> error {
- cond {
- "lastError!=0"
- }
- action {
- "ControlPort.error();"
- "try{"
- "socket.close();"
- "} catch(IOException e){"
- "System.err.println(e.toString());"
- "}"
- }
+ cond '''lastError!=0'''
+ action '''
+ ControlPort.error();
+ try{
+ socket.close();
+ }
+ catch(IOException e){
+ System.err.println(e.toString());
+ }'''
}
Transition tr3: opened -> opened {
triggers {
<send: PayloadPort>
}
- action {
- "try{"
- "outStreams.get(transitionData.getConnectionId()).write(transitionData.getData(),0,transitionData.length);"
- "}catch(IOException e){"
- "System.err.println(e.toString());"
- "}"
- }
+ action '''
+ try{
+ outStreams.get(transitionData.getConnectionId()).write(transitionData.getData(),0,transitionData.length);
+ }
+ catch(IOException e){
+ System.err.println(e.toString());
+ }'''
}
ChoicePoint cp0
State closed
@@ -168,119 +164,110 @@ RoomModel room.basic.service.tcp {
Port PayloadPort: PTcpPayload
}
Structure {
- usercode1 {
- "import java.net.Socket;"
- "import java.io.*;"
-
- " "
- "class ClientRxThread extends Thread{ "
- " private Socket sock;"
- " PTcpPayloadPort port;"
- " public ClientRxThread (PTcpPayloadPort port, Socket sock){"
- " this.sock = sock;"
- " this.port = port;"
- " }"
- " public void run(){"
- " try{"
- " InputStream in = sock.getInputStream();"
- " DTcpPayload d = new DTcpPayload();"
- " d.setConnectionId(0);"
- " int c;"
- " while ((c=in.read(d.getData()))!=-1){"
- " d.setLength(c);"
- " port.receive(d);"
- " }"
- " }catch (IOException e){"
- " System.err.println(\"ClientRx: \" + e.toString());"
- " }"
- " "
- " }"
- "}"
- ""
- }
- usercode2 {
- "Socket socket;"
- "InputStream in;"
- "OutputStream out;"
- }
+ usercode1 '''
+ import java.net.Socket;
+ import java.io.*;
+
+ class ClientRxThread extends Thread{
+ private Socket sock;
+ PTcpPayloadPort port;
+ public ClientRxThread (PTcpPayloadPort port, Socket sock){
+ this.sock = sock;
+ this.port = port;
+ }
+ public void run(){
+ try{
+ InputStream in = sock.getInputStream();
+ DTcpPayload d = new DTcpPayload();
+ d.setConnectionId(0);
+ int c;
+ while ((c=in.read(d.getData()))!=-1){
+ d.setLength(c);
+ port.receive(d);
+ }
+ }
+ catch (IOException e){
+ System.err.println("ClientRx: " + e.toString());
+ }
+
+ }
+ }
+ '''
+ usercode2 '''
+ Socket socket;
+ InputStream in;
+ OutputStream out;'''
external Port ControlPort
external Port PayloadPort
Attribute lastError: int32
}
Behavior {
- Operation stopUser() {
- "try{"
- "if(socket != null){"
- "socket.close();"
- "}"
- "}catch(IOException e){"
- "System.err.println(e.toString());}"
- }
+ Operation stopUser() '''
+ try{
+ if(socket != null){
+ socket.close();
+ }
+ }catch(IOException e){
+ System.err.println(e.toString());}'''
StateMachine {
Transition init: initial -> closed {
- action {
- "System.out.println(\"Client Init !\");"
- }
+ action '''System.out.println("Client Init !");'''
}
Transition tr0: closed -> cp cp0 {
triggers {
<open: ControlPort>
}
- action {
- "lastError=0;"
- "try{"
- "socket = new Socket(transitionData.IPAddr,transitionData.TcpPort);"
- "(new ClientRxThread(PayloadPort, socket)).start();"
- "out = socket.getOutputStream();"
- "}catch(IOException e){"
- "System.err.println(e.toString());"
- "lastError=1;"
- "}"
- }
+ action '''
+ lastError=0;
+ try{
+ socket = new Socket(transitionData.IPAddr,transitionData.TcpPort);
+ (new ClientRxThread(PayloadPort, socket)).start();
+ out = socket.getOutputStream();
+ }
+ catch(IOException e){
+ System.err.println(e.toString());
+ lastError=1;
+ }'''
}
Transition tr1: opened -> closed {
triggers {
<close: ControlPort>
}
- action {
- "try{"
- "\tif (socket!=null){"
- "\t\tsocket.close();"
- "\t}"
- "} catch (IOException e){"
- "System.err.println(e.toString());"
- "}"
- }
+ action '''
+ try{
+ if (socket!=null){
+ socket.close();
+ }
+ }
+ catch (IOException e){
+ System.err.println(e.toString());
+ }'''
}
Transition tr2: cp cp0 -> opened {
- action {
- "ControlPort.established();"
- }
+ action '''ControlPort.established();'''
}
Transition socketError: cp cp0 -> error {
- cond {
- "lastError!=0"
- }
- action {
- "ControlPort.error();"
- "try{"
- "socket.close();"
- "} catch(IOException e){"
- "System.err.println(e.toString());"
- "}"
- }
+ cond '''lastError!=0'''
+ action '''
+ ControlPort.error();
+ try{
+ socket.close();
+ }
+ catch(IOException e){
+ System.err.println(e.toString());
+ }'''
}
Transition tr3: opened -> opened {
triggers {
<send: PayloadPort>
}
- action {
- "try{"
- "\tout.write(transitionData.getData(),0,transitionData.length);"
- "\t}catch(IOException e){"
- "\t\tSystem.err.println(e.toString());"
- "\t}"
- }
+ action '''
+ try{
+ out.write(transitionData.getData(),0,transitionData.length);
+ }
+ catch(IOException e){
+ System.err.println(e.toString());
+ }'''
}
ChoicePoint cp0
State closed
@@ -292,7 +279,7 @@ RoomModel room.basic.service.tcp {
ProtocolClass PTcpControl {
incoming {
- Message open(data: DTcpControl)
+ Message open(DTcpControl)
Message close()
}
outgoing {
@@ -303,10 +290,10 @@ RoomModel room.basic.service.tcp {
ProtocolClass PTcpPayload {
incoming {
- Message send(data: DTcpPayload)
+ Message send(DTcpPayload)
}
outgoing {
- Message receive(data: DTcpPayload)
+ Message receive(DTcpPayload)
}
}
@@ -318,7 +305,6 @@ RoomModel room.basic.service.tcp {
DataClass DTcpPayload {
Attribute connectionId: int32
Attribute length: int32
- Attribute data [ 1000 ]: int8
+ Attribute data [1000]: int8
}
-
} \ No newline at end of file

Back to the top