From 576f596c72a1a0313c21d3d26f88dc96c81f36d4 Mon Sep 17 00:00:00 2001
From: Sven Robertz <sven@cs.lth.se>
Date: Mon, 15 Apr 2013 15:08:55 +0200
Subject: [PATCH] extended simple example to use typedef

---
 examples/simple/Decoder.java      | 19 +++++++++++++++----
 examples/simple/Encoder.java      |  6 +++---
 examples/simple/example_decoder.c | 11 ++++++++---
 examples/simple/example_encoder.c | 19 +++++++++++++------
 examples/simple/simple.lc         |  5 ++++-
 5 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/examples/simple/Decoder.java b/examples/simple/Decoder.java
index b4947f8..266b895 100644
--- a/examples/simple/Decoder.java
+++ b/examples/simple/Decoder.java
@@ -5,7 +5,7 @@ import java.io.InputStream;
 import se.lth.control.labcomm.LabCommDecoderChannel;
 
 public class Decoder
-  implements TwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler
+  implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler
 
 {
 
@@ -15,7 +15,8 @@ public class Decoder
     throws Exception 
   {
     decoder = new LabCommDecoderChannel(in);
-    TwoInts.register(decoder, this);
+    theTwoInts.register(decoder, this);
+    anotherTwoInts.register(decoder, this);
     IntString.register(decoder, this);
     TwoArrays.register(decoder, this);
     TwoFixedArrays.register(decoder, this);
@@ -28,8 +29,18 @@ public class Decoder
     }
   }
 
-  public void handle_TwoInts(TwoInts d) throws java.io.IOException {
-    System.out.println("Got TwoInts, a="+d.a+", b="+d.b);
+  public void printTwoInts(TwoInts d) throws java.io.IOException {
+    System.out.println("a="+d.a+", b="+d.b);
+  }
+
+  public void handle_theTwoInts(TwoInts d) throws java.io.IOException {
+    System.out.print("Got theTwoInts: ");
+    printTwoInts(d);
+  }
+
+  public void handle_anotherTwoInts(TwoInts d) throws java.io.IOException {
+    System.out.print("Got anotherheTwoInts: ");
+    printTwoInts(d);
   }
 
   public void handle_IntString(IntString d) throws java.io.IOException {
diff --git a/examples/simple/Encoder.java b/examples/simple/Encoder.java
index 3209f7a..2da41c7 100644
--- a/examples/simple/Encoder.java
+++ b/examples/simple/Encoder.java
@@ -16,7 +16,7 @@ public class Encoder
     throws Exception 
   {
     encoder = new LabCommEncoderChannel(out);
-    TwoInts.register(encoder);
+    theTwoInts.register(encoder);
     IntString.register(encoder);
   }
 
@@ -29,8 +29,8 @@ public class Encoder
     y.x = 37;
     y.s = "Testing, testing";
 
-    System.out.println("Encoding TwoInts, a="+x.a+", b="+x.b);
-    TwoInts.encode(encoder, x);
+    System.out.println("Encoding theTwoInts, a="+x.a+", b="+x.b);
+    theTwoInts.encode(encoder, x);
 
     System.out.println("Encoding IntString, x="+y.x+", s="+y.s);
     IntString.encode(encoder, y);
diff --git a/examples/simple/example_decoder.c b/examples/simple/example_decoder.c
index 50d2530..6774808 100644
--- a/examples/simple/example_decoder.c
+++ b/examples/simple/example_decoder.c
@@ -4,8 +4,12 @@
 #include <labcomm_fd_reader_writer.h>
 #include "gen/simple.h"
 
-static void handle_simple_TwoInts(simple_TwoInts *v,void *context) {
-  printf("Got TwoInts. a=%d, b=%d\n", v->a, v->b);
+static void handle_simple_theTwoInts(simple_TwoInts *v,void *context) {
+  printf("Got theTwoInts. a=%d, b=%d\n", v->a, v->b);
+}
+
+static void handle_simple_anotherTwoInts(simple_TwoInts *v,void *context) {
+  printf("Got anotherTwoInts. a=%d, b=%d\n", v->a, v->b);
 }
 
 static void handle_simple_IntString(simple_IntString *v,void *context) {
@@ -55,7 +59,8 @@ int main(int argc, char *argv[]) {
     return 1;
   }
 
-  labcomm_decoder_register_simple_TwoInts(decoder, handle_simple_TwoInts, context);
+  labcomm_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context);
+  labcomm_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context);
   labcomm_decoder_register_simple_IntString(decoder, handle_simple_IntString, context);
   labcomm_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context);
   labcomm_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context);
diff --git a/examples/simple/example_encoder.c b/examples/simple/example_encoder.c
index 8192f56..5ce76ea 100644
--- a/examples/simple/example_encoder.c
+++ b/examples/simple/example_encoder.c
@@ -13,7 +13,8 @@ int main(int argc, char *argv[]) {
   printf("C encoder writing to %s\n", filename);
   fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
   encoder = labcomm_encoder_new(labcomm_fd_writer, &fd);
-  labcomm_encoder_register_simple_TwoInts(encoder);
+  labcomm_encoder_register_simple_theTwoInts(encoder);
+  labcomm_encoder_register_simple_anotherTwoInts(encoder);
   labcomm_encoder_register_simple_IntString(encoder);
   simple_IntString is;
   is.x = 24;
@@ -21,11 +22,17 @@ int main(int argc, char *argv[]) {
   printf("Encoding IntString, x=%d, s=%s\n", is.x, is.s);
   labcomm_encode_simple_IntString(encoder, &is);
 
-  simple_TwoInts ti;
+  simple_theTwoInts ti;
   ti.a = 13;
   ti.b = 37;
-  printf("Encoding TwoInts, a=%d, b=%d\n", ti.a, ti.b);
-  labcomm_encode_simple_TwoInts(encoder, &ti);
+  printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
+  labcomm_encode_simple_theTwoInts(encoder, &ti);
+
+  simple_anotherTwoInts ati;
+  ati.a = 23;
+  ati.b = 47;
+  printf("Encoding anotherTwoInts, a=%d, b=%d\n", ati.a, ati.b);
+  labcomm_encode_simple_anotherTwoInts(encoder, &ati);
 
   int foo[20];
 
@@ -47,8 +54,8 @@ int main(int argc, char *argv[]) {
 
   ti.a = 23;
   ti.b = 47;
-  printf("Encoding TwoInts, a=%d, b=%d\n", ti.a, ti.b);
-  labcomm_encode_simple_TwoInts(encoder, &ti);
+  printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
+  labcomm_encode_simple_theTwoInts(encoder, &ti);
 
 
   simple_TwoFixedArrays tfa;
diff --git a/examples/simple/simple.lc b/examples/simple/simple.lc
index 9bb352f..5183957 100644
--- a/examples/simple/simple.lc
+++ b/examples/simple/simple.lc
@@ -1,8 +1,11 @@
-sample struct {
+typedef struct {
   int a;
   int b;
 } TwoInts;
 
+sample TwoInts theTwoInts;
+sample TwoInts anotherTwoInts;
+
 sample struct {
   int x;
   string s;
-- 
GitLab