Commit e70c1e31 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Fixed wiki_example

parent 4d657ef3
......@@ -11,6 +11,7 @@ all:
test:
echo More to be done...
cd simple ; sh compile.sh && sh run.sh
$(MAKE) -C wiki_example test
$(MAKE) -C duck_typing test
$(MAKE) -C twoway test
......
GENERATED=\
data.java \
example.c \
example.cs \
example.encoded \
example.h \
example.javaencoded \
example.py \
example_encoder \
log_message.java
all:
test:
./run
clean:
rm -f $(GENERATED) *.class
distclean:
distclean: clean
/*
sample float data;
*/
import java.io.IOException;
import se.lth.control.labcomm.Decoder;
import se.lth.control.labcomm.Dispatcher;
import se.lth.control.labcomm.Encoder;
import se.lth.control.labcomm.Handler;
import se.lth.control.labcomm.Sample;
public class data implements Sample {
public interface Handler extends Handler {
public void handle_data(float value) throws Exception;
}
public static void register(Decoder d, Handler h) throws IOException {
d.register(new Dispatcher(), h);
}
public static void register(Encoder e) throws IOException {
e.register(new Dispatcher());
}
private static class Dispatcher implements Dispatcher {
public Class getSampleClass() {
return data.class;
}
public String getName() {
return "data";
}
public byte[] getSignature() {
return signature;
}
public void decodeAndHandle(Decoder d,
Handler h) throws Exception {
((Handler)h).handle_data(data.decode(d));
}
}
public static void encode(Encoder e, float value) throws IOException {
e.begin(data.class);
e.encodeFloat(value);
e.end(data.class);
}
public static float decode(Decoder d) throws IOException {
float result;
result = d.decodeFloat();
return result;
}
private static byte[] signature = new byte[] {
37,
};
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm.h>
#include <labcomm_default_memory.h>
#include <labcomm_fd_reader.h>
#include <labcomm_fd_writer.h>
#include "example.h"
......@@ -8,10 +10,13 @@
int main(int argc, char *argv[]) {
int fd;
struct labcomm_encoder *encoder;
struct labcomm_writer *labcomm_fd_writer;
int i, j;
fd = open("example.encoded", O_WRONLY|O_CREAT|O_TRUNC, 0644);
encoder = labcomm_encoder_new(labcomm_fd_writer, &fd, NULL, NULL);
labcomm_fd_writer = labcomm_fd_writer_new(labcomm_default_memory, fd, 1);
encoder = labcomm_encoder_new(labcomm_fd_writer, NULL,
labcomm_default_memory, NULL);
labcomm_encoder_register_example_log_message(encoder);
labcomm_encoder_register_example_data(encoder);
for (i = 0 ; i < argc ; i++) {
......@@ -31,4 +36,5 @@ int main(int argc, char *argv[]) {
float f = i;
labcomm_encode_example_data(encoder, &f);
}
return 0;
}
#!/bin/sh
# Auto generate code from .lc file
java -jar ../../compiler/labcomm_compiler.jar \
java -jar ../../compiler/labcomm2014_compiler.jar \
--c=example.c --h=example.h \
--java=. \
--cs=example.cs \
--python=example.py \
example.lc
example.lc || exit 1
# Compile executables
(cd ../../lib/c; make liblabcomm.a)
(cd ../../lib/c; make all || exit 1)
gcc -o example_encoder -I ../../lib/c/ \
example_encoder.c \
example.c \
../../lib/c/liblabcomm.a
gcc -Wall -Werror -o example_encoder -I../../lib/c/2014 \
example_encoder.c \
example.c \
../../lib/c/liblabcomm2014.a || exit 1
javac -cp ../../lib/java:. *.java
javac -cp ../../lib/java:. *.java || exit 1
# Run through all executables (c->java->Python)
./example_encoder one two
java -cp ../../lib/java:. example_decoder_encoder example.encoded example.javaencoded
PYTHONPATH=../../lib/python ./example_decoder.py example.javaencoded
./example_encoder one two || exit 1
java -cp ../../lib/java:. example_decoder_encoder example.encoded example.javaencoded || exit 1
PYTHONPATH=../../lib/python ./example_decoder.py example.javaencoded || exit 1
Markdown is supported
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