Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Show changes
Showing
with 392 additions and 98 deletions
#!/bin/sh
set -x
set -e
### Example compile script, showing the steps required to build a labcomm application
### (including compiler and libs). Also illustrates how versions 2013 and 2006 coexist
# For current version (2013)
(cd ../..; make all)
mkdir -p gen
java -jar ../../compiler/labComm.jar --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc
java -jar ../../compiler/labcomm2014_compiler.jar --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc
javac -cp ../../lib/java:. gen/*.java Encoder.java Decoder.java
javac -cp ../../lib/java/labcomm2014.jar:. gen/*.java Encoder.java Decoder.java
gcc -Wall -Werror -I. -I../../lib/c -L../../lib/c \
gcc -Wall -Werror -Wno-unused-function \
-I. -I../../lib/c/2014 -L../../lib/c \
-o example_encoder example_encoder.c gen/simple.c \
-llabcomm -Tlabcomm.linkscript
gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
-llabcomm2014
gcc -Wall -Werror -I . -I ../../lib/c/2014 -L../../lib/c \
-o example_decoder example_decoder.c gen/simple.c \
-llabcomm -Tlabcomm.linkscript
#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
-llabcomm2014
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_reader.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_default_scheduler.h>
#include <labcomm2014_fd_reader.h>
#include <labcomm2014_default_error_handler.h>
#include <labcomm2014_default_memory.h>
#include <labcomm2014_default_scheduler.h>
#include "gen/simple.h"
#include <stdio.h>
static void handle_simple_doavoid(simple_doavoid *v, void *context) {
printf("Got a void.\n");
}
static void handle_simple_theTwoInts(simple_TwoInts *v,void *context) {
printf("Got theTwoInts. a=%d, b=%d\n", v->a, v->b);
}
......@@ -53,32 +57,33 @@ static void handle_simple_TwoFixedArrays(simple_TwoFixedArrays *d,void *context)
int main(int argc, char *argv[]) {
int fd;
struct labcomm_decoder *decoder;
struct labcomm2014_decoder *decoder;
void *context = NULL;
char *filename = argv[1];
printf("C decoder reading from %s\n", filename);
fd = open(filename, O_RDONLY);
decoder = labcomm_decoder_new(labcomm_fd_reader_new(
labcomm_default_memory, fd, 1),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm_default_scheduler);
decoder = labcomm2014_decoder_new(labcomm2014_fd_reader_new(
labcomm2014_default_memory, fd, 1),
labcomm2014_default_error_handler,
labcomm2014_default_memory,
labcomm2014_default_scheduler);
if (!decoder) {
printf("Failed to allocate decoder %s:%d\n", __FUNCTION__, __LINE__);
return 1;
}
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);
labcomm2014_decoder_register_simple_doavoid(decoder, handle_simple_doavoid, context);
labcomm2014_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context);
labcomm2014_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context);
labcomm2014_decoder_register_simple_IntString(decoder, handle_simple_IntString, context);
labcomm2014_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context);
labcomm2014_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context);
printf("Decoding:\n");
labcomm_decoder_run(decoder);
labcomm2014_decoder_run(decoder);
printf("--- End Of File ---:\n");
labcomm_decoder_free(decoder);
labcomm2014_decoder_free(decoder);
return 0;
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_writer.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_default_scheduler.h>
#include <labcomm2014_fd_writer.h>
#include <labcomm2014_default_error_handler.h>
#include <labcomm2014_default_memory.h>
#include <labcomm2014_default_scheduler.h>
#include "gen/simple.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
int fd;
struct labcomm_encoder *encoder;
struct labcomm2014_encoder *encoder;
char *filename = argv[1];
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_new(
labcomm_default_memory, fd, 1),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm_default_scheduler);
labcomm_encoder_register_simple_theTwoInts(encoder);
labcomm_encoder_register_simple_anotherTwoInts(encoder);
labcomm_encoder_register_simple_IntString(encoder);
encoder = labcomm2014_encoder_new(labcomm2014_fd_writer_new(
labcomm2014_default_memory, fd, 1),
labcomm2014_default_error_handler,
labcomm2014_default_memory,
labcomm2014_default_scheduler);
labcomm2014_encoder_register_simple_doavoid(encoder);
labcomm2014_encoder_register_simple_theTwoInts(encoder);
labcomm2014_encoder_register_simple_anotherTwoInts(encoder);
labcomm2014_encoder_register_simple_IntString(encoder);
labcomm2014_encode_simple_doavoid(encoder);
simple_IntString is;
is.x = 24;
is.s = "Hello, LabComm!";
printf("Encoding IntString, x=%d, s=%s\n", is.x, is.s);
labcomm_encode_simple_IntString(encoder, &is);
labcomm2014_encode_simple_IntString(encoder, &is);
simple_theTwoInts ti;
ti.a = 13;
ti.b = 37;
printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
labcomm_encode_simple_theTwoInts(encoder, &ti);
labcomm2014_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);
labcomm2014_encode_simple_anotherTwoInts(encoder, &ati);
int foo[20];
labcomm_encoder_register_simple_TwoArrays(encoder);
labcomm2014_encoder_register_simple_TwoArrays(encoder);
simple_TwoArrays ta;
ta.fixed.a[0] = 17;
......@@ -57,12 +61,12 @@ int main(int argc, char *argv[]) {
}
printf("Encoding TwoArrays...\n");
labcomm_encode_simple_TwoArrays(encoder, &ta);
labcomm2014_encode_simple_TwoArrays(encoder, &ta);
ti.a = 23;
ti.b = 47;
printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
labcomm_encode_simple_theTwoInts(encoder, &ti);
labcomm2014_encode_simple_theTwoInts(encoder, &ti);
simple_TwoFixedArrays tfa;
......@@ -78,8 +82,8 @@ int main(int argc, char *argv[]) {
tfa.b.a[1][2] = 63;
printf("Encoding TwoFixedArrays...\n");
labcomm_encoder_register_simple_TwoFixedArrays(encoder);
labcomm_encode_simple_TwoFixedArrays(encoder, &tfa);
labcomm2014_encoder_register_simple_TwoFixedArrays(encoder);
labcomm2014_encode_simple_TwoFixedArrays(encoder, &tfa);
return 0;
}
#!/usr/bin/python
import labcomm2014
import sys
import simple
if __name__ == '__main__':
version = sys.argv[2] if len(sys.argv) == 3 else "LabComm2014"
encoder = labcomm2014.Encoder(labcomm2014.StreamWriter(open(sys.argv[1], 'w')), version)
encoder.add_decl(simple.theTwoInts.signature)
encoder.add_decl(simple.IntString.signature)
foo = simple.theTwoInts()
foo.a = 13
foo.b = 37
encoder.encode(foo, simple.theTwoInts.signature)
bar = simple.IntString()
bar.x = 1742
bar.s = "A string from Python"
encoder.encode(bar, simple.IntString.signature)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_writer.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_default_scheduler.h>
#include "gen06/simple.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
int fd;
struct labcomm_encoder *encoder;
char *filename = argv[1];
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_new(
labcomm_default_memory, fd, 1),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm_default_scheduler);
labcomm_encoder_register_simple_theTwoInts(encoder);
labcomm_encoder_register_simple_anotherTwoInts(encoder);
labcomm_encoder_register_simple_IntString(encoder);
simple_IntString is;
is.x = 24;
is.s = "Hello, LabComm!";
printf("Encoding IntString, x=%d, s=%s\n", is.x, is.s);
labcomm_encode_simple_IntString(encoder, &is);
simple_theTwoInts ti;
ti.a = 13;
ti.b = 37;
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];
labcomm_encoder_register_simple_TwoArrays(encoder);
simple_TwoArrays ta;
ta.fixed.a[0] = 17;
ta.fixed.a[1] = 42;
ta.variable.n_1 = 10;
ta.variable.a = foo;
int k;
for(k=0; k<20; k++) {
foo[k] = k;
}
printf("Encoding TwoArrays...\n");
labcomm_encode_simple_TwoArrays(encoder, &ta);
ti.a = 23;
ti.b = 47;
printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b);
labcomm_encode_simple_theTwoInts(encoder, &ti);
simple_TwoFixedArrays tfa;
tfa.a.a[0] = 41;
tfa.a.a[1] = 42;
tfa.b.a[0][0] = 51;
tfa.b.a[0][1] = 52;
tfa.b.a[0][2] = 53;
tfa.b.a[1][0] = 61;
tfa.b.a[1][1] = 62;
tfa.b.a[1][2] = 63;
printf("Encoding TwoFixedArrays...\n");
labcomm_encoder_register_simple_TwoFixedArrays(encoder);
labcomm_encode_simple_TwoFixedArrays(encoder, &tfa);
return 0;
}
sample int AnInt;
sample struct {
int x;
string s;
} IntString;
sample struct {
struct {
float x;
float y;
} point;
boolean b;
} nestedStruct;
export LD_LIBRARY_PATH=../../lib/c/
echo
echo "********************************************"
echo "*** Running example for version 2013 ***"
echo "********************************************"
echo
java -cp .:../../lib/java:gen Encoder encoded_data
java -cp .:../../lib/java/labcomm2014.jar:gen Encoder encoded_data
./example_decoder encoded_data
PYTHONPATH=../../lib/python:gen ./example_encoder.py encoded_data
java -cp .:../../lib/java/labcomm2014.jar:gen Decoder encoded_data
./example_encoder encoded_data
java -cp .:../../lib/java:gen Decoder encoded_data
java -cp .:../../lib/java/labcomm2014.jar:gen Decoder encoded_data
echo "running python decoder (from wiki_example):"
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm2014
......@@ -25,3 +25,18 @@ sample struct {
int a[2];
int b[2,3];
} TwoFixedArrays;
typedef void avoid;
sample avoid doavoid;
// examples of errors: void may not be used
// in structs or arrays
//
// sample struct {
// int a;
// avoid error;
//} foo;
//
//sample void error2[2] ;
//sample avoid error3[_];
LCDIR=../..
LCC=java -jar ${LCDIR}/compiler/labComm.jar
CLASSPATH=.:${LCDIR}/lib/java/labcomm.jar
LABCOMM_JAR=../../compiler/labcomm2014_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
LCLJAR=${LCDIR}/lib/java/labcomm2014.jar # the LabComm library
JAVA_PKG=labcommTCPtest
${JAVA_PKG}/gen/FooSample.java: test.lc
${LCC} --javapackage=${JAVA_PKG}.gen --java=${JAVA_PKG}/gen $<
.PHONY : clean run runserver runOSserver runclient
${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java
#### The main example #########################
run : ${JAVA_PKG}/Example.class ${JAVA_PKG}/server/TestServer.class ${JAVA_PKG}/client/TestClient.class
java -cp ${CLASSPATH} $(<:.class=)
###############################################
### dependencies and parts ####################
###############################################
CLASSPATH=.:${LCLJAR}
${LABCOMM_JAR} :
cd ${LCDIR} && make make-compiler
${LCLJAR} :
cd ${LCDIR}/lib/java && make labcomm2014.jar
${JAVA_PKG}/gen/FooSample.java: test.lc ${LCCJAR}
${LABCOMM} --javapackage=${JAVA_PKG}.gen --java=${JAVA_PKG}/gen $<
${JAVA_PKG}/gen/FooSample.class: ${JAVA_PKG}/gen/FooSample.java test.lc ${LCLJAR}
javac -cp ${CLASSPATH} $<
${JAVA_PKG}/server/TestServer.class: ${JAVA_PKG}/server/TestServer.java ${JAVA_PKG}/gen/FooSample.class
${JAVA_PKG}/Example.class: ${JAVA_PKG}/Example.java ${JAVA_PKG}/gen/FooSample.class ${LCLJAR}
javac -cp ${CLASSPATH} $<
${JAVA_PKG}/server/OneShotServer.class: ${JAVA_PKG}/server/OneShotServer.java ${JAVA_PKG}/gen/FooSample.class
${JAVA_PKG}/server/TestServer.class: ${JAVA_PKG}/server/TestServer.java ${JAVA_PKG}/gen/FooSample.class ${LCLJAR}
javac -cp ${CLASSPATH} $<
${JAVA_PKG}/client/TestClient.class: ${JAVA_PKG}/client/TestClient.java ${JAVA_PKG}/gen//FooSample.class
${JAVA_PKG}/server/OneShotServer.class: ${JAVA_PKG}/server/OneShotServer.java ${JAVA_PKG}/gen/FooSample.class ${LCLJAR}
javac -cp ${CLASSPATH} $<
.PHONY : clean runserver runclient
${JAVA_PKG}/client/TestClient.class: ${JAVA_PKG}/client/TestClient.java ${JAVA_PKG}/gen//FooSample.class ${LCLJAR}
javac -cp ${CLASSPATH} $<
runserver : ${JAVA_PKG}/server/TestServer.class
java -cp ${CLASSPATH} $(<:.class=)
......@@ -30,4 +51,8 @@ runclient : ${JAVA_PKG}/client/TestClient.class
java -cp ${CLASSPATH} $(<:.class=)
clean :
rm ${JAVA_PKG}/server/*.class ${JAVA_PKG}/client/*.class ${JAVA_PKG}/gen/*
rm -f ${JAVA_PKG}/server/*.class
rm -f ${JAVA_PKG}/client/*.class
rm -f ${JAVA_PKG}/gen/*
distclean: clean
A simple (mostly Java) example of a LabComm channel over TCP
The class labcommTCPtest/Example.java contains set up of a server
and a client, and can be run by 'make run'
Also included is a generic decoder in python, and a server that only sends
one sample to the first client that connects, and then closes the connection
and exits.
Those can be run by
* first, in one terminal: make runOSserver
* then, in another terminal: ./runpy localhost 9999
......@@ -5,9 +5,9 @@ import sys
import socket
import rwsocket
if not any('labcomm' in p for p in sys.path):
if not any('labcomm2014' in p for p in sys.path):
sys.path.append('../../lib/python')
import labcomm
import labcomm2014
if __name__ == "__main__":
......@@ -19,7 +19,7 @@ if __name__ == "__main__":
sock.connect(addr)
print "Connected!"
d = labcomm.Decoder(labcomm.StreamReader(sock))
d = labcomm2014.Decoder(labcomm2014.StreamReader(sock))
while True:
try:
......
package labcommTCPtest;
import labcommTCPtest.server.TestServer;
import labcommTCPtest.client.TestClient;
import java.net.Socket;
import java.net.ServerSocket;
public class Example {
public static void main(String a[]) {
String server = "localhost";
int port = 9999;
ServerThread serverThread = new ServerThread(port);
ClientThread clientThread = new ClientThread(server, port);
serverThread.start();
clientThread.start();
}
private static class ServerThread extends Thread {
private int port;
public ServerThread(int port) {
this.port = port;
}
public void run() {
try {
ServerSocket ss = new ServerSocket(port);
Socket s = ss.accept();
TestServer ts = new TestServer(s);
ts.runOne();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private static class ClientThread extends Thread {
private String server;
private int port;
public ClientThread(String server, int port) {
this.server = server;
this.port = port;
}
public void run() {
try {
Socket s = new Socket(server, port);
TestClient c = new TestClient(s);
c.test();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
......@@ -6,8 +6,8 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.EncoderChannel;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample.Handler;
......@@ -25,19 +25,26 @@ public class TestClient implements Handler {
public void test() {
try {
LabCommEncoderChannel e = new LabCommEncoderChannel(out );
EncoderChannel e = new EncoderChannel(out );
FooSample.register(e);
FooSample sample = new FooSample();
int a[] = new int[3];
a[0] = 1;
a[1] = 2;
a[2] = 3;
sample.s = "Some random values";
sample.x = 17;
sample.y = 42;
sample.a = a;
sample.t = 1717;
sample.d = 0.42;
printSample("Client sending", sample);
FooSample.encode(e, sample);
LabCommDecoderChannel c = new LabCommDecoderChannel(in);
DecoderChannel c = new DecoderChannel(in);
FooSample.register(c,this);
c.run();
c.runOne();
} catch (Exception e) {
e.printStackTrace();
}
......@@ -57,9 +64,22 @@ public class TestClient implements Handler {
}
}
private String formatArray(int a[]) {
StringBuilder sb = new StringBuilder();
sb.append("[");
for(int i=0; i < a.length; i++) {
sb.append(a[i]);
if(i < a.length-1) {
sb.append(", ");
}
}
sb.append("]");
return sb.toString();
}
private void printSample(String header, FooSample sample2) throws Exception {
System.out.println(header);
System.out.format("TestClient.invoke(%d, %d, %d, %f)\n", sample2.x, sample2.y, sample2.t, sample2.d);
System.out.format("[TestClient] %s: (%s, %d, %d, %s, %d, %f )\n", header, sample2.s, sample2.x, sample2.y, formatArray(sample2.a), sample2.t, sample2.d);
}
public void handle_FooSample(FooSample sample2) throws Exception {
......
......@@ -6,8 +6,8 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.EncoderChannel;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample.Handler;
......@@ -25,7 +25,7 @@ public class TestClientSingleshot implements Handler {
public void test() {
try {
LabCommEncoderChannel e = new LabCommEncoderChannel(out );
EncoderChannel e = new EncoderChannel(out );
FooSample.register(e);
FooSample sample = new FooSample();
sample.x = 17;
......@@ -35,7 +35,7 @@ public class TestClientSingleshot implements Handler {
printSample("Client sending", sample);
FooSample.encode(e, sample);
LabCommDecoderChannel c = new LabCommDecoderChannel(in);
DecoderChannel c = new DecoderChannel(in);
FooSample.register(c,this);
c.runOne();
} catch (Exception e) {
......
......@@ -6,8 +6,8 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.ServerSocket;
import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.EncoderChannel;
import labcommTCPtest.gen.FooSample;
public class OneShotServer {//implements Handler {
......@@ -21,11 +21,13 @@ public class OneShotServer {//implements Handler {
public void test() {
try {
LabCommEncoderChannel e = new LabCommEncoderChannel(out );
EncoderChannel e = new EncoderChannel(out );
FooSample.register(e);
FooSample sample = new FooSample();
sample.s = "OneShotServer message";
sample.x = 17;
sample.y = 42;
sample.a = new int[]{10,11,12};
sample.t = 1717;
sample.d = 0.42;
printSample("Server sending", sample);
......
......@@ -8,8 +8,8 @@ import java.lang.reflect.Method;
import java.net.ServerSocket;
import java.net.Socket;
import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.EncoderChannel;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample.Handler;
......@@ -38,7 +38,7 @@ public class TestServer implements Handler {
public void runOne() {
try {
LabCommDecoderChannel c = new LabCommDecoderChannel(in);
DecoderChannel c = new DecoderChannel(in);
FooSample.register(c,this);
c.runOne();
} catch (Exception e) {
......@@ -47,11 +47,18 @@ public class TestServer implements Handler {
}
public void handle_FooSample(FooSample sample) throws Exception {
LabCommEncoderChannel e = new LabCommEncoderChannel(out );
EncoderChannel e = new EncoderChannel(out );
FooSample.register(e);
System.out.println("TestServer.handle_FooSample...");
System.out.println("TestServer.handle_FooSample: "+sample.s);
int tmp[] = new int[2*sample.a.length];
for (int i = 0; i < sample.a.length;i++) {
tmp[2*i] = tmp[2*i+1] = sample.a[i];
}
sample.s = "double!";
sample.x *= 2;
sample.y *= 2;
sample.a = tmp;
sample.t *= 2;
sample.d *= 2;
FooSample.encode(e, sample);
......
#!/bin/sh
PYTHONPATH=../../lib/python ./example_tcp_client_decoder.py
PYTHONPATH=../../lib/python ./example_tcp_client_decoder.py $@
sample struct {
string s;
int x;
int y;
int a[_];
long t;
double d;
} FooSample;
gen
UNAME_S=$(shell uname -s)
TARGETS=client server
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM=java -jar $(LABCOMM_JAR)
LABCOMM_JAR=../../compiler/labcomm2014_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
#include ../../lib/c/os_compat.mk
CFLAGS=-O3 -g -Wall -Werror -I../../lib/c/2014 -I. -Wno-unused-function
CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I.
ifeq ($(UNAME_S),Darwin)
CFLAGS+=-DLABCOMM_COMPAT=\"labcomm2014_compat_osx.h\" -DLABCOMM_OS_DARWIN=1
else
CFLAGS+=-Wno-tautological-compare
endif
all: $(TARGETS:%=gen/%)
test: all
LD_LIBRARY_PATH=../../lib/c ./gen/server 2000 &
LD_LIBRARY_PATH=../../lib/c ./gen/client localhost 2000
LD_LIBRARY_PATH=../../lib/c ./gen/client localhost 2000
gen/.dir:
mkdir -p $@
.PRECIOUS: gen/%.o
gen/%.o: gen/%.c | gen/.dir
$(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(CFLAGS) -c -o $@ $<
gen/%.o: %.c | gen/.dir
$(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(CFLAGS) -c -o $@ $<
.PRECIOUS: gen/%.c gen/%.h
gen/%.c gen/%.h: %.lc | gen/.dir
$(LABCOMM) --c=gen/$*.c --h=gen/$*.h $<
gen/client: client.c
gen/client: client.c
$(CC) -o $@ $(CFLAGS) $^ -lpthread \
-L../../lib/c -llabcomm
-L../../lib/c -llabcomm2014
gen/server: server.c
gen/server: server.c
$(CC) -o $@ $(CFLAGS) $^ -lpthread \
-L../../lib/c -llabcomm
-L../../lib/c -llabcomm2014
.PHONY: clean
clean:
.PHONY: clean distclean
clean distclean:
rm -rf gen
gen/decimating.o: decimating.h
......@@ -42,7 +52,7 @@ gen/introspecting.o: introspecting.h
gen/introspecting.o: gen/introspecting_messages.h
gen/client.o: decimating.h
gen/client.o: gen/types.h
gen/client: gen/decimating.o
gen/client: gen/decimating.o
gen/client: gen/decimating_messages.o
gen/client: gen/introspecting.o
gen/client: gen/introspecting_messages.o
......