From e70c1e31bc0556eab3348c1a8c2ee1e7d1190a94 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Tue, 9 Dec 2014 12:52:55 +0100
Subject: [PATCH] Fixed wiki_example

---
 examples/Makefile                       |  1 +
 examples/wiki_example/Makefile          | 17 ++++++-
 examples/wiki_example/data.java         | 62 -------------------------
 examples/wiki_example/example_encoder.c |  8 +++-
 examples/wiki_example/run               | 22 ++++-----
 5 files changed, 35 insertions(+), 75 deletions(-)
 delete mode 100644 examples/wiki_example/data.java

diff --git a/examples/Makefile b/examples/Makefile
index 7035255..2610a0a 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -11,6 +11,7 @@ all:
 test:
 	echo More to be done...
 	cd simple ; sh compile.sh && sh run.sh
+	$(MAKE) -C  wiki_example test
 	$(MAKE) -C duck_typing test
 	$(MAKE) -C twoway test 
 
diff --git a/examples/wiki_example/Makefile b/examples/wiki_example/Makefile
index 607a20a..64e50a0 100644
--- a/examples/wiki_example/Makefile
+++ b/examples/wiki_example/Makefile
@@ -1,5 +1,20 @@
+GENERATED=\
+	data.java \
+	example.c \
+	example.cs \
+	example.encoded \
+	example.h \
+	example.javaencoded \
+	example.py \
+	example_encoder \
+	log_message.java
+
 all:
 
+test:
+	./run
+
 clean:
+	rm -f $(GENERATED) *.class
 
-distclean:
+distclean: clean
diff --git a/examples/wiki_example/data.java b/examples/wiki_example/data.java
deleted file mode 100644
index 5860ed9..0000000
--- a/examples/wiki_example/data.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/* 
-sample float data;
-*/
-import java.io.IOException;
-import se.lth.control.labcomm.Decoder;
-import se.lth.control.labcomm.Dispatcher;
-import se.lth.control.labcomm.Encoder;
-import se.lth.control.labcomm.Handler;
-import se.lth.control.labcomm.Sample;
-
-public class data implements Sample {
-
-  public interface Handler extends Handler {
-    public void handle_data(float value) throws Exception;
-  }
-  
-  public static void register(Decoder d, Handler h) throws IOException {
-    d.register(new Dispatcher(), h);
-  }
-  
-  public static void register(Encoder e) throws IOException {
-    e.register(new Dispatcher());
-  }
-  
-  private static class Dispatcher implements Dispatcher {
-    
-    public Class getSampleClass() {
-      return data.class;
-    }
-    
-    public String getName() {
-      return "data";
-    }
-    
-    public byte[] getSignature() {
-      return signature;
-    }
-    
-    public void decodeAndHandle(Decoder d,
-                                Handler h) throws Exception {
-      ((Handler)h).handle_data(data.decode(d));
-    }
-    
-  }
-  
-  public static void encode(Encoder e, float value) throws IOException {
-    e.begin(data.class);
-    e.encodeFloat(value);
-    e.end(data.class);
-  }
-  
-  public static float decode(Decoder d) throws IOException {
-    float result;
-    result = d.decodeFloat();
-    return result;
-  }
-  
-  private static byte[] signature = new byte[] {
-    37, 
-  };
-
-}
diff --git a/examples/wiki_example/example_encoder.c b/examples/wiki_example/example_encoder.c
index b685a96..3983a13 100644
--- a/examples/wiki_example/example_encoder.c
+++ b/examples/wiki_example/example_encoder.c
@@ -1,6 +1,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <labcomm.h>
+#include <labcomm_default_memory.h>
 #include <labcomm_fd_reader.h>
 #include <labcomm_fd_writer.h>
 #include "example.h"
@@ -8,10 +10,13 @@
 int main(int argc, char *argv[]) {
   int fd;
   struct labcomm_encoder *encoder;
+  struct labcomm_writer *labcomm_fd_writer;
   int i, j;
 
   fd = open("example.encoded", O_WRONLY|O_CREAT|O_TRUNC, 0644);
-  encoder = labcomm_encoder_new(labcomm_fd_writer, &fd, NULL, NULL);
+  labcomm_fd_writer = labcomm_fd_writer_new(labcomm_default_memory, fd, 1);
+  encoder = labcomm_encoder_new(labcomm_fd_writer, NULL, 
+                                labcomm_default_memory, NULL);
   labcomm_encoder_register_example_log_message(encoder);
   labcomm_encoder_register_example_data(encoder);
   for (i = 0 ; i < argc ; i++) {
@@ -31,4 +36,5 @@ int main(int argc, char *argv[]) {
     float f = i;
     labcomm_encode_example_data(encoder, &f);
   }
+  return 0;
 }
diff --git a/examples/wiki_example/run b/examples/wiki_example/run
index baaf2a9..e3477ea 100755
--- a/examples/wiki_example/run
+++ b/examples/wiki_example/run
@@ -1,24 +1,24 @@
 #!/bin/sh
 
 # Auto generate code from .lc file
-java -jar ../../compiler/labcomm_compiler.jar \
+java -jar ../../compiler/labcomm2014_compiler.jar \
   --c=example.c --h=example.h \
   --java=. \
   --cs=example.cs \
   --python=example.py \
-  example.lc
+  example.lc || exit 1
 
 # Compile executables
-(cd ../../lib/c; make liblabcomm.a)
+(cd ../../lib/c; make all || exit 1)
 
-gcc -o example_encoder -I ../../lib/c/ \
-	example_encoder.c \
-        example.c \
-	../../lib/c/liblabcomm.a 
+gcc -Wall -Werror -o example_encoder -I../../lib/c/2014 \
+    example_encoder.c \
+    example.c \
+    ../../lib/c/liblabcomm2014.a || exit 1
 
-javac -cp ../../lib/java:. *.java
+javac -cp ../../lib/java:. *.java || exit 1
 
 # Run through all executables (c->java->Python)
-./example_encoder one two
-java -cp ../../lib/java:. example_decoder_encoder example.encoded example.javaencoded
-PYTHONPATH=../../lib/python ./example_decoder.py example.javaencoded 
+./example_encoder one two || exit 1
+java -cp ../../lib/java:. example_decoder_encoder example.encoded example.javaencoded || exit 1
+PYTHONPATH=../../lib/python ./example_decoder.py example.javaencoded || exit 1
-- 
GitLab