Commit ee498fe7 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

added typedefs of primitive types to examples/user_types

parent 7df66f2d
......@@ -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));
......
......@@ -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();
......
......@@ -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");
......
......@@ -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;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment