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
  • anders.blomdell
  • compiler-refactoring
  • labcomm2006
  • labcomm2013
  • labcomm2014
  • master
  • pragma
  • python_sig_hash
  • typedefs
  • typeref
  • v2006.0
  • v2013.0
  • v2014.0
  • v2014.1
  • v2014.2
  • v2014.3
  • v2014.4
  • v2014.5
  • v2014.6
  • v2015.0
20 results

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Select Git revision
  • anders.blomdell
  • compiler-refactoring
  • labcomm2013
  • master
  • pragma
  • typeref
  • v2013.0
  • v2014.0
  • v2014.1
9 results
Show changes
Showing
with 207 additions and 1138 deletions
LCDIR=../..
LABCOMM_JAR=../../compiler/labcomm_compiler.jar
LABCOMM_JAR=../../compiler/labcomm2014_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
LCLJAR=${LCDIR}/lib/java/labcomm.jar # the LabComm library
LCLJAR=${LCDIR}/lib/java/labcomm2014.jar # the LabComm library
JAVA_PKG=labcommTCPtest
.PHONY : clean run runserver runOSserver runclient
......@@ -21,7 +21,7 @@ ${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}
${LABCOMM} --javapackage=${JAVA_PKG}.gen --java=${JAVA_PKG}/gen $<
......
UNAME_S=$(shell uname -s)
TARGETS=client server
LABCOMM_JAR=../../compiler/labcomm_compiler.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
ifeq ($(UNAME_S),Darwin)
CFLAGS+=-DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" -DLABCOMM_OS_DARWIN=1 -Wno-tautological-compare
CFLAGS+=-DLABCOMM_COMPAT=\"labcomm2014_compat_osx.h\" -DLABCOMM_OS_DARWIN=1
else
CFLAGS+=-Wno-tautological-compare
endif
all: $(TARGETS:%=gen/%)
......
......@@ -6,6 +6,7 @@ import java.io.IOException;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.TypeDef;
import se.lth.control.labcomm2014.TypeDefParser;
import se.lth.control.labcomm2014.SigTypeDef;
//import se.lth.control.labcomm2014.TypeBinding;
public class Decoder
......@@ -65,10 +66,14 @@ public class Decoder
// System.out.println("Got TypeBinding: "+d.getSampleIndex()+" --> "+d.getTypeIndex()+"");
// }
public void onTypeDef(TypeDefParser.ParsedTypeDef d) {
public void onTypeDef(SigTypeDef d) {
System.out.println("ontype_def: ");
if(d != null) {
System.out.print((d.isSampleDef()?"sample ":"typedef ")+d);
System.out.println(" "+d.getName()+";");
} else {
System.out.println(" null???");
}
//for(byte b: d.getSignature()) {
// System.out.print(Integer.toHexString(b)+" ");
//}
......
......@@ -4,6 +4,7 @@ LCLJAR=${LCDIR}/lib/java/labcomm2014.jar# the LabComm library
EXECUTABLES=example_encoder example_decoder \
Encoder.class Decoder.class TDDecoder.class \
TestDataType.class \
ExampleEncoder.exe ExampleDecoder.exe
include ${LCDIR}/lib/c/os_compat.mk
......@@ -47,10 +48,11 @@ ExampleDecoder.exe: ExampleDecoder.cs gen/test.cs labcomm2014.dll Makefile
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
java -jar ${LCDIR}/compiler/labcomm2014_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/labcomm2014.jar:. ${GENDIR}/*.java Encoder.java Decoder.java
javac -cp ${LCDIR}/lib/java/labcomm2014.jar:${LCCJAR}:${GENDIR}:. TDDecoder.java
javac -cp ${LCDIR}/lib/java/labcomm2014.jar:${LCCJAR}:${GENDIR}:. TestDataType.java
${CC} ${CFLAGS} ${LDFLAGS} -Wall -Werror -Wno-unused-function \
-I. -I${LCDIR}/lib/c/2014 -L${LCDIR}/lib/c \
......@@ -76,23 +78,29 @@ run:
@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_j
@echo "************ running C decoder: *****************"
@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_j
@${LD_LIBRARY_PATH_NAME}=${LCDIR}/lib/c/ ./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 python decoder (with handlers):"
@PYTHONPATH=${LCDIR}/lib/python:gen:. ./example_handlers.py encoded_data_j LabComm2014
@echo "************ running C encoder: *****************"
@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_encoder encoded_data_c
@${LD_LIBRARY_PATH_NAME}=${LCDIR}/lib/c/ ./example_encoder encoded_data_c
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_c
@echo "************ running C decoder: *****************"
@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_c
@${LD_LIBRARY_PATH_NAME}=${LCDIR}/lib/c/ ./example_decoder encoded_data_c
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm2014
@echo "************ running python decoder (with handlers):"
@PYTHONPATH=${LCDIR}/lib/python:gen:. ./example_handlers.py encoded_data_j LabComm2014
@echo "************ running python encoder: *****************"
@PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm2014
......@@ -100,11 +108,15 @@ run:
@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_p
@echo "************ running C decoder: *****************"
@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_p
@${LD_LIBRARY_PATH_NAME}=${LCDIR}/lib/c/ ./example_decoder encoded_data_p
@echo "************ running python decoder (from wiki_example):"
PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm2014
@echo "************ running python decoder (with handlers):"
@PYTHONPATH=${LCDIR}/lib/python:gen:. ./example_handlers.py encoded_data_j LabComm2014
runwcs: build ExampleEncoder.exe ExampleDecoder.exe
@echo
@echo "********************************************"
......@@ -118,22 +130,22 @@ runwcs: build ExampleEncoder.exe ExampleDecoder.exe
@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_j
@echo "************ running C decoder: *****************"
@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_j
@${LD_LIBRARY_PATH_NAME}=${LCDIR}/lib/c/ ./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: *****************"
@LD_LIBRARY_PATH=${LCDIR}/lib/c/ mono ./ExampleDecoder.exe encoded_data_j
@${LD_LIBRARY_PATH_NAME}=${LCDIR}/lib/c/ mono ./ExampleDecoder.exe encoded_data_j
@echo "************ running C encoder: *****************"
@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_encoder encoded_data_c
@${LD_LIBRARY_PATH_NAME}=${LCDIR}/lib/c/ ./example_encoder encoded_data_c
@echo "************ running Java decoder: *****************"
@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_c
@echo "************ running C decoder: *****************"
@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_c
@${LD_LIBRARY_PATH_NAME}=${LCDIR}/lib/c/ ./example_decoder encoded_data_c
@echo "************ running python decoder (from wiki_example):"
@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm2014
......@@ -148,14 +160,14 @@ runwcs: build ExampleEncoder.exe ExampleDecoder.exe
@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_p
@echo "************ running C decoder: *****************"
@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_p
@echo "************ running python decoder (from wiki_example):"
PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm2014
@${LD_LIBRARY_PATH_NAME}=${LCDIR}/lib/c/ ./example_decoder encoded_data_p
@echo "************ running C# decoder: *****************"
@mono ./ExampleDecoder.exe encoded_data_p
@echo "************ running python decoder (from wiki_example):"
PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm2014
@echo "************ running C# encoder: *****************"
@mono ./ExampleEncoder.exe encoded_data_cs
......@@ -183,6 +195,15 @@ runjastadd: cleanbuild
@echo "************ running Java TypeDefdecoder: *****************"
java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${LCCJAR}:${GENDIR} TDDecoder encoded_data_j
rundatatype: cleanbuild
@echo
@echo "********************************************"
@echo "*************** running datatype example ***"
@echo "********************************************"
@echo
@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} TestDataType
clean:
rm -rf ${GENDIR}
......
......@@ -6,10 +6,13 @@ import java.io.IOException;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.TypeDef;
import se.lth.control.labcomm2014.TypeDefParser;
import se.lth.control.labcomm2014.SigTypeDef;
import se.lth.control.labcomm2014.ParsedSampleDef;
import se.lth.control.labcomm2014.ASTbuilder;
//import se.lth.control.labcomm2014.TypeBinding;
import se.lth.control.labcomm2014.DataType;
import se.lth.control.labcomm2014.compiler.Program;
import se.lth.control.labcomm2014.compiler.Specification;
import java.io.FileOutputStream;
import java.io.PrintStream;
......@@ -75,18 +78,29 @@ public class TDDecoder
// System.out.println("Got TypeBinding: "+d.getSampleIndex()+" --> "+d.getTypeIndex()+"");
// }
public void onTypeDef(TypeDefParser.ParsedTypeDef d) {
if(d.isSampleDef()){
public void onTypeDef(SigTypeDef d) {
if(d != null && d.isSampleDef()){
System.out.println("onTypeDef (sample): ");
//------------
try {
System.out.println("==================== DataType ======");
DataType.printDataType(System.out, d);
System.out.println();
System.out.println("==================== end ======");
} catch (IOException ioe) {
ioe.printStackTrace();
}
ASTbuilder v = new ASTbuilder();
Program p = v.makeProgram((TypeDefParser.ParsedSampleDef) d);
Specification p = v.makeSpecification((ParsedSampleDef) d);
try {
//FileOutputStream f = new FileOutputStream("/tmp/foopp"+d.getName()+".txt");
//PrintStream out = new PrintStream(f);
FileOutputStream f = new FileOutputStream("/tmp/foopp"+d.getName()+".txt");
PrintStream out = new PrintStream(f);
p.pp(System.out);
//p.C_genC(System.out, new Vector(), "lcname", "prefix", 2014);
//p.J_gen(out, "testpackage", 2014);
//out.close();
p.J_gen(out, "testpackage", 2014);
out.close();
} catch (Throwable e) {
System.err.println("Exception: " + e);
e.printStackTrace();
......
import java.io.PrintStream;
import se.lth.control.labcomm2014.*;
/**
* Test data type tree
*/
public class TestDataType
{
private PrintStream out;
public TestDataType(PrintStream out)
throws Exception
{
this.out = out;
}
public void doTest() throws java.io.IOException {
twoLines x = new twoLines();
DataType.printDataType(out, x.getDispatcher());
twoStructsAndInt y = new twoStructsAndInt();
DataType.printDataType(out, y.getDispatcher());
theFirstInt z = new theFirstInt();
DataType.printDataType(out, z.getDispatcher());
doavoid a = new doavoid();
DataType.printDataType(out, a.getDispatcher());
}
public static void main(String[] arg) throws Exception {
TestDataType example = new TestDataType(System.out);
example.doTest();
}
}
......@@ -13,7 +13,7 @@ static void handle_test_doavoid(test_doavoid *v,void *context) {
}
static void handle_test_intAndRef(test_intAndRef *v,void *context) {
printf("Got intAndRef. (%d : %s) \n", v->x, v->reference->name);
printf("Got intAndRef. (%d : %p) \n", v->x, v->reference);
}
static void handle_test_twoInts(test_twoInts *v,void *context) {
......
......@@ -8,31 +8,31 @@ 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(test.twoLines.signature)
tl = dict(
l1=dict(
start=dict(
x=dict(val=1),
y=dict(val=11)
),
end=dict(
x=dict(val=2),
y=dict(val=22)
)
),
l2=dict(
start=dict(
x=dict(val=3),
y=dict(val=33)
),
end=dict(
x=dict(val=4),
y=dict(val=44)
)
),
f=dict(
a=10,
b=20,
c=False
)
)
tl = {
(('','l1'),):{
(('','start'),):{
(('','x'),):{(('','val'),):1},
(('','y'),):{(('','val'),):11}
},
(('','end'),):{
(('','x'),):{(('','val'),):2},
(('','y'),):{(('','val'),):22}
}
},
(('','l2'),):{
(('','start'),):{
(('','x'),):{(('','val'),):3},
(('','y'),):{(('','val'),):33}
},
(('','end'),):{
(('','x'),):{(('','val'),):4},
(('','y'),):{(('','val'),):44}
}
},
(('','f'),):{
(('','a'),):10,
(('','b'),):20,
(('','c'),):False
}
}
encoder.encode(tl, test.twoLines.signature)
#!/usr/bin/python
import labcomm2014
import sys,traceback
import test
def handle_twoInts(val):
print "got twoInts: %s" % val
def handle_twoLines(val):
print "got twoLines: %s" % val
if __name__ == "__main__":
version = sys.argv[2] if len(sys.argv) == 3 else "LabComm2014"
d = labcomm2014.Decoder(labcomm2014.StreamReader(open(sys.argv[1])), version)
d.register_handler(test.twoInts.signature, handle_twoInts)
d.register_handler(test.twoLines.signature, handle_twoLines)
while True:
try:
d.runOne()
except EOFError:
print "got EOF"
break
except Exception, e:
print "got Exception"
print e
traceback.print_exc()
break
typedef struct {
int val;
(foo:bar) int val;
} coord;
typedef int anInt;
typedef void avoid;
sample avoid doavoid;
sample (function:"a trigger")(foo:bar) avoid doavoid;
sample struct {
int x;
sample (a:b) "A struct: an int and a ref." struct {
(e:f)(c:d) int x;
sample reference;
} intAndRef;
......@@ -29,9 +29,9 @@ typedef struct {
} foo;
sample struct {
line l1;
line l2;
foo f;
(name:l1)line l1;
(name:l2)line l2;
(b:"kalle anka")(c:hejdu)(a:"kalle anka")foo f;
} twoLines;
sample struct {
......@@ -41,3 +41,19 @@ sample struct {
sample anInt theFirstInt;
sample anInt theSecondInt;
sample struct {
struct {
int x;
int y;
} s1;
struct {
int a;
int b;
} s2;
int i;
double double_array[2,3,_][3][_];
} twoStructsAndInt;
......@@ -16,9 +16,9 @@ gcc -Wall -Werror -o example_encoder -I../../lib/c/2014 \
example.c \
../../lib/c/liblabcomm2014.a || exit 1
javac -cp ../../lib/java/labcomm.jar:. *.java || exit 1
javac -cp ../../lib/java/labcomm2014.jar:. *.java || exit 1
# Run through all executables (c->java->Python)
./example_encoder one two || exit 1
java -cp ../../lib/java/labcomm.jar:. example_decoder_encoder example.encoded example.javaencoded || exit 1
java -cp ../../lib/java/labcomm2014.jar:. example_decoder_encoder example.encoded example.javaencoded || exit 1
PYTHONPATH=../../lib/python ./example_decoder.py example.javaencoded || exit 1
## Macros
VERSION=2006
LIBVERSION=2006
include ../os_compat.mk
ALL_DEPS=../liblabcomm$(LIBVERSION).a ../liblabcomm$(LIBVERSION).so
# TODO: Support for Codesourcery ARM toolchain.
OBJS=labcomm$(VERSION).o \
labcomm$(VERSION)_memory.o \
labcomm$(VERSION)_error.o \
labcomm$(VERSION)_default_error_handler.o \
labcomm$(VERSION)_default_memory.o \
labcomm$(VERSION)_default_scheduler.o \
labcomm$(VERSION)_time.o \
labcomm$(VERSION)_scheduler.o \
labcomm$(VERSION)_encoder.o \
labcomm$(VERSION)_decoder.o \
labcomm$(VERSION)_dynamic_buffer_writer.o \
labcomm$(VERSION)_fd_reader.o \
labcomm$(VERSION)_fd_writer.o \
labcomm$(VERSION)_pthread_scheduler.o
LABCOMM_JAR=../../../compiler/labcomm$(LIBVERSION)_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
TESTS=test_labcomm_basic_type_encoding \
test_labcomm_generated_encoding \
test_signature_numbers \
test_labcomm \
test_labcomm_pthread_scheduler \
test_labcomm_copy
#FIXME: test_labcomm_errors
TEST_DIR=test
## Targets
.PHONY: all
all: $(ALL_DEPS)
.PHONY: test
test: all $(TESTS:%=run-test-%)
.PHONY: clean
clean:
$(RM) *.o
$(RM) experimental/*.o
$(RM) experimental/ThrottleDrv/*.o
$(RM) test/*.o
$(RM) test/*.gch
$(RM) test/test_labcomm_errors
$(RM) test/testdata/gen/*.[cho]
$(RM) test/gen/*.[cho]
$(RM) -rf test/gen
.PHONY: distclean
distclean: clean
$(RM) ../liblabcomm$(LIBVERSION).so.1
$(RM) ../liblabcomm$(LIBVERSION).a
# rules invoked by 'all'
../liblabcomm$(LIBVERSION).so: ../liblabcomm$(LIBVERSION).so.1
if [ -h $@ ] ; then rm $@ ; fi
ln -s $(<:../%=%) $@
../liblabcomm$(LIBVERSION).so.1: $(OBJS:%.o=%.pic.o)
$(call MAKESHARED,$@,$(@:../%=%),$^)
../liblabcomm$(LIBVERSION).a: $(OBJS)
ar -r $@ $^
# compilation rules
%.pic.o: %.c
$(CC) -fPIC $(CFLAGS) -c -o $@ $<
%.o: %.c %.h
$(CC) $(CFLAGS) -c -o $@ $<
# rules invoked by 'test'
.PHONY: run-test-%
run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen
$<
.PRECIOUS: $(TEST_DIR)/gen/%
$(TEST_DIR)/gen/%: $(TEST_DIR)/gen/%.o | $(TEST_DIR)/gen
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(TEST_DIR)/gen/%.o: $(TEST_DIR)/%.c | $(TEST_DIR)/gen
$(CC) $(CFLAGS_TEST) -o $@ -c $<
.PRECIOUS: $(TEST_DIR)/gen/%.c
.PRECIOUS: $(TEST_DIR)/gen/%.h
$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
$(LABCOMM) \
--ver=$(VERSION) \
--c=$(TEST_DIR)/gen/$*.c \
--h=$(TEST_DIR)/gen/$*.h \
$<
$(LABCOMM_JAR):
@echo "======Building LabComm compiler======"
cd $(shell dirname $(LABCOMM_JAR)); ant jar
@echo "======End building LabComm compiler======"
$(TEST_DIR)/gen:
mkdir -p $@
# Extra compilation dependencies
labcomm$(VERSION).o: \
labcomm$(VERSION).c \
labcomm$(VERSION).h \
labcomm$(VERSION)_private.h
labcomm$(VERSION)_fd_reader.o: \
labcomm$(VERSION)_private.h
labcomm$(VERSION)_fd_writer.o: \
labcomm$(VERSION)_private.h
labcomm$(VERSION)_dynamic_buffer_writer.o: \
labcomm$(VERSION)_private.h
$(TEST_DIR)/gen/test_labcomm_basic_type_encoding.o: \
labcomm$(VERSION)_private.h
$(TEST_DIR)/gen/test_labcomm_generated_encoding.o: \
labcomm$(VERSION)_private.h \
$(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/gen/test_labcomm_generated_encoding: \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_signature_numbers.c: \
$(TEST_DIR)/gen/another_encoding.h \
$(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/gen/test_signature_numbers: \
$(TEST_DIR)/gen/another_encoding.o \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_labcomm: \
$(TEST_DIR)/gen/test_sample.o
$(TEST_DIR)/gen/test_labcomm_copy: \
$(TEST_DIR)/gen/generated_encoding.o \
$(TEST_DIR)/gen/test_sample.o \
$(TEST_DIR)/gen/more_types.o
/*
labcomm.c -- runtime for handling encoding and decoding of
labcomm samples.
Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.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/>.
*/
#ifdef LABCOMM_COMPAT
#include LABCOMM_COMPAT
#else
#include <stdio.h>
#include <strings.h>
#endif
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include "labcomm2006.h"
#include "labcomm2006_private.h"
#include "labcomm2006_ioctl.h"
#include "labcomm2006_dynamic_buffer_writer.h"
/* Unwrapping reader/writer functions */
#define UNWRAP_ac(rw, ac, ...) ac
#define UNWRAP(func, ...) \
while (1) { \
if (UNWRAP_ac(__VA_ARGS__)->action->func) { \
return UNWRAP_ac(__VA_ARGS__)->action->func(__VA_ARGS__); } \
if (UNWRAP_ac(__VA_ARGS__)->next == NULL) { return -ENOSYS; } \
UNWRAP_ac( __VA_ARGS__) = UNWRAP_ac(__VA_ARGS__)->next; \
}
int labcomm2006_reader_alloc(struct labcomm2006_reader *r,
struct labcomm2006_reader_action_context *action_context)
{
UNWRAP(alloc, r, action_context);
}
int labcomm2006_reader_free(struct labcomm2006_reader *r,
struct labcomm2006_reader_action_context *action_context)
{
UNWRAP(free, r, action_context);
}
int labcomm2006_reader_start(struct labcomm2006_reader *r,
struct labcomm2006_reader_action_context *action_context,
int local_index, int remote_index,
const struct labcomm2006_signature *signature,
void *value)
{
UNWRAP(start, r, action_context, local_index, remote_index, signature, value);
}
int labcomm2006_reader_end(struct labcomm2006_reader *r,
struct labcomm2006_reader_action_context *action_context)
{
UNWRAP(end, r, action_context);
}
int labcomm2006_reader_fill(struct labcomm2006_reader *r,
struct labcomm2006_reader_action_context *action_context)
{
UNWRAP(fill, r, action_context);
}
int labcomm2006_reader_ioctl(struct labcomm2006_reader *r,
struct labcomm2006_reader_action_context *action_context,
int local_index, int remote_index,
const struct labcomm2006_signature *signature,
uint32_t ioctl_action, va_list args)
{
UNWRAP(ioctl, r, action_context,
local_index, remote_index, signature, ioctl_action, args);
}
int labcomm2006_writer_alloc(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context)
{
UNWRAP(alloc, w, action_context);
}
int labcomm2006_writer_free(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context)
{
UNWRAP(free, w, action_context);
}
int labcomm2006_writer_start(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context,
int index, const struct labcomm2006_signature *signature,
void *value)
{
UNWRAP(start, w, action_context, index, signature, value);
}
int labcomm2006_writer_end(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context)
{
UNWRAP(end, w, action_context);
}
int labcomm2006_writer_flush(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context)
{
UNWRAP(flush, w, action_context);
}
int labcomm2006_writer_ioctl(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context,
int index,
const struct labcomm2006_signature *signature,
uint32_t ioctl_action, va_list args)
{
UNWRAP(ioctl, w, action_context, index, signature, ioctl_action, args);
}
#undef UNWRAP
#undef UNWRAP_ac
static const char *labcomm2006_error_string[] = {
#define LABCOMM2006_ERROR(name, description) description ,
#include "labcomm2006_error.h"
#undef LABCOMM2006_ERROR
};
static const int labcomm2006_error_string_count = (sizeof(labcomm2006_error_string) /
sizeof(labcomm2006_error_string[0]));
const char *labcomm2006_error_get_str(enum labcomm2006_error error_id)
{
const char *error_str = NULL;
// Check if this is a known error ID.
if (error_id < labcomm2006_error_string_count) {
error_str = labcomm2006_error_string[error_id];
}
return error_str;
}
#ifndef LABCOMM_NO_STDIO
void labcomm2006_on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...)
{
const char *err_msg = labcomm2006_error_get_str(error_id); // The final string to print.
if (err_msg == NULL) {
err_msg = "Error with an unknown error ID occured.";
}
fprintf(stderr, "%s\n", err_msg);
if (nbr_va_args > 0) {
va_list arg_pointer;
va_start(arg_pointer, nbr_va_args);
fprintf(stderr, "%s\n", "Extra info {");
char *print_format = va_arg(arg_pointer, char *);
vfprintf(stderr, print_format, arg_pointer);
fprintf(stderr, "}\n");
va_end(arg_pointer);
}
}
#else
; // If labcomm can't be compiled with stdio the user will have to make an own error callback functionif he/she needs error reporting.
#error Define LABCOMM2006_ON_ERROR_FPRINTF
#endif
#if 0
static void dump(void *p, int size, int first, int last)
{
int i, j;
printf("%d %d (%p): ", first, last, p);
for (i = first ; i < last ; i++) {
for (j = 0 ; j < size ; j++) {
printf("%2.2d", ((char*)p)[(i-first)*size + j]);
}
printf(" ");
}
printf("\n");
}
#endif
void *labcomm2006_signature_array_ref(struct labcomm2006_memory *memory,
int *first, int *last, void **data,
int size, int index)
{
if (*first == 0 && *last == 0) {
*first = index;
*last = index + 1;
*data = labcomm2006_memory_alloc(memory, 0, size);
if (*data) {
memset(*data, 0, size);
}
} else if (index < *first || *last <= index) {
void *old_data = *data;
int old_first = *first;
int old_last = *last;
int n;
*first = (index<old_first)?index:old_first;
*last = (old_last<=index)?index+1:old_last;
n = (*last - *first);
*data = labcomm2006_memory_alloc(memory, 0, n * size);
if (*data) {
memset(*data, 0, n * size);
memcpy(*data + (old_first - *first) * size,
old_data,
(old_last - old_first) * size);
}
// dump(old_data, size, old_first, old_last);
labcomm2006_memory_free(memory, 0, old_data);
}
if (*data) {
// dump(*data, size, *first, *last);
return *data + (index - *first) * size;
} else {
return NULL;
}
}
static int local_index = LABCOMM_USER;
void labcomm2006_set_local_index(struct labcomm2006_signature *signature)
{
if (signature->index != 0) {
labcomm2006_error_fatal_global(LABCOMM2006_ERROR_SIGNATURE_ALREADY_SET,
"Signature already set: %s", signature->name);
}
signature->index = local_index;
local_index++;
}
int labcomm2006_get_local_index(const struct labcomm2006_signature *signature)
{
if (signature->index == 0) {
labcomm2006_error_fatal_global(LABCOMM2006_ERROR_SIGNATURE_NOT_SET,
"Signature not set: %s", signature->name);
}
return signature->index;
}
int labcomm2006_internal_sizeof(const struct labcomm2006_signature *signature,
void *v)
{
int length = signature->encoded_size(v);
return (labcomm2006_size_packed32(signature->index) +
length);
}
/*
labcomm2006.h -- user interface for handling encoding and decoding of
labcomm samples.
Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.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 __LABCOMM2006_H__
#define __LABCOMM2006_H__
#include <stdarg.h>
#ifdef LABCOMM_COMPAT
#include LABCOMM_COMPAT
#else
#include <stdint.h>
#include <unistd.h>
#endif
#include "labcomm2006_error.h"
#include "labcomm2006_scheduler.h"
/* Forward declaration */
struct labcomm2006_encoder;
struct labcomm2006_decoder;
/*
* Signature entry
*/
struct labcomm2006_signature {
char *name;
int (*encoded_size)(void *); /* void* refers to sample_data */
int size;
unsigned char *signature;
int index;
#ifdef LABCOMM_EXPERIMENTAL_CACHED_ENCODED_SIZE
int cached_encoded_size; // -1 if not initialized or type is variable size
#endif
};
/*
* Error handling.
*/
/* The callback prototype for error handling.
* First parameter is the error ID.
* The second paramters is the number of va_args that comes after this
* one. If none it should be 0.
* Optionaly other paramters can be supplied depending on what is needed
* for this error ID.
*/
typedef void (*labcomm2006_error_handler_callback)(enum labcomm2006_error error_id,
size_t nbr_va_args, ...);
/* Default error handler, prints message to stderr.
* Extra info about the error can be supplied as char* as VA-args. Especially user defined errors should supply a describing string. if nbr_va_args > 1 the first variable argument must be a printf format string and the possibly following arguments are passed as va_args to vprintf.
*/
void labcomm2006_on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...);
/* Register a callback for the error handler for this encoder. */
void labcomm2006_register_error_handler_encoder(struct labcomm2006_encoder *encoder, labcomm2006_error_handler_callback callback);
/* Register a callback for the error handler for this decoder. */
void labcomm2006_register_error_handler_decoder(struct labcomm2006_decoder *decoder, labcomm2006_error_handler_callback callback);
/* Get a string describing the supplied standrad labcomm error. */
const char *labcomm2006_error_get_str(enum labcomm2006_error error_id);
typedef int (*labcomm2006_handle_new_datatype_callback)(
struct labcomm2006_decoder *decoder,
struct labcomm2006_signature *sig);
void labcomm2006_decoder_register_new_datatype_handler(struct labcomm2006_decoder *d,
labcomm2006_handle_new_datatype_callback on_new_datatype);
/*
* Dynamic memory handling
* lifetime == 0 memory that will live for as long as the
* encoder/decoder or that are allocated/deallocated
* during the communication setup phase
* otherwise memory will live for approximately this number of
* sent/received samples
*/
struct labcomm2006_memory;
void *labcomm2006_memory_alloc(struct labcomm2006_memory *m, int lifetime, size_t size);
void *labcomm2006_memory_realloc(struct labcomm2006_memory *m, int lifetime,
void *ptr, size_t size);
void labcomm2006_memory_free(struct labcomm2006_memory *m, int lifetime, void *ptr);
/*
* Decoder
*/
struct labcomm2006_reader;
struct labcomm2006_decoder *labcomm2006_decoder_new(
struct labcomm2006_reader *reader,
struct labcomm2006_error_handler *error,
struct labcomm2006_memory *memory,
struct labcomm2006_scheduler *scheduler);
void labcomm2006_decoder_free(
struct labcomm2006_decoder *decoder);
int labcomm2006_decoder_decode_one(
struct labcomm2006_decoder *decoder);
void labcomm2006_decoder_run(
struct labcomm2006_decoder *decoder);
/* See labcomm2006_ioctl.h for predefined ioctl_action values */
int labcomm2006_decoder_ioctl(struct labcomm2006_decoder *decoder,
uint32_t ioctl_action,
...);
/*
* Encoder
*/
struct labcomm2006_writer;
struct labcomm2006_encoder *labcomm2006_encoder_new(
struct labcomm2006_writer *writer,
struct labcomm2006_error_handler *error,
struct labcomm2006_memory *memory,
struct labcomm2006_scheduler *scheduler);
void labcomm2006_encoder_free(
struct labcomm2006_encoder *encoder);
/* See labcomm2006_ioctl.h for predefined ioctl_action values */
int labcomm2006_encoder_ioctl(struct labcomm2006_encoder *encoder,
uint32_t ioctl_action,
...);
#define LABCOMM_VOID ((void*)1)
#endif
/*
labcomm2006_decoder.c -- runtime for handling decoding of labcomm samples.
Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.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 "labcomm2006.h"
#include "labcomm2006_private.h"
#include "labcomm2006_ioctl.h"
#include "labcomm2006_dynamic_buffer_writer.h"
struct sample_entry {
int remote_index;
const struct labcomm2006_signature *signature;
labcomm2006_decoder_function decode;
labcomm2006_handler_function handler;
void *context;
};
struct labcomm2006_decoder {
struct labcomm2006_reader *reader;
int reader_allocated;
struct labcomm2006_error_handler *error;
struct labcomm2006_memory *memory;
struct labcomm2006_scheduler *scheduler;
labcomm2006_error_handler_callback on_error;
labcomm2006_handle_new_datatype_callback on_new_datatype;
LABCOMM_SIGNATURE_ARRAY_DEF(local, struct sample_entry);
LABCOMM_SIGNATURE_ARRAY_DEF(remote_to_local, int);
};
struct labcomm2006_decoder *labcomm2006_decoder_new(
struct labcomm2006_reader *reader,
struct labcomm2006_error_handler *error,
struct labcomm2006_memory *memory,
struct labcomm2006_scheduler *scheduler)
{
struct labcomm2006_decoder *result;
result = labcomm2006_memory_alloc(memory, 0, sizeof(*result));
if (result) {
result->reader = reader;
result->reader->decoder = result;
result->reader->data = 0;
result->reader->data_size = 0;
result->reader->count = 0;
result->reader->pos = 0;
result->reader->error = 0;
result->reader_allocated = 0;
result->error = error;
result->memory = memory;
result->scheduler = scheduler;
LABCOMM_SIGNATURE_ARRAY_INIT(result->local, struct sample_entry);
LABCOMM_SIGNATURE_ARRAY_INIT(result->remote_to_local, int);
}
return result;
}
void labcomm2006_decoder_free(struct labcomm2006_decoder* d)
{
struct labcomm2006_memory *memory = d->memory;
labcomm2006_reader_free(d->reader, d->reader->action_context);
LABCOMM_SIGNATURE_ARRAY_FREE(memory, d->local, struct sample_entry);
LABCOMM_SIGNATURE_ARRAY_FREE(memory, d->remote_to_local, int);
labcomm2006_memory_free(memory, 0, d);
}
static int collect_flat_signature(
struct labcomm2006_decoder *decoder,
struct labcomm2006_writer *writer)
{
int result, type;
type = labcomm2006_read_packed32(decoder->reader);
result = decoder->reader->error;
if (result < 0) { goto out; }
if (type >= LABCOMM_USER) {
decoder->on_error(LABCOMM2006_ERROR_UNIMPLEMENTED_FUNC, 3,
"Implement %s ... (1) for type 0x%x\n", __FUNCTION__, type);
} else {
labcomm2006_write_packed32(writer, type);
switch (type) {
case LABCOMM_ARRAY: {
int dimensions, i;
dimensions = labcomm2006_read_packed32(decoder->reader);
labcomm2006_write_packed32(writer, dimensions);
for (i = 0 ; i < dimensions ; i++) {
int n = labcomm2006_read_packed32(decoder->reader);
labcomm2006_write_packed32(writer, n);
}
result = collect_flat_signature(decoder, writer);
if (result < 0) { goto out; }
} break;
case LABCOMM_STRUCT: {
int fields, i;
fields = labcomm2006_read_packed32(decoder->reader);
labcomm2006_write_packed32(writer, fields);
for (i = 0 ; i < fields ; i++) {
char *name = labcomm2006_read_string(decoder->reader);
labcomm2006_write_string(writer, name);
labcomm2006_memory_free(decoder->memory, 1, name);
result = collect_flat_signature(decoder, writer);
if (result < 0) { goto out; }
}
} break;
case LABCOMM_BOOLEAN:
case LABCOMM_BYTE:
case LABCOMM_SHORT:
case LABCOMM_INT:
case LABCOMM_LONG:
case LABCOMM_FLOAT:
case LABCOMM_DOUBLE:
case LABCOMM_STRING: {
} break;
default: {
result = -ENOSYS;
decoder->on_error(LABCOMM2006_ERROR_UNIMPLEMENTED_FUNC, 3,
"Implement %s (2) for type 0x%x...\n", __FUNCTION__, type);
} break;
}
}
out:
return result;
}
static int writer_ioctl(struct labcomm2006_writer *writer,
uint32_t action,
...)
{
int result;
va_list va;
if (LABCOMM_IOC_SIG(action) != LABCOMM_IOC_NOSIG) {
result = -EINVAL;
goto out;
}
va_start(va, action);
result = labcomm2006_writer_ioctl(writer, writer->action_context,
0, NULL, action, va);
va_end(va);
out:
return result;
}
static int decode_typedef_or_sample(struct labcomm2006_decoder *d, int kind)
{
int result;
/* TODO: should the labcomm2006_dynamic_buffer_writer be
a permanent part of labcomm2006_decoder? */
struct labcomm2006_writer_action_context action_context = {
.next = NULL,
.action = labcomm2006_dynamic_buffer_writer_action,
.context = NULL
};
struct labcomm2006_writer writer = {
.action_context = &action_context,
.memory = d->memory,
.data = NULL,
.data_size = 0,
.count = 0,
.pos = 0,
.error = 0,
};
struct labcomm2006_signature signature;
const struct labcomm2006_signature *local_signature;
int remote_index, local_index, err;
local_signature = NULL;
local_index = 0;
labcomm2006_writer_alloc(&writer, writer.action_context);
labcomm2006_writer_start(&writer, writer.action_context, 0, NULL, NULL);
remote_index = labcomm2006_read_packed32(d->reader);
signature.name = labcomm2006_read_string(d->reader);
collect_flat_signature(d, &writer);
labcomm2006_writer_end(&writer, writer.action_context);
err = writer_ioctl(&writer,
LABCOMM_IOCTL_WRITER_GET_BYTES_WRITTEN,
&signature.size);
if (err < 0) {
fprintf(stderr, "Failed to get size: %s\n", strerror(-err));
result = -ENOENT;
goto free_signature_name;
}
err = writer_ioctl(&writer,
LABCOMM_IOCTL_WRITER_GET_BYTE_POINTER,
&signature.signature);
if (err < 0) {
fprintf(stderr, "Failed to get pointer: %s\n", strerror(-err));
result = -ENOENT;
goto free_signature_name;
}
{
int i;
labcomm2006_scheduler_data_lock(d->scheduler);
LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local, struct sample_entry, i) {
struct sample_entry *s;
int *remote_to_local;
result = -ENOENT;
s = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local, struct sample_entry, i);
if (s->signature &&
s->signature->size == signature.size &&
strcmp(s->signature->name, signature.name) == 0 &&
memcmp((void*)s->signature->signature, (void*)signature.signature,
signature.size) == 0) {
s->remote_index = remote_index;
local_signature = s->signature;
local_index = i;
remote_to_local = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local, int,
remote_index);
*remote_to_local = i;
result = remote_index;
break;
}
}
labcomm2006_scheduler_data_unlock(d->scheduler);
if (local_signature) {
labcomm2006_reader_start(d->reader, d->reader->action_context,
local_index, remote_index, local_signature,
NULL);
labcomm2006_reader_end(d->reader, d->reader->action_context);
}
}
#if 0
if (! entry) {
/* Unknown datatype, bail out */
d->on_new_datatype(d, &signature);
result = -ENOENT;
} else if (entry->index && entry->index != remote_index) {
d->on_error(LABCOMM2006_ERROR_DEC_INDEX_MISMATCH, 5,
"%s(): index mismatch '%s' (id=0x%x != 0x%x)\n",
__FUNCTION__, signature.name, entry->index, remote_index);
result = -ENOENT;
#endif
free_signature_name:
labcomm2006_memory_free(d->memory, 0, signature.name);
labcomm2006_writer_free(&writer, writer.action_context);
return result;
}
struct call_handler_context {
struct labcomm2006_reader *reader;
int local_index;
int remote_index;
const struct labcomm2006_signature *signature;
labcomm2006_handler_function handler;
void *context;
};
static void call_handler(void *value, void *context)
{
struct call_handler_context *wrap = context;
if (wrap->reader->error >= 0) {
labcomm2006_reader_start(wrap->reader, wrap->reader->action_context,
wrap->local_index, wrap->remote_index, wrap->signature,
value);
wrap->handler(value, wrap->context);
labcomm2006_reader_end(wrap->reader, wrap->reader->action_context);
}
}
static void reader_alloc(struct labcomm2006_decoder *d)
{
if (!d->reader_allocated) {
d->reader_allocated = 1;
labcomm2006_reader_alloc(d->reader, d->reader->action_context);
}
}
int labcomm2006_decoder_decode_one(struct labcomm2006_decoder *d)
{
int result, remote_index;
reader_alloc(d);
remote_index = labcomm2006_read_packed32(d->reader);
if (d->reader->error < 0) {
result = d->reader->error;
goto out;
}
if (remote_index == LABCOMM_SAMPLE) {
result = decode_typedef_or_sample(d, remote_index);
} else {
int *local_index;
struct call_handler_context wrap = {
.reader = d->reader,
.remote_index = remote_index,
.signature = NULL,
.handler = NULL,
.context = NULL,
};
labcomm2006_decoder_function do_decode = NULL;
labcomm2006_scheduler_data_lock(d->scheduler);
local_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local, int,
remote_index);
if (*local_index != 0) {
struct sample_entry *entry;
entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local, struct sample_entry,
*local_index);
wrap.local_index = *local_index;
wrap.signature = entry->signature;
wrap.handler = entry->handler;
wrap.context = entry->context;
do_decode = entry->decode;
result = *local_index;
}
labcomm2006_scheduler_data_unlock(d->scheduler);
if (do_decode) {
do_decode(d->reader, call_handler, &wrap);
if (d->reader->error < 0) {
result = d->reader->error;
}
} else {
result = -ENOENT;
}
}
out:
return result;
}
void labcomm2006_decoder_run(struct labcomm2006_decoder *d)
{
while (labcomm2006_decoder_decode_one(d) > 0) {
}
}
int labcomm2006_decoder_ioctl(struct labcomm2006_decoder *d,
uint32_t action,
...)
{
int result;
va_list va;
va_start(va, action);
result = labcomm2006_reader_ioctl(d->reader,
d->reader->action_context,
0, 0, NULL, action, va);
va_end(va);
return result;
}
int labcomm2006_internal_decoder_ioctl(struct labcomm2006_decoder *d,
const struct labcomm2006_signature *signature,
uint32_t action, va_list va)
{
int result;
int local_index, remote_index;
local_index = labcomm2006_get_local_index(signature);
labcomm2006_scheduler_data_lock(d->scheduler);
remote_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local,
struct sample_entry,
local_index)->remote_index;
labcomm2006_scheduler_data_unlock(d->scheduler);
result = labcomm2006_reader_ioctl(d->reader, d->reader->action_context,
local_index, remote_index,
signature, action, va);
return result;
}
int labcomm2006_internal_decoder_register(
struct labcomm2006_decoder *d,
const struct labcomm2006_signature *signature,
labcomm2006_decoder_function decode,
labcomm2006_handler_function handler,
void *context)
{
int local_index;
struct sample_entry *entry;
reader_alloc(d);
local_index = labcomm2006_get_local_index(signature);
if (local_index <= 0) { goto out; }
labcomm2006_reader_start(d->reader, d->reader->action_context,
local_index, 0, signature,
NULL);
labcomm2006_reader_end(d->reader, d->reader->action_context);
labcomm2006_scheduler_data_lock(d->scheduler);
entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local, struct sample_entry,
local_index);
if (entry == NULL) { local_index = -ENOMEM; goto unlock; }
entry->remote_index = 0;
entry->signature = signature;
entry->decode = decode;
entry->handler = handler;
entry->context = context;
unlock:
labcomm2006_scheduler_data_unlock(d->scheduler);
out:
return local_index;
}
/*
test_default_error_handler.c -- LabComm default error handler
Copyright 2013 Anders Blomdell <anders.blomdell@control.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 "labcomm2006.h"
struct labcomm2006_error_handler *labcomm2006_default_error_handler = NULL;
/*
test_default_memory.c -- LabComm default memory allocator
Copyright 2013 Anders Blomdell <anders.blomdell@control.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 <stdlib.h>
#include "labcomm2006.h"
#include "labcomm2006_private.h"
void *default_alloc2006(struct labcomm2006_memory *m, int lifetime, size_t size)
{
return malloc(size);
}
void *default_realloc2006(struct labcomm2006_memory *m, int lifetime,
void *ptr, size_t size)
{
return realloc(ptr, size);
}
void default_free2006(struct labcomm2006_memory *m, int lifetime, void *ptr)
{
free(ptr);
}
struct labcomm2006_memory memory2006 = {
.alloc = default_alloc2006,
.realloc = default_realloc2006,
.free = default_free2006,
.context = NULL
};
struct labcomm2006_memory *labcomm2006_default_memory = &memory2006;