diff --git a/examples/simple_java/compile.sh b/examples/simple_java/compile.sh index 84a0e83e8f8c31364890f54c497b3ced3d7a77a5..fe65e2c1de4a045d6531a1f6a9b44e38303bca43 100644 --- a/examples/simple_java/compile.sh +++ b/examples/simple_java/compile.sh @@ -2,5 +2,7 @@ java -jar ../../labComm.jar --java=gen --c=gen/simple.c --h=gen/simple.h simple javac -cp ../../lib/java:. gen/*.java Encoder.java Decoder.java -gcc -o encoder -I . -I ../../lib/c example_encoder.c gen/simple.c ../../lib/c/labcomm.c ../../lib/c/labcomm_fd_reader_writer.c +gcc -o example_encoder -I . -I ../../lib/c example_encoder.c gen/simple.c ../../lib/c/labcomm.c ../../lib/c/labcomm_fd_reader_writer.c + +gcc -o example_decoder -I . -I ../../lib/c example_decoder.c gen/simple.c ../../lib/c/labcomm.c ../../lib/c/labcomm_fd_reader_writer.c diff --git a/examples/simple_java/example_decoder.c b/examples/simple_java/example_decoder.c new file mode 100644 index 0000000000000000000000000000000000000000..bfe8430ab604e71a652b499dd8b80f3fe112aa59 --- /dev/null +++ b/examples/simple_java/example_decoder.c @@ -0,0 +1,37 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#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_IntString(simple_IntString *v,void *context) { + printf("Got IntString. x=%d, s=%s\n", v->x, v->s); +} + +int main(int argc, char *argv[]) { + int fd; + struct labcomm_decoder *decoder; + void *context = NULL; + int i, j; + + char *filename = argv[1]; + printf("C decoder reading from %s\n", filename); + fd = open(filename, O_RDONLY); + decoder = labcomm_decoder_new(labcomm_fd_reader, &fd); + if (!decoder) { + printf("Failed to allocate decoder %s:%d\n", __FUNCTION__, __LINE__); + return 1; + } + + labcomm_decoder_register_simple_TwoInts(decoder, handle_simple_TwoInts, context); + labcomm_decoder_register_simple_IntString(decoder, handle_simple_IntString, context); + + printf("Decoding:\n"); + labcomm_decoder_run(decoder); + printf("--- End Of File ---:\n"); + labcomm_decoder_free(decoder); +} diff --git a/examples/simple_java/run.sh b/examples/simple_java/run.sh index 95a1d728389317010c1ef317d862939ce3c6b75b..cd3542dd8a4f12bc3d6fb61c106372dd78e085bb 100644 --- a/examples/simple_java/run.sh +++ b/examples/simple_java/run.sh @@ -1,2 +1,3 @@ java -cp .:../../lib/java:gen Encoder encoded_data java -cp .:../../lib/java:gen Decoder encoded_data +./example_decoder encoded_data