From 825efef0470f1f06b2f0c8cf07a0af669287f3cb Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Mon, 2 Dec 2013 10:05:22 +0100
Subject: [PATCH] added var array and string

---
 examples/tcp/Makefile                         |  6 ++---
 .../tcp/labcommTCPtest/client/TestClient.java | 23 ++++++++++++++++++-
 .../tcp/labcommTCPtest/server/TestServer.java |  9 +++++++-
 examples/tcp/test.lc                          |  2 ++
 4 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/examples/tcp/Makefile b/examples/tcp/Makefile
index f5004cc..da81761 100644
--- a/examples/tcp/Makefile
+++ b/examples/tcp/Makefile
@@ -1,6 +1,6 @@
 LCDIR=../..
-LCCJAR=${LCDIR}/compiler/labComm.jar
-LCLJAR=${LCDIR}/lib/java/labcomm.jar
+LCCJAR=${LCDIR}/compiler/labComm.jar  # the LabComm compiler
+LCLJAR=${LCDIR}/lib/java/labcomm.jar  # the LabComm library
 JAVA_PKG=labcommTCPtest
 
 .PHONY : clean run runserver runOSserver runclient
@@ -26,7 +26,7 @@ ${LCLJAR} :
 ${JAVA_PKG}/gen/FooSample.java: test.lc ${LCCJAR}
 	${LCC} --javapackage=${JAVA_PKG}.gen --java=${JAVA_PKG}/gen $<
 
-${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java ${LCLJAR}   
+${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java test.lc ${LCLJAR}   
 	javac -cp ${CLASSPATH} $<
 
 ${JAVA_PKG}/Example.class: ${JAVA_PKG}/Example.java ${JAVA_PKG}/gen/FooSample.class ${LCLJAR} 
diff --git a/examples/tcp/labcommTCPtest/client/TestClient.java b/examples/tcp/labcommTCPtest/client/TestClient.java
index ef581dc..d9040fb 100644
--- a/examples/tcp/labcommTCPtest/client/TestClient.java
+++ b/examples/tcp/labcommTCPtest/client/TestClient.java
@@ -28,8 +28,15 @@ public class TestClient implements Handler {
 			LabCommEncoderChannel e = new LabCommEncoderChannel(out );
 			FooSample.register(e);
 			FooSample sample = new FooSample();
+			int a[] = new int[3];
+			a[0] = 1;
+			a[1] = 2;
+			a[2] = 3;
+
+			sample.s = "Some random values";
 			sample.x = 17;
 			sample.y = 42;
+			sample.a = a;
 			sample.t = 1717;
 			sample.d = 0.42;
 			printSample("Client sending", sample);
@@ -57,8 +64,22 @@ public class TestClient implements Handler {
 		}
 	}
 
+	private String formatArray(int a[]) {
+		StringBuilder sb = new StringBuilder();
+		sb.append("[");
+		for(int i=0; i < a.length; i++) {
+			sb.append(a[i]);
+			if(i < a.length-1) {
+				sb.append(", ");
+			}
+		}
+		sb.append("]");
+
+		return sb.toString();
+	}
+
 	private void printSample(String header, FooSample sample2) throws Exception {
-		System.out.format("[TestClient] %s: (%d, %d, %d, %f)\n", header, sample2.x, sample2.y, sample2.t, sample2.d);
+		System.out.format("[TestClient] %s: (%s, %d, %d, %s, %d, %f )\n", header, sample2.s, sample2.x, sample2.y, formatArray(sample2.a), sample2.t, sample2.d);
 	}
 
 	public void handle_FooSample(FooSample sample2) throws Exception {
diff --git a/examples/tcp/labcommTCPtest/server/TestServer.java b/examples/tcp/labcommTCPtest/server/TestServer.java
index d53c7f9..b9b6d0b 100644
--- a/examples/tcp/labcommTCPtest/server/TestServer.java
+++ b/examples/tcp/labcommTCPtest/server/TestServer.java
@@ -49,9 +49,16 @@ public class TestServer implements Handler {
 	public void handle_FooSample(FooSample sample) throws Exception {
 		LabCommEncoderChannel e = new LabCommEncoderChannel(out );
 		FooSample.register(e);
-		System.out.println("TestServer.handle_FooSample...");
+		System.out.println("TestServer.handle_FooSample: "+sample.s);
+		int tmp[] = new int[2*sample.a.length];
+		for (int i = 0; i < sample.a.length;i++) {
+			tmp[2*i] = tmp[2*i+1] = sample.a[i];
+		}
+		
+		sample.s = "double!";
 		sample.x *= 2;
 		sample.y *= 2;
+		sample.a = tmp;
 		sample.t *= 2;
 		sample.d *= 2;
 		FooSample.encode(e, sample);
diff --git a/examples/tcp/test.lc b/examples/tcp/test.lc
index fe104e9..b87779d 100644
--- a/examples/tcp/test.lc
+++ b/examples/tcp/test.lc
@@ -1,6 +1,8 @@
 sample struct {
+    string s;
     int x;
     int y;
+    int a[_];
     long t;
     double d;
 } FooSample;
-- 
GitLab