Skip to content
Snippets Groups Projects
Commit 576f596c authored by Sven Robertz's avatar Sven Robertz
Browse files

extended simple example to use typedef

parent 75a92c86
Branches
Tags
No related merge requests found
......@@ -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 {
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
sample struct {
typedef struct {
int a;
int b;
} TwoInts;
sample TwoInts theTwoInts;
sample TwoInts anotherTwoInts;
sample struct {
int x;
string s;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment