diff --git a/examples/user_types/Decoder.java b/examples/user_types/Decoder.java index 558131b741439ebf95c8157ecd61f83c56ce4f5c..07bd7ba6b5784611836dd15c9b886d164c2c1bf1 100644 --- a/examples/user_types/Decoder.java +++ b/examples/user_types/Decoder.java @@ -6,7 +6,9 @@ import se.lth.control.labcomm.DecoderChannel; public class Decoder implements twoLines.Handler, - twoInts.Handler + twoInts.Handler, + theFirstInt.Handler, + theSecondInt.Handler { @@ -18,6 +20,8 @@ public class Decoder decoder = new DecoderChannel(in); twoInts.register(decoder, this); twoLines.register(decoder, this); + theFirstInt.register(decoder, this); + theSecondInt.register(decoder, this); try { System.out.println("Running decoder."); @@ -40,6 +44,14 @@ public class Decoder System.out.println(d.a +", "+d.b); } + public void handle_theFirstInt(int d) throws java.io.IOException { + System.out.println("Got theFirstInt: "+d); + } + + public void handle_theSecondInt(int d) throws java.io.IOException { + System.out.println("Got theSecondInt: "+d); + } + public void handle_twoLines(twoLines d) throws java.io.IOException { System.out.print("Got twoLines: "); System.out.println("Line l1: "+genLine(d.l1)); diff --git a/examples/user_types/Encoder.java b/examples/user_types/Encoder.java index acee88936e922a14fd902a2563a1c4a088f41d89..335bc4f48e85182fe23421e4cab771f541f68bc6 100644 --- a/examples/user_types/Encoder.java +++ b/examples/user_types/Encoder.java @@ -18,6 +18,8 @@ public class Encoder encoder = new EncoderChannel(out); twoInts.register(encoder); twoLines.register(encoder); + theFirstInt.register(encoder); + theSecondInt.register(encoder); } public void doEncode() throws java.io.IOException { @@ -28,6 +30,10 @@ public class Encoder System.out.println("Encoding twoInts"); twoInts.encode(encoder, ti); + System.out.println("Encoding the Ints"); + theFirstInt.encode(encoder, 71); + theSecondInt.encode(encoder, 24); + twoLines x = new twoLines(); line l1 = new line(); point p11 = new point(); diff --git a/examples/user_types/example_decoder.c b/examples/user_types/example_decoder.c index ed3310020b1e6427018535a20f947f02ee335351..830a4c51856ec602bdff099ba27c5681001d40c4 100644 --- a/examples/user_types/example_decoder.c +++ b/examples/user_types/example_decoder.c @@ -12,6 +12,14 @@ static void handle_test_twoInts(test_twoInts *v,void *context) { printf("Got twoInts. (%d,%d) \n", v->a, v->b); } +static void handle_test_theFirstInt(int *v,void *context) { + printf("Got theFirstInt. (%d) \n", *v); +} + +static void handle_test_theSecondInt(int *v,void *context) { + printf("Got theSecondInt. (%d) \n", *v); +} + static void handle_test_twoLines(test_twoLines *v,void *context) { printf("Got twoLines. (%d,%d) -> (%d,%d), (%d,%d) -> (%d,%d)\n", v->l1.start.x.val, v->l1.start.y.val, v->l1.end.x.val, v->l1.end.y.val, @@ -38,6 +46,8 @@ int main(int argc, char *argv[]) { } labcomm_decoder_register_test_twoInts(decoder, handle_test_twoInts, context); + labcomm_decoder_register_test_theFirstInt(decoder, handle_test_theFirstInt, context); + labcomm_decoder_register_test_theSecondInt(decoder, handle_test_theSecondInt, context); labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context); printf("Decoding:\n"); diff --git a/examples/user_types/test.lc b/examples/user_types/test.lc index 9df2ebc98ec815fbd0db894e8f1a200de88392d3..b232512685d3dd130a5c3eb36168f0cc7655d11f 100644 --- a/examples/user_types/test.lc +++ b/examples/user_types/test.lc @@ -2,6 +2,8 @@ typedef struct { int val; } coord; +typedef int anInt; + typedef struct { coord x; coord y; @@ -28,3 +30,6 @@ sample struct { int a; int b; } twoInts; + +sample anInt theFirstInt; +sample anInt theSecondInt;