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
Select Git revision
Loading items

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Select Git revision
Loading items
Show changes
Commits on Source (19)
Showing
with 577 additions and 118 deletions
SUBDIRS=compiler lib test examples
export LABCOMM_JAR=$(shell pwd)/compiler/labComm.jar
export LABCOMM_JAR=$(shell pwd)/compiler/labcomm_compiler.jar
export LABCOMM=java -jar $(LABCOMM_JAR)
all: $(SUBDIRS:%=make-%)
......
......@@ -90,7 +90,7 @@ classpath="tools/jastadd2.jar"/>
<target name="jar" depends="build">
<jar destfile="labComm.jar">
<jar destfile="labcomm_compiler.jar">
<fileset dir="." includes="LabComm*.class"/>
<fileset dir="." includes="AST/*.class"/>
<zipfileset src="tools/beaver-rt.jar" includes="beaver/*.class"/>
......
Discussion 141023
TODO:
*** new labcomm packet types:
TYPE_DEF = 0x03 // for (possibly) hierarchical type definitions
TYPE_BINDING = 0x04 // binding a sample def to a type def
*** rewrite malloc of received samples to utilize the packet length field
to allocate a single object before parsing the sample byte stream
*** labcomm language: add type for type_ref to facilitate references to
labcomm sample_defs (and type_defs) in (primarily) pragmas
E.g., sample ... foo;
sample ... bar;
sample struct {
...
type[2] some_refs;
} some_pragma;
my_lc_some_pragma sp;
sp.some_refs = {&labcomm_signature_my_lc_foo,
&labcomm_signature_my_lc_bar};
labcomm_encode_my_lc_some_pragma(enc, &sp);
This is to avoid exposing local_to_remote and remote_to_local
*** refactor {encoder,decoder}registry to separate the actual encoder
from the registry
- currently, the assignment of local indices is done in the "constructor"
which means that the registries will be very thin
*** labcomm_pragma_builder(struct labcomm_encoder *enc);
- looks like an encoder to enable reuse of the generated encode functions
- allocates memory in the enclosing encoder, enc.
- deallocates memory when packet is sent
*** Pragma handler
- is a decoder, to which the user registers handlers for pragma samples
- has/gets a byte_array_reader in the context
- the "surrounding" decoder will deallocate the pragma packet when the
pragma handler returns
______________________________________________________________
______________preliminary sketch of pragma____________________
A pragma "packet" is a sequence of fields, where each field is
a labcomm sample (in order to keep labcomm in-band self-describing).
A pragma packet has a type, which is a globally unique string
(e.g., java package-like name, URI, or UUID)
One predefined pragma sample type is labcomm_type_ref, which is used to refer
to labcomm sample types in a way that is unique on a given encoder/channel.
Sending:
/* create a pragma packet for pragma type type
allocated in e->memory */
// (or, if that is visible to user code, should
// the parameter be a struct labcomm_memory*?)
struct labcom_pragma_packet * = labcomm_pragma_new(struct labcomm_encoder e*,
char *type);
/* add type reference field*/
void labcomm_pragma_add_ref(struct labcomm_signature sig);
// the semantics if more than one type reference field is undefined
// (as far as labcomm is concerned).
// One possible (pragma-type defined) semantic is that the latest type
// reference applies to the fields following it.
A pragma packet is (under the hood) a struct labcomm_encoder, so that we
can reuse the sample_type_encode() function for adding pragma fields.
// an example session
struct labcom_pragma_packet pp = labcomm_pragma_new(enc, some_type));
labcomm_pragma_add_ref(some_sig);
some_pragma_type_encode(pp, some_pragma_instance);
another_pragma_type_encode(pp, another_pragma_instance);
labcomm_pragma_send(pp, enc);
#define labcomm_pragma_add_field(some_pragma_sample_type, value) \
labcomm_encode_#some_pragma_sample_type, value)
int labcomm_encode_test_twoLines( struct labcomm_encoder *e,
test_twoLines *v)
{
return labcomm_internal_encode(e,
&labcomm_signature_test_twoLines,
(labcomm_enc oder_function) encode_test_twoLines,
v);
}
receiving:
alt 1. standard handlers, parameter pragma_type to handle function
-- this means adding a parameter to all handlers
(where null means not pragma)
void handle_some_pragma(some_pragma *v, void *context, char * pragma_type);
alt 2. standard handlers, but separate register_pragma_handler function
use the handler context to store and communicate pragma-specific data.
-- this means that the decoder interface needs to be extended,
and that the handler context for pragmas need to be specified
(by labcomm)
alt 3 have a single handler for pragma packets as the interface upwards
from the labcomm lib. That handler is then responsible for managing
and multiplexing pragma types based on the type field in the pragma
packet.
The labcomm libraries can provide a default implementation of a
pragma_handler, to facilitate the common cases and reduce the
amount of boilerplate code.
struct pragma_packet {
char *pragma_type;
char *packed_data;
}
void handle_pragma(struct pragma_packet *p, void *context);
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM_JAR=../../compiler/labcomm_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
all: gen/animal.py
......
LCDIR=../..
LCC=java -jar ${LCDIR}/compiler/labComm.jar
LCC=java -jar ${LCDIR}/compiler/labcomm_compiler.jar
CLASSPATH=.:${LCDIR}/lib/java/labcomm.jar
JAVA_PKG=labcommTCPtest
SAMPLENAME=foo
LCC=java -jar ${LCDIR}/compiler/labComm.jar
LCLIBDIR=${LCDIR}/lib/c
LCFILE=jg
......
......@@ -5,7 +5,7 @@
(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/labcomm_compiler.jar --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc
javac -cp ../../lib/java/labcomm20141009.jar:. gen/*.java Encoder.java Decoder.java
......@@ -20,7 +20,7 @@ gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
# For version 2006
mkdir -p gen06
java -jar ../../compiler/labComm.jar --ver=2006 --java=gen06 --c=gen06/simple.c --h=gen06/simple.h --python=gen06/simple.py simple.lc
java -jar ../../compiler/labcomm_compiler.jar --ver=2006 --java=gen06 --c=gen06/simple.c --h=gen06/simple.h --python=gen06/simple.py simple.lc
javac -cp ../../lib/java/labcomm2006.jar:. gen06/*.java Encoder06.java Decoder06.java
......
LCDIR=../..
LCCJAR=${LCDIR}/compiler/labComm.jar # the LabComm compiler
LCCJAR=${LCDIR}/compiler/labcomm_compiler.jar # the LabComm compiler
LCLJAR=${LCDIR}/lib/java/labcomm.jar # the LabComm library
JAVA_PKG=labcommTCPtest
......
TARGETS=client server
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM_JAR=../../compiler/labcomm_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I. -Wno-unused-function
......
......@@ -5,7 +5,7 @@ import java.io.InputStream;
import se.lth.control.labcomm.DecoderChannel;
public class Decoder
implements twoLines.Handler
implements twoLines.Handler, theint.Handler, Comment.Handler//, Typedef.Handler
{
......@@ -16,6 +16,9 @@ public class Decoder
{
decoder = new DecoderChannel(in);
twoLines.register(decoder, this);
theint.register(decoder,this);
Comment.register(decoder, this);
//Typedef.register(decoder, this);
try {
System.out.println("Running decoder.");
......@@ -39,6 +42,20 @@ public class Decoder
System.out.println(" Line l2: "+genLine(d.l2));
}
public void handle_theint(int d) throws java.io.IOException {
System.out.println("Got theint: "+d);
}
public void handle_Comment(Comment c) throws java.io.IOException {
System.out.print("Decoder got Comment: ");
System.out.println("id: "+c.id);
System.out.println("comment: "+c.comment);
}
//public void handle_Typedef(Typedef t) throws java.io.IOException {
// System.out.print("Decoder got Typedef: ");
// t.dump();
//}
public static void main(String[] arg) throws Exception {
Decoder example = new Decoder(
......
......@@ -2,21 +2,35 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import se.lth.control.labcomm.Encoder;
import se.lth.control.labcomm.EncoderChannel;
/**
* Simple encoder
*/
public class Encoder
public class ExampleEncoder
{
EncoderChannel encoder;
public Encoder(OutputStream out)
public ExampleEncoder(OutputStream out)
throws Exception
{
encoder = new EncoderChannel(out);
twoLines.register(encoder);
theint.register(encoder);
Encoder.PragmaPacketBuilder t = encoder.newPragma("se.lth.cs.sven.pragma");
Comment.register(t);
Comment c = new Comment();
//c.id = encoder.getTypeId(twoLines.class);
c.id = 42;
c.comment = "Test comment";
Comment.encode(t,c);
t.send();
t = encoder.newPragma(null);
afoo.register(t);
afoo.encode(t, new foo());
t.send();
}
public void doEncode() throws java.io.IOException {
......@@ -74,12 +88,14 @@ public class Encoder
System.out.println("Encoding theTwoLines");
twoLines.encode(encoder, x);
theint.encode(encoder, 1337);
}
public static void main(String[] arg) throws Exception {
FileOutputStream fos = new FileOutputStream(arg[0]);
Encoder example = new Encoder(fos);
ExampleEncoder example = new ExampleEncoder(fos);
example.doEncode();
fos.close();
}
......
all:
LCDIR=../..
LCCJAR=${LCDIR}/compiler/labcomm_compiler.jar # the LabComm compiler
LCLJAR=${LCDIR}/lib/java/labcomm.jar # the LabComm library
EXECUTABLES=example_encoder example_decoder ExampleEncoder.class Decoder.class Encoder.exe Decoder.exe
include ${LCDIR}/lib/c/os_compat.mk
GENDIR=gen
.PHONY: all cleanbuild clean distclean build run allall buildcs runwcs
all: cleanbuild run
allall: clean build buildcs runwcs
###############################################
### dependencies and parts ####################
###############################################
LCC=java -jar ${LCCJAR}
CLASSPATH=.:${LCLJAR}
${LCCJAR} :
$MAKE -C ${LCDIR} make-compiler
${LCLJAR} :
$MAKE -C ${LCDIR} labcomm.jar
cleanbuild: clean build
labcomm.dll:
ln -sf ../../lib/csharp/labcomm.dll $@
Encoder.exe: Encoder.cs gen/test.cs labcomm.dll Makefile
mcs -out:$@ $(filter %.cs, $^) -lib:../../lib/csharp/ -r:labcomm
chmod a+x $@
Decoder.exe: Decoder.cs gen/test.cs labcomm.dll Makefile
mcs -out:$@ $(filter %.cs, $^) -lib:../../lib/csharp/ -r:labcomm
chmod a+x $@
build :
mkdir -p ${GENDIR}
java -jar ${LCDIR}/compiler/labcomm_compiler.jar --java=${GENDIR} --c=${GENDIR}/test.c --h=${GENDIR}/test.h --python=${GENDIR}/test.py --cs=${GENDIR}/test.cs test.lc
javac -cp ${LCDIR}/lib/java/labcomm.jar:. ${GENDIR}/*.java ExampleEncoder.java Decoder.java
${CC} ${CFLAGS} ${LDFLAGS} -Wall -Werror -Wno-unused-function \
-I. -I${LCDIR}/lib/c -L${LCDIR}/lib/c \
-o example_encoder example_encoder.c ${GENDIR}/test.c \
-llabcomm20141009
${CC} ${CFLAGS} ${LDFLAGS} -Wall -Werror -I . -I ${LCDIR}/lib/c -L${LCDIR}/lib/c \
-o example_decoder example_decoder.c ${GENDIR}/test.c \
-llabcomm20141009
buildcs: Encoder.exe Decoder.exe
run:
export LD_LIBRARY_PATH=${LCDIR}/lib/c/
@echo
@echo "********************************************"
@echo "*** ************ running example for version 2014 ***"
@echo "********************************************"
@echo
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} ExampleEncoder encoded_data_j
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_j
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_j
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_j LabComm20141009
@echo "************ running C encoder: *****************"
@./example_encoder encoded_data_c
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_c
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_c
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm20141009
# @echo "************ running python encoder: *****************"
# @PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm20141009
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_p
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_p
@echo "************ running python decoder (from wiki_example):"
PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm20141009
runwcs: Encoder.exe Decoder.exe
export LD_LIBRARY_PATH=${LCDIR}/lib/c/
@echo
@echo "********************************************"
@echo "*** ************ running example for version 2014 ***"
@echo "********************************************"
@echo
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} ExampleEncoder encoded_data_j
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_j
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_j
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_j LabComm2014
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_j
@echo "************ running C encoder: *****************"
@./example_encoder encoded_data_c
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_c
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_c
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm20141009
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_c
# @echo "************ running python encoder: *****************"
# @PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm20141009
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_p
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_p
@echo "************ running python decoder (from wiki_example):"
PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm20141009
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_p
@echo "************ running C# encoder: *****************"
@./Encoder.exe encoded_data_cs
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_cs
@echo "************ running C decoder: *****************"
@./example_decoder encoded_data_cs
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_cs LabComm20141009
@echo "************ running C# decoder: *****************"
@./Decoder.exe encoded_data_cs
clean:
rm -rf ${GENDIR}
distclean:
rm -rf gen
rm -f encoded_data
distclean: clean
rm -f ${EXECUTABLES}
### Example compile script, showing the steps required to build a labcomm application
### (including compiler and libs).
# For current version (2013)
(cd ../..; make all)
mkdir -p gen
java -jar ../../compiler/labComm.jar --java=gen --c=gen/test.c --h=gen/test.h --python=gen/test.py test.lc
javac -cp ../../lib/java/labcomm20141009.jar:. gen/*.java Encoder.java Decoder.java
# for macOS, add -DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
gcc -Wall -Werror -Wno-unused-function \
-I. -I../../lib/c -L../../lib/c \
-o example_encoder example_encoder.c gen/test.c \
-llabcomm20141009
gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
-o example_decoder example_decoder.c gen/test.c \
-llabcomm20141009
#-Tlabcomm.linkscript
......@@ -15,6 +15,14 @@ static void handle_test_twoLines(test_twoLines *v,void *context) {
v->l2.end.x.val, v->l2.end.y.val);
}
static void handle_test_theint(test_theint *v,void *context) {
printf("Got theint. %d\n", *v);
}
static void handle_test_Comment(test_Comment *v,void *context) {
printf("Got comment (0x%x): %s\n", v->id, v->comment);
}
int main(int argc, char *argv[]) {
int fd;
struct labcomm_decoder *decoder;
......@@ -34,6 +42,8 @@ int main(int argc, char *argv[]) {
}
labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context);
labcomm_decoder_register_test_theint(decoder, handle_test_theint, context);
labcomm_decoder_register_test_Comment(decoder, handle_test_Comment, context);
printf("Decoding:\n");
labcomm_decoder_run(decoder);
......
......@@ -8,6 +8,7 @@
#include "gen/test.h"
#include <stdio.h>
extern struct labcomm_signature labcomm_signature_test_twoLines;
int main(int argc, char *argv[]) {
int fd;
struct labcomm_encoder *encoder;
......@@ -22,6 +23,16 @@ int main(int argc, char *argv[]) {
labcomm_default_scheduler);
labcomm_encoder_register_test_twoLines(encoder);
#ifndef WITHOUT_PRAGMA
struct labcomm_encoder *pb = labcomm_pragma_builder_new(encoder,
"se.lth.cs.sven.pragma");
labcomm_encoder_register_test_Comment(pb);
test_Comment comment;
comment.id = 17;
comment.comment = "This is a metadata comment...";
labcomm_encode_test_Comment(pb, &comment);
labcomm_pragma_send(pb);
#endif
test_twoLines tl;
tl.l1.start.x.val = 11;
......
export LD_LIBRARY_PATH=../../lib/c/
echo
echo "********************************************"
echo "*** Running example for version 2013 ***"
echo "********************************************"
echo
java -cp .:../../lib/java/labcomm20141009.jar:gen Encoder encoded_data
echo "running Java decoder:"
java -cp .:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data
echo "running C decoder:"
./example_decoder encoded_data
echo "running python decoder (from wiki_example):"
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm20141009
echo "running C encoder:"
./example_encoder encoded_data
echo "running Java decoder:"
java -cp .:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data
echo "running C decoder:"
./example_decoder encoded_data
echo "running python decoder (from wiki_example):"
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm20141009
echo "running python encoder:"
PYTHONPATH=../../lib/python:gen ./example_encoder.py encoded_data2
echo "running Java decoder:"
java -cp .:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data2
echo "running C decoder:"
./example_decoder encoded_data2
......@@ -12,14 +12,34 @@ typedef struct {
point end;
} line;
typedef int anint;
typedef struct {
int a;
int b;
anint a;
anint b;
boolean c;
} foo;
sample anint theint;
sample struct {
line l1;
line l2;
foo f;
} twoLines;
sample line fixedLineArray[2];
sample line varLineArray[_];
sample struct {
int x;
int y;
} structArray[2];
sample struct {
int id;
string comment;
} Comment; // For use in metadata
sample foo afoo; // to test unregistered metadata
## Macros
UNAME_S=$(shell uname -s)
ALL_DEPS=liblabcomm.a liblabcomm.so.1 liblabcomm2006.a liblabcomm2006.so.1 liblabcomm20141009.a liblabcomm20141009.so.1
include os_compat.mk
ifeq ($(UNAME_S),Linux)
CFLAGS=-std=c99 -g -Wall -Werror -O3 -I. -Itest -I2006
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
LDFLAGS=-L.
LDLIBS=-llabcomm -llabcomm2006 -lrt
MAKESHARED=gcc -o $1 -shared -Wl,-soname,$2 $3 -lc -lrt
else ifeq ($(UNAME_S),Darwin)
CC=$(CROSS_COMPILE)clang
LD=$(CROSS_COMPILE)ld
CFLAGS=-g -Wall -Werror -O3 -I. -Itest \
-DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
-Wno-tautological-compare -Wno-unused-function
LDFLAGS=-L.
LDLIBS=-llabcomm -llabcomm2006
MAKESHARED=clang -o $1 -shared -Wl,-install_name,$2 $3 -lc
else ifneq ($(findstring CYGWIN,$(UNAME_S)),)
CFLAGS=-std=c99 -g -Wall -Werror -O3 -I. -Itest
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
LDFLAGS=-L.
LDLIBS=-llabcomm -lrt
ALL_DEPS:=$(filter-out %.so.1, $(ALL_DEPS)) # No -fPIC supported in windows?
else
$(error Unknown system $(UNAME_S))
endif
ALL_DEPS=liblabcomm.a liblabcomm.so.1 liblabcomm2006.a liblabcomm2006.so.1 liblabcomm20141009.a liblabcomm20141009.so.1
ifeq ($(CROSS_COMPILE),i586-wrs-vxworks-)
ALL_DEPS:=$(filter-out %.so.1, $(ALL_DEPS)) # PIC is only supported for RTPs
CFLAGS:=$(CFLAGS) -DLABCOMM_COMPAT=\"labcomm_compat_vxworks.h\"
endif
# TODO: Support for Codesourcery ARM toolchain.
OBJS2006=2006/labcomm2006_memory.o \
......@@ -57,10 +27,11 @@ OBJS=labcomm_memory.o \
labcomm.o \
labcomm_dynamic_buffer_writer.o \
labcomm_fd_reader.o labcomm_fd_writer.o \
labcomm_bytearray_reader.o \
labcomm_pthread_scheduler.o
#FIXME: labcomm_mem_reader.o labcomm_mem_writer.o
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM_JAR=../../compiler/labcomm_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
......
......@@ -117,7 +117,7 @@ void labcomm_decoder_free(
struct labcomm_decoder *decoder);
int labcomm_decoder_decode_one(
struct labcomm_decoder *decoder);
void labcomm_decoder_run(
int labcomm_decoder_run(
struct labcomm_decoder *decoder);
/* See labcomm_ioctl.h for predefined ioctl_action values */
......@@ -125,6 +125,25 @@ int labcomm_decoder_ioctl(struct labcomm_decoder *decoder,
uint32_t ioctl_action,
...);
/* pragma */
struct labcomm_encoder *labcomm_pragma_builder_new(
struct labcomm_encoder *e,
char * pragma_type) ;
int labcomm_pragma_send(struct labcomm_encoder* e);
struct labcomm_pragma_handler {
//struct labcomm_decoder_registry *registry;
//TODO: implement map (char * pragma_type) --> decoder_registry *
//to allow having different sets of handlers for different pragma types
int foo;
};
typedef int (*labcomm_pragma_handler_callback)(
struct labcomm_decoder *decoder,
char *pragma_type);
void labcomm_decoder_register_pragma_handler(struct labcomm_decoder *d,
labcomm_pragma_handler_callback pragma_dispatcher);
/*
* Encoder
*/
......
/*
labcomm_bytearray_reader.c -- a reader for data in a byte array
Copyright 2014 Sen Gestegård Robertz <sven.robertz@cs.lth.se>
This file is part of LabComm.
LabComm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LabComm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "labcomm_private.h"
#include "labcomm_bytearray_reader.h"
struct labcomm_bytearray_reader {
struct labcomm_reader reader;
struct labcomm_reader_action_context action_context;
unsigned char *bytearray;
int bytearray_size;
};
#if 0
// XXX HERE BE DRAGONS: version removed?
static int bytearray_alloc(struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context,
char *version)
#else
static int bytearray_alloc(struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context)
#endif
{
int result = 0;
r->data = ((struct labcomm_bytearray_reader *)action_context->context)->bytearray;
r->count =((struct labcomm_bytearray_reader *)action_context->context)->bytearray_size;
r->pos = 0;
return result;
}
static int bytearray_free(struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context)
{
struct labcomm_bytearray_reader *bytearray_reader = action_context->context;
struct labcomm_memory *memory = r->memory;
//HERE BE DRAGONS labcomm_memory_free(memory, 0, r->data);
r->data = 0;
r->data_size = 0;
r->count = 0;
r->pos = 0;
labcomm_memory_free(memory, 0, bytearray_reader);
return 0;
}
static int bytearray_fill(struct labcomm_reader *r,
struct labcomm_reader_action_context *action_context)
{
int result = 0;
if (r->pos < r->count) {
//printf("BAreader.fill: pos %d count: %d\n", r->pos, r->count);
result = r->count - r->pos;
} else {
r->pos = 0;
r->error = -EPIPE;
result = -EPIPE;
}
return result;
}
static const struct labcomm_reader_action action = {
.alloc = bytearray_alloc,
.free = bytearray_free,
.start = NULL,
.fill = bytearray_fill,
.end = NULL,
.ioctl = NULL
};
struct labcomm_reader *labcomm_bytearray_reader_new(struct labcomm_memory *memory,
unsigned char *data, int size)
{
struct labcomm_bytearray_reader *result;
result = labcomm_memory_alloc(memory, 0, sizeof(*result));
if (result == NULL) {
return NULL;
} else {
result->action_context.next = NULL;
result->action_context.action = &action;
result->action_context.context = result;
result->reader.action_context = &result->action_context;
result->reader.memory = memory;
result->bytearray = data;
result->bytearray_size = size;
struct labcomm_reader * res = &result->reader;
// printf("reader: %p, size: %d\n", res, res->data_size);
return res;
}
}
/*
labcomm_bytearray_reader.h -- a reader for data in a byte array
Copyright 2014 Sen Gestegård Robertz <sven.robertz@cs.lth.se>
This file is part of LabComm.
LabComm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LabComm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LABCOMM_BYTEARRAY_READER_H_
#define _LABCOMM_BYTEARRAY_READER_H_
#include "labcomm.h"
struct labcomm_reader *labcomm_bytearray_reader_new(struct labcomm_memory *memory,
unsigned char *data, int size);
#endif