From 4a14ea73807a7cce49233293a8be2c172943a433 Mon Sep 17 00:00:00 2001 From: Sven Robertz <sven@cs.lth.se> Date: Tue, 16 Jul 2013 15:07:48 +0200 Subject: [PATCH] fixed static part so it runs. Still not integrated the demo --- examples/dynamic/StaticPart.java | 74 +++++++++++++--------------- examples/dynamic/TestLabcommGen.java | 1 + 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/examples/dynamic/StaticPart.java b/examples/dynamic/StaticPart.java index 1ffe501..9ce424c 100644 --- a/examples/dynamic/StaticPart.java +++ b/examples/dynamic/StaticPart.java @@ -12,7 +12,7 @@ public class StaticPart { /** * Simple encoder */ - public class Encoder { + public static class Encoder { LabCommEncoderChannel encoder; @@ -20,30 +20,28 @@ public class StaticPart { throws Exception { encoder = new LabCommEncoderChannel(out); - theTwoInts.register(encoder); - IntString.register(encoder); - TwoArrays.register(encoder); + foo.register(encoder); + bar.register(encoder); } public void doEncode() throws java.io.IOException { - TwoInts x = new TwoInts(); - x.a = 17; - x.b = 42; - - IntString y = new IntString(); - y.x = 37; - y.s = "Testing, testing"; - - 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); + foo f = new foo(); + f.x = 17; + f.y = 42; + f.z = 37; + + int b = 13; + + System.out.println("Encoding foo, x="+f.x+", y="+f.y+", z="+f.z); + foo.encode(encoder, f); + + System.out.println("Encoding bar: "+b); + bar.encode(encoder, b); } } - public class Decoder - implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler + public static class Decoder + implements foo.Handler, bar.Handler { LabCommDecoderChannel decoder; @@ -52,46 +50,40 @@ public class StaticPart { throws Exception { decoder = new LabCommDecoderChannel(in); - theTwoInts.register(decoder, this); - anotherTwoInts.register(decoder, this); - IntString.register(decoder, this); - TwoArrays.register(decoder, this); - TwoFixedArrays.register(decoder, this); + foo.register(decoder, this); + bar.register(decoder, this); + + } + public void doDecode() throws java.io.IOException { try { System.out.println("Running decoder."); decoder.run(); } catch (java.io.EOFException e) { System.out.println("Decoder reached end of file."); + } catch (Exception e) { + e.printStackTrace(); } } - 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_foo(foo d) throws java.io.IOException { + System.out.println("Got foo, x="+d.x+", y="+d.y+", z="+d.z); } - public void handle_IntString(IntString d) throws java.io.IOException { - System.out.println("Got IntString, x="+d.x+", s="+d.s); + public void handle_bar(int d) throws java.io.IOException { + System.out.println("Got bar: "+d); } } public static void main(String[] arg) throws Exception { FileOutputStream fos = new FileOutputStream(arg[0]); - FileInputStream fis = new FileInputStream(new File(arg[0])) - Encoder example = new Encoder(fos); - Decoder example = new Decoder(fis); - example.doEncode(); + FileInputStream fis = new FileInputStream(new File(arg[0])); + Encoder enc = new Encoder(fos); + Decoder dec = new Decoder(fis); + enc.doEncode(); + dec.doDecode(); fos.close(); fis.close(); } diff --git a/examples/dynamic/TestLabcommGen.java b/examples/dynamic/TestLabcommGen.java index 6c975da..d9df125 100644 --- a/examples/dynamic/TestLabcommGen.java +++ b/examples/dynamic/TestLabcommGen.java @@ -31,6 +31,7 @@ public class TestLabcommGen { private static final String SAMPLE_NAME_FOO = "foo"; private static final String SAMPLE_NAME_BAR = "bar"; + /** A class representing the source code for one Labcomm handler */ static class HandlerSrc { private String sampleName; private String param; -- GitLab