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 390 additions and 248 deletions
#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:gen Decoder 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=../..
LCCJAR=${LCDIR}/compiler/labComm.jar # the LabComm compiler
LCLJAR=${LCDIR}/lib/java/labcomm.jar # the LabComm library
LABCOMM_JAR=../../compiler/labcomm2014_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
LCLJAR=${LCDIR}/lib/java/labcomm2014.jar # the LabComm library
JAVA_PKG=labcommTCPtest
.PHONY : clean run runserver runOSserver runclient
......@@ -14,17 +15,16 @@ run : ${JAVA_PKG}/Example.class ${JAVA_PKG}/server/TestServer.class ${JAVA_PKG}/
### dependencies and parts ####################
###############################################
LCC=java -jar ${LCCJAR}
CLASSPATH=.:${LCLJAR}
${LCCJAR} :
${LABCOMM_JAR} :
cd ${LCDIR} && make make-compiler
${LCLJAR} :
cd ${LCDIR}/lib/java && make labcomm.jar
cd ${LCDIR}/lib/java && make labcomm2014.jar
${JAVA_PKG}/gen/FooSample.java: test.lc ${LCCJAR}
${LCC} --javapackage=${JAVA_PKG}.gen --java=${JAVA_PKG}/gen $<
${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} $<
......@@ -51,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
......@@ -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:
......
......@@ -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 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];
......@@ -42,7 +42,7 @@ public class TestClient 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.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,7 +21,7 @@ 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";
......
......@@ -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,7 +47,7 @@ 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: "+sample.s);
int tmp[] = new int[2*sample.a.length];
......
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
......
......@@ -21,7 +21,12 @@
#include <errno.h>
#include <arpa/inet.h>
#ifndef LABCOMM_OS_DARWIN
#include <linux/tcp.h>
#else
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#include <netdb.h>
#include <pthread.h>
#include <stdio.h>
......@@ -31,12 +36,12 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <labcomm.h>
#include <labcomm_fd_reader.h>
#include <labcomm_fd_writer.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_pthread_scheduler.h>
#include <labcomm2014.h>
#include <labcomm2014_fd_reader.h>
#include <labcomm2014_fd_writer.h>
#include <labcomm2014_default_error_handler.h>
#include <labcomm2014_default_memory.h>
#include <labcomm2014_pthread_scheduler.h>
#include "decimating.h"
#include "introspecting.h"
#include "gen/types.h"
......@@ -58,13 +63,13 @@ static void handle_Product(int32_t *value, void *context)
static void *run_decoder(void *context)
{
struct labcomm_decoder *decoder = context;
struct labcomm2014_decoder *decoder = context;
int result;
labcomm_decoder_register_types_Sum(decoder, handle_Sum, NULL);
labcomm_decoder_register_types_Diff(decoder, handle_Diff, NULL);
labcomm2014_decoder_register_types_Sum(decoder, handle_Sum, NULL);
labcomm2014_decoder_register_types_Diff(decoder, handle_Diff, NULL);
do {
result = labcomm_decoder_decode_one(decoder);
result = labcomm2014_decoder_decode_one(decoder);
} while (result >= 0);
return NULL;
}
......@@ -82,10 +87,10 @@ int main(int argc, char *argv[])
struct introspecting *introspecting;
char *hostname;
int port;
struct labcomm_scheduler *scheduler;
struct labcomm_decoder *decoder;
struct labcomm_encoder *encoder;
struct labcomm_time *next;
struct labcomm2014_scheduler *scheduler;
struct labcomm2014_decoder *decoder;
struct labcomm2014_encoder *encoder;
struct labcomm2014_time *next;
int32_t i, j;
hostname = argv[1];
......@@ -123,13 +128,13 @@ int main(int argc, char *argv[])
nodelay = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay));
scheduler = labcomm_pthread_scheduler_new(labcomm_default_memory);
decimating = decimating_new(labcomm_fd_reader_new(labcomm_default_memory,
scheduler = labcomm2014_pthread_scheduler_new(labcomm2014_default_memory);
decimating = decimating_new(labcomm2014_fd_reader_new(labcomm2014_default_memory,
fd, 1),
labcomm_fd_writer_new(labcomm_default_memory,
labcomm2014_fd_writer_new(labcomm2014_default_memory,
fd, 0),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
scheduler);
if (decimating == NULL) {
/* Warning: might leak reader and writer at this point */
......@@ -137,45 +142,45 @@ int main(int argc, char *argv[])
}
introspecting = introspecting_new(decimating->reader,
decimating->writer,
labcomm_default_error_handler,
labcomm_default_memory,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
scheduler);
if (introspecting == NULL) {
/* Warning: might leak reader and writer at this point */
goto out;
}
decoder = labcomm_decoder_new(introspecting->reader,
labcomm_default_error_handler,
labcomm_default_memory,
decoder = labcomm2014_decoder_new(introspecting->reader,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
scheduler);
encoder = labcomm_encoder_new(introspecting->writer,
labcomm_default_error_handler,
labcomm_default_memory,
encoder = labcomm2014_encoder_new(introspecting->writer,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
scheduler);
pthread_t rdt;
pthread_create(&rdt, NULL, run_decoder, decoder);
labcomm_encoder_register_types_A(encoder);
labcomm_encoder_register_types_B(encoder);
labcomm_encoder_register_types_Terminate(encoder);
labcomm2014_encoder_register_types_A(encoder);
labcomm2014_encoder_register_types_B(encoder);
labcomm2014_encoder_register_types_Terminate(encoder);
err = labcomm_decoder_ioctl_types_Sum(decoder, SET_DECIMATION, 2);
err = labcomm_decoder_ioctl_types_Diff(decoder, SET_DECIMATION, 4);
err = labcomm2014_decoder_ioctl_types_Sum(decoder, SET_DECIMATION, 2);
err = labcomm2014_decoder_ioctl_types_Diff(decoder, SET_DECIMATION, 4);
next = labcomm_scheduler_now(scheduler);
next = labcomm2014_scheduler_now(scheduler);
for (i = 0 ; i < 4 ; i++) {
if (i == 2) {
labcomm_decoder_register_types_Product(decoder, handle_Product, NULL);
labcomm2014_decoder_register_types_Product(decoder, handle_Product, NULL);
}
for (j = 0 ; j < 4 ; j++) {
printf("\nA=%d B=%d: ", i, j);
labcomm_encode_types_A(encoder, &i);
labcomm_encode_types_B(encoder, &j);
labcomm_time_add_usec(next, 100000);
labcomm_scheduler_sleep(scheduler, next);
labcomm2014_encode_types_A(encoder, &i);
labcomm2014_encode_types_B(encoder, &j);
labcomm2014_time_add_usec(next, 100000);
labcomm2014_scheduler_sleep(scheduler, next);
}
}
printf("\n");
labcomm_encode_types_Terminate(encoder, LABCOMM_VOID);
labcomm2014_encode_types_Terminate(encoder);
out:
return 0;
......
......@@ -23,18 +23,18 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "labcomm_private.h"
#include "labcomm2014_private.h"
#include "decimating.h"
#include "gen/decimating_messages.h"
struct decimating_private {
struct decimating decimating;
struct labcomm_error_handler *error;
struct labcomm_memory *memory;
struct labcomm_scheduler *scheduler;
struct labcomm2014_error_handler *error;
struct labcomm2014_memory *memory;
struct labcomm2014_scheduler *scheduler;
int encoder_initialized;
struct labcomm_reader_action_context reader_action_context;
struct labcomm_writer_action_context writer_action_context;
struct labcomm2014_reader_action_context reader_action_context;
struct labcomm2014_writer_action_context writer_action_context;
LABCOMM_SIGNATURE_ARRAY_DEF(writer_decimation,
struct decimation {
int n;
......@@ -50,26 +50,25 @@ static void set_decimation(
struct decimating_private *decimating = context;
struct decimation *decimation;
labcomm_scheduler_data_lock(decimating->scheduler);
labcomm2014_scheduler_data_lock(decimating->scheduler);
decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory,
decimating->writer_decimation,
struct decimation,
value->signature_index);
decimation->n = value->decimation;
decimation->current = 0;
labcomm_scheduler_data_unlock(decimating->scheduler);
labcomm2014_scheduler_data_unlock(decimating->scheduler);
}
static int wrap_reader_alloc(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
char *labcomm_version)
struct labcomm2014_reader *r,
struct labcomm2014_reader_action_context *action_context)
{
struct decimating_private *decimating = action_context->context;
labcomm_decoder_register_decimating_messages_set_decimation(
labcomm2014_decoder_register_decimating_messages_set_decimation(
r->decoder, set_decimation, decimating);
return labcomm_reader_alloc(r, action_context->next, labcomm_version);
return labcomm2014_reader_alloc(r, action_context->next);
}
struct send_set_decimation {
......@@ -81,11 +80,11 @@ struct send_set_decimation {
static void send_set_decimation(void *arg)
{
struct send_set_decimation *msg = arg;
struct labcomm_memory *memory = msg->decimating->memory;
struct labcomm2014_memory *memory = msg->decimating->memory;
labcomm_encode_decimating_messages_set_decimation(
labcomm2014_encode_decimating_messages_set_decimation(
msg->decimating->decimating.writer->encoder, &msg->set_decimation);
labcomm_memory_free(memory, 1, msg);
labcomm2014_memory_free(memory, 1, msg);
}
static void enqueue_decimation(struct decimating_private *decimating,
......@@ -93,21 +92,21 @@ static void enqueue_decimation(struct decimating_private *decimating,
int amount)
{
struct send_set_decimation *msg;
msg = labcomm_memory_alloc(decimating->memory, 1, sizeof(*msg));
msg = labcomm2014_memory_alloc(decimating->memory, 1, sizeof(*msg));
if (msg) {
msg->decimating = decimating;
msg->set_decimation.decimation = amount;
msg->set_decimation.signature_index = remote_index;
labcomm_scheduler_enqueue(decimating->scheduler, 0,
labcomm2014_scheduler_enqueue(decimating->scheduler, 0,
send_set_decimation, msg);
}
}
static int wrap_reader_start(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
int local_index, int remote_index, struct labcomm_signature *signature,
struct labcomm2014_reader *r,
struct labcomm2014_reader_action_context *action_context,
int local_index, int remote_index, const struct labcomm2014_signature *signature,
void *value)
{
struct decimating_private *decimating = action_context->context;
......@@ -115,26 +114,26 @@ static int wrap_reader_start(
if (value == NULL) {
int *decimation, amount;
labcomm_scheduler_data_lock(decimating->scheduler);
labcomm2014_scheduler_data_lock(decimating->scheduler);
decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory,
decimating->reader_decimation,
int,
local_index);
amount = *decimation;
labcomm_scheduler_data_unlock(decimating->scheduler);
labcomm2014_scheduler_data_unlock(decimating->scheduler);
if (remote_index != 0 && amount != 0) {
enqueue_decimation(decimating, remote_index, amount);
}
}
return labcomm_reader_start(r, action_context->next,
return labcomm2014_reader_start(r, action_context->next,
local_index, remote_index, signature, value);
}
static int wrap_reader_ioctl(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
struct labcomm2014_reader *r,
struct labcomm2014_reader_action_context *action_context,
int local_index, int remote_index,
struct labcomm_signature *signature,
const struct labcomm2014_signature *signature,
uint32_t action, va_list args)
{
struct decimating_private *decimating = action_context->context;
......@@ -148,26 +147,26 @@ static int wrap_reader_ioctl(
amount = va_arg(va, int);
va_end(va);
labcomm_scheduler_data_lock(decimating->scheduler);
labcomm2014_scheduler_data_lock(decimating->scheduler);
decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory,
decimating->reader_decimation,
int,
local_index);
*decimation = amount;
labcomm_scheduler_data_unlock(decimating->scheduler);
labcomm2014_scheduler_data_unlock(decimating->scheduler);
if (remote_index) {
enqueue_decimation(decimating, remote_index, amount);
}
} else {
return labcomm_reader_ioctl(r, action_context->next,
return labcomm2014_reader_ioctl(r, action_context->next,
local_index, remote_index, signature,
action, args);
}
return 0;
}
struct labcomm_reader_action decimating_reader_action = {
struct labcomm2014_reader_action decimating_reader_action = {
.alloc = wrap_reader_alloc,
.free = NULL,
.start = wrap_reader_start,
......@@ -180,54 +179,55 @@ static void register_signatures(void *context)
{
struct decimating_private *decimating = context;
labcomm_encoder_register_decimating_messages_set_decimation(
labcomm2014_encoder_register_decimating_messages_set_decimation(
decimating->decimating.writer->encoder);
}
static int wrap_writer_alloc(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
char *labcomm_version)
struct labcomm2014_writer *w,
struct labcomm2014_writer_action_context *action_context)
{
struct decimating_private *decimating = action_context->context;
labcomm_scheduler_enqueue(decimating->scheduler,
labcomm2014_scheduler_enqueue(decimating->scheduler,
0, register_signatures, decimating);
return labcomm_writer_alloc(w, action_context->next, labcomm_version);
return labcomm2014_writer_alloc(w, action_context->next);
}
static int wrap_writer_start(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
int index, struct labcomm_signature *signature,
struct labcomm2014_writer *w,
struct labcomm2014_writer_action_context *action_context,
int index, const struct labcomm2014_signature *signature,
void *value)
{
struct decimating_private *decimating = action_context->context;
struct decimation *decimation;
int result;
labcomm_scheduler_data_lock(decimating->scheduler);
decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory,
decimating->writer_decimation,
struct decimation, index);
decimation->current++;
if (decimation->current < decimation->n) {
result = -EALREADY;
} else {
decimation->current = 0;
if (index < LABCOMM_USER) {
result = 0;
} else {
labcomm2014_scheduler_data_lock(decimating->scheduler);
decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory,
decimating->writer_decimation,
struct decimation, index);
decimation->current++;
if (decimation->current < decimation->n) {
result = -EALREADY;
} else {
decimation->current = 0;
result = 0;
}
labcomm2014_scheduler_data_unlock(decimating->scheduler);
}
labcomm_scheduler_data_unlock(decimating->scheduler);
if (result == 0) {
result = labcomm_writer_start(w, action_context->next,
result = labcomm2014_writer_start(w, action_context->next,
index, signature, value);
}
return result;
}
struct labcomm_writer_action decimating_writer_action = {
struct labcomm2014_writer_action decimating_writer_action = {
.alloc = wrap_writer_alloc,
.free = NULL,
.start = wrap_writer_start,
......@@ -237,11 +237,11 @@ struct labcomm_writer_action decimating_writer_action = {
};
struct decimating *decimating_new(
struct labcomm_reader *reader,
struct labcomm_writer *writer,
struct labcomm_error_handler *error,
struct labcomm_memory *memory,
struct labcomm_scheduler *scheduler)
struct labcomm2014_reader *reader,
struct labcomm2014_writer *writer,
struct labcomm2014_error_handler *error,
struct labcomm2014_memory *memory,
struct labcomm2014_scheduler *scheduler)
{
struct decimating_private *result;
......
#ifndef __DECIMATING_H__
#define __DECIMATING_H__
#include <labcomm.h>
#include <labcomm_ioctl.h>
#include <labcomm2014.h>
#include <labcomm2014_ioctl.h>
struct decimating {
struct labcomm_reader *reader;
struct labcomm_writer *writer;
struct labcomm2014_reader *reader;
struct labcomm2014_writer *writer;
};
extern struct decimating *decimating_new(
struct labcomm_reader *reader,
struct labcomm_writer *writer,
struct labcomm_error_handler *error,
struct labcomm_memory *memory,
struct labcomm_scheduler *scheduler);
struct labcomm2014_reader *reader,
struct labcomm2014_writer *writer,
struct labcomm2014_error_handler *error,
struct labcomm2014_memory *memory,
struct labcomm2014_scheduler *scheduler);
#define SET_DECIMATION LABCOMM_IOSW('d',0,int)
......
sample struct {
int decimation;
int signature_index;
} set_decimation;
\ No newline at end of file
} set_decimation;
......@@ -23,18 +23,18 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "labcomm_private.h"
#include "labcomm2014_private.h"
#include "introspecting.h"
#include "gen/introspecting_messages.h"
struct introspecting_private {
struct introspecting introspecting;
struct labcomm_error_handler *error;
struct labcomm_memory *memory;
struct labcomm_scheduler *scheduler;
struct labcomm2014_error_handler *error;
struct labcomm2014_memory *memory;
struct labcomm2014_scheduler *scheduler;
struct labcomm_reader_action_context reader_action_context;
struct labcomm_writer_action_context writer_action_context;
struct labcomm2014_reader_action_context reader_action_context;
struct labcomm2014_writer_action_context writer_action_context;
LABCOMM_SIGNATURE_ARRAY_DEF(remote,
struct remote {
char *name;
......@@ -44,13 +44,13 @@ struct introspecting_private {
LABCOMM_SIGNATURE_ARRAY_DEF(local,
struct local {
enum introspecting_status status;
struct labcomm_signature *signature;
const struct labcomm2014_signature *signature;
});
};
static struct local *get_local(struct introspecting_private *introspecting,
int index,
struct labcomm_signature *signature)
const struct labcomm2014_signature *signature)
{
/* Called with data_lock held */
struct local *local;
......@@ -91,7 +91,7 @@ static void handles_signature(
struct introspecting_private *introspecting = context;
struct remote *remote;
labcomm_scheduler_data_lock(introspecting->scheduler);
labcomm2014_scheduler_data_lock(introspecting->scheduler);
remote = LABCOMM_SIGNATURE_ARRAY_REF(introspecting->memory,
introspecting->remote,
struct remote,
......@@ -119,26 +119,25 @@ static void handles_signature(
}
}
}
labcomm_scheduler_data_unlock(introspecting->scheduler);
labcomm2014_scheduler_data_unlock(introspecting->scheduler);
}
static int wrap_reader_alloc(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
char *labcomm_version)
struct labcomm2014_reader *r,
struct labcomm2014_reader_action_context *action_context)
{
struct introspecting_private *introspecting = action_context->context;
labcomm_decoder_register_introspecting_messages_handles_signature(
labcomm2014_decoder_register_introspecting_messages_handles_signature(
introspecting->introspecting.reader->decoder,
handles_signature, introspecting);
return labcomm_reader_alloc(r, action_context->next, labcomm_version);
return labcomm2014_reader_alloc(r, action_context->next);
}
struct handles_signature {
struct introspecting_private *introspecting;
int index;
struct labcomm_signature *signature;
const struct labcomm2014_signature *signature;
};
static void send_handles_signature(void *arg)
......@@ -150,14 +149,14 @@ static void send_handles_signature(void *arg)
handles_signature.name = h->signature->name;
handles_signature.signature.n_0 = h->signature->size;
handles_signature.signature.a = h->signature->signature;
labcomm_encode_introspecting_messages_handles_signature(
labcomm2014_encode_introspecting_messages_handles_signature(
h->introspecting->introspecting.writer->encoder, &handles_signature);
}
static int wrap_reader_start(
struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
int local_index, int remote_index, struct labcomm_signature *signature,
struct labcomm2014_reader *r,
struct labcomm2014_reader_action_context *action_context,
int local_index, int remote_index, const struct labcomm2014_signature *signature,
void *value)
{
struct introspecting_private *introspecting = action_context->context;
......@@ -165,23 +164,23 @@ static int wrap_reader_start(
if (value == NULL) {
struct handles_signature *handles_signature;
handles_signature = labcomm_memory_alloc(introspecting->memory, 1,
handles_signature = labcomm2014_memory_alloc(introspecting->memory, 1,
sizeof(*handles_signature));
handles_signature->introspecting = introspecting;
handles_signature->index = local_index;
handles_signature->signature = signature;
labcomm_scheduler_enqueue(introspecting->scheduler,
labcomm2014_scheduler_enqueue(introspecting->scheduler,
0, send_handles_signature, handles_signature);
}
return labcomm_reader_start(r, action_context->next,
return labcomm2014_reader_start(r, action_context->next,
local_index, remote_index, signature, value);
}
void encode_handles_signature(
struct labcomm_encoder *encoder,
struct labcomm2014_encoder *encoder,
void *context)
{
struct labcomm_signature *signature = context;
const struct labcomm2014_signature *signature = context;
introspecting_messages_handles_signature handles_signature;
int index = 0;
......@@ -190,11 +189,11 @@ static int wrap_reader_start(
handles_signature.signature.n_0 = signature->size;
handles_signature.signature.a = signature->signature;
labcomm_encode_introspecting_messages_handles_signature(
labcomm2014_encode_introspecting_messages_handles_signature(
NULL, &handles_signature);
}
struct labcomm_reader_action introspecting_reader_action = {
struct labcomm2014_reader_action introspecting_reader_action = {
.alloc = wrap_reader_alloc,
.free = NULL,
.start = wrap_reader_start,
......@@ -207,45 +206,44 @@ static void register_encoder_signatures(void *context)
{
struct introspecting_private *introspecting = context;
labcomm_encoder_register_introspecting_messages_handles_signature(
labcomm2014_encoder_register_introspecting_messages_handles_signature(
introspecting->introspecting.writer->encoder);
}
static int wrap_writer_alloc(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
char *labcomm_version)
struct labcomm2014_writer *w,
struct labcomm2014_writer_action_context *action_context)
{
struct introspecting_private *introspecting = action_context->context;
labcomm_scheduler_enqueue(introspecting->scheduler,
labcomm2014_scheduler_enqueue(introspecting->scheduler,
0, register_encoder_signatures, introspecting);
return labcomm_writer_alloc(w, action_context->next, labcomm_version);
return labcomm2014_writer_alloc(w, action_context->next);
}
static int wrap_writer_start(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
int index, struct labcomm_signature *signature,
struct labcomm2014_writer *w,
struct labcomm2014_writer_action_context *action_context,
int index, const struct labcomm2014_signature *signature,
void *value)
{
struct introspecting_private *introspecting = action_context->context;
if (value == NULL) {
if (index >= LABCOMM_USER && value == NULL) {
struct local *local;
labcomm_scheduler_data_lock(introspecting->scheduler);
labcomm2014_scheduler_data_lock(introspecting->scheduler);
local = get_local(introspecting, index, signature);
local->status = introspecting_registered;
labcomm_scheduler_data_unlock(introspecting->scheduler);
labcomm2014_scheduler_data_unlock(introspecting->scheduler);
}
return labcomm_writer_start(w, action_context->next, index, signature, value);
return labcomm2014_writer_start(w, action_context->next, index, signature, value);
}
static int wrap_writer_ioctl(
struct labcomm_writer *w,
struct labcomm_writer_action_context *action_context,
int index, struct labcomm_signature *signature,
struct labcomm2014_writer *w,
struct labcomm2014_writer_action_context *action_context,
int index, const struct labcomm2014_signature *signature,
uint32_t ioctl_action, va_list args)
{
struct introspecting_private *introspecting = action_context->context;
......@@ -255,20 +253,20 @@ static int wrap_writer_ioctl(
struct local *local;
int result;
labcomm_scheduler_data_lock(introspecting->scheduler);
labcomm2014_scheduler_data_lock(introspecting->scheduler);
local = get_local(introspecting, index, signature);
result = local->status;
labcomm_scheduler_data_unlock(introspecting->scheduler);
labcomm2014_scheduler_data_unlock(introspecting->scheduler);
return result;
}
default: {
return labcomm_writer_ioctl(w, action_context->next, index, signature,
return labcomm2014_writer_ioctl(w, action_context->next, index, signature,
ioctl_action, args);
} break;
}
}
struct labcomm_writer_action introspecting_writer_action = {
struct labcomm2014_writer_action introspecting_writer_action = {
.alloc = wrap_writer_alloc,
.free = NULL,
.start = wrap_writer_start,
......@@ -278,11 +276,11 @@ struct labcomm_writer_action introspecting_writer_action = {
};
extern struct introspecting *introspecting_new(
struct labcomm_reader *reader,
struct labcomm_writer *writer,
struct labcomm_error_handler *error,
struct labcomm_memory *memory,
struct labcomm_scheduler *scheduler)
struct labcomm2014_reader *reader,
struct labcomm2014_writer *writer,
struct labcomm2014_error_handler *error,
struct labcomm2014_memory *memory,
struct labcomm2014_scheduler *scheduler)
{
struct introspecting_private *result;
......
......@@ -23,22 +23,22 @@
#ifndef __INTROSPECTING_H__
#define __INTROSPECTING_H__
#include <labcomm.h>
#include <labcomm_ioctl.h>
#include <labcomm_fd_reader.h>
#include <labcomm_fd_writer.h>
#include <labcomm2014.h>
#include <labcomm2014_ioctl.h>
#include <labcomm2014_fd_reader.h>
#include <labcomm2014_fd_writer.h>
struct introspecting {
struct labcomm_reader *reader;
struct labcomm_writer *writer;
struct labcomm2014_reader *reader;
struct labcomm2014_writer *writer;
};
extern struct introspecting *introspecting_new(
struct labcomm_reader *reader,
struct labcomm_writer *writer,
struct labcomm_error_handler *error,
struct labcomm_memory *memory,
struct labcomm_scheduler *scheduler);
struct labcomm2014_reader *reader,
struct labcomm2014_writer *writer,
struct labcomm2014_error_handler *error,
struct labcomm2014_memory *memory,
struct labcomm2014_scheduler *scheduler);
#define HAS_SIGNATURE LABCOMM_IOS('i',2)
enum introspecting_status { introspecting_unknown,
......
......@@ -20,7 +20,12 @@
*/
#include <arpa/inet.h>
#ifndef LABCOMM_OS_DARWIN
#include <linux/tcp.h>
#else
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
......@@ -28,11 +33,11 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <labcomm_default_error_handler.h>
#include <labcomm_default_memory.h>
#include <labcomm_pthread_scheduler.h>
#include <labcomm_fd_reader.h>
#include <labcomm_fd_writer.h>
#include <labcomm2014_default_error_handler.h>
#include <labcomm2014_default_memory.h>
#include <labcomm2014_pthread_scheduler.h>
#include <labcomm2014_fd_reader.h>
#include <labcomm2014_fd_writer.h>
#include "decimating.h"
#include "introspecting.h"
#include "gen/types.h"
......@@ -44,9 +49,9 @@ struct client {
struct sockaddr_in adr;
unsigned int adrlen;
int32_t A, B, Sum, Diff, Product;
struct labcomm_decoder *decoder;
struct labcomm_encoder *encoder;
struct labcomm_scheduler *scheduler;
struct labcomm2014_decoder *decoder;
struct labcomm2014_encoder *encoder;
struct labcomm2014_scheduler *scheduler;
};
static void handle_A(int32_t *value, void *context)
......@@ -62,22 +67,22 @@ static void handle_B(int32_t *value, void *context)
int status;
client->B = *value;
status = labcomm_encoder_ioctl_types_Product(client->encoder, HAS_SIGNATURE);
status = labcomm2014_encoder_ioctl_types_Product(client->encoder, HAS_SIGNATURE);
switch (status) {
case introspecting_unregistered:
labcomm_encoder_register_types_Product(client->encoder);
labcomm2014_encoder_register_types_Product(client->encoder);
/* fall through */
case introspecting_registered:
client->Product = client->A * client->B;
labcomm_encode_types_Product(client->encoder, &client->Product);
labcomm2014_encode_types_Product(client->encoder, &client->Product);
break;
default:
break;
}
client->Sum = client->A + client->B;
client->Diff = client->A - client->B;
labcomm_encode_types_Sum(client->encoder, &client->Sum);
labcomm_encode_types_Diff(client->encoder, &client->Diff);
labcomm2014_encode_types_Sum(client->encoder, &client->Sum);
labcomm2014_encode_types_Diff(client->encoder, &client->Diff);
}
static void handle_Terminate(types_Terminate *value, void *context)
......@@ -90,14 +95,14 @@ static void *run_decoder(void *arg)
struct client *client = arg;
int result;
labcomm_decoder_register_types_A(client->decoder, handle_A, client);
labcomm_decoder_register_types_B(client->decoder, handle_B, client);
labcomm_decoder_register_types_Terminate(client->decoder, handle_Terminate,
labcomm2014_decoder_register_types_A(client->decoder, handle_A, client);
labcomm2014_decoder_register_types_B(client->decoder, handle_B, client);
labcomm2014_decoder_register_types_Terminate(client->decoder, handle_Terminate,
NULL);
do {
result = labcomm_decoder_decode_one(client->decoder);
result = labcomm2014_decoder_decode_one(client->decoder);
} while (result >= 0);
labcomm_scheduler_wakeup(client->scheduler);
labcomm2014_scheduler_wakeup(client->scheduler);
return NULL;
}
......@@ -110,13 +115,13 @@ static void *run_client(void *arg)
printf("Client start\n");
client->A = 0;
client->B = 0;
client->scheduler = labcomm_pthread_scheduler_new(labcomm_default_memory);
decimating = decimating_new(labcomm_fd_reader_new(labcomm_default_memory,
client->scheduler = labcomm2014_pthread_scheduler_new(labcomm2014_default_memory);
decimating = decimating_new(labcomm2014_fd_reader_new(labcomm2014_default_memory,
client->fd, 1),
labcomm_fd_writer_new(labcomm_default_memory,
labcomm2014_fd_writer_new(labcomm2014_default_memory,
client->fd, 0),
labcomm_default_error_handler,
labcomm_default_memory,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
client->scheduler);
if (decimating == NULL) {
/* Warning: might leak reader and writer at this point */
......@@ -124,26 +129,26 @@ static void *run_client(void *arg)
}
introspecting = introspecting_new(decimating->reader,
decimating->writer,
labcomm_default_error_handler,
labcomm_default_memory,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
client->scheduler);
if (introspecting == NULL) {
/* Warning: might leak reader and writer at this point */
goto out;
}
client->decoder = labcomm_decoder_new(introspecting->reader,
labcomm_default_error_handler,
labcomm_default_memory,
client->decoder = labcomm2014_decoder_new(introspecting->reader,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
client->scheduler);
client->encoder = labcomm_encoder_new(introspecting->writer,
labcomm_default_error_handler,
labcomm_default_memory,
client->encoder = labcomm2014_encoder_new(introspecting->writer,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
client->scheduler);
pthread_t rdt;
pthread_create(&rdt, NULL, run_decoder, client);
labcomm_encoder_register_types_Sum(client->encoder);
labcomm_encoder_register_types_Diff(client->encoder);
labcomm_scheduler_sleep(client->scheduler, NULL);
labcomm2014_encoder_register_types_Sum(client->encoder);
labcomm2014_encoder_register_types_Diff(client->encoder);
labcomm2014_scheduler_sleep(client->scheduler, NULL);
printf("Awoken\n");
pthread_join(rdt, NULL);
out:
......
......@@ -3,4 +3,4 @@ sample int B;
sample int Sum;
sample int Diff;
sample int Product;
sample void Terminate;
\ No newline at end of file
sample void Terminate;