summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortjung2012-03-18 15:56:35 (EDT)
committertjung2012-03-18 15:56:35 (EDT)
commit207883c14ff33c084f6b78af3a8db9fe22e78777 (patch)
tree1dca46870601eb5d65c4e0c0dbd0164bdf4ff0ab
parent8368a52c6652ae25e7d92529a09f9ad937bf6f7b (diff)
downloadorg.eclipse.etrice-207883c14ff33c084f6b78af3a8db9fe22e78777.zip
org.eclipse.etrice-207883c14ff33c084f6b78af3a8db9fe22e78777.tar.gz
org.eclipse.etrice-207883c14ff33c084f6b78af3a8db9fe22e78777.tar.bz2
[modellib.models] First Version
-rw-r--r--runtime/org.eclipse.etrice.modellib/models/TcpService.room323
1 files changed, 323 insertions, 0 deletions
diff --git a/runtime/org.eclipse.etrice.modellib/models/TcpService.room b/runtime/org.eclipse.etrice.modellib/models/TcpService.room
new file mode 100644
index 0000000..b0dad2b
--- /dev/null
+++ b/runtime/org.eclipse.etrice.modellib/models/TcpService.room
@@ -0,0 +1,323 @@
+RoomModel room.basic.service.tcp {
+
+ import room.basic.types.java.* from "JavaTypes.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);
+ }
+ "
+ }
+ 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());}"
+ }
+ StateMachine {
+ Transition init: initial -> closed {
+ }
+ Transition tr0: closed -> cp cp0 {
+ triggers {
+ <open: ControlPort>
+ }
+ action {
+ "lastError=0;"
+ "try{"
+ "socket = new ServerSocket(data.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());"
+ "}"
+ }
+ }
+ Transition tr2: cp cp0 -> opened {
+ 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());"
+ "}"
+ }
+ }
+ Transition tr3: opened -> opened {
+ triggers {
+ <send: PayloadPort>
+ }
+ action {
+ "try{"
+ "outStreams.get(data.getConnectionId()).write(data.data);"
+ "}catch(IOException e){"
+ "System.err.println(e.toString());"
+ "}"
+ }
+ }
+ ChoicePoint cp0
+ State closed
+ State opened
+ State error
+ }
+ }
+ }
+
+ ActorClass ATcpClient {
+ Interface {
+ Port ControlPort: PTcpControl
+ 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;"
+ }
+ 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());}"
+ }
+ StateMachine {
+ Transition init: initial -> closed {
+ action {
+ "System.out.println(\"Client Init !\");"
+ }
+ }
+ Transition tr0: closed -> cp cp0 {
+ triggers {
+ <open: ControlPort>
+ }
+ action {
+ "lastError=0;"
+ "try{"
+ "socket = new Socket(data.IPAddr,data.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());"
+ "}"
+ }
+ }
+ Transition tr2: cp cp0 -> opened {
+ 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());"
+ "}"
+ }
+ }
+ Transition tr3: opened -> opened {
+ triggers {
+ <send: PayloadPort>
+ }
+ action {
+ "try{"
+ "\tout.write(data.getData());"
+ "\t}catch(IOException e){"
+ "\t\tSystem.err.println(e.toString());"
+ "\t}"
+ }
+ }
+ ChoicePoint cp0
+ State closed
+ State opened
+ State error
+ }
+ }
+ }
+
+ ProtocolClass PTcpControl {
+ incoming {
+ Message open(data: DTcpControl)
+ Message close()
+ }
+ outgoing {
+ Message established()
+ Message error()
+ }
+ }
+
+ ProtocolClass PTcpPayload {
+ incoming {
+ Message send(data: DTcpPayload)
+ }
+ outgoing {
+ Message receive(data: DTcpPayload)
+ }
+ }
+
+ DataClass DTcpControl {
+ Attribute IPAddr: string
+ Attribute TcpPort: int32
+ }
+
+ DataClass DTcpPayload {
+ Attribute connectionId: int32
+ Attribute length: int32
+ Attribute data [ 1000 ]: int8
+ }
+
+} \ No newline at end of file