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

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Select Git revision
Show changes
Showing
with 939 additions and 449 deletions
......@@ -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
......@@ -51,6 +52,7 @@ build :
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;
......@@ -22,7 +22,11 @@ OBJS=labcomm$(VERSION).o \
labcomm$(VERSION)_fd_reader.o \
labcomm$(VERSION)_type_signature.o \
labcomm$(VERSION)_fd_writer.o \
labcomm$(VERSION)_pthread_scheduler.o
labcomm$(VERSION)_pthread_scheduler.o \
labcomm$(VERSION)_renaming.o \
labcomm$(VERSION)_renaming_registry.o \
labcomm$(VERSION)_renaming_encoder.o \
labcomm$(VERSION)_renaming_decoder.o
# Enable experimental objects by `make LABCOMM_EXPERIMENTAL=true`
ifeq ($(LABCOMM_EXPERIMENTAL),true)
......@@ -35,7 +39,7 @@ endif
# Enable experimental objects by `make LABCOMM_SIG_PARSER=true`
ifeq ($(LABCOMM_SIG_PARSER),true)
OBJS += experimental/labcomm_sig_parser.o
OBJS += experimental/labcomm2014_sig_parser.o
endif
LABCOMM_JAR=../../../compiler/labcomm$(LIBVERSION)_compiler.jar
......@@ -46,7 +50,10 @@ TESTS=test_labcomm_basic_type_encoding \
test_signature_numbers \
test_labcomm \
test_labcomm_pthread_scheduler \
test_labcomm_copy
test_labcomm_copy \
test_labcomm_renaming_registry \
test_labcomm_renaming_encoder \
test_labcomm_renaming_decoder
#FIXME: test_labcomm_errors
TEST_DIR=test
......@@ -88,9 +95,9 @@ distclean: clean
../liblabcomm$(LIBVERSION).a: $(OBJS)
ar -r $@ $^
# Enable sig parser objects by `make LABCOMM_SIG_PARSER=true`
# Enable sig parser objects by `make labcomm2014_sig_PARSER=true`
ifeq ($(LABCOMM_SIG_PARSER),true)
experimental/test_sig_parser : experimental/labcomm_sig_parser.o experimental/test_sig_parser.c
experimental/test_sig_parser : experimental/labcomm2014_sig_parser.o experimental/test_sig_parser.c
endif
# compilation rules
......@@ -103,7 +110,7 @@ endif
# rules invoked by 'test'
.PHONY: run-test-%
run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen
$<
$(VALGRIND) $<
.PRECIOUS: $(TEST_DIR)/gen/%
......@@ -169,3 +176,12 @@ $(TEST_DIR)/gen/test_labcomm_copy: \
$(TEST_DIR)/gen/generated_encoding.o \
$(TEST_DIR)/gen/test_sample.o \
$(TEST_DIR)/gen/more_types.o
$(TEST_DIR)/gen/test_labcomm_renaming_registry: \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_labcomm_renaming_encoder: \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_labcomm_renaming_decoder: \
$(TEST_DIR)/gen/generated_encoding.o
/* labcomm_sig_parser.h:
/* labcomm2014_sig_parser.h:
* an example parser for labcomm signatures, illustrating how to skip samples
* based on their signature. Intended as an embryo for introducing this
* functionality into the lib to allow a channel to survive types with no
......@@ -8,10 +8,10 @@
#ifndef LABCOMM_SIG_PARSER_H
#define LABCOMM_SIG_PARSER_H
#include "../labcomm.h"
#include "../labcomm_private.h"
#include "labcomm2014.h"
#include "labcomm2014_private.h"
#define DEBUG
#undef DEBUG
#define QUIET_STACK // don't print anything for push/pop
#undef DEBUG_STACK_VERBOSE // dump stack, otherwise just print value of top
......@@ -25,7 +25,7 @@
#ifdef STATIC_ALLOCATION
#define MAX_SIGNATURES 16
#define MAX_SIGNATURES 100
#define MAX_NAME_LEN 32
#define MAX_SIG_LEN 128
#define TYPEDEF_BASE MAX_SIGNATURES
......@@ -52,14 +52,14 @@ typedef struct {
// signatures start at index 0
// typedefs start at index MAX_SIGNATURES
#ifdef STATIC_ALLOCATION
struct labcomm_signature sig_ts[2*MAX_SIGNATURES];
struct labcomm2014_signature sig_ts[2*MAX_SIGNATURES];
unsigned int signatures_length[2*MAX_SIGNATURES];
unsigned int signatures_name_length[2*MAX_SIGNATURES];
unsigned char signatures_name[2*MAX_SIGNATURES][MAX_NAME_LEN];
unsigned char signatures[2*MAX_SIGNATURES][MAX_SIG_LEN];
#else
struct labcomm_signature *sig_ts; // [2*MAX_SIGNATURES]
struct labcomm2014_signature *sig_ts; // [2*MAX_SIGNATURES]
unsigned int *signatures_length; // [2*MAX_SIGNATURES]
unsigned char **signatures; // [2*MAX_SIGNATURES][MAX_SIG_LEN];
......@@ -68,30 +68,31 @@ typedef struct {
char **signatures_name; // [2*MAX_SIGNATURES][MAX_NAME_LEN];
#endif
} labcomm_sig_parser_t;
} labcomm2014_sig_parser_t;
int labcomm_sig_parser_init(labcomm_sig_parser_t *p, size_t size,
int labcomm2014_sig_parser_init(labcomm2014_sig_parser_t *p, size_t size,
size_t stacksize, size_t max_num_signatures,
size_t max_name_len, size_t max_sig_len);
int labcomm_sig_parser_read_file(labcomm_sig_parser_t *p, FILE *f);
void labcomm2014_sig_parser_free(labcomm2014_sig_parser_t *b);
int labcomm2014_sig_parser_read_file(labcomm2014_sig_parser_t *p, FILE *f);
int accept_packet(labcomm_sig_parser_t *p);
int accept_packet(labcomm2014_sig_parser_t *p);
struct labcomm_signature *get_sig_t(labcomm_sig_parser_t *p,unsigned int uid);
struct labcomm2014_signature *get_sig_t(labcomm2014_sig_parser_t *p,unsigned int uid);
unsigned int get_signature_len(labcomm_sig_parser_t *p,unsigned int uid);
char* get_signature_name(labcomm_sig_parser_t *p,unsigned int uid);
unsigned char* get_signature(labcomm_sig_parser_t *p,unsigned int uid);
void dump_signature(labcomm_sig_parser_t *p,unsigned int uid);
unsigned int get_signature_len(labcomm2014_sig_parser_t *p,unsigned int uid);
char* get_signature_name(labcomm2014_sig_parser_t *p,unsigned int uid);
unsigned char* get_signature(labcomm2014_sig_parser_t *p,unsigned int uid);
void dump_signature(labcomm2014_sig_parser_t *p,unsigned int uid);
int more(labcomm_sig_parser_t *b);
int more(labcomm2014_sig_parser_t *b);
/* parse signature and skip the corresponding bytes in the labcomm_sig_parser
/* parse signature and skip the corresponding bytes in the labcomm2014_sig_parser
*/
int skip_packed_sample_data(labcomm_sig_parser_t *p, struct labcomm_signature *sig);
int skip_packed_sample_data(labcomm2014_sig_parser_t *p, struct labcomm2014_signature *sig);
#ifdef QUIET
#define INFO_PRINTF(format, args...)
......@@ -131,5 +132,5 @@ typedef enum{
TYPE_DOUBLE = LABCOMM_DOUBLE,
TYPE_STRING = LABCOMM_STRING,
TYPE_SAMPLE_REF = LABCOMM_REF
} labcomm_type ;
} labcomm2014_type ;
#endif
/* labcomm_sig_parser.c:
/* labcomm2014_sig_parser.c:
* a main program for the example labcomm signatures parser
*/
#include <stdio.h>
#include <stdlib.h>
#include "labcomm_sig_parser.h"
#include "experimental/labcomm2014_sig_parser.h"
#define DEBUG_READ
#define BUF_SIZE 1024
#define STACK_SIZE 16
#define MAX_NUM_SIGNATURES 10
#define MAX_SIGNATURES 16
#define MAX_NAME_LEN 32
#define MAX_SIG_LEN 128
#define MAX_SIGNATURES 100
#define MAX_NAME_LEN 64
#define MAX_SIG_LEN 512
void test_read(labcomm_sig_parser_t *p) {
int r = labcomm_sig_parser_read_file(p, stdin);
void test_read(labcomm2014_sig_parser_t *p) {
int r = labcomm2014_sig_parser_read_file(p, stdin);
#ifdef DEBUG_READ
printf("read %d bytes:\n\n", r);
int i;
......@@ -29,9 +29,9 @@ void test_read(labcomm_sig_parser_t *p) {
#endif
}
int main() {
labcomm_sig_parser_t p;
labcomm2014_sig_parser_t p;
if(labcomm_sig_parser_init(&p, BUF_SIZE, STACK_SIZE,
if(labcomm2014_sig_parser_init(&p, BUF_SIZE, STACK_SIZE,
MAX_NUM_SIGNATURES, MAX_NAME_LEN, MAX_SIG_LEN) ) {
printf("failed to init buffer\n");
exit(1);
......@@ -41,5 +41,6 @@ int main() {
printf("--------------------------------------------- new packet: \n");
} while(more(&p) && accept_packet(&p));
printf("EOF\n");
labcomm2014_sig_parser_free(&p);
}
......@@ -250,11 +250,18 @@ void labcomm2014_set_local_index(struct labcomm2014_signature *signature)
int labcomm2014_get_local_index(const struct labcomm2014_signature *signature)
{
int result;
if (! signature) {
result = 0;
} else {
if (signature->index == 0) {
labcomm2014_error_fatal_global(LABCOMM2014_ERROR_SIGNATURE_NOT_SET,
"Signature not set: %s\n", signature->name);
"Signature not set: %s\n",
signature->name);
}
result = signature->index;
}
return signature->index;
return result;
}
int labcomm2014_get_local_type_index(const struct labcomm2014_signature *signature)
......@@ -265,7 +272,7 @@ int labcomm2014_get_local_type_index(const struct labcomm2014_signature *signatu
int labcomm2014_internal_sizeof(const struct labcomm2014_signature *signature,
void *v)
{
int length = signature->encoded_size(v);
int length = signature->encoded_size(signature, v);
return (labcomm2014_size_packed32(signature->index) +
labcomm2014_size_packed32(length) +
length);
......
......@@ -20,8 +20,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LABCOMM_H__
#define __LABCOMM_H__
#ifndef __LABCOMM2014_H__
#define __LABCOMM2014_H__
#include <stdarg.h>
......@@ -112,6 +112,10 @@ int labcomm2014_decoder_ioctl(struct labcomm2014_decoder *decoder,
uint32_t ioctl_action,
...);
const struct labcomm2014_sample_ref *labcomm2014_decoder_get_sample_ref(
struct labcomm2014_decoder *decoder,
const struct labcomm2014_signature *signature);
/*
* Encoder
*/
......@@ -133,6 +137,8 @@ int labcomm2014_encoder_ioctl(struct labcomm2014_encoder *encoder,
uint32_t ioctl_action,
...);
#define LABCOMM_VOID ((void*)1)
const struct labcomm2014_sample_ref *labcomm2014_encoder_get_sample_ref(
struct labcomm2014_encoder *encoder,
const struct labcomm2014_signature *signature);
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -24,16 +24,38 @@
#include <stdarg.h>
#include "labcomm2014_error.h"
static char *description[] = {
#define LABCOMM2014_ERROR(name, description) description ,
#include "labcomm2014_error.h"
#undef LABCOMM2014_ERROR
};
void labcomm2014_error_fatal_global(enum labcomm2014_error error,
char *format,
...)
{
va_list args;
fprintf(stderr, "Fatal error %d\n", error);
fprintf(stderr, "Fatal error %d (%s)\n", error, description[error]);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
exit(1);
}
void labcomm2014_error_warning(struct labcomm2014_error_handler *e,
enum labcomm2014_error error,
char *format,
...)
{
va_list args;
fprintf(stderr, "Fatal warning %d (%s)\n", error, description[error]);
va_start(args, format);
vprintf(format, args);
vfprintf(stderr, format, args);
va_end(args);
exit(1);
}
......@@ -52,6 +52,9 @@ LABCOMM2014_ERROR(LABCOMM2014_ERROR_ENC_NO_REG_SIGNATURE,
"Encoder has no registration for this signature")
LABCOMM2014_ERROR(LABCOMM2014_ERROR_ENC_BUF_FULL,
"The labcomm2014 buffer is full")
LABCOMM2014_ERROR(LABCOMM2014_ERROR_DEC_NO_REG_SIGNATURE,
"Decoder has no registration for this signature")
LABCOMM2014_ERROR(LABCOMM2014_ERROR_DEC_UNKNOWN_DATATYPE,
"Decoder: Unknown datatype")
LABCOMM2014_ERROR(LABCOMM2014_ERROR_DEC_INDEX_MISMATCH,
......
......@@ -26,9 +26,14 @@
#include <stdarg.h>
#include "labcomm2014_private.h"
#include "labcomm2014_fd_writer.h"
#include "labcomm2014_ioctl.h"
#define BUFFER_SIZE 2048
#ifdef LABCOMM_WITH_SANITY_CHECKS
static int bytecount_carry = 0;
#endif
struct labcomm2014_fd_writer {
struct labcomm2014_writer writer;
struct labcomm2014_writer_action_context action_context;
......@@ -82,6 +87,9 @@ static int fd_start(struct labcomm2014_writer *w,
const struct labcomm2014_signature *signature,
void *value)
{
#ifdef LABCOMM_WITH_SANITY_CHECKS
bytecount_carry = w->pos;
#endif
w->pos = 0;
return w->error;
......@@ -107,18 +115,45 @@ static int fd_flush(struct labcomm2014_writer *w,
} else if (err == 0) {
w->error = -EINVAL;
}
#ifdef LABCOMM_WITH_SANITY_CHECKS
bytecount_carry = w->pos;
#endif
w->pos = 0;
return w->error;
}
#ifdef LABCOMM_WITH_SANITY_CHECKS
static int fd_ioctl(struct labcomm2014_writer *w,
struct labcomm2014_writer_action_context *action_context,
int signature_index,
const struct labcomm2014_signature *signature,
uint32_t action, va_list arg)
{
int result = -ENOTSUP;
switch (action) {
case LABCOMM_IOCTL_WRITER_GET_BYTES_WRITTEN: {
int *value = va_arg(arg, int*);
*value = w->pos + bytecount_carry;
result = 0;
} break;
}
return result;
}
#endif
static const struct labcomm2014_writer_action action = {
.alloc = fd_alloc,
.free = fd_free,
.start = fd_start,
.end = fd_flush,
.flush = fd_flush,
#ifdef LABCOMM_WITH_SANITY_CHECKS
.ioctl = fd_ioctl
#else
.ioctl = NULL
#endif
};
struct labcomm2014_writer *labcomm2014_fd_writer_new(struct labcomm2014_memory *memory,
......