From 6e6d97002ae332be48c98c04442de15a787fdeb6 Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Fri, 7 Feb 2014 17:51:29 +0100 Subject: [PATCH] non-working libc --- compiler/C_CodeGen.jrag | 106 +++---- examples/simple/compile.sh | 17 +- examples/simple/example_decoder06.c | 84 ++++++ examples/simple/example_encoder06.c | 85 ++++++ lib/c/2006/labcomm2006.c | 108 +++---- lib/c/2006/labcomm2006.h | 96 +++--- lib/c/2006/labcomm2006_decoder.c | 182 ++++++------ .../2006/labcomm2006_default_error_handler.c | 4 +- .../2006/labcomm2006_default_error_handler.h | 4 +- lib/c/2006/labcomm2006_default_memory.c | 20 +- lib/c/2006/labcomm2006_default_memory.h | 6 +- lib/c/2006/labcomm2006_default_scheduler.c | 32 +- lib/c/2006/labcomm2006_default_scheduler.h | 4 +- .../2006/labcomm2006_dynamic_buffer_writer.c | 66 ++--- .../2006/labcomm2006_dynamic_buffer_writer.h | 10 +- lib/c/2006/labcomm2006_encoder.c | 102 +++---- lib/c/2006/labcomm2006_error.c | 6 +- lib/c/2006/labcomm2006_error.h | 14 +- lib/c/2006/labcomm2006_fd_reader.c | 48 +-- lib/c/2006/labcomm2006_fd_reader.h | 6 +- lib/c/2006/labcomm2006_fd_writer.c | 56 ++-- lib/c/2006/labcomm2006_fd_writer.h | 6 +- lib/c/2006/labcomm2006_ioctl.h | 4 +- lib/c/2006/labcomm2006_memory.c | 10 +- lib/c/2006/labcomm2006_private.h | 278 +++++++++--------- lib/c/2006/labcomm2006_pthread_scheduler.c | 98 +++--- lib/c/2006/labcomm2006_pthread_scheduler.h | 8 +- lib/c/2006/labcomm2006_scheduler.c | 24 +- lib/c/2006/labcomm2006_scheduler.h | 30 +- lib/c/2006/labcomm2006_scheduler_private.h | 36 +-- lib/c/2006/labcomm2006_time.c | 8 +- lib/c/Makefile | 42 ++- 32 files changed, 905 insertions(+), 695 deletions(-) create mode 100644 examples/simple/example_decoder06.c create mode 100644 examples/simple/example_encoder06.c diff --git a/compiler/C_CodeGen.jrag b/compiler/C_CodeGen.jrag index 4531c86..4d4c76b 100644 --- a/compiler/C_CodeGen.jrag +++ b/compiler/C_CodeGen.jrag @@ -34,6 +34,7 @@ aspect C_CodeGenEnv { } public final int version; //labcomm version (2006 or 2013) + public final String verStr; // version suffix to append (currently _2006 and empty string) public final String qualid; public final String lcName; @@ -46,6 +47,7 @@ aspect C_CodeGenEnv { private C_env(String qualid, String lcName, String rawPrefix, int indent, int depth, C_printer printer, int version) { this.version = version; + this.verStr = (version == 2006 ? "2006" : ""); this.qualid = qualid; this.lcName = lcName; this.rawPrefix = rawPrefix; @@ -155,7 +157,7 @@ aspect C_CodeGen { // Include env.println("#include <stdint.h>"); - env.println("#include \"labcomm.h\""); + env.println("#include \"labcomm"+env.verStr+".h\""); for (int i = 0 ; i < includes.size() ; i++) { env.println("#include \"" + includes.get(i) + "\""); } @@ -171,8 +173,8 @@ aspect C_CodeGen { C_env env = new C_env("", lcName, prefix, out, version); // Include - env.println("#include \"labcomm.h\""); - env.println("#include \"labcomm_private.h\""); + env.println("#include \"labcomm"+env.verStr+".h\""); + env.println("#include \"labcomm"+env.verStr+"_private.h\""); for (int i = 0 ; i < includes.size() ; i++) { env.println("#include \"" + includes.get(i) + "\""); } @@ -334,10 +336,10 @@ aspect C_Declarations { } public void SampleDecl.C_emitDecoderDeclaration(C_env env) { - env.println("int labcomm_decoder_register_" + + env.println("int labcomm"+env.verStr+"_decoder_register_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_decoder *d,"); + env.println("struct labcomm"+env.verStr+"_decoder *d,"); env.println("void (*handler)("); env.indent(); env.println(env.prefix + getName() + " *v,"); @@ -348,9 +350,9 @@ aspect C_Declarations { env.unindent(); env.println(");"); - env.println("int labcomm_decoder_ioctl_" + env.prefix + getName() + "("); + env.println("int labcomm"+env.verStr+"_decoder_ioctl_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_decoder *d,"); + env.println("struct labcomm"+env.verStr+"_decoder *d,"); env.println("int ioctl_action,"); env.println("..."); env.unindent(); @@ -361,22 +363,22 @@ aspect C_Declarations { } public void SampleDecl.C_emitEncoderDeclaration(C_env env) { - env.println("int labcomm_encoder_register_" + + env.println("int labcomm"+env.verStr+"_encoder_register_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_encoder *e);"); + env.println("struct labcomm"+env.verStr+"_encoder *e);"); env.unindent(); - env.println("int labcomm_encode_" + env.prefix + getName() + "("); + env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_encoder *e,"); + env.println("struct labcomm"+env.verStr+"_encoder *e,"); env.println(env.prefix + getName() + " *v"); env.unindent(); env.println(");"); - env.println("int labcomm_encoder_ioctl_" + env.prefix + getName() + "("); + env.println("int labcomm"+env.verStr+"_encoder_ioctl_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_encoder *e,"); + env.println("struct labcomm"+env.verStr+"_encoder *e,"); env.println("int ioctl_action,"); env.println("..."); env.unindent(); @@ -438,7 +440,7 @@ aspect C_Decoder { env = env.nestStruct("v"); env.println("static void decode_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_reader *r,"); + env.println("struct labcomm"+env.verStr+"_reader *r,"); env.println("void (*handle)("); env.indent(); env.println(env.prefix + getName() + " *v,"); @@ -474,7 +476,7 @@ aspect C_Decoder { } public void PrimType.C_emitDecoder(C_env env) { - env.println(env.qualid + " = labcomm_read_" + getName() + "(r);"); + env.println(env.qualid + " = labcomm"+env.verStr+"_read_" + getName() + "(r);"); } public void UserType.C_emitDecoder(C_env env) { @@ -520,7 +522,7 @@ aspect C_Decoder { } public void VariableSize.C_emitDecoderDecodeLimit(C_env env, int i) { - env.println(env.qualid + ".n_" + i + " = labcomm_read_packed32(r);"); + env.println(env.qualid + ".n_" + i + " = labcomm"+env.verStr+"_read_packed32(r);"); } public void ArrayType.C_emitDecoderDecodeLimit(C_env env) { @@ -534,7 +536,7 @@ aspect C_Decoder { public void VariableArrayType.C_emitDecoderArrayAllocate(C_env env) { env.print(env.qualid + - ".a = labcomm_memory_alloc(r->memory, 1, sizeof(" + + ".a = labcomm"+env.verStr+"_memory_alloc(r->memory, 1, sizeof(" + env.qualid + ".a[0])"); for (int i = 0 ; i < getNumExp() ; i++) { env.print(" * " + getExp(i).C_getLimit(env, i)); @@ -552,7 +554,7 @@ aspect C_Decoder { public void PrimType.C_emitDecoderDeallocation(C_env env) { if (C_isDynamic()) { - env.println("labcomm_memory_free(r->memory, 1, " + + env.println("labcomm"+env.verStr+"_memory_free(r->memory, 1, " + env.qualid + ");"); } } @@ -598,7 +600,7 @@ aspect C_Decoder { public void VariableArrayType.C_emitDecoderDeallocation(C_env env) { super.C_emitDecoderDeallocation(env); - env.println("labcomm_memory_free(r->memory, 1, " + + env.println("labcomm"+env.verStr+"_memory_free(r->memory, 1, " + env.qualid + ".a);"); } @@ -616,10 +618,10 @@ aspect C_Decoder { } public void SampleDecl.C_emitDecoderRegisterHandler(C_env env) { - env.println("int labcomm_decoder_register_" + + env.println("int labcomm"+env.verStr+"_decoder_register_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_decoder *d,"); + env.println("struct labcomm"+env.verStr+"_decoder *d,"); env.println("void (*handler)("); env.indent(); env.println(env.prefix + getName() + " *v,"); @@ -631,12 +633,12 @@ aspect C_Decoder { env.println(")"); env.println("{"); env.indent(); - env.println("return labcomm_internal_decoder_register("); + env.println("return labcomm"+env.verStr+"_internal_decoder_register("); env.indent(); env.println("d,"); - env.println("&labcomm_signature_" + env.prefix + getName() + ","); - env.println("(labcomm_decoder_function)decode_" + env.prefix + getName() + ","); - env.println("(labcomm_handler_function)handler,"); + env.println("&labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ","); + env.println("(labcomm"+env.verStr+"_decoder_function)decode_" + env.prefix + getName() + ","); + env.println("(labcomm"+env.verStr+"_handler_function)handler,"); env.println("context"); env.unindent(); env.println(");"); @@ -658,9 +660,9 @@ aspect C_DecoderIoctl { } public void SampleDecl.C_emitDecoderIoctl(C_env env) { - env.println("int labcomm_decoder_ioctl_" + env.prefix + getName() + "("); + env.println("int labcomm"+env.verStr+"_decoder_ioctl_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_decoder *d,"); + env.println("struct labcomm"+env.verStr+"_decoder *d,"); env.println("int ioctl_action,"); env.println("..."); env.unindent(); @@ -670,9 +672,9 @@ aspect C_DecoderIoctl { env.println("int result;"); env.println("va_list va;"); env.println("va_start(va, ioctl_action);"); - env.println("result = labcomm_internal_decoder_ioctl("); + env.println("result = labcomm"+env.verStr+"_internal_decoder_ioctl("); env.indent(); - env.println("d, &labcomm_signature_" + env.prefix + getName() + ", "); + env.println("d, &labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ", "); env.println("ioctl_action, va);"); env.unindent(); env.println("va_end(va);"); @@ -698,7 +700,7 @@ aspect C_Encoder { env = env.nestStruct("(*v)"); env.println("static int encode_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_writer *w,"); + env.println("struct labcomm"+env.verStr+"_writer *w,"); env.println(env.prefix + getName() + " *v"); env.unindent(); env.println(")"); @@ -711,16 +713,16 @@ aspect C_Encoder { env.println("}"); // Typesafe encode wrapper - env.println("int labcomm_encode_" + env.prefix + getName() + "("); - env.println("struct labcomm_encoder *e,"); + env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "("); + env.println("struct labcomm"+env.verStr+"_encoder *e,"); env.println(env.prefix + getName() + " *v"); env.unindent(); env.println(")"); env.println("{"); env.indent(); - env.println("return labcomm_internal_encode(e, &labcomm_signature_" + + env.println("return labcomm"+env.verStr+"_internal_encode(e, &labcomm"+env.verStr+"_signature_" + env.prefix + getName() + - ", (labcomm_encoder_function)encode_" + env.prefix + getName() + + ", (labcomm"+env.verStr+"_encoder_function)encode_" + env.prefix + getName() + ", v);"); env.unindent(); env.println("}"); @@ -737,7 +739,7 @@ aspect C_Encoder { } public void PrimType.C_emitEncoder(C_env env) { - env.println("result = labcomm_write_" + getName() + + env.println("result = labcomm"+env.verStr+"_write_" + getName() + "(w, " + env.qualid + ");"); env.println("if (result != 0) { return result; }"); } @@ -784,7 +786,7 @@ aspect C_Encoder { } public void VariableSize.C_emitEncoderEncodeLimit(C_env env, int i) { - env.println("labcomm_write_packed32(w, " + env.qualid + ".n_" + i + ");"); + env.println("labcomm"+env.verStr+"_write_packed32(w, " + env.qualid + ".n_" + i + ");"); } public void ArrayType.C_emitEncoderEncodeLimit(C_env env) { @@ -803,19 +805,19 @@ aspect C_Encoder { } public void SampleDecl.C_emitEncoderRegisterHandler(C_env env) { - env.println("int labcomm_encoder_register_" + + env.println("int labcomm"+env.verStr+"_encoder_register_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_encoder *e"); + env.println("struct labcomm"+env.verStr+"_encoder *e"); env.unindent(); env.println(")"); env.println("{"); env.indent(); - env.println("return labcomm_internal_encoder_register("); + env.println("return labcomm"+env.verStr+"_internal_encoder_register("); env.indent(); env.println("e,"); - env.println("&labcomm_signature_" + env.prefix + getName() + ","); - env.println("(labcomm_encoder_function)encode_" + env.prefix + getName()); + env.println("&labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ","); + env.println("(labcomm"+env.verStr+"_encoder_function)encode_" + env.prefix + getName()); env.unindent(); env.println(");"); env.unindent(); @@ -836,9 +838,9 @@ aspect C_EncoderIoctl { } public void SampleDecl.C_emitEncoderIoctl(C_env env) { - env.println("int labcomm_encoder_ioctl_" + env.prefix + getName() + "("); + env.println("int labcomm"+env.verStr+"_encoder_ioctl_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm_encoder *e,"); + env.println("struct labcomm"+env.verStr+"_encoder *e,"); env.println("int ioctl_action,"); env.println("..."); env.unindent(); @@ -848,9 +850,9 @@ aspect C_EncoderIoctl { env.println("int result;"); env.println("va_list va;"); env.println("va_start(va, ioctl_action);"); - env.println("result = labcomm_internal_encoder_ioctl("); + env.println("result = labcomm"+env.verStr+"_internal_encoder_ioctl("); env.indent(); - env.println("e, &labcomm_signature_" + env.prefix + getName() + ", "); + env.println("e, &labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ", "); env.println("ioctl_action, va);"); env.unindent(); env.println("va_end(va);"); @@ -891,11 +893,11 @@ aspect C_Signature { } } env.println("};"); - env.println("struct labcomm_signature labcomm_signature_" + + env.println("struct labcomm"+env.verStr+"_signature labcomm"+env.verStr+"_signature_" + env.prefix + getName() + " = {"); env.indent(); env.println("LABCOMM_SAMPLE, \"" + getName() + "\","); - env.println("(int (*)(struct labcomm_signature *, void *))labcomm_sizeof_" + + env.println("(int (*)(struct labcomm"+env.verStr+"_signature *, void *))labcomm"+env.verStr+"_sizeof_" + env.prefix + getName() + ","); env.println("sizeof(signature_bytes_" + env.prefix + getName() + "),"); env.println("signature_bytes_" + env.prefix + getName() + ","); @@ -932,7 +934,7 @@ aspect C_Signature { } public void SampleDecl.C_emitConstructor(C_env env) { - env.println("labcomm_set_local_index(&labcomm_signature_" + + env.println("labcomm"+env.verStr+"_set_local_index(&labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ");"); } @@ -955,7 +957,7 @@ aspect C_Sizeof { } public void SampleDecl.C_emitSizeofDeclaration(C_env env) { - env.println("extern int labcomm_sizeof_" + env.prefix + getName() + + env.println("extern int labcomm"+env.verStr+"_sizeof_" + env.prefix + getName() + "(" + env.prefix + getName() + " *v);"); } @@ -1016,11 +1018,11 @@ aspect C_Sizeof { public void SampleDecl.C_emitSizeof(C_env env) { env = env.nestStruct("(*v)"); - env.println("int labcomm_sizeof_" + env.prefix + getName() + + env.println("int labcomm"+env.verStr+"_sizeof_" + env.prefix + getName() + "(" + env.prefix + getName() + " *v)"); env.println("{"); env.indent(); - env.println("int result = labcomm_size_packed32(labcomm_signature_" + + env.println("int result = labcomm"+env.verStr+"_size_packed32(labcomm"+env.verStr+"_signature_" + env.prefix + getName() +".index);"); if (C_isDynamic()) { getType().C_emitSizeof(env); @@ -1094,7 +1096,7 @@ aspect C_Sizeof { env.println("}"); } else { for (int i = 0 ; i < getNumExp() ; i++) { - env.println("result += labcomm_size_packed32(" + + env.println("result += labcomm"+env.verStr+"_size_packed32(" + getExp(i).C_getLimit(env, i) + ");"); } env.print("result += " + getType().C_fixedSizeof()); diff --git a/examples/simple/compile.sh b/examples/simple/compile.sh index 7e5de1c..009d747 100644 --- a/examples/simple/compile.sh +++ b/examples/simple/compile.sh @@ -1,15 +1,22 @@ (cd ../..; make all) mkdir -p gen -java -jar ../../compiler/labComm.jar --ver=2013 --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc +java -jar ../../compiler/labComm.jar --ver=2006 --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc javac -cp ../../lib/java:. gen/*.java Encoder.java Decoder.java -gcc -Wall -Werror -I. -I../../lib/c -L../../lib/c \ - -o example_encoder example_encoder.c gen/simple.c \ +# gcc -Wall -Werror -I. -I../../lib/c -L../../lib/c \ +# -o example_encoder example_encoder.c gen/simple.c \ +# -llabcomm -Tlabcomm.linkscript +#gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \ +# -o example_decoder example_decoder.c gen/simple.c \ +# -llabcomm -Tlabcomm.linkscript + +gcc -Wall -Werror -I. -I../../lib/c/2006 -L../../lib/c \ + -o example_encoder06 example_encoder06.c gen/simple.c \ -llabcomm -Tlabcomm.linkscript -gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \ - -o example_decoder example_decoder.c gen/simple.c \ +gcc -Wall -Werror -I . -I ../../lib/c/2006 -L../../lib/c \ + -o example_decoder06 example_decoder06.c gen/simple.c \ -llabcomm -Tlabcomm.linkscript #gcc -o example_encoder -I . -I ../../lib/c example_encoder.c gen/simple.c ../../lib/c/labcomm.c ../../lib/c/labcomm_fd_reader_writer.c diff --git a/examples/simple/example_decoder06.c b/examples/simple/example_decoder06.c new file mode 100644 index 0000000..fb32870 --- /dev/null +++ b/examples/simple/example_decoder06.c @@ -0,0 +1,84 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <labcomm2006_fd_reader.h> +#include <labcomm2006_default_error_handler.h> +#include <labcomm2006_default_memory.h> +#include <labcomm2006_default_scheduler.h> +#include "gen/simple.h" +#include <stdio.h> + +static void handle_simple_theTwoInts(simple_TwoInts *v,void *context) { + printf("Got theTwoInts. a=%d, b=%d\n", v->a, v->b); +} + +static void handle_simple_anotherTwoInts(simple_TwoInts *v,void *context) { + printf("Got anotherTwoInts. a=%d, b=%d\n", v->a, v->b); +} + +static void handle_simple_IntString(simple_IntString *v,void *context) { + printf("Got IntString. x=%d, s=%s\n", v->x, v->s); +} + +static void handle_simple_TwoArrays(simple_TwoArrays *d,void *context) { + printf("Got TwoArrays:"); + int i,j; + for(i=0; i<2; i++) { + printf("%d ",d->fixed.a[i]); + } + printf("\n"); + for(i=0; i<2; i++) { + for(j=0; j<d->variable.n_1; j++) { + printf("%d ",d->variable.a[i *d->variable.n_1 + j]); + } + printf("\n"); + } + printf("\n"); +} + +static void handle_simple_TwoFixedArrays(simple_TwoFixedArrays *d,void *context) { + printf("Got TwoFixedArrays:"); + int i,j; + for(i=0; i<2; i++) { + printf("%d ",d->a.a[i]); + } + printf("\n"); + for(i=0; i<2; i++) { + for(j=0; j<3; j++) { + printf("%d ",d->b.a[i][j]); + } + printf("\n"); + } +} + +int main(int argc, char *argv[]) { + int fd; + struct labcomm2006_decoder *decoder; + void *context = NULL; + + char *filename = argv[1]; + printf("C decoder reading from %s\n", filename); + fd = open(filename, O_RDONLY); + decoder = labcomm2006_decoder_new(labcomm2006_fd_reader_new( + labcomm2006_default_memory, fd, 1), + labcomm2006_default_error_handler, + labcomm2006_default_memory, + labcomm2006_default_scheduler); + if (!decoder) { + printf("Failed to allocate decoder %s:%d\n", __FUNCTION__, __LINE__); + return 1; + } + + labcomm2006_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context); + labcomm2006_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context); + labcomm2006_decoder_register_simple_IntString(decoder, handle_simple_IntString, context); + labcomm2006_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context); + labcomm2006_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context); + + printf("Decoding:\n"); + labcomm2006_decoder_run(decoder); + printf("--- End Of File ---:\n"); + labcomm2006_decoder_free(decoder); + + return 0; +} diff --git a/examples/simple/example_encoder06.c b/examples/simple/example_encoder06.c new file mode 100644 index 0000000..ec17f2e --- /dev/null +++ b/examples/simple/example_encoder06.c @@ -0,0 +1,85 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <labcomm2006_fd_writer.h> +#include <labcomm2006_default_error_handler.h> +#include <labcomm2006_default_memory.h> +#include <labcomm2006_default_scheduler.h> +#include "gen/simple.h" +#include <stdio.h> + +int main(int argc, char *argv[]) { + int fd; + struct labcomm2006_encoder *encoder; + + char *filename = argv[1]; + printf("C encoder writing to %s\n", filename); + fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644); + encoder = labcomm2006_encoder_new(labcomm2006_fd_writer_new( + labcomm2006_default_memory, fd, 1), + labcomm2006_default_error_handler, + labcomm2006_default_memory, + labcomm2006_default_scheduler); + labcomm2006_encoder_register_simple_theTwoInts(encoder); + labcomm2006_encoder_register_simple_anotherTwoInts(encoder); + labcomm2006_encoder_register_simple_IntString(encoder); + simple_IntString is; + is.x = 24; + is.s = "Hello, LabComm!"; + printf("Encoding IntString, x=%d, s=%s\n", is.x, is.s); + labcomm2006_encode_simple_IntString(encoder, &is); + + simple_theTwoInts ti; + ti.a = 13; + ti.b = 37; + printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b); + labcomm2006_encode_simple_theTwoInts(encoder, &ti); + + simple_anotherTwoInts ati; + ati.a = 23; + ati.b = 47; + printf("Encoding anotherTwoInts, a=%d, b=%d\n", ati.a, ati.b); + labcomm2006_encode_simple_anotherTwoInts(encoder, &ati); + + int foo[20]; + + labcomm2006_encoder_register_simple_TwoArrays(encoder); + + simple_TwoArrays ta; + ta.fixed.a[0] = 17; + ta.fixed.a[1] = 42; + ta.variable.n_1 = 10; + ta.variable.a = foo; + + int k; + for(k=0; k<20; k++) { + foo[k] = k; + } + + printf("Encoding TwoArrays...\n"); + labcomm2006_encode_simple_TwoArrays(encoder, &ta); + + ti.a = 23; + ti.b = 47; + printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b); + labcomm2006_encode_simple_theTwoInts(encoder, &ti); + + + simple_TwoFixedArrays tfa; + + tfa.a.a[0] = 41; + tfa.a.a[1] = 42; + + tfa.b.a[0][0] = 51; + tfa.b.a[0][1] = 52; + tfa.b.a[0][2] = 53; + tfa.b.a[1][0] = 61; + tfa.b.a[1][1] = 62; + tfa.b.a[1][2] = 63; + + printf("Encoding TwoFixedArrays...\n"); + labcomm2006_encoder_register_simple_TwoFixedArrays(encoder); + labcomm2006_encode_simple_TwoFixedArrays(encoder, &tfa); + + return 0; +} diff --git a/lib/c/2006/labcomm2006.c b/lib/c/2006/labcomm2006.c index 6ffce30..34c5b06 100644 --- a/lib/c/2006/labcomm2006.c +++ b/lib/c/2006/labcomm2006.c @@ -32,10 +32,10 @@ #include <stdarg.h> #include <stddef.h> -#include "labcomm.h" -#include "labcomm_private.h" -#include "labcomm_ioctl.h" -#include "labcomm_dynamic_buffer_writer.h" +#include "labcomm2006.h" +#include "labcomm2006_private.h" +#include "labcomm2006_ioctl.h" +#include "labcomm2006_dynamic_buffer_writer.h" #define LABCOMM_VERSION "LabComm2006" @@ -49,87 +49,87 @@ UNWRAP_ac( __VA_ARGS__) = UNWRAP_ac(__VA_ARGS__)->next; \ } -int labcomm_reader_alloc(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, - char *labcomm_version) +int labcomm2006_reader_alloc(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, + char *labcomm2006_version) { - UNWRAP(alloc, r, action_context, labcomm_version); + UNWRAP(alloc, r, action_context, labcomm2006_version); } -int labcomm_reader_free(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +int labcomm2006_reader_free(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context) { UNWRAP(free, r, action_context); } -int labcomm_reader_start(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, +int labcomm2006_reader_start(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, int local_index, int remote_index, - struct labcomm_signature *signature, + struct labcomm2006_signature *signature, void *value) { UNWRAP(start, r, action_context, local_index, remote_index, signature, value); } -int labcomm_reader_end(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +int labcomm2006_reader_end(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context) { UNWRAP(end, r, action_context); } -int labcomm_reader_fill(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +int labcomm2006_reader_fill(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context) { UNWRAP(fill, r, action_context); } -int labcomm_reader_ioctl(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, +int labcomm2006_reader_ioctl(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, int local_index, int remote_index, - struct labcomm_signature *signature, + 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 labcomm_writer_alloc(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - char *labcomm_version) +int labcomm2006_writer_alloc(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, + char *labcomm2006_version) { - UNWRAP(alloc, w, action_context, labcomm_version); + UNWRAP(alloc, w, action_context, labcomm2006_version); } -int labcomm_writer_free(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +int labcomm2006_writer_free(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context) { UNWRAP(free, w, action_context); } -int labcomm_writer_start(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int index, struct labcomm_signature *signature, +int labcomm2006_writer_start(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, + int index, struct labcomm2006_signature *signature, void *value) { UNWRAP(start, w, action_context, index, signature, value); } -int labcomm_writer_end(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +int labcomm2006_writer_end(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context) { UNWRAP(end, w, action_context); } -int labcomm_writer_flush(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +int labcomm2006_writer_flush(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context) { UNWRAP(flush, w, action_context); } -int labcomm_writer_ioctl(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, +int labcomm2006_writer_ioctl(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, int index, - struct labcomm_signature *signature, + struct labcomm2006_signature *signature, uint32_t ioctl_action, va_list args) { UNWRAP(ioctl, w, action_context, index, signature, ioctl_action, args); @@ -141,29 +141,30 @@ int labcomm_writer_ioctl(struct labcomm_writer *w, -static const char *labcomm_error_string[] = { +static const char *labcomm2006_error_string[] = { #define LABCOMM_ERROR(name, description) description , -#include "labcomm_error.h" +#include "labcomm2006_error.h" #undef LABCOMM_ERROR }; -static const int labcomm_error_string_count = (sizeof(labcomm_error_string) / - sizeof(labcomm_error_string[0])); +static const int labcomm2006_error_string_count = (sizeof(labcomm2006_error_string) / + sizeof(labcomm2006_error_string[0])); -const char *labcomm_error_get_str(enum labcomm_error error_id) +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 < labcomm_error_string_count) { - error_str = labcomm_error_string[error_id]; + if (error_id < labcomm2006_error_string_count) { + error_str = labcomm2006_error_string[error_id]; } return error_str; } -void on_error_fprintf(enum labcomm_error error_id, size_t nbr_va_args, ...) +#if 0 //XXX hack to avoid name clash. is this really the same as in 2013? +void on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...) { #ifndef LABCOMM_NO_STDIO - const char *err_msg = labcomm_error_get_str(error_id); // The final string to print. + 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."; } @@ -184,6 +185,7 @@ void on_error_fprintf(enum labcomm_error error_id, size_t nbr_va_args, ...) ; // If labcomm can't be compiled with stdio the user will have to make an own error callback functionif he/she needs error reporting. #endif } +#endif @@ -203,14 +205,14 @@ static void dump(void *p, int size, int first, int last) } #endif -void *labcomm_signature_array_ref(struct labcomm_memory *memory, +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 = labcomm_memory_alloc(memory, 0, size); + *data = labcomm2006_memory_alloc(memory, 0, size); if (*data) { memset(*data, 0, size); } @@ -222,7 +224,7 @@ void *labcomm_signature_array_ref(struct labcomm_memory *memory, *first = (index<old_first)?index:old_first; *last = (old_last<=index)?index+1:old_last; n = (*last - *first); - *data = labcomm_memory_alloc(memory, 0, n * size); + *data = labcomm2006_memory_alloc(memory, 0, n * size); if (*data) { memset(*data, 0, n * size); memcpy(*data + (old_first - *first) * size, @@ -230,7 +232,7 @@ void *labcomm_signature_array_ref(struct labcomm_memory *memory, (old_last - old_first) * size); } // dump(old_data, size, old_first, old_last); - labcomm_memory_free(memory, 0, old_data); + labcomm2006_memory_free(memory, 0, old_data); } if (*data) { // dump(*data, size, *first, *last); @@ -242,20 +244,20 @@ void *labcomm_signature_array_ref(struct labcomm_memory *memory, static int local_index = 0x40; -void labcomm_set_local_index(struct labcomm_signature *signature) +void labcomm2006_set_local_index(struct labcomm2006_signature *signature) { if (signature->index != 0) { - labcomm_error_fatal_global(LABCOMM_ERROR_SIGNATURE_ALREADY_SET, + labcomm2006_error_fatal_global(LABCOMM_ERROR_SIGNATURE_ALREADY_SET, "%s", signature->name); } signature->index = local_index; local_index++; } -int labcomm_get_local_index(struct labcomm_signature *signature) +int labcomm2006_get_local_index(struct labcomm2006_signature *signature) { if (signature->index == 0) { - labcomm_error_fatal_global(LABCOMM_ERROR_SIGNATURE_NOT_SET, + labcomm2006_error_fatal_global(LABCOMM_ERROR_SIGNATURE_NOT_SET, "%s", signature->name); } return signature->index; diff --git a/lib/c/2006/labcomm2006.h b/lib/c/2006/labcomm2006.h index b83cdf8..eb7ad2c 100644 --- a/lib/c/2006/labcomm2006.h +++ b/lib/c/2006/labcomm2006.h @@ -26,20 +26,20 @@ #include <stdarg.h> #include <stdint.h> #include <unistd.h> -#include "labcomm_error.h" -#include "labcomm_scheduler.h" +#include "labcomm2006_error.h" +#include "labcomm2006_scheduler.h" /* Forward declaration */ -struct labcomm_encoder; -struct labcomm_decoder; +struct labcomm2006_encoder; +struct labcomm2006_decoder; /* * Signature entry */ -struct labcomm_signature { +struct labcomm2006_signature { int type; char *name; - int (*encoded_size)(struct labcomm_signature *, void *); // void * == encoded_sample * + int (*encoded_size)(struct labcomm2006_signature *, void *); // void * == encoded_sample * int size; unsigned char *signature; int index; @@ -59,29 +59,29 @@ struct labcomm_signature { * Optionaly other paramters can be supplied depending on what is needed * for this error ID. */ -typedef void (*labcomm_error_handler_callback)(enum labcomm_error 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 on_error_fprintf(enum labcomm_error error_id, size_t nbr_va_args, ...); +void on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...); /* Register a callback for the error handler for this encoder. */ -void labcomm_register_error_handler_encoder(struct labcomm_encoder *encoder, labcomm_error_handler_callback callback); +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 labcomm_register_error_handler_decoder(struct labcomm_decoder *decoder, labcomm_error_handler_callback callback); +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 *labcomm_error_get_str(enum labcomm_error error_id); +const char *labcomm2006_error_get_str(enum labcomm2006_error error_id); -typedef int (*labcomm_handle_new_datatype_callback)( - struct labcomm_decoder *decoder, - struct labcomm_signature *sig); +typedef int (*labcomm2006_handle_new_datatype_callback)( + struct labcomm2006_decoder *decoder, + struct labcomm2006_signature *sig); -void labcomm_decoder_register_new_datatype_handler(struct labcomm_decoder *d, - labcomm_handle_new_datatype_callback on_new_datatype); +void labcomm2006_decoder_register_new_datatype_handler(struct labcomm2006_decoder *d, + labcomm2006_handle_new_datatype_callback on_new_datatype); /* * Dynamic memory handling @@ -91,50 +91,50 @@ void labcomm_decoder_register_new_datatype_handler(struct labcomm_decoder *d, * otherwise memory will live for approximately this number of * sent/received samples */ -struct labcomm_memory; +struct labcomm2006_memory; -void *labcomm_memory_alloc(struct labcomm_memory *m, int lifetime, size_t size); -void *labcomm_memory_realloc(struct labcomm_memory *m, int lifetime, +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 labcomm_memory_free(struct labcomm_memory *m, int lifetime, void *ptr); +void labcomm2006_memory_free(struct labcomm2006_memory *m, int lifetime, void *ptr); /* * Decoder */ -struct labcomm_reader; - -struct labcomm_decoder *labcomm_decoder_new( - struct labcomm_reader *reader, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler); -void labcomm_decoder_free( - struct labcomm_decoder *decoder); -int labcomm_decoder_decode_one( - struct labcomm_decoder *decoder); -void labcomm_decoder_run( - struct labcomm_decoder *decoder); - -/* See labcomm_ioctl.h for predefined ioctl_action values */ -int labcomm_decoder_ioctl(struct labcomm_decoder *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 labcomm_writer; - -struct labcomm_encoder *labcomm_encoder_new( - struct labcomm_writer *writer, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler); -void labcomm_encoder_free( - struct labcomm_encoder *encoder); - -/* See labcomm_ioctl.h for predefined ioctl_action values */ -int labcomm_encoder_ioctl(struct labcomm_encoder *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, ...); diff --git a/lib/c/2006/labcomm2006_decoder.c b/lib/c/2006/labcomm2006_decoder.c index 0a49164..3ee2f3c 100644 --- a/lib/c/2006/labcomm2006_decoder.c +++ b/lib/c/2006/labcomm2006_decoder.c @@ -1,5 +1,5 @@ /* - labcomm_decoder.c -- runtime for handling decoding of labcomm samples. + labcomm2006_decoder.c -- runtime for handling decoding of labcomm samples. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -21,40 +21,40 @@ #define LABCOMM_VERSION "LabComm2006" #include <errno.h> -#include "labcomm.h" -#include "labcomm_private.h" -#include "labcomm_ioctl.h" -#include "labcomm_dynamic_buffer_writer.h" +#include "labcomm2006.h" +#include "labcomm2006_private.h" +#include "labcomm2006_ioctl.h" +#include "labcomm2006_dynamic_buffer_writer.h" struct sample_entry { int remote_index; - struct labcomm_signature *signature; - labcomm_decoder_function decode; - labcomm_handler_function handler; + struct labcomm2006_signature *signature; + labcomm2006_decoder_function decode; + labcomm2006_handler_function handler; void *context; }; -struct labcomm_decoder { - struct labcomm_reader *reader; +struct labcomm2006_decoder { + struct labcomm2006_reader *reader; int reader_allocated; - struct labcomm_error_handler *error; - struct labcomm_memory *memory; - struct labcomm_scheduler *scheduler; - labcomm_error_handler_callback on_error; - labcomm_handle_new_datatype_callback on_new_datatype; + 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 labcomm_decoder *labcomm_decoder_new( - struct labcomm_reader *reader, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler) +struct labcomm2006_decoder *labcomm2006_decoder_new( + struct labcomm2006_reader *reader, + struct labcomm2006_error_handler *error, + struct labcomm2006_memory *memory, + struct labcomm2006_scheduler *scheduler) { - struct labcomm_decoder *result; + struct labcomm2006_decoder *result; - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); + result = labcomm2006_memory_alloc(memory, 0, sizeof(*result)); if (result) { result->reader = reader; result->reader->decoder = result; @@ -73,39 +73,39 @@ struct labcomm_decoder *labcomm_decoder_new( return result; } -void labcomm_decoder_free(struct labcomm_decoder* d) +void labcomm2006_decoder_free(struct labcomm2006_decoder* d) { - struct labcomm_memory *memory = d->memory; + struct labcomm2006_memory *memory = d->memory; - labcomm_reader_free(d->reader, d->reader->action_context); + 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); - labcomm_memory_free(memory, 0, d); + labcomm2006_memory_free(memory, 0, d); } static int collect_flat_signature( - struct labcomm_decoder *decoder, - struct labcomm_writer *writer) + struct labcomm2006_decoder *decoder, + struct labcomm2006_writer *writer) { int result, type; - type = labcomm_read_packed32(decoder->reader); + type = labcomm2006_read_packed32(decoder->reader); result = decoder->reader->error; if (result < 0) { goto out; } if (type >= LABCOMM_USER) { decoder->on_error(LABCOMM_ERROR_UNIMPLEMENTED_FUNC, 3, "Implement %s ... (1) for type 0x%x\n", __FUNCTION__, type); } else { - labcomm_write_packed32(writer, type); + labcomm2006_write_packed32(writer, type); switch (type) { case LABCOMM_ARRAY: { int dimensions, i; - dimensions = labcomm_read_packed32(decoder->reader); - labcomm_write_packed32(writer, dimensions); + dimensions = labcomm2006_read_packed32(decoder->reader); + labcomm2006_write_packed32(writer, dimensions); for (i = 0 ; i < dimensions ; i++) { - int n = labcomm_read_packed32(decoder->reader); - labcomm_write_packed32(writer, n); + int n = labcomm2006_read_packed32(decoder->reader); + labcomm2006_write_packed32(writer, n); } result = collect_flat_signature(decoder, writer); if (result < 0) { goto out; } @@ -113,12 +113,12 @@ static int collect_flat_signature( case LABCOMM_STRUCT: { int fields, i; - fields = labcomm_read_packed32(decoder->reader); - labcomm_write_packed32(writer, fields); + fields = labcomm2006_read_packed32(decoder->reader); + labcomm2006_write_packed32(writer, fields); for (i = 0 ; i < fields ; i++) { - char *name = labcomm_read_string(decoder->reader); - labcomm_write_string(writer, name); - labcomm_memory_free(decoder->memory, 1, name); + 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; } } @@ -143,7 +143,7 @@ out: return result; } -static int writer_ioctl(struct labcomm_writer *writer, +static int writer_ioctl(struct labcomm2006_writer *writer, uint32_t action, ...) { @@ -156,25 +156,25 @@ static int writer_ioctl(struct labcomm_writer *writer, } va_start(va, action); - result = labcomm_writer_ioctl(writer, writer->action_context, + 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 labcomm_decoder *d, int kind) +static int decode_typedef_or_sample(struct labcomm2006_decoder *d, int kind) { int result; - /* TODO: should the labcomm_dynamic_buffer_writer be - a permanent part of labcomm_decoder? */ - struct labcomm_writer_action_context action_context = { + /* TODO: should the labcomm2006_dynamic_buffer_writer be + a permanent part of labcomm2006_decoder? */ + struct labcomm2006_writer_action_context action_context = { .next = NULL, - .action = labcomm_dynamic_buffer_writer_action, + .action = labcomm2006_dynamic_buffer_writer_action, .context = NULL }; - struct labcomm_writer writer = { + struct labcomm2006_writer writer = { .action_context = &action_context, .memory = d->memory, .data = NULL, @@ -183,18 +183,18 @@ static int decode_typedef_or_sample(struct labcomm_decoder *d, int kind) .pos = 0, .error = 0, }; - struct labcomm_signature signature, *local_signature; + struct labcomm2006_signature signature, *local_signature; int remote_index, local_index, err; local_signature = NULL; local_index = 0; - labcomm_writer_alloc(&writer, writer.action_context, ""); - labcomm_writer_start(&writer, writer.action_context, 0, NULL, NULL); - remote_index = labcomm_read_packed32(d->reader); - signature.name = labcomm_read_string(d->reader); + 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); signature.type = kind; collect_flat_signature(d, &writer); - labcomm_writer_end(&writer, writer.action_context); + labcomm2006_writer_end(&writer, writer.action_context); err = writer_ioctl(&writer, LABCOMM_IOCTL_WRITER_GET_BYTES_WRITTEN, &signature.size); @@ -214,7 +214,7 @@ static int decode_typedef_or_sample(struct labcomm_decoder *d, int kind) { int i; - labcomm_scheduler_data_lock(d->scheduler); + labcomm2006_scheduler_data_lock(d->scheduler); LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local, struct sample_entry, i) { struct sample_entry *s; int *remote_to_local; @@ -239,12 +239,12 @@ static int decode_typedef_or_sample(struct labcomm_decoder *d, int kind) break; } } - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2006_scheduler_data_unlock(d->scheduler); if (local_signature) { - labcomm_reader_start(d->reader, d->reader->action_context, + labcomm2006_reader_start(d->reader, d->reader->action_context, local_index, remote_index, local_signature, NULL); - labcomm_reader_end(d->reader, d->reader->action_context); + labcomm2006_reader_end(d->reader, d->reader->action_context); } } #if 0 @@ -259,17 +259,17 @@ static int decode_typedef_or_sample(struct labcomm_decoder *d, int kind) result = -ENOENT; #endif free_signature_name: - labcomm_memory_free(d->memory, 0, signature.name); - labcomm_writer_free(&writer, writer.action_context); + labcomm2006_memory_free(d->memory, 0, signature.name); + labcomm2006_writer_free(&writer, writer.action_context); return result; } struct call_handler_context { - struct labcomm_reader *reader; + struct labcomm2006_reader *reader; int local_index; int remote_index; - struct labcomm_signature *signature; - labcomm_handler_function handler; + struct labcomm2006_signature *signature; + labcomm2006_handler_function handler; void *context; }; @@ -278,29 +278,29 @@ static void call_handler(void *value, void *context) struct call_handler_context *wrap = context; if (wrap->reader->error >= 0) { - labcomm_reader_start(wrap->reader, wrap->reader->action_context, + labcomm2006_reader_start(wrap->reader, wrap->reader->action_context, wrap->local_index, wrap->remote_index, wrap->signature, value); wrap->handler(value, wrap->context); - labcomm_reader_end(wrap->reader, wrap->reader->action_context); + labcomm2006_reader_end(wrap->reader, wrap->reader->action_context); } } -static void reader_alloc(struct labcomm_decoder *d) +static void reader_alloc(struct labcomm2006_decoder *d) { if (!d->reader_allocated) { d->reader_allocated = 1; - labcomm_reader_alloc(d->reader, d->reader->action_context, + labcomm2006_reader_alloc(d->reader, d->reader->action_context, LABCOMM_VERSION); } } -int labcomm_decoder_decode_one(struct labcomm_decoder *d) +int labcomm2006_decoder_decode_one(struct labcomm2006_decoder *d) { int result, remote_index; reader_alloc(d); - remote_index = labcomm_read_packed32(d->reader); + remote_index = labcomm2006_read_packed32(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto out; @@ -316,9 +316,9 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d) .handler = NULL, .context = NULL, }; - labcomm_decoder_function do_decode = NULL; + labcomm2006_decoder_function do_decode = NULL; - labcomm_scheduler_data_lock(d->scheduler); + labcomm2006_scheduler_data_lock(d->scheduler); local_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, d->remote_to_local, int, remote_index); @@ -335,7 +335,7 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d) do_decode = entry->decode; result = *local_index; } - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2006_scheduler_data_unlock(d->scheduler); if (do_decode) { do_decode(d->reader, call_handler, &wrap); if (d->reader->error < 0) { @@ -349,13 +349,13 @@ out: return result; } -void labcomm_decoder_run(struct labcomm_decoder *d) +void labcomm2006_decoder_run(struct labcomm2006_decoder *d) { - while (labcomm_decoder_decode_one(d) > 0) { + while (labcomm2006_decoder_decode_one(d) > 0) { } } -int labcomm_decoder_ioctl(struct labcomm_decoder *d, +int labcomm2006_decoder_ioctl(struct labcomm2006_decoder *d, uint32_t action, ...) { @@ -363,52 +363,52 @@ int labcomm_decoder_ioctl(struct labcomm_decoder *d, va_list va; va_start(va, action); - result = labcomm_reader_ioctl(d->reader, + result = labcomm2006_reader_ioctl(d->reader, d->reader->action_context, 0, 0, NULL, action, va); va_end(va); return result; } -int labcomm_internal_decoder_ioctl(struct labcomm_decoder *d, - struct labcomm_signature *signature, +int labcomm2006_internal_decoder_ioctl(struct labcomm2006_decoder *d, + struct labcomm2006_signature *signature, uint32_t action, va_list va) { int result; int local_index, remote_index; - local_index = labcomm_get_local_index(signature); - labcomm_scheduler_data_lock(d->scheduler); + 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; - labcomm_scheduler_data_unlock(d->scheduler); - result = labcomm_reader_ioctl(d->reader, d->reader->action_context, + 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 labcomm_internal_decoder_register( - struct labcomm_decoder *d, - struct labcomm_signature *signature, - labcomm_decoder_function decode, - labcomm_handler_function handler, +int labcomm2006_internal_decoder_register( + struct labcomm2006_decoder *d, + 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 = labcomm_get_local_index(signature); + local_index = labcomm2006_get_local_index(signature); if (local_index <= 0) { goto out; } - labcomm_reader_start(d->reader, d->reader->action_context, + labcomm2006_reader_start(d->reader, d->reader->action_context, local_index, 0, signature, NULL); - labcomm_reader_end(d->reader, d->reader->action_context); + labcomm2006_reader_end(d->reader, d->reader->action_context); - labcomm_scheduler_data_lock(d->scheduler); + labcomm2006_scheduler_data_lock(d->scheduler); entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, d->local, struct sample_entry, local_index); @@ -419,7 +419,7 @@ int labcomm_internal_decoder_register( entry->handler = handler; entry->context = context; unlock: - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2006_scheduler_data_unlock(d->scheduler); out: return local_index; } diff --git a/lib/c/2006/labcomm2006_default_error_handler.c b/lib/c/2006/labcomm2006_default_error_handler.c index 61e04dd..ad8acd3 100644 --- a/lib/c/2006/labcomm2006_default_error_handler.c +++ b/lib/c/2006/labcomm2006_default_error_handler.c @@ -19,6 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "labcomm.h" +#include "labcomm2006.h" -struct labcomm_error_handler *labcomm_default_error_handler = NULL; +struct labcomm2006_error_handler *labcomm2006_default_error_handler = NULL; diff --git a/lib/c/2006/labcomm2006_default_error_handler.h b/lib/c/2006/labcomm2006_default_error_handler.h index 4cd642a..b8254f8 100644 --- a/lib/c/2006/labcomm2006_default_error_handler.h +++ b/lib/c/2006/labcomm2006_default_error_handler.h @@ -19,6 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "labcomm.h" +#include "labcomm2006.h" -extern struct labcomm_error_handler *labcomm_default_error_handler; +extern struct labcomm2006_error_handler *labcomm2006_default_error_handler; diff --git a/lib/c/2006/labcomm2006_default_memory.c b/lib/c/2006/labcomm2006_default_memory.c index d6b13c5..85a9ee0 100644 --- a/lib/c/2006/labcomm2006_default_memory.c +++ b/lib/c/2006/labcomm2006_default_memory.c @@ -20,30 +20,30 @@ */ #include <stdlib.h> -#include "labcomm.h" -#include "labcomm_private.h" +#include "labcomm2006.h" +#include "labcomm2006_private.h" -void *default_alloc(struct labcomm_memory *m, int lifetime, size_t size) +void *default_alloc2006(struct labcomm2006_memory *m, int lifetime, size_t size) { return malloc(size); } -void *default_realloc(struct labcomm_memory *m, int lifetime, +void *default_realloc2006(struct labcomm2006_memory *m, int lifetime, void *ptr, size_t size) { return realloc(ptr, size); } -void default_free(struct labcomm_memory *m, int lifetime, void *ptr) +void default_free2006(struct labcomm2006_memory *m, int lifetime, void *ptr) { free(ptr); } -struct labcomm_memory memory = { - .alloc = default_alloc, - .realloc = default_realloc, - .free = default_free, +struct labcomm2006_memory memory2006 = { + .alloc = default_alloc2006, + .realloc = default_realloc2006, + .free = default_free2006, .context = NULL }; -struct labcomm_memory *labcomm_default_memory = &memory; +struct labcomm2006_memory *labcomm2006_default_memory = &memory2006; diff --git a/lib/c/2006/labcomm2006_default_memory.h b/lib/c/2006/labcomm2006_default_memory.h index 0911209..86b97f8 100644 --- a/lib/c/2006/labcomm2006_default_memory.h +++ b/lib/c/2006/labcomm2006_default_memory.h @@ -20,8 +20,8 @@ */ #include <stdlib.h> -#include "labcomm.h" -#include "labcomm_private.h" +#include "labcomm2006.h" +#include "labcomm2006_private.h" -extern struct labcomm_memory *labcomm_default_memory; +extern struct labcomm2006_memory *labcomm2006_default_memory; diff --git a/lib/c/2006/labcomm2006_default_scheduler.c b/lib/c/2006/labcomm2006_default_scheduler.c index a567b61..5db88cd 100644 --- a/lib/c/2006/labcomm2006_default_scheduler.c +++ b/lib/c/2006/labcomm2006_default_scheduler.c @@ -21,11 +21,11 @@ #include <stdio.h> #include <stdlib.h> -#include "labcomm_default_scheduler.h" -#include "labcomm_scheduler.h" -#include "labcomm_scheduler_private.h" +#include "labcomm2006_default_scheduler.h" +#include "labcomm2006_scheduler.h" +#include "labcomm2006_scheduler_private.h" -static int scheduler_free(struct labcomm_scheduler *s) +static int scheduler_free(struct labcomm2006_scheduler *s) { fprintf(stderr, "%s:%d %s %s", __FILE__, __LINE__, __FUNCTION__, "not implemented"); @@ -33,27 +33,27 @@ static int scheduler_free(struct labcomm_scheduler *s) return 0; } -static int scheduler_writer_lock(struct labcomm_scheduler *s) +static int scheduler_writer_lock(struct labcomm2006_scheduler *s) { return 0; } -static int scheduler_writer_unlock(struct labcomm_scheduler *s) +static int scheduler_writer_unlock(struct labcomm2006_scheduler *s) { return 0; } -static int scheduler_data_lock(struct labcomm_scheduler *s) +static int scheduler_data_lock(struct labcomm2006_scheduler *s) { return 0; } -static int scheduler_data_unlock(struct labcomm_scheduler *s) +static int scheduler_data_unlock(struct labcomm2006_scheduler *s) { return 0; } -static struct labcomm_time *scheduler_now(struct labcomm_scheduler *s) +static struct labcomm2006_time *scheduler_now(struct labcomm2006_scheduler *s) { fprintf(stderr, "%s:%d %s %s", __FILE__, __LINE__, __FUNCTION__, "not implemented"); @@ -61,8 +61,8 @@ static struct labcomm_time *scheduler_now(struct labcomm_scheduler *s) return NULL; } -static int scheduler_sleep(struct labcomm_scheduler *s, - struct labcomm_time *t) +static int scheduler_sleep(struct labcomm2006_scheduler *s, + struct labcomm2006_time *t) { fprintf(stderr, "%s:%d %s %s", __FILE__, __LINE__, __FUNCTION__, "not implemented"); @@ -70,7 +70,7 @@ static int scheduler_sleep(struct labcomm_scheduler *s, return 0; } -static int scheduler_wakeup(struct labcomm_scheduler *s) +static int scheduler_wakeup(struct labcomm2006_scheduler *s) { fprintf(stderr, "%s:%d %s %s", __FILE__, __LINE__, __FUNCTION__, "not implemented"); @@ -78,7 +78,7 @@ static int scheduler_wakeup(struct labcomm_scheduler *s) return 0; } -static int scheduler_enqueue(struct labcomm_scheduler *s, +static int scheduler_enqueue(struct labcomm2006_scheduler *s, uint32_t delay, void (*deferred)(void *context), void *context) @@ -89,7 +89,7 @@ static int scheduler_enqueue(struct labcomm_scheduler *s, return 0; } -static const struct labcomm_scheduler_action scheduler_action = { +static const struct labcomm2006_scheduler_action scheduler_action = { .free = scheduler_free, .writer_lock = scheduler_writer_lock, .writer_unlock = scheduler_writer_unlock, @@ -101,9 +101,9 @@ static const struct labcomm_scheduler_action scheduler_action = { .enqueue = scheduler_enqueue }; -static struct labcomm_scheduler scheduler = { +static struct labcomm2006_scheduler scheduler = { .action = &scheduler_action, .context = NULL }; -struct labcomm_scheduler *labcomm_default_scheduler = &scheduler; +struct labcomm2006_scheduler *labcomm2006_default_scheduler = &scheduler; diff --git a/lib/c/2006/labcomm2006_default_scheduler.h b/lib/c/2006/labcomm2006_default_scheduler.h index 923ea20..bd271f0 100644 --- a/lib/c/2006/labcomm2006_default_scheduler.h +++ b/lib/c/2006/labcomm2006_default_scheduler.h @@ -19,6 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "labcomm.h" +#include "labcomm2006.h" -extern struct labcomm_scheduler *labcomm_default_scheduler; +extern struct labcomm2006_scheduler *labcomm2006_default_scheduler; diff --git a/lib/c/2006/labcomm2006_dynamic_buffer_writer.c b/lib/c/2006/labcomm2006_dynamic_buffer_writer.c index 3a7425d..02acb62 100644 --- a/lib/c/2006/labcomm2006_dynamic_buffer_writer.c +++ b/lib/c/2006/labcomm2006_dynamic_buffer_writer.c @@ -1,5 +1,5 @@ /* - labcomm_dynamic_buffer_writer.c -- LabComm dynamic memory writer. + labcomm2006_dynamic_buffer_writer.c -- LabComm dynamic memory writer. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,18 +22,18 @@ #include <errno.h> #include <stdlib.h> #include <stdarg.h> -#include "labcomm.h" -#include "labcomm_private.h" -#include "labcomm_ioctl.h" -#include "labcomm_dynamic_buffer_writer.h" - -static int dyn_alloc(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - char *labcomm_version) +#include "labcomm2006.h" +#include "labcomm2006_private.h" +#include "labcomm2006_ioctl.h" +#include "labcomm2006_dynamic_buffer_writer.h" + +static int dyn_alloc(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, + char *labcomm2006_version) { w->data_size = 1000; w->count = w->data_size; - w->data = labcomm_memory_alloc(w->memory, 1, w->data_size); + w->data = labcomm2006_memory_alloc(w->memory, 1, w->data_size); if (w->data == NULL) { w->error = -ENOMEM; } @@ -42,29 +42,29 @@ static int dyn_alloc(struct labcomm_writer *w, return w->error; } -static int dyn_free(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +static int dyn_free(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context) { - labcomm_memory_free(w->memory, 1, w->data); + labcomm2006_memory_free(w->memory, 1, w->data); w->data = 0; w->data_size = 0; w->count = 0; w->pos = 0; - labcomm_memory_free(w->memory, 0, action_context->context); + labcomm2006_memory_free(w->memory, 0, action_context->context); return 0; } -static int dyn_start(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, +static int dyn_start(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, int index, - struct labcomm_signature *signature, + struct labcomm2006_signature *signature, void *value) { void *tmp; w->data_size = 1000; w->count = w->data_size; - tmp = labcomm_memory_realloc(w->memory, 1, w->data, w->data_size); + tmp = labcomm2006_memory_realloc(w->memory, 1, w->data, w->data_size); if (tmp != NULL) { w->data = tmp; w->error = 0; @@ -76,20 +76,20 @@ static int dyn_start(struct labcomm_writer *w, return w->error; } -static int dyn_end(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +static int dyn_end(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context) { return 0; } -static int dyn_flush(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +static int dyn_flush(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context) { void *tmp; w->data_size += 1000; w->count = w->data_size; - tmp = labcomm_memory_realloc(w->memory, 1, w->data, w->data_size); + tmp = labcomm2006_memory_realloc(w->memory, 1, w->data, w->data_size); if (tmp != NULL) { w->data = tmp; w->error = 0; @@ -101,10 +101,10 @@ static int dyn_flush(struct labcomm_writer *w, return w->error; } -static int dyn_ioctl(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, +static int dyn_ioctl(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, int signature_index, - struct labcomm_signature *signature, + struct labcomm2006_signature *signature, uint32_t action, va_list arg) { int result = -ENOTSUP; @@ -123,7 +123,7 @@ static int dyn_ioctl(struct labcomm_writer *w, return result; } -static const struct labcomm_writer_action action = { +static const struct labcomm2006_writer_action action = { .alloc = dyn_alloc, .free = dyn_free, .start = dyn_start, @@ -131,18 +131,18 @@ static const struct labcomm_writer_action action = { .flush = dyn_flush, .ioctl = dyn_ioctl }; -const struct labcomm_writer_action *labcomm_dynamic_buffer_writer_action = +const struct labcomm2006_writer_action *labcomm2006_dynamic_buffer_writer_action = &action; -struct labcomm_writer *labcomm_dynamic_buffer_writer_new( - struct labcomm_memory *memory) +struct labcomm2006_writer *labcomm2006_dynamic_buffer_writer_new( + struct labcomm2006_memory *memory) { struct result { - struct labcomm_writer writer; - struct labcomm_writer_action_context action_context; + struct labcomm2006_writer writer; + struct labcomm2006_writer_action_context action_context; } *result; - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); + result = labcomm2006_memory_alloc(memory, 0, sizeof(*result)); if (result != NULL) { result->action_context.next = NULL; result->action_context.context = result; diff --git a/lib/c/2006/labcomm2006_dynamic_buffer_writer.h b/lib/c/2006/labcomm2006_dynamic_buffer_writer.h index 53a65d4..c0ab9d0 100644 --- a/lib/c/2006/labcomm2006_dynamic_buffer_writer.h +++ b/lib/c/2006/labcomm2006_dynamic_buffer_writer.h @@ -1,5 +1,5 @@ /* - labcomm_dynamic_buffer_writer.h -- LabComm dynamic memory writer. + labcomm2006_dynamic_buffer_writer.h -- LabComm dynamic memory writer. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,11 +22,11 @@ #ifndef _LABCOMM_DYNAMIC_BUFFER_READER_WRITER_H_ #define _LABCOMM_DYNAMIC_BUFFER_READER_WRITER_H_ -#include "labcomm.h" +#include "labcomm2006.h" -extern const struct labcomm_writer_action *labcomm_dynamic_buffer_writer_action; +extern const struct labcomm2006_writer_action *labcomm2006_dynamic_buffer_writer_action; -struct labcomm_writer *labcomm_dynamic_buffer_writer_new( - struct labcomm_memory *memory); +struct labcomm2006_writer *labcomm2006_dynamic_buffer_writer_new( + struct labcomm2006_memory *memory); #endif diff --git a/lib/c/2006/labcomm2006_encoder.c b/lib/c/2006/labcomm2006_encoder.c index 47e6320..a84f82a 100644 --- a/lib/c/2006/labcomm2006_encoder.c +++ b/lib/c/2006/labcomm2006_encoder.c @@ -1,5 +1,5 @@ /* - labcomm_encoder.c -- handling encoding of labcomm samples. + labcomm2006_encoder.c -- handling encoding of labcomm samples. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -21,27 +21,27 @@ #define LABCOMM_VERSION "LabComm2006" #include <errno.h> -#include "labcomm.h" -#include "labcomm_private.h" -#include "labcomm_ioctl.h" - -struct labcomm_encoder { - struct labcomm_writer *writer; - struct labcomm_error_handler *error; - struct labcomm_memory *memory; - struct labcomm_scheduler *scheduler; +#include "labcomm2006.h" +#include "labcomm2006_private.h" +#include "labcomm2006_ioctl.h" + +struct labcomm2006_encoder { + struct labcomm2006_writer *writer; + struct labcomm2006_error_handler *error; + struct labcomm2006_memory *memory; + struct labcomm2006_scheduler *scheduler; LABCOMM_SIGNATURE_ARRAY_DEF(registered, int); }; -struct labcomm_encoder *labcomm_encoder_new( - struct labcomm_writer *writer, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler) +struct labcomm2006_encoder *labcomm2006_encoder_new( + struct labcomm2006_writer *writer, + struct labcomm2006_error_handler *error, + struct labcomm2006_memory *memory, + struct labcomm2006_scheduler *scheduler) { - struct labcomm_encoder *result; + struct labcomm2006_encoder *result; - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); + result = labcomm2006_memory_alloc(memory, 0, sizeof(*result)); if (result) { result->writer = writer; result->writer->encoder = result; @@ -54,83 +54,83 @@ struct labcomm_encoder *labcomm_encoder_new( result->memory = memory; result->scheduler = scheduler; LABCOMM_SIGNATURE_ARRAY_INIT(result->registered, int); - labcomm_writer_alloc(result->writer, + labcomm2006_writer_alloc(result->writer, result->writer->action_context, LABCOMM_VERSION); } return result; } -void labcomm_encoder_free(struct labcomm_encoder* e) +void labcomm2006_encoder_free(struct labcomm2006_encoder* e) { - struct labcomm_memory *memory = e->memory; + struct labcomm2006_memory *memory = e->memory; - labcomm_writer_free(e->writer, e->writer->action_context); + labcomm2006_writer_free(e->writer, e->writer->action_context); LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, e->registered, int); - labcomm_memory_free(memory, 0, e); + labcomm2006_memory_free(memory, 0, e); } -int labcomm_internal_encoder_register( - struct labcomm_encoder *e, - struct labcomm_signature *signature, - labcomm_encoder_function encode) +int labcomm2006_internal_encoder_register( + struct labcomm2006_encoder *e, + struct labcomm2006_signature *signature, + labcomm2006_encoder_function encode) { int result = -EINVAL; int index, *done, err, i; - index = labcomm_get_local_index(signature); - labcomm_scheduler_writer_lock(e->scheduler); + index = labcomm2006_get_local_index(signature); + labcomm2006_scheduler_writer_lock(e->scheduler); if (signature->type != LABCOMM_SAMPLE) { goto out; } if (index <= 0) { goto out; } done = LABCOMM_SIGNATURE_ARRAY_REF(e->memory, e->registered, int, index); if (*done) { goto out; } *done = 1; - err = labcomm_writer_start(e->writer, e->writer->action_context, + err = labcomm2006_writer_start(e->writer, e->writer->action_context, index, signature, NULL); if (err == -EALREADY) { result = 0; goto out; } if (err != 0) { result = err; goto out; } - labcomm_write_packed32(e->writer, signature->type); - labcomm_write_packed32(e->writer, index); - labcomm_write_string(e->writer, signature->name); + labcomm2006_write_packed32(e->writer, signature->type); + labcomm2006_write_packed32(e->writer, index); + labcomm2006_write_string(e->writer, signature->name); for (i = 0 ; i < signature->size ; i++) { if (e->writer->pos >= e->writer->count) { - labcomm_writer_flush(e->writer, e->writer->action_context); + labcomm2006_writer_flush(e->writer, e->writer->action_context); } e->writer->data[e->writer->pos] = signature->signature[i]; e->writer->pos++; } - labcomm_writer_end(e->writer, e->writer->action_context); + labcomm2006_writer_end(e->writer, e->writer->action_context); result = e->writer->error; out: - labcomm_scheduler_writer_unlock(e->scheduler); + labcomm2006_scheduler_writer_unlock(e->scheduler); return result; } -int labcomm_internal_encode( - struct labcomm_encoder *e, - struct labcomm_signature *signature, - labcomm_encoder_function encode, +int labcomm2006_internal_encode( + struct labcomm2006_encoder *e, + struct labcomm2006_signature *signature, + labcomm2006_encoder_function encode, void *value) { int result; int index; - index = labcomm_get_local_index(signature); - labcomm_scheduler_writer_lock(e->scheduler); - result = labcomm_writer_start(e->writer, e->writer->action_context, + index = labcomm2006_get_local_index(signature); + labcomm2006_scheduler_writer_lock(e->scheduler); + result = labcomm2006_writer_start(e->writer, e->writer->action_context, index, signature, value); if (result == -EALREADY) { result = 0; goto no_end; } if (result != 0) { goto out; } - result = labcomm_write_packed32(e->writer, index); + result = labcomm2006_write_packed32(e->writer, index); if (result != 0) { goto out; } result = encode(e->writer, value); out: - labcomm_writer_end(e->writer, e->writer->action_context); + labcomm2006_writer_end(e->writer, e->writer->action_context); no_end: - labcomm_scheduler_writer_unlock(e->scheduler); + labcomm2006_scheduler_writer_unlock(e->scheduler); return result; } -int labcomm_encoder_ioctl(struct labcomm_encoder *encoder, +int labcomm2006_encoder_ioctl(struct labcomm2006_encoder *encoder, uint32_t action, ...) { @@ -143,7 +143,7 @@ int labcomm_encoder_ioctl(struct labcomm_encoder *encoder, } va_start(va, action); - result = labcomm_writer_ioctl(encoder->writer, + result = labcomm2006_writer_ioctl(encoder->writer, encoder->writer->action_context, 0, NULL, action, va); va_end(va); @@ -152,15 +152,15 @@ out: return result; } -int labcomm_internal_encoder_ioctl(struct labcomm_encoder *encoder, - struct labcomm_signature *signature, +int labcomm2006_internal_encoder_ioctl(struct labcomm2006_encoder *encoder, + struct labcomm2006_signature *signature, uint32_t action, va_list va) { int result = -ENOTSUP; int index; - index = labcomm_get_local_index(signature); - result = labcomm_writer_ioctl(encoder->writer, + index = labcomm2006_get_local_index(signature); + result = labcomm2006_writer_ioctl(encoder->writer, encoder->writer->action_context, index, signature, action, va); return result; diff --git a/lib/c/2006/labcomm2006_error.c b/lib/c/2006/labcomm2006_error.c index 278c5f3..079c812 100644 --- a/lib/c/2006/labcomm2006_error.c +++ b/lib/c/2006/labcomm2006_error.c @@ -1,5 +1,5 @@ /* - labcomm_error.c -- labcomm error handling + labcomm2006_error.c -- labcomm error handling Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -21,9 +21,9 @@ #include <stdlib.h> #include <stdio.h> -#include "labcomm_error.h" +#include "labcomm2006_error.h" -void labcomm_error_fatal_global(enum labcomm_error error, +void labcomm2006_error_fatal_global(enum labcomm2006_error error, char *format, ...) { diff --git a/lib/c/2006/labcomm2006_error.h b/lib/c/2006/labcomm2006_error.h index dd124c9..27a0e72 100644 --- a/lib/c/2006/labcomm2006_error.h +++ b/lib/c/2006/labcomm2006_error.h @@ -1,5 +1,5 @@ /* - labcomm_error.h -- labcomm error declarations + labcomm2006_error.h -- labcomm error declarations Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,20 +22,20 @@ #ifndef __LABCOMM_ERROR_H__ #define __LABCOMM_ERROR_H__ -enum labcomm_error { +enum labcomm2006_error { #define LABCOMM_ERROR(name, description) name , -#include "labcomm_error.h" +#include "labcomm2006_error.h" #undef LABCOMM_ERROR }; -struct labcomm_error_handler; +struct labcomm2006_error_handler; -void labcomm_error_warning(struct labcomm_error_handler *e, - enum labcomm_error, +void labcomm2006_error_warning(struct labcomm2006_error_handler *e, + enum labcomm2006_error, char *format, ...); -void labcomm_error_fatal_global(enum labcomm_error error, +void labcomm2006_error_fatal_global(enum labcomm2006_error error, char *format, ...); diff --git a/lib/c/2006/labcomm2006_fd_reader.c b/lib/c/2006/labcomm2006_fd_reader.c index e397c84..a934832 100644 --- a/lib/c/2006/labcomm2006_fd_reader.c +++ b/lib/c/2006/labcomm2006_fd_reader.c @@ -1,5 +1,5 @@ /* - labcomm_fd_reader.c -- LabComm reader for Unix file descriptors. + labcomm2006_fd_reader.c -- LabComm reader for Unix file descriptors. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -23,27 +23,27 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> -#include "labcomm_private.h" -#include "labcomm_fd_reader.h" +#include "labcomm2006_private.h" +#include "labcomm2006_fd_reader.h" #define BUFFER_SIZE 2048 -struct labcomm_fd_reader { - struct labcomm_reader reader; - struct labcomm_reader_action_context action_context; +struct labcomm2006_fd_reader { + struct labcomm2006_reader reader; + struct labcomm2006_reader_action_context action_context; int fd; int close_fd_on_free; }; -static int fd_alloc(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, +static int fd_alloc(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, char *version) { int result = 0; r->count = 0; r->pos = 0; - r->data = labcomm_memory_alloc(r->memory, 0, BUFFER_SIZE); + r->data = labcomm2006_memory_alloc(r->memory, 0, BUFFER_SIZE); if (! r->data) { r->data_size = 0; result = -ENOMEM; @@ -54,25 +54,25 @@ static int fd_alloc(struct labcomm_reader *r, if (version && version[0]) { char *tmp; - tmp = labcomm_read_string(r); + tmp = labcomm2006_read_string(r); if (strcmp(tmp, version) != 0) { result = -EINVAL; } else { result = r->data_size; } - labcomm_memory_free(r->memory, 1, tmp); + labcomm2006_memory_free(r->memory, 1, tmp); } } return result; } -static int fd_free(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +static int fd_free(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context) { - struct labcomm_fd_reader *fd_reader = action_context->context; - struct labcomm_memory *memory = r->memory; + struct labcomm2006_fd_reader *fd_reader = action_context->context; + struct labcomm2006_memory *memory = r->memory; - labcomm_memory_free(memory, 0, r->data); + labcomm2006_memory_free(memory, 0, r->data); r->data = 0; r->data_size = 0; r->count = 0; @@ -81,16 +81,16 @@ static int fd_free(struct labcomm_reader *r, if (fd_reader->close_fd_on_free) { close(fd_reader->fd); } - labcomm_memory_free(memory, 0, fd_reader); + labcomm2006_memory_free(memory, 0, fd_reader); return 0; } -static int fd_fill(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +static int fd_fill(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context) { int result = 0; - struct labcomm_fd_reader *fd_reader = action_context->context; + struct labcomm2006_fd_reader *fd_reader = action_context->context; if (r->pos < r->count) { result = r->count - r->pos; @@ -111,7 +111,7 @@ static int fd_fill(struct labcomm_reader *r, return result; } -static const struct labcomm_reader_action action = { +static const struct labcomm2006_reader_action action = { .alloc = fd_alloc, .free = fd_free, .start = NULL, @@ -120,12 +120,12 @@ static const struct labcomm_reader_action action = { .ioctl = NULL }; -struct labcomm_reader *labcomm_fd_reader_new(struct labcomm_memory *memory, +struct labcomm2006_reader *labcomm2006_fd_reader_new(struct labcomm2006_memory *memory, int fd, int close_fd_on_free) { - struct labcomm_fd_reader *result; + struct labcomm2006_fd_reader *result; - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); + result = labcomm2006_memory_alloc(memory, 0, sizeof(*result)); if (result == NULL) { return NULL; } else { diff --git a/lib/c/2006/labcomm2006_fd_reader.h b/lib/c/2006/labcomm2006_fd_reader.h index b04aa8e..066ac81 100644 --- a/lib/c/2006/labcomm2006_fd_reader.h +++ b/lib/c/2006/labcomm2006_fd_reader.h @@ -1,5 +1,5 @@ /* - labcomm_fd_reader.c -- a reader for unix style file-descriptors + labcomm2006_fd_reader.c -- a reader for unix style file-descriptors Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,9 +22,9 @@ #ifndef _LABCOMM_FD_READER_H_ #define _LABCOMM_FD_READER_H_ -#include "labcomm.h" +#include "labcomm2006.h" -struct labcomm_reader *labcomm_fd_reader_new(struct labcomm_memory *memory, +struct labcomm2006_reader *labcomm2006_fd_reader_new(struct labcomm2006_memory *memory, int fd, int close_fd_on_free); #endif diff --git a/lib/c/2006/labcomm2006_fd_writer.c b/lib/c/2006/labcomm2006_fd_writer.c index acf6934..159fa30 100644 --- a/lib/c/2006/labcomm2006_fd_writer.c +++ b/lib/c/2006/labcomm2006_fd_writer.c @@ -1,5 +1,5 @@ /* - labcomm_fd_writer.c -- LabComm writer for Unix file descriptors. + labcomm2006_fd_writer.c -- LabComm writer for Unix file descriptors. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -24,26 +24,26 @@ #include <string.h> #include <stdlib.h> #include <stdarg.h> -#include "labcomm_private.h" -#include "labcomm_fd_writer.h" +#include "labcomm2006_private.h" +#include "labcomm2006_fd_writer.h" #define BUFFER_SIZE 2048 -struct labcomm_fd_writer { - struct labcomm_writer writer; - struct labcomm_writer_action_context action_context; +struct labcomm2006_fd_writer { + struct labcomm2006_writer writer; + struct labcomm2006_writer_action_context action_context; int fd; int close_fd_on_free; }; -static int fd_flush(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); +static int fd_flush(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context); -static int fd_alloc(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, +static int fd_alloc(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, char *version) { - w->data = labcomm_memory_alloc(w->memory, 0, BUFFER_SIZE); + w->data = labcomm2006_memory_alloc(w->memory, 0, BUFFER_SIZE); if (! w->data) { w->error = -ENOMEM; w->data_size = 0; @@ -54,7 +54,7 @@ static int fd_alloc(struct labcomm_writer *w, w->count = BUFFER_SIZE; w->pos = 0; if (version && version[0]) { - labcomm_write_string(w, version); + labcomm2006_write_string(w, version); fd_flush(w, action_context); } } @@ -62,13 +62,13 @@ static int fd_alloc(struct labcomm_writer *w, return w->error; } -static int fd_free(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +static int fd_free(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context) { - struct labcomm_fd_writer *fd_writer = action_context->context; - struct labcomm_memory *memory = w->memory; + struct labcomm2006_fd_writer *fd_writer = action_context->context; + struct labcomm2006_memory *memory = w->memory; - labcomm_memory_free(memory, 0, w->data); + labcomm2006_memory_free(memory, 0, w->data); w->data = 0; w->data_size = 0; w->count = 0; @@ -77,14 +77,14 @@ static int fd_free(struct labcomm_writer *w, if (fd_writer->close_fd_on_free) { close(fd_writer->fd); } - labcomm_memory_free(memory, 0, fd_writer); + labcomm2006_memory_free(memory, 0, fd_writer); return 0; } -static int fd_start(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, +static int fd_start(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, int index, - struct labcomm_signature *signature, + struct labcomm2006_signature *signature, void *value) { w->pos = 0; @@ -92,10 +92,10 @@ static int fd_start(struct labcomm_writer *w, return w->error; } -static int fd_flush(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +static int fd_flush(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context) { - struct labcomm_fd_writer *fd_context = action_context->context; + struct labcomm2006_fd_writer *fd_context = action_context->context; int start, err; start = 0; @@ -117,7 +117,7 @@ static int fd_flush(struct labcomm_writer *w, return w->error; } -static const struct labcomm_writer_action action = { +static const struct labcomm2006_writer_action action = { .alloc = fd_alloc, .free = fd_free, .start = fd_start, @@ -126,12 +126,12 @@ static const struct labcomm_writer_action action = { .ioctl = NULL }; -struct labcomm_writer *labcomm_fd_writer_new(struct labcomm_memory *memory, +struct labcomm2006_writer *labcomm2006_fd_writer_new(struct labcomm2006_memory *memory, int fd, int close_fd_on_free) { - struct labcomm_fd_writer *result; + struct labcomm2006_fd_writer *result; - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); + result = labcomm2006_memory_alloc(memory, 0, sizeof(*result)); if (result == NULL) { return NULL; } else { diff --git a/lib/c/2006/labcomm2006_fd_writer.h b/lib/c/2006/labcomm2006_fd_writer.h index e89b5e7..56fda84 100644 --- a/lib/c/2006/labcomm2006_fd_writer.h +++ b/lib/c/2006/labcomm2006_fd_writer.h @@ -1,5 +1,5 @@ /* - labcomm_fd_writer.c -- a writer for unix style file-descriptors + labcomm2006_fd_writer.c -- a writer for unix style file-descriptors Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,9 +22,9 @@ #ifndef _LABCOMM_FD_WRITER_H_ #define _LABCOMM_FD_WRITER_H_ -#include "labcomm.h" +#include "labcomm2006.h" -struct labcomm_writer *labcomm_fd_writer_new(struct labcomm_memory *memory, +struct labcomm2006_writer *labcomm2006_fd_writer_new(struct labcomm2006_memory *memory, int fd, int close_on_free); #endif diff --git a/lib/c/2006/labcomm2006_ioctl.h b/lib/c/2006/labcomm2006_ioctl.h index 1ebf653..22794ba 100644 --- a/lib/c/2006/labcomm2006_ioctl.h +++ b/lib/c/2006/labcomm2006_ioctl.h @@ -1,5 +1,5 @@ /* - labcomm_ioctl.h -- labcomm ioctl declarations + labcomm2006_ioctl.h -- labcomm ioctl declarations Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,7 +22,7 @@ #ifndef __LABCOMM_IOCTL_H__ #define __LABCOMM_IOCTL_H__ -#include "labcomm.h" +#include "labcomm2006.h" /* * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ diff --git a/lib/c/2006/labcomm2006_memory.c b/lib/c/2006/labcomm2006_memory.c index 62bc9ac..67b51e3 100644 --- a/lib/c/2006/labcomm2006_memory.c +++ b/lib/c/2006/labcomm2006_memory.c @@ -1,5 +1,5 @@ /* - labcomm_memory.c -- dynamic memory handlig dispatcher + labcomm2006_memory.c -- dynamic memory handlig dispatcher Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -19,21 +19,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "labcomm_private.h" +#include "labcomm2006_private.h" -void *labcomm_memory_alloc(struct labcomm_memory *m, int lifetime, +void *labcomm2006_memory_alloc(struct labcomm2006_memory *m, int lifetime, size_t size) { return m->alloc(m, lifetime, size); } -void *labcomm_memory_realloc(struct labcomm_memory *m, int lifetime, +void *labcomm2006_memory_realloc(struct labcomm2006_memory *m, int lifetime, void *ptr, size_t size) { return m->realloc(m, lifetime, ptr, size); } -void labcomm_memory_free(struct labcomm_memory *m, int lifetime, +void labcomm2006_memory_free(struct labcomm2006_memory *m, int lifetime, void *ptr) { m->free(m, lifetime, ptr); diff --git a/lib/c/2006/labcomm2006_private.h b/lib/c/2006/labcomm2006_private.h index e6db4c1..89fa6ee 100644 --- a/lib/c/2006/labcomm2006_private.h +++ b/lib/c/2006/labcomm2006_private.h @@ -1,5 +1,5 @@ /* - labcomm_private.h -- semi private declarations for handling encoding and + labcomm2006_private.h -- semi private declarations for handling encoding and decoding of labcomm samples. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -34,7 +34,7 @@ //#include <stdlib.h> #include <string.h> #include <unistd.h> -#include "labcomm.h" +#include "labcomm2006.h" /* * Predeclared aggregate type indices @@ -74,29 +74,29 @@ * Semi private dynamic memory declarations */ -struct labcomm_memory { - void *(*alloc)(struct labcomm_memory *m, int lifetime, size_t size); - void *(*realloc)(struct labcomm_memory *m, int lifetime, +struct labcomm2006_memory { + void *(*alloc)(struct labcomm2006_memory *m, int lifetime, size_t size); + void *(*realloc)(struct labcomm2006_memory *m, int lifetime, void *ptr, size_t size); - void (*free)(struct labcomm_memory *m, int lifetime, void *ptr); + void (*free)(struct labcomm2006_memory *m, int lifetime, void *ptr); void *context; }; /* * Semi private decoder declarations */ -typedef void (*labcomm_handler_function)(void *value, void *context); +typedef void (*labcomm2006_handler_function)(void *value, void *context); -typedef void (*labcomm_decoder_function)( - struct labcomm_reader *r, - labcomm_handler_function handler, +typedef void (*labcomm2006_decoder_function)( + struct labcomm2006_reader *r, + labcomm2006_handler_function handler, void *context); -struct labcomm_reader_action_context; +struct labcomm2006_reader_action_context; -struct labcomm_reader_action { - /* 'alloc' is called at the first invocation of 'labcomm_decoder_decode_one' - on the decoder containing the reader. If 'labcomm_version' != NULL +struct labcomm2006_reader_action { + /* 'alloc' is called at the first invocation of 'labcomm2006_decoder_decode_one' + on the decoder containing the reader. If 'labcomm2006_version' != NULL and non-empty the transport layer may use it to ensure that compatible versions are used. @@ -104,9 +104,9 @@ struct labcomm_reader_action { > 0 Number of bytes allocated for buffering <= 0 Error */ - int (*alloc)(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, - char *labcomm_version); + int (*alloc)(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, + char *labcomm2006_version); /* 'free' returns the resources claimed by 'alloc' and might have other reader specific side-effects as well. @@ -114,8 +114,8 @@ struct labcomm_reader_action { == 0 Success != 0 Error */ - int (*free)(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context); + int (*free)(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context); /* 'start' is called at the following instances: 1. When a sample is registered (local_index != 0, remote_index == 0, value == NULL) @@ -124,33 +124,33 @@ struct labcomm_reader_action { 3. When a sample is received (local_index != 0, remote_index != 0, value != NULL) */ - int (*start)(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, + int (*start)(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, int local_index, int remote_index, - struct labcomm_signature *signature, + struct labcomm2006_signature *signature, void *value); - int (*end)(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context); - int (*fill)(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context); - int (*ioctl)(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, + int (*end)(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context); + int (*fill)(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context); + int (*ioctl)(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, int local_index, int remote_index, - struct labcomm_signature *signature, + struct labcomm2006_signature *signature, uint32_t ioctl_action, va_list args); }; -struct labcomm_reader_action_context { - struct labcomm_reader_action_context *next; - const struct labcomm_reader_action *action; +struct labcomm2006_reader_action_context { + struct labcomm2006_reader_action_context *next; + const struct labcomm2006_reader_action *action; void *context; }; -struct labcomm_reader { - struct labcomm_reader_action_context *action_context; - struct labcomm_memory *memory; - /* The following fields are initialized by labcomm_decoder_new */ - struct labcomm_decoder *decoder; +struct labcomm2006_reader { + struct labcomm2006_reader_action_context *action_context; + struct labcomm2006_memory *memory; + /* The following fields are initialized by labcomm2006_decoder_new */ + struct labcomm2006_decoder *decoder; unsigned char *data; int data_size; int count; @@ -158,49 +158,49 @@ struct labcomm_reader { int error; }; -int labcomm_reader_alloc(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, - char *labcomm_version); -int labcomm_reader_free(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context); -int labcomm_reader_start(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, +int labcomm2006_reader_alloc(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, + char *labcomm2006_version); +int labcomm2006_reader_free(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context); +int labcomm2006_reader_start(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, int local_index, int remote_index, - struct labcomm_signature *signature, + struct labcomm2006_signature *signature, void *value); -int labcomm_reader_end(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context); -int labcomm_reader_fill(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context); -int labcomm_reader_ioctl(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, +int labcomm2006_reader_end(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context); +int labcomm2006_reader_fill(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context); +int labcomm2006_reader_ioctl(struct labcomm2006_reader *r, + struct labcomm2006_reader_action_context *action_context, int local_index, int remote_index, - struct labcomm_signature *signature, + struct labcomm2006_signature *signature, uint32_t ioctl_action, va_list args); /* * Non typesafe registration function to be called from - * generated labcomm_decoder_register_* functions. + * generated labcomm2006_decoder_register_* functions. */ -int labcomm_internal_decoder_register( - struct labcomm_decoder *d, - struct labcomm_signature *s, - labcomm_decoder_function decoder, - labcomm_handler_function handler, +int labcomm2006_internal_decoder_register( + struct labcomm2006_decoder *d, + struct labcomm2006_signature *s, + labcomm2006_decoder_function decoder, + labcomm2006_handler_function handler, void *context); -int labcomm_internal_decoder_ioctl(struct labcomm_decoder *decoder, - struct labcomm_signature *signature, +int labcomm2006_internal_decoder_ioctl(struct labcomm2006_decoder *decoder, + struct labcomm2006_signature *signature, uint32_t ioctl_action, va_list args); #if __BYTE_ORDER == __LITTLE_ENDIAN #define LABCOMM_DECODE(name, type) \ - static inline type labcomm_read_##name(struct labcomm_reader *r) { \ + static inline type labcomm2006_read_##name(struct labcomm2006_reader *r) { \ type result; int i; \ for (i = sizeof(type) - 1 ; i >= 0 ; i--) { \ if (r->pos >= r->count) { \ - labcomm_reader_fill(r, r->action_context); \ + labcomm2006_reader_fill(r, r->action_context); \ if (r->error < 0) { \ return 0; \ } \ @@ -214,11 +214,11 @@ int labcomm_internal_decoder_ioctl(struct labcomm_decoder *decoder, #else #define LABCOMM_DECODE(name, type) \ - static inline type labcomm_read_##name(struct labcomm_reader *r) { \ + static inline type labcomm2006_read_##name(struct labcomm2006_reader *r) { \ type result; int i; \ for (i = 0 ; i < sizeof(type) ; i++) { \ if (r->pos >= r->count) { \ - labcomm_reader_fille(r, r->action_context); \ + labcomm2006_reader_fille(r, r->action_context); \ if (r->error < 0) { \ return 0; \ } \ @@ -240,10 +240,10 @@ LABCOMM_DECODE(float, float) LABCOMM_DECODE(double, double) //compatibility with 2013 version -#define labcomm_read_packed32 labcomm_read_int +#define labcomm2006_read_packed32 labcomm2006_read_int #if 0 -static inline unsigned int labcomm_read_packed32(struct labcomm_reader *r) +static inline unsigned int labcomm2006_read_packed32(struct labcomm2006_reader *r) { unsigned int result = 0; @@ -251,7 +251,7 @@ static inline unsigned int labcomm_read_packed32(struct labcomm_reader *r) unsigned char tmp; if (r->pos >= r->count) { - labcomm_reader_fill(r, r->action_context); + labcomm2006_reader_fill(r, r->action_context); if (r->error != 0) { goto out; } @@ -268,16 +268,16 @@ out: } #endif -static inline char *labcomm_read_string(struct labcomm_reader *r) +static inline char *labcomm2006_read_string(struct labcomm2006_reader *r) { char *result = NULL; int length, pos; - length = labcomm_read_packed32(r); - result = labcomm_memory_alloc(r->memory, 1, length + 1); + length = labcomm2006_read_packed32(r); + result = labcomm2006_memory_alloc(r->memory, 1, length + 1); for (pos = 0 ; pos < length ; pos++) { if (r->pos >= r->count) { - labcomm_reader_fill(r, r->action_context); + labcomm2006_reader_fill(r, r->action_context); if (r->error < 0) { goto out; } @@ -293,16 +293,16 @@ out: /* * Semi private encoder declarations */ -typedef int (*labcomm_encoder_function)(struct labcomm_writer *, +typedef int (*labcomm2006_encoder_function)(struct labcomm2006_writer *, void *value); -struct labcomm_writer_action_context; - -struct labcomm_writer_action { - int (*alloc)(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - char *labcomm_version); - int (*free)(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); +struct labcomm2006_writer_action_context; + +struct labcomm2006_writer_action { + int (*alloc)(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, + char *labcomm2006_version); + int (*free)(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context); /* 'start' is called right before a sample is to be sent. In the case of a sample or typedef, 'value' == NULL. @@ -312,31 +312,31 @@ struct labcomm_writer_action { 'end' will not be called < 0 Error */ - int (*start)(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int index, struct labcomm_signature *signature, + int (*start)(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, + int index, struct labcomm2006_signature *signature, void *value); - int (*end)(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); - int (*flush)(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); - int (*ioctl)(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int index, struct labcomm_signature *signature, + int (*end)(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context); + int (*flush)(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context); + int (*ioctl)(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, + int index, struct labcomm2006_signature *signature, uint32_t ioctl_action, va_list args); }; -struct labcomm_writer_action_context { - struct labcomm_writer_action_context *next; - const struct labcomm_writer_action *action; +struct labcomm2006_writer_action_context { + struct labcomm2006_writer_action_context *next; + const struct labcomm2006_writer_action *action; void *context; }; -struct labcomm_writer { - struct labcomm_writer_action_context *action_context; - struct labcomm_memory *memory; - /* The following fields are initialized by labcomm_encoder_new */ - struct labcomm_encoder *encoder; +struct labcomm2006_writer { + struct labcomm2006_writer_action_context *action_context; + struct labcomm2006_memory *memory; + /* The following fields are initialized by labcomm2006_encoder_new */ + struct labcomm2006_encoder *encoder; unsigned char *data; int data_size; int count; @@ -344,48 +344,48 @@ struct labcomm_writer { int error; }; -int labcomm_writer_alloc(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - char *labcomm_version); -int labcomm_writer_free(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); -int labcomm_writer_start(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int index, struct labcomm_signature *signature, +int labcomm2006_writer_alloc(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, + char *labcomm2006_version); +int labcomm2006_writer_free(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context); +int labcomm2006_writer_start(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, + int index, struct labcomm2006_signature *signature, void *value); -int labcomm_writer_end(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); -int labcomm_writer_flush(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); -int labcomm_writer_ioctl(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int index, struct labcomm_signature *signature, +int labcomm2006_writer_end(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context); +int labcomm2006_writer_flush(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context); +int labcomm2006_writer_ioctl(struct labcomm2006_writer *w, + struct labcomm2006_writer_action_context *action_context, + int index, struct labcomm2006_signature *signature, uint32_t ioctl_action, va_list args); -int labcomm_internal_encoder_register( - struct labcomm_encoder *encoder, - struct labcomm_signature *signature, - labcomm_encoder_function encode); +int labcomm2006_internal_encoder_register( + struct labcomm2006_encoder *encoder, + struct labcomm2006_signature *signature, + labcomm2006_encoder_function encode); -int labcomm_internal_encode( - struct labcomm_encoder *encoder, - struct labcomm_signature *signature, - labcomm_encoder_function encode, +int labcomm2006_internal_encode( + struct labcomm2006_encoder *encoder, + struct labcomm2006_signature *signature, + labcomm2006_encoder_function encode, void *value); -int labcomm_internal_encoder_ioctl(struct labcomm_encoder *encoder, - struct labcomm_signature *signature, +int labcomm2006_internal_encoder_ioctl(struct labcomm2006_encoder *encoder, + struct labcomm2006_signature *signature, uint32_t ioctl_action, va_list args); #if __BYTE_ORDER == __LITTLE_ENDIAN #define LABCOMM_ENCODE(name, type) \ - static inline int labcomm_write_##name(struct labcomm_writer *w, type data) { \ + static inline int labcomm2006_write_##name(struct labcomm2006_writer *w, type data) { \ int i; \ for (i = sizeof(type) - 1 ; i >= 0 ; i--) { \ if (w->pos >= w->count) { /*buffer is full*/ \ int err; \ - err = labcomm_writer_flush(w, w->action_context); \ + err = labcomm2006_writer_flush(w, w->action_context); \ if (err != 0) { return err; } \ } \ w->data[w->pos] = ((unsigned char*)(&data))[i]; \ @@ -397,12 +397,12 @@ int labcomm_internal_encoder_ioctl(struct labcomm_encoder *encoder, #else #define LABCOMM_ENCODE(name, type) \ - static inline int labcomm_write_##name(struct labcomm_writer *w, type data) { \ + static inline int labcomm2006_write_##name(struct labcomm2006_writer *w, type data) { \ int i; \ for (i = 0 ; i < sizeof(type) ; i++) { \ if (w->pos >= w->count) { \ int err; \ - err = labcomm_writer_flush(w, w->action_context); \ + err = labcomm2006_writer_flush(w, w->action_context); \ if (err != 0) { return err; } \ } \ w->data[w->pos] = ((unsigned char*)(&data))[i]; \ @@ -421,10 +421,10 @@ LABCOMM_ENCODE(long, long long) LABCOMM_ENCODE(float, float) LABCOMM_ENCODE(double, double) -#define labcomm_write_packed32 labcomm_write_int +#define labcomm2006_write_packed32 labcomm2006_write_int #if 0 -static inline int labcomm_write_packed32(struct labcomm_writer *w, +static inline int labcomm2006_write_packed32(struct labcomm2006_writer *w, unsigned int data) { unsigned char tmp[5]; @@ -436,7 +436,7 @@ static inline int labcomm_write_packed32(struct labcomm_writer *w, for (i = i - 1 ; i >= 0 ; i--) { if (w->pos >= w->count) { int err; - err = labcomm_writer_flush(w, w->action_context); + err = labcomm2006_writer_flush(w, w->action_context); if (err != 0) { return err; } } w->data[w->pos++] = tmp[i] | (i?0x80:0x00); @@ -445,17 +445,17 @@ static inline int labcomm_write_packed32(struct labcomm_writer *w, } #endif -static inline int labcomm_write_string(struct labcomm_writer *w, char *s) +static inline int labcomm2006_write_string(struct labcomm2006_writer *w, char *s) { int length, i, err; length = strlen((char*)s); - err = labcomm_write_packed32(w, length); + err = labcomm2006_write_packed32(w, length); if (err != 0) { return err; } for (i = 0 ; i < length ; i++) { if (w->pos >= w->count) { int err; - err = labcomm_writer_flush(w, w->action_context); + err = labcomm2006_writer_flush(w, w->action_context); if (err != 0) { return err; } } w->data[w->pos] = s[i]; @@ -465,7 +465,7 @@ static inline int labcomm_write_string(struct labcomm_writer *w, char *s) } /* Size of packed32 variable is 4 as we use int*/ -static inline int labcomm_size_packed32(unsigned int data) +static inline int labcomm2006_size_packed32(unsigned int data) { return 4; } @@ -489,10 +489,10 @@ static inline int labcomm_size_packed32(unsigned int data) name.data = (kind *)name.data; /* typechecking no-op */ #define LABCOMM_SIGNATURE_ARRAY_FREE(memory, name, kind) \ - if (name.data) { labcomm_memory_free(memory, 0, name.data); } \ + if (name.data) { labcomm2006_memory_free(memory, 0, name.data); } \ name.data = (kind *)NULL; /* typechecking */ -void *labcomm_signature_array_ref(struct labcomm_memory * memory, +void *labcomm2006_signature_array_ref(struct labcomm2006_memory * memory, int *first, int *last, void **data, int size, int index); /* @@ -504,7 +504,7 @@ void *labcomm_signature_array_ref(struct labcomm_memory * memory, */ #define LABCOMM_SIGNATURE_ARRAY_REF(memory, name, kind, index) \ (name.data = (kind *)name.data, /* typechecking no-op */ \ - (kind *)(labcomm_signature_array_ref(memory, \ + (kind *)(labcomm2006_signature_array_ref(memory, \ &name.first, &name.last, \ (void **)&name.data, \ sizeof(kind), index))) @@ -514,9 +514,9 @@ void *labcomm_signature_array_ref(struct labcomm_memory * memory, var = name.first ; var < name.last ; var++) /* Give signature a free local index, this may not be used concurrently */ -void labcomm_set_local_index(struct labcomm_signature *signature); +void labcomm2006_set_local_index(struct labcomm2006_signature *signature); /* Get the local index for a signature */ -int labcomm_get_local_index(struct labcomm_signature *s); +int labcomm2006_get_local_index(struct labcomm2006_signature *s); #endif diff --git a/lib/c/2006/labcomm2006_pthread_scheduler.c b/lib/c/2006/labcomm2006_pthread_scheduler.c index a9b516a..e69ca14 100644 --- a/lib/c/2006/labcomm2006_pthread_scheduler.c +++ b/lib/c/2006/labcomm2006_pthread_scheduler.c @@ -1,5 +1,5 @@ /* - labcomm_pthread_scheduler.c -- labcomm pthread based task coordination + labcomm2006_pthread_scheduler.c -- labcomm pthread based task coordination Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -23,18 +23,18 @@ #include <stdlib.h> #include <errno.h> #include <pthread.h> -#include "labcomm.h" -#include "labcomm_scheduler.h" -#include "labcomm_scheduler_private.h" -#include "labcomm_pthread_scheduler.h" +#include "labcomm2006.h" +#include "labcomm2006_scheduler.h" +#include "labcomm2006_scheduler_private.h" +#include "labcomm2006_pthread_scheduler.h" #ifdef LABCOMM_COMPAT #include LABCOMM_COMPAT #endif struct pthread_time { - struct labcomm_time time; - struct labcomm_memory *memory; + struct labcomm2006_time time; + struct labcomm2006_memory *memory; struct timespec abstime; }; @@ -47,8 +47,8 @@ struct pthread_deferred { }; struct pthread_scheduler { - struct labcomm_scheduler scheduler; - struct labcomm_memory *memory; + struct labcomm2006_scheduler scheduler; + struct labcomm2006_memory *memory; int wakeup; pthread_mutex_t writer_mutex; pthread_mutex_t data_mutex; @@ -58,7 +58,7 @@ struct pthread_scheduler { struct pthread_deferred deferred_with_delay; }; -static struct labcomm_time_action time_action; +static struct labcomm2006_time_action time_action; static int queue_empty(struct pthread_deferred *queue) { @@ -100,11 +100,11 @@ static int timespec_compare(struct timespec *t1, struct timespec *t2) } } -static struct labcomm_time *time_new(struct labcomm_memory *memory) +static struct labcomm2006_time *time_new(struct labcomm2006_memory *memory) { struct pthread_time *time; - time = labcomm_memory_alloc(memory, 0, sizeof(*time)); + time = labcomm2006_memory_alloc(memory, 0, sizeof(*time)); if (time == NULL) { return NULL; } else { @@ -116,17 +116,17 @@ static struct labcomm_time *time_new(struct labcomm_memory *memory) } } -static int time_free(struct labcomm_time *t) +static int time_free(struct labcomm2006_time *t) { struct pthread_time *time = t->context; - struct labcomm_memory *memory = time->memory; + struct labcomm2006_memory *memory = time->memory; - labcomm_memory_free(memory, 0, time); + labcomm2006_memory_free(memory, 0, time); return 0; } -static int time_add_usec(struct labcomm_time *t, uint32_t usec) +static int time_add_usec(struct labcomm2006_time *t, uint32_t usec) { struct pthread_time *time = t->context; @@ -135,7 +135,7 @@ static int time_add_usec(struct labcomm_time *t, uint32_t usec) return 0; } -static struct labcomm_time_action time_action = { +static struct labcomm2006_time_action time_action = { .free = time_free, .add_usec = time_add_usec }; @@ -146,10 +146,10 @@ static int run_action(struct pthread_scheduler *scheduler, /* Called with data_lock held */ element->prev->next = element->next; element->next->prev = element->prev; - labcomm_scheduler_data_unlock(&scheduler->scheduler); + labcomm2006_scheduler_data_unlock(&scheduler->scheduler); element->action(element->context); - labcomm_memory_free(scheduler->memory, 1, element); - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2006_memory_free(scheduler->memory, 1, element); + labcomm2006_scheduler_data_lock(&scheduler->scheduler); return 0; } @@ -175,44 +175,44 @@ out: return 0; } -static int scheduler_free(struct labcomm_scheduler *s) +static int scheduler_free(struct labcomm2006_scheduler *s) { struct pthread_scheduler *scheduler = s->context; - struct labcomm_memory *memory = scheduler->memory; + struct labcomm2006_memory *memory = scheduler->memory; - labcomm_memory_free(memory, 0, scheduler); + labcomm2006_memory_free(memory, 0, scheduler); return 0; } -static int scheduler_writer_lock(struct labcomm_scheduler *s) +static int scheduler_writer_lock(struct labcomm2006_scheduler *s) { struct pthread_scheduler *scheduler = s->context; - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2006_scheduler_data_lock(&scheduler->scheduler); run_deferred(scheduler); /* Run deferred tasks before taking lock */ - labcomm_scheduler_data_unlock(&scheduler->scheduler); + labcomm2006_scheduler_data_unlock(&scheduler->scheduler); if (pthread_mutex_lock(&scheduler->writer_mutex) != 0) { return -errno; } return 0; } -static int scheduler_writer_unlock(struct labcomm_scheduler *s) +static int scheduler_writer_unlock(struct labcomm2006_scheduler *s) { struct pthread_scheduler *scheduler = s->context; if (pthread_mutex_unlock(&scheduler->writer_mutex) != 0) { return -errno; } - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2006_scheduler_data_lock(&scheduler->scheduler); run_deferred(scheduler); /* Run deferred tasks after releasing lock */ - labcomm_scheduler_data_unlock(&scheduler->scheduler); + labcomm2006_scheduler_data_unlock(&scheduler->scheduler); return 0; } -static int scheduler_data_lock(struct labcomm_scheduler *s) +static int scheduler_data_lock(struct labcomm2006_scheduler *s) { struct pthread_scheduler *scheduler = s->context; @@ -223,7 +223,7 @@ static int scheduler_data_lock(struct labcomm_scheduler *s) return 0; } -static int scheduler_data_unlock(struct labcomm_scheduler *s) +static int scheduler_data_unlock(struct labcomm2006_scheduler *s) { struct pthread_scheduler *scheduler = s->context; @@ -235,20 +235,20 @@ static int scheduler_data_unlock(struct labcomm_scheduler *s) return 0; } -static struct labcomm_time *scheduler_now(struct labcomm_scheduler *s) +static struct labcomm2006_time *scheduler_now(struct labcomm2006_scheduler *s) { struct pthread_scheduler *scheduler = s->context; return time_new(scheduler->memory); } -static int scheduler_sleep(struct labcomm_scheduler *s, - struct labcomm_time *t) +static int scheduler_sleep(struct labcomm2006_scheduler *s, + struct labcomm2006_time *t) { struct pthread_scheduler *scheduler = s->context; struct pthread_time *time = t?t->context:NULL; - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2006_scheduler_data_lock(&scheduler->scheduler); while (1) { struct timespec *wakeup, now; @@ -281,23 +281,23 @@ static int scheduler_sleep(struct labcomm_scheduler *s, &scheduler->data_mutex); } } - labcomm_scheduler_data_unlock(&scheduler->scheduler); + labcomm2006_scheduler_data_unlock(&scheduler->scheduler); return 0; } -static int scheduler_wakeup(struct labcomm_scheduler *s) +static int scheduler_wakeup(struct labcomm2006_scheduler *s) { struct pthread_scheduler *scheduler = s->context; - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2006_scheduler_data_lock(&scheduler->scheduler); scheduler->wakeup = 1; pthread_cond_signal(&scheduler->data_cond); - labcomm_scheduler_data_unlock(&scheduler->scheduler); + labcomm2006_scheduler_data_unlock(&scheduler->scheduler); return 0; } -static int scheduler_enqueue(struct labcomm_scheduler *s, +static int scheduler_enqueue(struct labcomm2006_scheduler *s, uint32_t delay, void (*deferred)(void *context), void *context) @@ -306,7 +306,7 @@ static int scheduler_enqueue(struct labcomm_scheduler *s, int result = 0; struct pthread_deferred *element, *insert_before; - element = labcomm_memory_alloc(scheduler->memory, 1, sizeof(*element)); + element = labcomm2006_memory_alloc(scheduler->memory, 1, sizeof(*element)); if (element == NULL) { result = -ENOMEM; goto out; @@ -314,7 +314,7 @@ static int scheduler_enqueue(struct labcomm_scheduler *s, element->action = deferred; element->context = context; - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2006_scheduler_data_lock(&scheduler->scheduler); if (delay == 0) { insert_before = &scheduler->deferred; } else { @@ -330,13 +330,13 @@ static int scheduler_enqueue(struct labcomm_scheduler *s, element->prev->next = element; element->next->prev = element; pthread_cond_signal(&scheduler->data_cond); - labcomm_scheduler_data_unlock(&scheduler->scheduler); + labcomm2006_scheduler_data_unlock(&scheduler->scheduler); out: return result; } -static const struct labcomm_scheduler_action scheduler_action = { +static const struct labcomm2006_scheduler_action scheduler_action = { .free = scheduler_free, .writer_lock = scheduler_writer_lock, .writer_unlock = scheduler_writer_unlock, @@ -348,13 +348,13 @@ static const struct labcomm_scheduler_action scheduler_action = { .enqueue = scheduler_enqueue }; -struct labcomm_scheduler *labcomm_pthread_scheduler_new( - struct labcomm_memory *memory) +struct labcomm2006_scheduler *labcomm2006_pthread_scheduler_new( + struct labcomm2006_memory *memory) { - struct labcomm_scheduler *result = NULL; + struct labcomm2006_scheduler *result = NULL; struct pthread_scheduler *scheduler; - scheduler = labcomm_memory_alloc(memory, 0, sizeof(*scheduler)); + scheduler = labcomm2006_memory_alloc(memory, 0, sizeof(*scheduler)); if (scheduler == NULL) { goto out; } else { @@ -386,7 +386,7 @@ destroy_data_mutex: destroy_writer_mutex: pthread_mutex_destroy(&scheduler->writer_mutex); free_scheduler: - labcomm_memory_free(memory, 0, scheduler); + labcomm2006_memory_free(memory, 0, scheduler); out: return result; diff --git a/lib/c/2006/labcomm2006_pthread_scheduler.h b/lib/c/2006/labcomm2006_pthread_scheduler.h index c8b20ec..101cfde 100644 --- a/lib/c/2006/labcomm2006_pthread_scheduler.h +++ b/lib/c/2006/labcomm2006_pthread_scheduler.h @@ -1,5 +1,5 @@ /* - labcomm_pthread_scheduler.h -- labcomm pthread based task coordination + labcomm2006_pthread_scheduler.h -- labcomm pthread based task coordination Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,10 +22,10 @@ #ifndef _LABCOMM_PTHREAD_SCHEDULER_H_ #define _LABCOMM_PTHREAD_SCHEDULER_H_ -#include "labcomm.h" +#include "labcomm2006.h" -struct labcomm_scheduler *labcomm_pthread_scheduler_new( - struct labcomm_memory *memory); +struct labcomm2006_scheduler *labcomm2006_pthread_scheduler_new( + struct labcomm2006_memory *memory); #endif diff --git a/lib/c/2006/labcomm2006_scheduler.c b/lib/c/2006/labcomm2006_scheduler.c index 3ef62f3..bf2b04f 100644 --- a/lib/c/2006/labcomm2006_scheduler.c +++ b/lib/c/2006/labcomm2006_scheduler.c @@ -1,5 +1,5 @@ /* - labcomm_scheduler.c -- labcomm task coordination + labcomm2006_scheduler.c -- labcomm task coordination Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -20,7 +20,7 @@ */ #include <errno.h> -#include "labcomm_scheduler_private.h" +#include "labcomm2006_scheduler_private.h" #define SCHEDULER_scheduler(scheduler, ...) scheduler #define SCHEDULER(func, ...) \ @@ -30,32 +30,32 @@ } \ return -ENOSYS; -int labcomm_scheduler_free(struct labcomm_scheduler *s) +int labcomm2006_scheduler_free(struct labcomm2006_scheduler *s) { SCHEDULER(free, s); } -int labcomm_scheduler_writer_lock(struct labcomm_scheduler *s) +int labcomm2006_scheduler_writer_lock(struct labcomm2006_scheduler *s) { SCHEDULER(writer_lock, s); } -int labcomm_scheduler_writer_unlock(struct labcomm_scheduler *s) +int labcomm2006_scheduler_writer_unlock(struct labcomm2006_scheduler *s) { SCHEDULER(writer_unlock, s); } -int labcomm_scheduler_data_lock(struct labcomm_scheduler *s) +int labcomm2006_scheduler_data_lock(struct labcomm2006_scheduler *s) { SCHEDULER(data_lock, s); } -int labcomm_scheduler_data_unlock(struct labcomm_scheduler *s) +int labcomm2006_scheduler_data_unlock(struct labcomm2006_scheduler *s) { SCHEDULER(data_unlock, s); } -struct labcomm_time *labcomm_scheduler_now(struct labcomm_scheduler *s) +struct labcomm2006_time *labcomm2006_scheduler_now(struct labcomm2006_scheduler *s) { if (s && s->action->now) { return s->action->now(s); @@ -63,18 +63,18 @@ struct labcomm_time *labcomm_scheduler_now(struct labcomm_scheduler *s) return NULL; } -int labcomm_scheduler_sleep(struct labcomm_scheduler *s, - struct labcomm_time *wakeup) +int labcomm2006_scheduler_sleep(struct labcomm2006_scheduler *s, + struct labcomm2006_time *wakeup) { SCHEDULER(sleep, s, wakeup); } -int labcomm_scheduler_wakeup(struct labcomm_scheduler *s) +int labcomm2006_scheduler_wakeup(struct labcomm2006_scheduler *s) { SCHEDULER(wakeup, s); } -int labcomm_scheduler_enqueue(struct labcomm_scheduler *s, +int labcomm2006_scheduler_enqueue(struct labcomm2006_scheduler *s, uint32_t delay, void (*func)(void *context), void *context) diff --git a/lib/c/2006/labcomm2006_scheduler.h b/lib/c/2006/labcomm2006_scheduler.h index 4aef48d..d4a6c6d 100644 --- a/lib/c/2006/labcomm2006_scheduler.h +++ b/lib/c/2006/labcomm2006_scheduler.h @@ -1,5 +1,5 @@ /* - labcomm_scheduler.h -- labcomm task coordination + labcomm2006_scheduler.h -- labcomm task coordination Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -25,29 +25,29 @@ #include <unistd.h> #include <stdint.h> -struct labcomm_time; +struct labcomm2006_time; -int labcomm_time_free(struct labcomm_time *t); -int labcomm_time_add_usec(struct labcomm_time *t, uint32_t usec); +int labcomm2006_time_free(struct labcomm2006_time *t); +int labcomm2006_time_add_usec(struct labcomm2006_time *t, uint32_t usec); -struct labcomm_scheduler; +struct labcomm2006_scheduler; -int labcomm_scheduler_free(struct labcomm_scheduler *s); +int labcomm2006_scheduler_free(struct labcomm2006_scheduler *s); /* Lock and event handling */ -int labcomm_scheduler_writer_lock(struct labcomm_scheduler *s); -int labcomm_scheduler_writer_unlock(struct labcomm_scheduler *s); -int labcomm_scheduler_data_lock(struct labcomm_scheduler *s); -int labcomm_scheduler_data_unlock(struct labcomm_scheduler *s); +int labcomm2006_scheduler_writer_lock(struct labcomm2006_scheduler *s); +int labcomm2006_scheduler_writer_unlock(struct labcomm2006_scheduler *s); +int labcomm2006_scheduler_data_lock(struct labcomm2006_scheduler *s); +int labcomm2006_scheduler_data_unlock(struct labcomm2006_scheduler *s); /* Time handling */ -struct labcomm_time *labcomm_scheduler_now(struct labcomm_scheduler *s); -int labcomm_scheduler_sleep(struct labcomm_scheduler *s, - struct labcomm_time *wakeup); -int labcomm_scheduler_wakeup(struct labcomm_scheduler *s); +struct labcomm2006_time *labcomm2006_scheduler_now(struct labcomm2006_scheduler *s); +int labcomm2006_scheduler_sleep(struct labcomm2006_scheduler *s, + struct labcomm2006_time *wakeup); +int labcomm2006_scheduler_wakeup(struct labcomm2006_scheduler *s); /* Deferred action handling */ -int labcomm_scheduler_enqueue(struct labcomm_scheduler *s, +int labcomm2006_scheduler_enqueue(struct labcomm2006_scheduler *s, uint32_t delay, void (*deferred)(void *context), void *context); diff --git a/lib/c/2006/labcomm2006_scheduler_private.h b/lib/c/2006/labcomm2006_scheduler_private.h index cc4d50e..4ed6bb1 100644 --- a/lib/c/2006/labcomm2006_scheduler_private.h +++ b/lib/c/2006/labcomm2006_scheduler_private.h @@ -1,5 +1,5 @@ /* - labcomm_scheduler.h -- labcomm task coordination, semi-private part + labcomm2006_scheduler.h -- labcomm task coordination, semi-private part Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -23,28 +23,28 @@ #define _LABCOMM_SCHEDULER_PRIVATE_H_ #include <unistd.h> -#include "labcomm_scheduler.h" +#include "labcomm2006_scheduler.h" -struct labcomm_time { - const struct labcomm_time_action { - int (*free)(struct labcomm_time *t); - int (*add_usec)(struct labcomm_time *t, uint32_t usec); +struct labcomm2006_time { + const struct labcomm2006_time_action { + int (*free)(struct labcomm2006_time *t); + int (*add_usec)(struct labcomm2006_time *t, uint32_t usec); } *action; void *context; }; -struct labcomm_scheduler { - const struct labcomm_scheduler_action { - int (*free)(struct labcomm_scheduler *s); - int (*writer_lock)(struct labcomm_scheduler *s); - int (*writer_unlock)(struct labcomm_scheduler *s); - int (*data_lock)(struct labcomm_scheduler *s); - int (*data_unlock)(struct labcomm_scheduler *s); - struct labcomm_time *(*now)(struct labcomm_scheduler *s); - int (*sleep)(struct labcomm_scheduler *s, - struct labcomm_time *wakeup); - int (*wakeup)(struct labcomm_scheduler *s); - int (*enqueue)(struct labcomm_scheduler *s, +struct labcomm2006_scheduler { + const struct labcomm2006_scheduler_action { + int (*free)(struct labcomm2006_scheduler *s); + int (*writer_lock)(struct labcomm2006_scheduler *s); + int (*writer_unlock)(struct labcomm2006_scheduler *s); + int (*data_lock)(struct labcomm2006_scheduler *s); + int (*data_unlock)(struct labcomm2006_scheduler *s); + struct labcomm2006_time *(*now)(struct labcomm2006_scheduler *s); + int (*sleep)(struct labcomm2006_scheduler *s, + struct labcomm2006_time *wakeup); + int (*wakeup)(struct labcomm2006_scheduler *s); + int (*enqueue)(struct labcomm2006_scheduler *s, uint32_t delay, void (*deferred)(void *context), void *context); diff --git a/lib/c/2006/labcomm2006_time.c b/lib/c/2006/labcomm2006_time.c index a1a5235..24fc3c4 100644 --- a/lib/c/2006/labcomm2006_time.c +++ b/lib/c/2006/labcomm2006_time.c @@ -1,5 +1,5 @@ /* - labcomm_time.c -- labcomm time handling + labcomm2006_time.c -- labcomm time handling Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -20,7 +20,7 @@ */ #include <errno.h> -#include "labcomm_scheduler_private.h" +#include "labcomm2006_scheduler_private.h" #define TIME_time(time, ...) time #define TIME(func, ...) \ @@ -30,12 +30,12 @@ } \ return -ENOSYS; -int labcomm_time_free(struct labcomm_time *s) +int labcomm2006_time_free(struct labcomm2006_time *s) { TIME(free, s); } -int labcomm_time_add_usec(struct labcomm_time *s, uint32_t usec) +int labcomm2006_time_add_usec(struct labcomm2006_time *s, uint32_t usec) { TIME(add_usec, s, usec); } diff --git a/lib/c/Makefile b/lib/c/Makefile index 886d818..966d17c 100644 --- a/lib/c/Makefile +++ b/lib/c/Makefile @@ -2,9 +2,9 @@ UNAME_S=$(shell uname -s) ifeq ($(UNAME_S),Linux) CC=gcc - CFLAGS=-std=c99 -g -Wall -Werror -O3 -I. -Itest + CFLAGS=-std=c99 -g -Wall -Werror -O3 -I. -Itest -I2006 LDFLAGS=-L. - LDLIBS=-llabcomm -lrt + LDLIBS=-llabcomm -llabcomm2006 -lrt MAKESHARED=gcc -o $1 -shared -Wl,-soname,$2 $3 -lc -lrt else ifeq ($(UNAME_S),Darwin) CC=clang @@ -12,12 +12,24 @@ else ifeq ($(UNAME_S),Darwin) -DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \ -Wno-tautological-compare -Wno-unused-function LDFLAGS=-L. - LDLIBS=-llabcomm + LDLIBS=-llabcomm -llabcomm2006 MAKESHARED=clang -o $1 -shared -Wl,-install_name,$2 $3 -lc else $(error Unknown system $(UNAME_S)) endif +OBJS2006=2006/labcomm2006_memory.o \ + 2006/labcomm2006_error.o \ + 2006/labcomm2006_default_error_handler.o \ + 2006/labcomm2006_default_memory.o \ + 2006/labcomm2006_default_scheduler.o \ + 2006/labcomm2006_time.o labcomm_scheduler.o \ + 2006/labcomm2006_encoder.o labcomm_decoder.o \ + 2006/labcomm2006.o \ + 2006/labcomm2006_dynamic_buffer_writer.o \ + 2006/labcomm2006_fd_reader.o labcomm_fd_writer.o \ + 2006/labcomm2006_pthread_scheduler.o + OBJS=labcomm_memory.o \ labcomm_error.o \ labcomm_default_error_handler.o \ @@ -57,18 +69,34 @@ endif .PHONY: all run-test clean distclean -all: liblabcomm.a liblabcomm.so.1 +all: liblabcomm.a liblabcomm.so.1 liblabcomm2006.a liblabcomm2006.so.1 + +liblabcomm.a: $(OBJS) $(OBJS2006) + ar -r $@ $^ + +liblabcomm.so.1: $(OBJS:%.o=%.pic.o) $(OBJS2006:%.o=%.pic.o) + $(call MAKESHARED,$@,$@,$^) -liblabcomm.a: $(OBJS) +liblabcomm2013.a: $(OBJS) ar -r $@ $^ -liblabcomm.so.1: $(OBJS:%.o=%.pic.o) +liblabcomm2013.so.1: $(OBJS:%.o=%.pic.o) + $(call MAKESHARED,$@,$@,$^) + +liblabcomm2006.a: $(OBJS2006) + ar -r $@ $^ + +liblabcomm2006.so.1: $(OBJS2006:%.o=%.pic.o) $(call MAKESHARED,$@,$@,$^) labcomm.o : labcomm.c labcomm.h labcomm_private.h labcomm_fd_reader_writer.o : labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h labcomm.h labcomm_private.h +2006/labcomm2006.o : 2006/labcomm2006.c 2006/labcomm2006.h 2006/labcomm2006_private.h + +2006/labcomm2006_fd_reader_writer.o : 2006/labcomm2006_fd_reader_writer.c 2006/labcomm2006_fd_reader_writer.h labcomm.h 2006/labcomm2006_private.h + #$(TEST_DIR)/labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h #$(TEST_DIR)/labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h @@ -126,6 +154,8 @@ clean: distclean: clean $(RM) liblabcomm.so.1 $(RM) liblabcomm.a + $(RM) liblabcomm2006.so.1 + $(RM) liblabcomm2006.a # Extra dependencies $(TEST_DIR)/test_labcomm_basic_type_encoding.o: labcomm_private.h -- GitLab