From e3c16fdacde72d618cd0a9f36b93fb6121e43dfc Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Tue, 24 Feb 2015 13:19:32 +0100 Subject: [PATCH] Changed 'labcomm' to 'labcomm2014' for C-code. --- compiler/2014/C_CodeGen.jrag | 166 ++++---- examples/simple/example_decoder.c | 36 +- examples/simple/example_encoder.c | 48 +-- examples/twoway/client.c | 78 ++-- examples/twoway/decimating.c | 94 ++--- examples/twoway/decimating.h | 18 +- examples/twoway/introspecting.c | 98 ++--- examples/twoway/introspecting.h | 22 +- examples/twoway/server.c | 68 +-- examples/user_types/example_decoder.c | 46 +- examples/user_types/example_encoder.c | 24 +- examples/wiki_example/example_encoder.c | 26 +- lib/c/2014/Makefile | 2 +- lib/c/2014/labcomm.h | 138 ------ lib/c/2014/{labcomm.c => labcomm2014.c} | 114 ++--- lib/c/2014/labcomm2014.h | 138 ++++++ ...m3.h => labcomm2014_compat_arm_cortexm3.h} | 0 ..._compat_osx.h => labcomm2014_compat_osx.h} | 0 ...vxworks.h => labcomm2014_compat_vxworks.h} | 0 ...abcomm_decoder.c => labcomm2014_decoder.c} | 284 ++++++------- ....c => labcomm2014_default_error_handler.c} | 4 +- ....h => labcomm2014_default_error_handler.h} | 8 +- ..._memory.c => labcomm2014_default_memory.c} | 14 +- ..._memory.h => labcomm2014_default_memory.h} | 8 +- ...uler.c => labcomm2014_default_scheduler.c} | 32 +- ...uler.h => labcomm2014_default_scheduler.h} | 8 +- ....c => labcomm2014_dynamic_buffer_writer.c} | 62 +-- ....h => labcomm2014_dynamic_buffer_writer.h} | 14 +- lib/c/2014/labcomm2014_encoder.c | 398 ++++++++++++++++++ .../{labcomm_error.c => labcomm2014_error.c} | 6 +- .../{labcomm_error.h => labcomm2014_error.h} | 20 +- ...mm_fd_reader.c => labcomm2014_fd_reader.c} | 44 +- ...mm_fd_reader.h => labcomm2014_fd_reader.h} | 10 +- ...mm_fd_writer.c => labcomm2014_fd_writer.c} | 54 +-- ...mm_fd_writer.h => labcomm2014_fd_writer.h} | 10 +- .../{labcomm_ioctl.h => labcomm2014_ioctl.h} | 10 +- ...{labcomm_memory.c => labcomm2014_memory.c} | 10 +- ...abcomm_private.h => labcomm2014_private.h} | 300 ++++++------- ...uler.c => labcomm2014_pthread_scheduler.c} | 98 ++--- ...uler.h => labcomm2014_pthread_scheduler.h} | 12 +- ...mm_scheduler.c => labcomm2014_scheduler.c} | 24 +- ...mm_scheduler.h => labcomm2014_scheduler.h} | 34 +- lib/c/2014/labcomm2014_scheduler_private.h | 60 +++ .../{labcomm_time.c => labcomm2014_time.c} | 8 +- ...gnature.c => labcomm2014_type_signature.c} | 32 +- ...gnature.h => labcomm2014_type_signature.h} | 46 +- lib/c/2014/labcomm_encoder.c | 398 ------------------ lib/c/2014/labcomm_scheduler_private.h | 60 --- lib/c/2014/test/test_labcomm.c | 88 ++-- .../test/test_labcomm_basic_type_encoding.c | 12 +- lib/c/2014/test/test_labcomm_copy.c | 170 ++++---- .../test/test_labcomm_generated_encoding.c | 132 +++--- .../test/test_labcomm_pthread_scheduler.c | 32 +- lib/c/2014/test/test_signature_numbers.c | 10 +- lib/c/version_compare.py | 6 +- test/relay_gen_c.py | 56 ++- 56 files changed, 1842 insertions(+), 1848 deletions(-) delete mode 100644 lib/c/2014/labcomm.h rename lib/c/2014/{labcomm.c => labcomm2014.c} (54%) create mode 100644 lib/c/2014/labcomm2014.h rename lib/c/2014/{labcomm_compat_arm_cortexm3.h => labcomm2014_compat_arm_cortexm3.h} (100%) rename lib/c/2014/{labcomm_compat_osx.h => labcomm2014_compat_osx.h} (100%) rename lib/c/2014/{labcomm_compat_vxworks.h => labcomm2014_compat_vxworks.h} (100%) rename lib/c/2014/{labcomm_decoder.c => labcomm2014_decoder.c} (63%) rename lib/c/2014/{labcomm_default_error_handler.c => labcomm2014_default_error_handler.c} (88%) rename lib/c/2014/{labcomm_default_error_handler.h => labcomm2014_default_error_handler.h} (80%) rename lib/c/2014/{labcomm_default_memory.c => labcomm2014_default_memory.c} (73%) rename lib/c/2014/{labcomm_default_memory.h => labcomm2014_default_memory.h} (82%) rename lib/c/2014/{labcomm_default_scheduler.c => labcomm2014_default_scheduler.c} (67%) rename lib/c/2014/{labcomm_default_scheduler.h => labcomm2014_default_scheduler.h} (81%) rename lib/c/2014/{labcomm_dynamic_buffer_writer.c => labcomm2014_dynamic_buffer_writer.c} (57%) rename lib/c/2014/{labcomm_dynamic_buffer_writer.h => labcomm2014_dynamic_buffer_writer.h} (65%) create mode 100644 lib/c/2014/labcomm2014_encoder.c rename lib/c/2014/{labcomm_error.c => labcomm2014_error.c} (86%) rename lib/c/2014/{labcomm_error.h => labcomm2014_error.h} (81%) rename lib/c/2014/{labcomm_fd_reader.c => labcomm2014_fd_reader.c} (64%) rename lib/c/2014/{labcomm_fd_reader.h => labcomm2014_fd_reader.h} (75%) rename lib/c/2014/{labcomm_fd_writer.c => labcomm2014_fd_writer.c} (60%) rename lib/c/2014/{labcomm_fd_writer.h => labcomm2014_fd_writer.h} (75%) rename lib/c/2014/{labcomm_ioctl.h => labcomm2014_ioctl.h} (95%) rename lib/c/2014/{labcomm_memory.c => labcomm2014_memory.c} (74%) rename lib/c/2014/{labcomm_private.h => labcomm2014_private.h} (52%) rename lib/c/2014/{labcomm_pthread_scheduler.c => labcomm2014_pthread_scheduler.c} (75%) rename lib/c/2014/{labcomm_pthread_scheduler.h => labcomm2014_pthread_scheduler.h} (71%) rename lib/c/2014/{labcomm_scheduler.c => labcomm2014_scheduler.c} (66%) rename lib/c/2014/{labcomm_scheduler.h => labcomm2014_scheduler.h} (50%) create mode 100644 lib/c/2014/labcomm2014_scheduler_private.h rename lib/c/2014/{labcomm_time.c => labcomm2014_time.c} (82%) rename lib/c/2014/{labcomm_type_signature.c => labcomm2014_type_signature.c} (70%) rename lib/c/2014/{labcomm_type_signature.h => labcomm2014_type_signature.h} (67%) delete mode 100644 lib/c/2014/labcomm_encoder.c delete mode 100644 lib/c/2014/labcomm_scheduler_private.h diff --git a/compiler/2014/C_CodeGen.jrag b/compiler/2014/C_CodeGen.jrag index d0dc920..9b7cac5 100644 --- a/compiler/2014/C_CodeGen.jrag +++ b/compiler/2014/C_CodeGen.jrag @@ -192,7 +192,7 @@ aspect C_CodeGen { env.println(""); // Include - env.println("#include \"labcomm"+env.verStr+".h\""); + env.println("#include \"labcomm2014.h\""); for (int i = 0 ; i < includes.size() ; i++) { env.println("#include \"" + includes.get(i) + "\""); } @@ -208,8 +208,8 @@ aspect C_CodeGen { C_env env = new C_env("", lcName, prefix, out, version); // Include - env.println("#include \"labcomm"+env.verStr+".h\""); - env.println("#include \"labcomm"+env.verStr+"_private.h\""); + env.println("#include \"labcomm2014.h\""); + env.println("#include \"labcomm2014_private.h\""); for (int i = 0 ; i < includes.size() ; i++) { env.println("#include \"" + includes.get(i) + "\""); } @@ -285,8 +285,8 @@ aspect C_Type { env.println(";"); env.println("#define LABCOMM_DEFINED_" + env.prefix + getName()); env.println("#endif"); - env.println("extern const struct labcomm"+env.verStr+"_signature " + - "*labcomm"+env.verStr+"_signature_" + env.prefix + getName() + + env.println("extern const struct labcomm2014_signature " + + "*labcomm2014_signature_" + env.prefix + getName() + ";"); } @@ -311,7 +311,7 @@ aspect C_Type { case LABCOMM_DOUBLE: { env.print("double"); } break; case LABCOMM_STRING: { env.print("char*"); } break; case LABCOMM_SAMPLE: { - env.print("const struct labcomm_signature *"); + env.print("const struct labcomm2014_signature *"); } break; } env.print(" " + name); @@ -383,10 +383,10 @@ aspect C_Declarations { } public void SampleDecl.C_emitDecoderDeclaration(C_env env) { - env.println("int labcomm"+env.verStr+"_decoder_register_" + + env.println("int labcomm2014_decoder_register_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_decoder *d,"); + env.println("struct labcomm2014_decoder *d,"); env.println("void (*handler)("); env.indent(); env.println(env.prefix + getName() + " *v,"); @@ -397,9 +397,9 @@ aspect C_Declarations { env.unindent(); env.println(");"); - env.println("int labcomm"+env.verStr+"_decoder_ioctl_" + env.prefix + getName() + "("); + env.println("int labcomm2014_decoder_ioctl_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_decoder *d,"); + env.println("struct labcomm2014_decoder *d,"); env.println("int ioctl_action,"); env.println("..."); env.unindent(); @@ -410,24 +410,24 @@ aspect C_Declarations { } public void SampleDecl.C_emitEncoderDeclaration(C_env env) { - env.println("int labcomm"+env.verStr+"_encoder_register_" + + env.println("int labcomm2014_encoder_register_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_encoder *e);"); + env.println("struct labcomm2014_encoder *e);"); env.unindent(); - env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "("); + env.println("int labcomm2014_encode_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_encoder *e"); + env.println("struct labcomm2014_encoder *e"); if(!isVoid() ) { env.println(", "+env.prefix + getName() + " *v"); } env.unindent(); env.println(");"); - env.println("int labcomm"+env.verStr+"_encoder_ioctl_" + env.prefix + getName() + "("); + env.println("int labcomm2014_encoder_ioctl_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_encoder *e,"); + env.println("struct labcomm2014_encoder *e,"); env.println("int ioctl_action,"); env.println("..."); env.unindent(); @@ -489,7 +489,7 @@ aspect C_Decoder { env = env.nestStruct("v"); env.println("static void decode_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_reader *r,"); + env.println("struct labcomm2014_reader *r,"); env.println("void (*handle)("); env.indent(); env.println(env.prefix + getName() + " *v,"); @@ -528,11 +528,11 @@ aspect C_Decoder { env.print(env.qualid + " = "); switch (getToken()) { case LABCOMM_SAMPLE: { - env.println("labcomm_internal_decoder_index_to_signature(" + - "r->decoder, labcomm"+env.verStr+"_read_int(r));"); + env.println("labcomm2014_internal_decoder_index_to_signature(" + + "r->decoder, labcomm2014_read_int(r));"); } break; default: { - env.println("labcomm"+env.verStr+"_read_" + getName() + "(r);"); + env.println("labcomm2014_read_" + getName() + "(r);"); }; break; } } @@ -580,7 +580,7 @@ aspect C_Decoder { } public void VariableSize.C_emitDecoderDecodeLimit(C_env env, int i) { - env.println(env.qualid + ".n_" + i + " = labcomm"+env.verStr+"_read_packed32(r);"); + env.println(env.qualid + ".n_" + i + " = labcomm2014_read_packed32(r);"); } public void ArrayType.C_emitDecoderDecodeLimit(C_env env) { @@ -594,7 +594,7 @@ aspect C_Decoder { public void VariableArrayType.C_emitDecoderArrayAllocate(C_env env) { env.print(env.qualid + - ".a = labcomm"+env.verStr+"_memory_alloc(r->memory, 1, sizeof(" + + ".a = labcomm2014_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)); @@ -612,7 +612,7 @@ aspect C_Decoder { public void PrimType.C_emitDecoderDeallocation(C_env env) { if (C_isDynamic()) { - env.println("labcomm"+env.verStr+"_memory_free(r->memory, 1, " + + env.println("labcomm2014_memory_free(r->memory, 1, " + env.qualid + ");"); } } @@ -658,7 +658,7 @@ aspect C_Decoder { public void VariableArrayType.C_emitDecoderDeallocation(C_env env) { super.C_emitDecoderDeallocation(env); - env.println("labcomm"+env.verStr+"_memory_free(r->memory, 1, " + + env.println("labcomm2014_memory_free(r->memory, 1, " + env.qualid + ".a);"); } @@ -676,10 +676,10 @@ aspect C_Decoder { } public void SampleDecl.C_emitDecoderRegisterHandler(C_env env) { - env.println("int labcomm"+env.verStr+"_decoder_register_" + + env.println("int labcomm2014_decoder_register_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_decoder *d,"); + env.println("struct labcomm2014_decoder *d,"); env.println("void (*handler)("); env.indent(); env.println(env.prefix + getName() + " *v,"); @@ -691,12 +691,12 @@ aspect C_Decoder { env.println(")"); env.println("{"); env.indent(); - env.println("return labcomm"+env.verStr+"_internal_decoder_register("); + env.println("return labcomm2014_internal_decoder_register("); env.indent(); env.println("d,"); env.println("&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("(labcomm2014_decoder_function)decode_" + env.prefix + getName() + ","); + env.println("(labcomm2014_handler_function)handler,"); env.println("context"); env.unindent(); env.println(");"); @@ -711,10 +711,10 @@ aspect C_copy { private void SampleDecl.C_emitCopyFunctionParam(C_env env, String src, String dst) { - env.println("void labcomm" + env.verStr + "_copy_" + + env.println("void labcomm2014_copy_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm" + env.verStr + "_memory *mem,"); + env.println("struct labcomm2014_memory *mem,"); env.println(env.prefix + getName() + " *" + dst + ","); env.println(env.prefix + getName() + " *" + src); env.unindent(); @@ -765,9 +765,8 @@ aspect C_copy { public void PrimType.C_emitCopy(C_env env_src, C_env env_dst) { if (C_isDynamic()) { env_src.println(String.format( - "%s%s = labcomm%s_memory_alloc(mem, 1, strlen(%s%s)+1);", + "%s%s = labcomm2014_memory_alloc(mem, 1, strlen(%s%s)+1);", env_dst.accessor(), env_dst.qualid, - env_src.verStr, env_src.accessor(), env_src.qualid)); env_src.println(String.format( "memcpy(%s%s, %s%s, strlen(%s%s)+1);", @@ -843,8 +842,7 @@ aspect C_copy { C_env env_dst) { env_src.print(env_dst.qualid + env_dst.memberAccessor() + - "a = labcomm" + env_src.verStr + - "_memory_alloc(mem, 1, sizeof(" + + "a = labcomm2014_memory_alloc(mem, 1, sizeof(" + env_src.qualid + env_src.memberAccessor() + "a[0])"); for (int i = 0 ; i < getNumExp() ; i++) { env_src.print(" * " + getExp(i).C_getLimit(env_src, i)); @@ -857,10 +855,10 @@ aspect C_copy { private void SampleDecl.C_emitCopyDeallocationFunctionParam(C_env env, String par) { - env.println("void labcomm" + env.verStr + "_copy_free_" + + env.println("void labcomm2014_copy_free_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm" + env.verStr + "_memory *mem,"); + env.println("struct labcomm2014_memory *mem,"); env.println(env.prefix + getName() + " *" + par); env.unindent(); env.print(")"); @@ -907,7 +905,7 @@ aspect C_copy { public void PrimType.C_emitCopyDeallocation(C_env env) { if (C_isDynamic()) { - env.println("labcomm" + env.verStr + "_memory_free(mem, 1, " + + env.println("labcomm2014_memory_free(mem, 1, " + env.accessor() + env.qualid + ");"); } } @@ -953,7 +951,7 @@ aspect C_copy { public void VariableArrayType.C_emitCopyDeallocation(C_env env) { super.C_emitCopyDeallocation(env); - env.println("labcomm" + env.verStr + "_memory_free(mem, 1, " + + env.println("labcomm2014_memory_free(mem, 1, " + env.qualid + env.memberAccessor() + "a);"); } @@ -975,9 +973,9 @@ aspect C_DecoderIoctl { } public void SampleDecl.C_emitDecoderIoctl(C_env env) { - env.println("int labcomm"+env.verStr+"_decoder_ioctl_" + env.prefix + getName() + "("); + env.println("int labcomm2014_decoder_ioctl_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_decoder *d,"); + env.println("struct labcomm2014_decoder *d,"); env.println("int ioctl_action,"); env.println("..."); env.unindent(); @@ -987,7 +985,7 @@ aspect C_DecoderIoctl { env.println("int result;"); env.println("va_list va;"); env.println("va_start(va, ioctl_action);"); - env.println("result = labcomm"+env.verStr+"_internal_decoder_ioctl("); + env.println("result = labcomm2014_internal_decoder_ioctl("); env.indent(); env.println("d, &signature_" + env.prefix + getName() + ", "); env.println("ioctl_action, va);"); @@ -1016,7 +1014,7 @@ aspect C_Encoder { env = env.nestStruct("(*v)"); env.println("static int encode_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_writer *w"); + env.println("struct labcomm2014_writer *w"); if(!isVoid() ) { env.println(", "+env.prefix + getName() + " *v"); } @@ -1031,8 +1029,8 @@ aspect C_Encoder { env.println("}"); // Typesafe encode wrapper - env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "("); - env.println("struct labcomm"+env.verStr+"_encoder *e"); + env.println("int labcomm2014_encode_" + env.prefix + getName() + "("); + env.println("struct labcomm2014_encoder *e"); if(!isVoid() ) { env.println(", "+env.prefix + getName() + " *v"); } @@ -1040,9 +1038,9 @@ aspect C_Encoder { env.println(")"); env.println("{"); env.indent(); - env.println("return labcomm"+env.verStr+"_internal_encode(e, &signature_" + + env.println("return labcomm2014_internal_encode(e, &signature_" + env.prefix + getName() + - ", (labcomm"+env.verStr+"_encoder_function)encode_" + + ", (labcomm2014_encoder_function)encode_" + env.prefix + getName() + (!isVoid()?", v":", NULL")+");"); env.unindent(); @@ -1063,12 +1061,12 @@ aspect C_Encoder { env.print("result = "); switch (getToken()) { case LABCOMM_SAMPLE: { - env.println("labcomm"+env.verStr+"_write_int(w, " + - "labcomm_internal_encoder_signature_to_index(w->encoder, " + + env.println("labcomm2014_write_int(w, " + + "labcomm2014_internal_encoder_signature_to_index(w->encoder, " + env.qualid + "));"); } break; default: { - env.println("labcomm"+env.verStr+"_write_" + getName() + + env.println("labcomm2014_write_" + getName() + "(w, " + env.qualid + ");"); } break; } @@ -1117,7 +1115,7 @@ aspect C_Encoder { } public void VariableSize.C_emitEncoderEncodeLimit(C_env env, int i) { - env.println("labcomm"+env.verStr+"_write_packed32(w, " + env.qualid + ".n_" + i + ");"); + env.println("labcomm2014_write_packed32(w, " + env.qualid + ".n_" + i + ");"); } public void ArrayType.C_emitEncoderEncodeLimit(C_env env) { @@ -1133,10 +1131,10 @@ aspect C_Encoder { } protected void Decl.C_emitEncoderTypeRegister(C_env env) { - env.println("int labcomm"+env.verStr+"_encoder_type_register_" + + env.println("int labcomm2014_encoder_type_register_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_encoder *e"); + env.println("struct labcomm2014_encoder *e"); env.unindent(); env.println(")"); env.println("{"); @@ -1146,7 +1144,7 @@ aspect C_Encoder { C_emitUserTypeDeps(env, null, true); if(!isSampleDecl() || hasDependencies()) { - env.println("return labcomm"+env.verStr+"_internal_encoder_type_register("); + env.println("return labcomm2014_internal_encoder_type_register("); env.indent(); env.println("e,"); env.println("&signature_" + env.prefix + getName() + ""); @@ -1165,10 +1163,10 @@ aspect C_Encoder { public void SampleDecl.C_emitEncoderRegisterHandler(C_env env) { C_emitEncoderTypeRegister(env); - env.println("int labcomm"+env.verStr+"_encoder_register_" + + env.println("int labcomm2014_encoder_register_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_encoder *e"); + env.println("struct labcomm2014_encoder *e"); env.unindent(); env.println(")"); env.println("{"); @@ -1176,17 +1174,17 @@ aspect C_Encoder { C_emitUserTypeDeps(env, null, false); //XXX HERE BE DRAGONS //currently set to false to turn off //outputting of code - env.println("int result = labcomm"+env.verStr+"_internal_encoder_register("); + env.println("int result = labcomm2014_internal_encoder_register("); env.indent(); env.println("e,"); env.println("&signature_" + env.prefix + getName() + ","); - env.println("(labcomm"+env.verStr+"_encoder_function)encode_" + env.prefix + getName()); + env.println("(labcomm2014_encoder_function)encode_" + env.prefix + getName()); env.unindent(); env.println(");"); env.println("if(result >= 0) {\n"); env.indent(); - env.println("labcomm"+env.verStr+"_encoder_type_register_" + env.prefix + getName()+"(e);"); - env.println("labcomm"+env.verStr+"_internal_encoder_type_bind("); + env.println("labcomm2014_encoder_type_register_" + env.prefix + getName()+"(e);"); + env.println("labcomm2014_internal_encoder_type_bind("); env.indent(); env.println("e,"); env.println("&signature_" + env.prefix + getName() + ","); @@ -1212,9 +1210,9 @@ aspect C_EncoderIoctl { } public void SampleDecl.C_emitEncoderIoctl(C_env env) { - env.println("int labcomm"+env.verStr+"_encoder_ioctl_" + env.prefix + getName() + "("); + env.println("int labcomm2014_encoder_ioctl_" + env.prefix + getName() + "("); env.indent(); - env.println("struct labcomm"+env.verStr+"_encoder *e,"); + env.println("struct labcomm2014_encoder *e,"); env.println("int ioctl_action,"); env.println("..."); env.unindent(); @@ -1224,7 +1222,7 @@ aspect C_EncoderIoctl { env.println("int result;"); env.println("va_list va;"); env.println("va_start(va, ioctl_action);"); - env.println("result = labcomm"+env.verStr+"_internal_encoder_ioctl("); + env.println("result = labcomm2014_internal_encoder_ioctl("); env.indent(); env.println("e, &signature_" + env.prefix + getName() + ", "); env.println("ioctl_action, va);"); @@ -1246,7 +1244,7 @@ aspect C_TypeDependencies { t.C_emitUserTypeDeps(env, t.getName(), outputCode); if(outputCode) { - env.println("labcomm"+env.verStr+"_encoder_type_register_"+env.prefix + t.getName()+"(e);"); + env.println("labcomm2014_encoder_type_register_"+env.prefix + t.getName()+"(e);"); } else { // Just output a comment String refpath = (via == null) ? "directly" : "indirectly via "+via; env.println(" //Depends ("+refpath+") on "+t.getName() ); @@ -1263,7 +1261,7 @@ aspect C_TypeDependencies { t.C_emitUserTypeRefs(env, t.getName(), outputCode); if(outputCode) { - env.println("labcomm"+env.verStr+"_encoder_type_register_"+env.prefix + t.getName()+"(e);"); + env.println("labcomm2014_encoder_type_register_"+env.prefix + t.getName()+"(e);"); } else { // Just output a comment String refpath = (via == null) ? "directly" : "indirectly via "+via; env.println(" //Is referenced ("+refpath+") by "+t.getName() ); @@ -1305,7 +1303,7 @@ aspect C_Signature { public void TypeDecl.C_emitFlatSignature(C_env env) { C_emitSizeofValue(env); - env.println("static struct labcomm"+env.verStr+"_signature " + + env.println("static struct labcomm2014_signature " + "signature_" + env.prefix + getName() + " = {"); env.indent(); env.println("\"" + getName() + "\","); @@ -1319,8 +1317,8 @@ aspect C_Signature { env.println("signature_tree_" + env.prefix + getName() + ""); env.unindent(); env.println(" };"); - env.println("const struct labcomm"+env.verStr+"_signature " + - "*labcomm"+env.verStr+"_signature_" + env.prefix + getName() + + env.println("const struct labcomm2014_signature " + + "*labcomm2014_signature_" + env.prefix + getName() + " = &signature_" + env.prefix + getName() + ";"); } @@ -1345,7 +1343,7 @@ aspect C_Signature { env.println("};"); C_emitSizeofValue(env); - env.println("static struct labcomm"+env.verStr+"_signature " + + env.println("static struct labcomm2014_signature " + "signature_" + env.prefix + getName() + " = {"); env.indent(); env.println("\"" + getName() + "\","); @@ -1357,8 +1355,8 @@ aspect C_Signature { env.println("signature_tree_" + env.prefix + getName() + ""); env.unindent(); env.println(" };"); - env.println("const struct labcomm"+env.verStr+"_signature " + - "*labcomm"+env.verStr+"_signature_" + env.prefix + getName() + + env.println("const struct labcomm2014_signature " + + "*labcomm2014_signature_" + env.prefix + getName() + " = &signature_" + env.prefix + getName() + ";"); } @@ -1370,7 +1368,7 @@ aspect C_Signature { public void TypeRefSignatureLine.C_emitSignature(C_env env, boolean isDecl){ env.print(getIndentString()); - // env.println("LABCOMM_SIGDEF_SIGNATURE(labcomm"+env.verStr+"_signature_" + env.prefix + decl.getName() +"),"); + // env.println("LABCOMM_SIGDEF_SIGNATURE(labcomm2014_signature_" + env.prefix + decl.getName() +"),"); env.println("LABCOMM_SIGDEF_SIGNATURE(signature_" + env.prefix + decl.getName() +"),"); } @@ -1399,8 +1397,8 @@ aspect C_Signature { // if (data != null) { // for (int j = 0 ; j < data.length ; j++) { // env.print(getIndentString()); -// //env.print("printf(\"labcomm"+env.verStr+"_write_byte( w, (unsigned char)"+ String.format("0x%02X ", data[j]) +")\\n\"); "); -// env.print("labcomm"+env.verStr+"_write_byte( w, (unsigned char)"+ String.format("0x%02X ", data[j]) +"); "); +// //env.print("printf(\"labcomm2014_write_byte( w, (unsigned char)"+ String.format("0x%02X ", data[j]) +")\\n\"); "); +// env.print("labcomm2014_write_byte( w, (unsigned char)"+ String.format("0x%02X ", data[j]) +"); "); // env.println("if (result != 0) { return result; }"); // } // env.println(); @@ -1408,7 +1406,7 @@ aspect C_Signature { // //} public void SignatureList.C_emitSignature(C_env env, boolean decl) { - env.println("static struct labcomm_signature_data signature_tree_" + + env.println("static struct labcomm2014_signature_data signature_tree_" + env.prefix + parentDecl().getName() + "[] = {"); env.indent(); for (int i = 0 ; i < size() ; i++) { @@ -1443,11 +1441,11 @@ aspect C_Signature { // } // } // env.println("};"); -// env.println("struct labcomm"+env.verStr+"_signature labcomm"+env.verStr+"_signature_" + +// env.println("struct labcomm2014_signature labcomm2014_signature_" + // env.prefix + getName() + " = {"); // env.indent(); // env.println("LABCOMM_SAMPLE, \"" + getName() + "\","); -// env.println("(int (*)(struct labcomm"+env.verStr+"_signature *, void *))labcomm"+env.verStr+"_sizeof_" + +// env.println("(int (*)(struct labcomm2014_signature *, void *))labcomm2014_sizeof_" + // env.prefix + getName() + ","); // env.println("sizeof(signature_bytes_" + env.prefix + getName() + "),"); // env.println("signature_bytes_" + env.prefix + getName() + ","); @@ -1484,13 +1482,13 @@ aspect C_Constructor { public void TypeDecl.C_emitConstructor(C_env env) { if (isReferenced()) { - env.println("labcomm"+env.verStr+"_set_local_index(&signature_" + + env.println("labcomm2014_set_local_index(&signature_" + env.prefix + getName() + ");"); } } public void SampleDecl.C_emitConstructor(C_env env) { - env.println("labcomm"+env.verStr+"_set_local_index(&signature_" + + env.println("labcomm2014_set_local_index(&signature_" + env.prefix + getName() + ");"); } @@ -1513,7 +1511,7 @@ aspect C_Sizeof { } public void SampleDecl.C_emitSizeofDeclaration(C_env env) { - env.println("extern int labcomm"+env.verStr+"_sizeof_" + env.prefix + getName() + + env.println("extern int labcomm2014_sizeof_" + env.prefix + getName() + "(" + env.prefix + getName() + " *v);"); } @@ -1526,11 +1524,11 @@ aspect C_Sizeof { public void SampleDecl.C_emitSizeof(C_env env) { env = env.nestStruct("(*v)"); - env.println("int labcomm"+env.verStr+"_sizeof_" + env.prefix + getName() + + env.println("int labcomm2014_sizeof_" + env.prefix + getName() + "(" + env.prefix + getName() + " *v)"); env.println("{"); env.indent(); - env.println("return labcomm"+env.verStr+"_internal_sizeof(" + + env.println("return labcomm2014_internal_sizeof(" + "&signature_" + env.prefix + getName() + ", v);"); env.unindent(); @@ -1616,7 +1614,7 @@ aspect C_Sizeof { switch (getToken()) { case LABCOMM_STRING: { env.print("{ int l = strlen(" + env.qualid + "); "); - env.println("result += labcomm"+env.verStr+"_size_packed32(l) + l; }"); + env.println("result += labcomm2014_size_packed32(l) + l; }"); } break; default: { throw new Error(this.getClass().getName() + @@ -1649,7 +1647,7 @@ aspect C_Sizeof { } public void VariableSize.C_emitSizeof(C_env env, int i) { - env.println("result += labcomm"+env.verStr+"_size_packed32(" + + env.println("result += labcomm2014_size_packed32(" + env.qualid + env.memberAccessor() + "n_" + i + ");"); } diff --git a/examples/simple/example_decoder.c b/examples/simple/example_decoder.c index 107aada..493ae34 100644 --- a/examples/simple/example_decoder.c +++ b/examples/simple/example_decoder.c @@ -1,10 +1,10 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <labcomm_fd_reader.h> -#include <labcomm_default_error_handler.h> -#include <labcomm_default_memory.h> -#include <labcomm_default_scheduler.h> +#include <labcomm2014_fd_reader.h> +#include <labcomm2014_default_error_handler.h> +#include <labcomm2014_default_memory.h> +#include <labcomm2014_default_scheduler.h> #include "gen/simple.h" #include <stdio.h> @@ -57,33 +57,33 @@ static void handle_simple_TwoFixedArrays(simple_TwoFixedArrays *d,void *context) int main(int argc, char *argv[]) { int fd; - struct labcomm_decoder *decoder; + struct labcomm2014_decoder *decoder; void *context = NULL; char *filename = argv[1]; printf("C decoder reading from %s\n", filename); fd = open(filename, O_RDONLY); - decoder = labcomm_decoder_new(labcomm_fd_reader_new( - labcomm_default_memory, fd, 1), - labcomm_default_error_handler, - labcomm_default_memory, - labcomm_default_scheduler); + decoder = labcomm2014_decoder_new(labcomm2014_fd_reader_new( + labcomm2014_default_memory, fd, 1), + labcomm2014_default_error_handler, + labcomm2014_default_memory, + labcomm2014_default_scheduler); if (!decoder) { printf("Failed to allocate decoder %s:%d\n", __FUNCTION__, __LINE__); return 1; } - labcomm_decoder_register_simple_doavoid(decoder, handle_simple_doavoid, context); - labcomm_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context); - labcomm_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context); - labcomm_decoder_register_simple_IntString(decoder, handle_simple_IntString, context); - labcomm_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context); - labcomm_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context); + labcomm2014_decoder_register_simple_doavoid(decoder, handle_simple_doavoid, context); + labcomm2014_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context); + labcomm2014_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context); + labcomm2014_decoder_register_simple_IntString(decoder, handle_simple_IntString, context); + labcomm2014_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context); + labcomm2014_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context); printf("Decoding:\n"); - labcomm_decoder_run(decoder); + labcomm2014_decoder_run(decoder); printf("--- End Of File ---:\n"); - labcomm_decoder_free(decoder); + labcomm2014_decoder_free(decoder); return 0; } diff --git a/examples/simple/example_encoder.c b/examples/simple/example_encoder.c index ea77e11..c13e83d 100644 --- a/examples/simple/example_encoder.c +++ b/examples/simple/example_encoder.c @@ -1,53 +1,53 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <labcomm_fd_writer.h> -#include <labcomm_default_error_handler.h> -#include <labcomm_default_memory.h> -#include <labcomm_default_scheduler.h> +#include <labcomm2014_fd_writer.h> +#include <labcomm2014_default_error_handler.h> +#include <labcomm2014_default_memory.h> +#include <labcomm2014_default_scheduler.h> #include "gen/simple.h" #include <stdio.h> int main(int argc, char *argv[]) { int fd; - struct labcomm_encoder *encoder; + struct labcomm2014_encoder *encoder; char *filename = argv[1]; printf("C encoder writing to %s\n", filename); fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644); - encoder = labcomm_encoder_new(labcomm_fd_writer_new( - labcomm_default_memory, fd, 1), - labcomm_default_error_handler, - labcomm_default_memory, - labcomm_default_scheduler); - labcomm_encoder_register_simple_doavoid(encoder); - labcomm_encoder_register_simple_theTwoInts(encoder); - labcomm_encoder_register_simple_anotherTwoInts(encoder); - labcomm_encoder_register_simple_IntString(encoder); - - labcomm_encode_simple_doavoid(encoder); + encoder = labcomm2014_encoder_new(labcomm2014_fd_writer_new( + labcomm2014_default_memory, fd, 1), + labcomm2014_default_error_handler, + labcomm2014_default_memory, + labcomm2014_default_scheduler); + labcomm2014_encoder_register_simple_doavoid(encoder); + labcomm2014_encoder_register_simple_theTwoInts(encoder); + labcomm2014_encoder_register_simple_anotherTwoInts(encoder); + labcomm2014_encoder_register_simple_IntString(encoder); + + labcomm2014_encode_simple_doavoid(encoder); simple_IntString is; is.x = 24; is.s = "Hello, LabComm!"; printf("Encoding IntString, x=%d, s=%s\n", is.x, is.s); - labcomm_encode_simple_IntString(encoder, &is); + labcomm2014_encode_simple_IntString(encoder, &is); simple_theTwoInts ti; ti.a = 13; ti.b = 37; printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b); - labcomm_encode_simple_theTwoInts(encoder, &ti); + labcomm2014_encode_simple_theTwoInts(encoder, &ti); simple_anotherTwoInts ati; ati.a = 23; ati.b = 47; printf("Encoding anotherTwoInts, a=%d, b=%d\n", ati.a, ati.b); - labcomm_encode_simple_anotherTwoInts(encoder, &ati); + labcomm2014_encode_simple_anotherTwoInts(encoder, &ati); int foo[20]; - labcomm_encoder_register_simple_TwoArrays(encoder); + labcomm2014_encoder_register_simple_TwoArrays(encoder); simple_TwoArrays ta; ta.fixed.a[0] = 17; @@ -61,12 +61,12 @@ int main(int argc, char *argv[]) { } printf("Encoding TwoArrays...\n"); - labcomm_encode_simple_TwoArrays(encoder, &ta); + labcomm2014_encode_simple_TwoArrays(encoder, &ta); ti.a = 23; ti.b = 47; printf("Encoding theTwoInts, a=%d, b=%d\n", ti.a, ti.b); - labcomm_encode_simple_theTwoInts(encoder, &ti); + labcomm2014_encode_simple_theTwoInts(encoder, &ti); simple_TwoFixedArrays tfa; @@ -82,8 +82,8 @@ int main(int argc, char *argv[]) { tfa.b.a[1][2] = 63; printf("Encoding TwoFixedArrays...\n"); - labcomm_encoder_register_simple_TwoFixedArrays(encoder); - labcomm_encode_simple_TwoFixedArrays(encoder, &tfa); + labcomm2014_encoder_register_simple_TwoFixedArrays(encoder); + labcomm2014_encode_simple_TwoFixedArrays(encoder, &tfa); return 0; } diff --git a/examples/twoway/client.c b/examples/twoway/client.c index 0166a35..f0e5447 100644 --- a/examples/twoway/client.c +++ b/examples/twoway/client.c @@ -36,12 +36,12 @@ #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> -#include <labcomm.h> -#include <labcomm_fd_reader.h> -#include <labcomm_fd_writer.h> -#include <labcomm_default_error_handler.h> -#include <labcomm_default_memory.h> -#include <labcomm_pthread_scheduler.h> +#include <labcomm2014.h> +#include <labcomm2014_fd_reader.h> +#include <labcomm2014_fd_writer.h> +#include <labcomm2014_default_error_handler.h> +#include <labcomm2014_default_memory.h> +#include <labcomm2014_pthread_scheduler.h> #include "decimating.h" #include "introspecting.h" #include "gen/types.h" @@ -63,13 +63,13 @@ static void handle_Product(int32_t *value, void *context) static void *run_decoder(void *context) { - struct labcomm_decoder *decoder = context; + struct labcomm2014_decoder *decoder = context; int result; - labcomm_decoder_register_types_Sum(decoder, handle_Sum, NULL); - labcomm_decoder_register_types_Diff(decoder, handle_Diff, NULL); + labcomm2014_decoder_register_types_Sum(decoder, handle_Sum, NULL); + labcomm2014_decoder_register_types_Diff(decoder, handle_Diff, NULL); do { - result = labcomm_decoder_decode_one(decoder); + result = labcomm2014_decoder_decode_one(decoder); } while (result >= 0); return NULL; } @@ -87,10 +87,10 @@ int main(int argc, char *argv[]) struct introspecting *introspecting; char *hostname; int port; - struct labcomm_scheduler *scheduler; - struct labcomm_decoder *decoder; - struct labcomm_encoder *encoder; - struct labcomm_time *next; + struct labcomm2014_scheduler *scheduler; + struct labcomm2014_decoder *decoder; + struct labcomm2014_encoder *encoder; + struct labcomm2014_time *next; int32_t i, j; hostname = argv[1]; @@ -128,13 +128,13 @@ int main(int argc, char *argv[]) nodelay = 1; setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay)); - scheduler = labcomm_pthread_scheduler_new(labcomm_default_memory); - decimating = decimating_new(labcomm_fd_reader_new(labcomm_default_memory, + scheduler = labcomm2014_pthread_scheduler_new(labcomm2014_default_memory); + decimating = decimating_new(labcomm2014_fd_reader_new(labcomm2014_default_memory, fd, 1), - labcomm_fd_writer_new(labcomm_default_memory, + labcomm2014_fd_writer_new(labcomm2014_default_memory, fd, 0), - labcomm_default_error_handler, - labcomm_default_memory, + labcomm2014_default_error_handler, + labcomm2014_default_memory, scheduler); if (decimating == NULL) { /* Warning: might leak reader and writer at this point */ @@ -142,45 +142,45 @@ int main(int argc, char *argv[]) } introspecting = introspecting_new(decimating->reader, decimating->writer, - labcomm_default_error_handler, - labcomm_default_memory, + labcomm2014_default_error_handler, + labcomm2014_default_memory, scheduler); if (introspecting == NULL) { /* Warning: might leak reader and writer at this point */ goto out; } - decoder = labcomm_decoder_new(introspecting->reader, - labcomm_default_error_handler, - labcomm_default_memory, + decoder = labcomm2014_decoder_new(introspecting->reader, + labcomm2014_default_error_handler, + labcomm2014_default_memory, scheduler); - encoder = labcomm_encoder_new(introspecting->writer, - labcomm_default_error_handler, - labcomm_default_memory, + encoder = labcomm2014_encoder_new(introspecting->writer, + labcomm2014_default_error_handler, + labcomm2014_default_memory, scheduler); pthread_t rdt; pthread_create(&rdt, NULL, run_decoder, decoder); - labcomm_encoder_register_types_A(encoder); - labcomm_encoder_register_types_B(encoder); - labcomm_encoder_register_types_Terminate(encoder); + labcomm2014_encoder_register_types_A(encoder); + labcomm2014_encoder_register_types_B(encoder); + labcomm2014_encoder_register_types_Terminate(encoder); - err = labcomm_decoder_ioctl_types_Sum(decoder, SET_DECIMATION, 2); - err = labcomm_decoder_ioctl_types_Diff(decoder, SET_DECIMATION, 4); + err = labcomm2014_decoder_ioctl_types_Sum(decoder, SET_DECIMATION, 2); + err = labcomm2014_decoder_ioctl_types_Diff(decoder, SET_DECIMATION, 4); - next = labcomm_scheduler_now(scheduler); + next = labcomm2014_scheduler_now(scheduler); for (i = 0 ; i < 4 ; i++) { if (i == 2) { - labcomm_decoder_register_types_Product(decoder, handle_Product, NULL); + labcomm2014_decoder_register_types_Product(decoder, handle_Product, NULL); } for (j = 0 ; j < 4 ; j++) { printf("\nA=%d B=%d: ", i, j); - labcomm_encode_types_A(encoder, &i); - labcomm_encode_types_B(encoder, &j); - labcomm_time_add_usec(next, 100000); - labcomm_scheduler_sleep(scheduler, next); + labcomm2014_encode_types_A(encoder, &i); + labcomm2014_encode_types_B(encoder, &j); + labcomm2014_time_add_usec(next, 100000); + labcomm2014_scheduler_sleep(scheduler, next); } } printf("\n"); - labcomm_encode_types_Terminate(encoder); + labcomm2014_encode_types_Terminate(encoder); out: return 0; diff --git a/examples/twoway/decimating.c b/examples/twoway/decimating.c index ea3cfab..705f4ce 100644 --- a/examples/twoway/decimating.c +++ b/examples/twoway/decimating.c @@ -23,18 +23,18 @@ #include <errno.h> #include <stdio.h> #include <stdlib.h> -#include "labcomm_private.h" +#include "labcomm2014_private.h" #include "decimating.h" #include "gen/decimating_messages.h" struct decimating_private { struct decimating decimating; - struct labcomm_error_handler *error; - struct labcomm_memory *memory; - struct labcomm_scheduler *scheduler; + struct labcomm2014_error_handler *error; + struct labcomm2014_memory *memory; + struct labcomm2014_scheduler *scheduler; int encoder_initialized; - struct labcomm_reader_action_context reader_action_context; - struct labcomm_writer_action_context writer_action_context; + struct labcomm2014_reader_action_context reader_action_context; + struct labcomm2014_writer_action_context writer_action_context; LABCOMM_SIGNATURE_ARRAY_DEF(writer_decimation, struct decimation { int n; @@ -50,25 +50,25 @@ static void set_decimation( struct decimating_private *decimating = context; struct decimation *decimation; - labcomm_scheduler_data_lock(decimating->scheduler); + labcomm2014_scheduler_data_lock(decimating->scheduler); decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory, decimating->writer_decimation, struct decimation, value->signature_index); decimation->n = value->decimation; decimation->current = 0; - labcomm_scheduler_data_unlock(decimating->scheduler); + labcomm2014_scheduler_data_unlock(decimating->scheduler); } static int wrap_reader_alloc( - struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) + struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context) { struct decimating_private *decimating = action_context->context; - labcomm_decoder_register_decimating_messages_set_decimation( + labcomm2014_decoder_register_decimating_messages_set_decimation( r->decoder, set_decimation, decimating); - return labcomm_reader_alloc(r, action_context->next); + return labcomm2014_reader_alloc(r, action_context->next); } struct send_set_decimation { @@ -80,11 +80,11 @@ struct send_set_decimation { static void send_set_decimation(void *arg) { struct send_set_decimation *msg = arg; - struct labcomm_memory *memory = msg->decimating->memory; + struct labcomm2014_memory *memory = msg->decimating->memory; - labcomm_encode_decimating_messages_set_decimation( + labcomm2014_encode_decimating_messages_set_decimation( msg->decimating->decimating.writer->encoder, &msg->set_decimation); - labcomm_memory_free(memory, 1, msg); + labcomm2014_memory_free(memory, 1, msg); } static void enqueue_decimation(struct decimating_private *decimating, @@ -92,21 +92,21 @@ static void enqueue_decimation(struct decimating_private *decimating, int amount) { struct send_set_decimation *msg; - msg = labcomm_memory_alloc(decimating->memory, 1, sizeof(*msg)); + msg = labcomm2014_memory_alloc(decimating->memory, 1, sizeof(*msg)); if (msg) { msg->decimating = decimating; msg->set_decimation.decimation = amount; msg->set_decimation.signature_index = remote_index; - labcomm_scheduler_enqueue(decimating->scheduler, 0, + labcomm2014_scheduler_enqueue(decimating->scheduler, 0, send_set_decimation, msg); } } static int wrap_reader_start( - struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, - int local_index, int remote_index, const struct labcomm_signature *signature, + struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context, + int local_index, int remote_index, const struct labcomm2014_signature *signature, void *value) { struct decimating_private *decimating = action_context->context; @@ -114,26 +114,26 @@ static int wrap_reader_start( if (value == NULL) { int *decimation, amount; - labcomm_scheduler_data_lock(decimating->scheduler); + labcomm2014_scheduler_data_lock(decimating->scheduler); decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory, decimating->reader_decimation, int, local_index); amount = *decimation; - labcomm_scheduler_data_unlock(decimating->scheduler); + labcomm2014_scheduler_data_unlock(decimating->scheduler); if (remote_index != 0 && amount != 0) { enqueue_decimation(decimating, remote_index, amount); } } - return labcomm_reader_start(r, action_context->next, + return labcomm2014_reader_start(r, action_context->next, local_index, remote_index, signature, value); } static int wrap_reader_ioctl( - struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, + struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context, int local_index, int remote_index, - const struct labcomm_signature *signature, + const struct labcomm2014_signature *signature, uint32_t action, va_list args) { struct decimating_private *decimating = action_context->context; @@ -147,26 +147,26 @@ static int wrap_reader_ioctl( amount = va_arg(va, int); va_end(va); - labcomm_scheduler_data_lock(decimating->scheduler); + labcomm2014_scheduler_data_lock(decimating->scheduler); decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory, decimating->reader_decimation, int, local_index); *decimation = amount; - labcomm_scheduler_data_unlock(decimating->scheduler); + labcomm2014_scheduler_data_unlock(decimating->scheduler); if (remote_index) { enqueue_decimation(decimating, remote_index, amount); } } else { - return labcomm_reader_ioctl(r, action_context->next, + return labcomm2014_reader_ioctl(r, action_context->next, local_index, remote_index, signature, action, args); } return 0; } -struct labcomm_reader_action decimating_reader_action = { +struct labcomm2014_reader_action decimating_reader_action = { .alloc = wrap_reader_alloc, .free = NULL, .start = wrap_reader_start, @@ -179,25 +179,25 @@ static void register_signatures(void *context) { struct decimating_private *decimating = context; - labcomm_encoder_register_decimating_messages_set_decimation( + labcomm2014_encoder_register_decimating_messages_set_decimation( decimating->decimating.writer->encoder); } static int wrap_writer_alloc( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { struct decimating_private *decimating = action_context->context; - labcomm_scheduler_enqueue(decimating->scheduler, + labcomm2014_scheduler_enqueue(decimating->scheduler, 0, register_signatures, decimating); - return labcomm_writer_alloc(w, action_context->next); + return labcomm2014_writer_alloc(w, action_context->next); } static int wrap_writer_start( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int index, const struct labcomm_signature *signature, + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int index, const struct labcomm2014_signature *signature, void *value) { struct decimating_private *decimating = action_context->context; @@ -207,7 +207,7 @@ static int wrap_writer_start( if (index < LABCOMM_USER) { result = 0; } else { - labcomm_scheduler_data_lock(decimating->scheduler); + labcomm2014_scheduler_data_lock(decimating->scheduler); decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory, decimating->writer_decimation, struct decimation, index); @@ -218,16 +218,16 @@ static int wrap_writer_start( decimation->current = 0; result = 0; } - labcomm_scheduler_data_unlock(decimating->scheduler); + labcomm2014_scheduler_data_unlock(decimating->scheduler); } if (result == 0) { - result = labcomm_writer_start(w, action_context->next, + result = labcomm2014_writer_start(w, action_context->next, index, signature, value); } return result; } -struct labcomm_writer_action decimating_writer_action = { +struct labcomm2014_writer_action decimating_writer_action = { .alloc = wrap_writer_alloc, .free = NULL, .start = wrap_writer_start, @@ -237,11 +237,11 @@ struct labcomm_writer_action decimating_writer_action = { }; struct decimating *decimating_new( - struct labcomm_reader *reader, - struct labcomm_writer *writer, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler) + struct labcomm2014_reader *reader, + struct labcomm2014_writer *writer, + struct labcomm2014_error_handler *error, + struct labcomm2014_memory *memory, + struct labcomm2014_scheduler *scheduler) { struct decimating_private *result; diff --git a/examples/twoway/decimating.h b/examples/twoway/decimating.h index cdfedd7..3d91c67 100644 --- a/examples/twoway/decimating.h +++ b/examples/twoway/decimating.h @@ -1,20 +1,20 @@ #ifndef __DECIMATING_H__ #define __DECIMATING_H__ -#include <labcomm.h> -#include <labcomm_ioctl.h> +#include <labcomm2014.h> +#include <labcomm2014_ioctl.h> struct decimating { - struct labcomm_reader *reader; - struct labcomm_writer *writer; + struct labcomm2014_reader *reader; + struct labcomm2014_writer *writer; }; extern struct decimating *decimating_new( - struct labcomm_reader *reader, - struct labcomm_writer *writer, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler); + struct labcomm2014_reader *reader, + struct labcomm2014_writer *writer, + struct labcomm2014_error_handler *error, + struct labcomm2014_memory *memory, + struct labcomm2014_scheduler *scheduler); #define SET_DECIMATION LABCOMM_IOSW('d',0,int) diff --git a/examples/twoway/introspecting.c b/examples/twoway/introspecting.c index 3c64c19..87bffeb 100644 --- a/examples/twoway/introspecting.c +++ b/examples/twoway/introspecting.c @@ -23,18 +23,18 @@ #include <errno.h> #include <stdio.h> #include <stdlib.h> -#include "labcomm_private.h" +#include "labcomm2014_private.h" #include "introspecting.h" #include "gen/introspecting_messages.h" struct introspecting_private { struct introspecting introspecting; - struct labcomm_error_handler *error; - struct labcomm_memory *memory; - struct labcomm_scheduler *scheduler; + struct labcomm2014_error_handler *error; + struct labcomm2014_memory *memory; + struct labcomm2014_scheduler *scheduler; - struct labcomm_reader_action_context reader_action_context; - struct labcomm_writer_action_context writer_action_context; + struct labcomm2014_reader_action_context reader_action_context; + struct labcomm2014_writer_action_context writer_action_context; LABCOMM_SIGNATURE_ARRAY_DEF(remote, struct remote { char *name; @@ -44,13 +44,13 @@ struct introspecting_private { LABCOMM_SIGNATURE_ARRAY_DEF(local, struct local { enum introspecting_status status; - const struct labcomm_signature *signature; + const struct labcomm2014_signature *signature; }); }; static struct local *get_local(struct introspecting_private *introspecting, int index, - const struct labcomm_signature *signature) + const struct labcomm2014_signature *signature) { /* Called with data_lock held */ struct local *local; @@ -91,7 +91,7 @@ static void handles_signature( struct introspecting_private *introspecting = context; struct remote *remote; - labcomm_scheduler_data_lock(introspecting->scheduler); + labcomm2014_scheduler_data_lock(introspecting->scheduler); remote = LABCOMM_SIGNATURE_ARRAY_REF(introspecting->memory, introspecting->remote, struct remote, @@ -119,25 +119,25 @@ static void handles_signature( } } } - labcomm_scheduler_data_unlock(introspecting->scheduler); + labcomm2014_scheduler_data_unlock(introspecting->scheduler); } static int wrap_reader_alloc( - struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) + struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context) { struct introspecting_private *introspecting = action_context->context; - labcomm_decoder_register_introspecting_messages_handles_signature( + labcomm2014_decoder_register_introspecting_messages_handles_signature( introspecting->introspecting.reader->decoder, handles_signature, introspecting); - return labcomm_reader_alloc(r, action_context->next); + return labcomm2014_reader_alloc(r, action_context->next); } struct handles_signature { struct introspecting_private *introspecting; int index; - const struct labcomm_signature *signature; + const struct labcomm2014_signature *signature; }; static void send_handles_signature(void *arg) @@ -149,14 +149,14 @@ static void send_handles_signature(void *arg) handles_signature.name = h->signature->name; handles_signature.signature.n_0 = h->signature->size; handles_signature.signature.a = h->signature->signature; - labcomm_encode_introspecting_messages_handles_signature( + labcomm2014_encode_introspecting_messages_handles_signature( h->introspecting->introspecting.writer->encoder, &handles_signature); } static int wrap_reader_start( - struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context, - int local_index, int remote_index, const struct labcomm_signature *signature, + struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context, + int local_index, int remote_index, const struct labcomm2014_signature *signature, void *value) { struct introspecting_private *introspecting = action_context->context; @@ -164,23 +164,23 @@ static int wrap_reader_start( if (value == NULL) { struct handles_signature *handles_signature; - handles_signature = labcomm_memory_alloc(introspecting->memory, 1, + handles_signature = labcomm2014_memory_alloc(introspecting->memory, 1, sizeof(*handles_signature)); handles_signature->introspecting = introspecting; handles_signature->index = local_index; handles_signature->signature = signature; - labcomm_scheduler_enqueue(introspecting->scheduler, + labcomm2014_scheduler_enqueue(introspecting->scheduler, 0, send_handles_signature, handles_signature); } - return labcomm_reader_start(r, action_context->next, + return labcomm2014_reader_start(r, action_context->next, local_index, remote_index, signature, value); } void encode_handles_signature( - struct labcomm_encoder *encoder, + struct labcomm2014_encoder *encoder, void *context) { - const struct labcomm_signature *signature = context; + const struct labcomm2014_signature *signature = context; introspecting_messages_handles_signature handles_signature; int index = 0; @@ -189,11 +189,11 @@ static int wrap_reader_start( handles_signature.signature.n_0 = signature->size; handles_signature.signature.a = signature->signature; - labcomm_encode_introspecting_messages_handles_signature( + labcomm2014_encode_introspecting_messages_handles_signature( NULL, &handles_signature); } -struct labcomm_reader_action introspecting_reader_action = { +struct labcomm2014_reader_action introspecting_reader_action = { .alloc = wrap_reader_alloc, .free = NULL, .start = wrap_reader_start, @@ -206,25 +206,25 @@ static void register_encoder_signatures(void *context) { struct introspecting_private *introspecting = context; - labcomm_encoder_register_introspecting_messages_handles_signature( + labcomm2014_encoder_register_introspecting_messages_handles_signature( introspecting->introspecting.writer->encoder); } static int wrap_writer_alloc( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { struct introspecting_private *introspecting = action_context->context; - labcomm_scheduler_enqueue(introspecting->scheduler, + labcomm2014_scheduler_enqueue(introspecting->scheduler, 0, register_encoder_signatures, introspecting); - return labcomm_writer_alloc(w, action_context->next); + return labcomm2014_writer_alloc(w, action_context->next); } static int wrap_writer_start( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int index, const struct labcomm_signature *signature, + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int index, const struct labcomm2014_signature *signature, void *value) { struct introspecting_private *introspecting = action_context->context; @@ -232,18 +232,18 @@ static int wrap_writer_start( if (index >= LABCOMM_USER && value == NULL) { struct local *local; - labcomm_scheduler_data_lock(introspecting->scheduler); + labcomm2014_scheduler_data_lock(introspecting->scheduler); local = get_local(introspecting, index, signature); local->status = introspecting_registered; - labcomm_scheduler_data_unlock(introspecting->scheduler); + labcomm2014_scheduler_data_unlock(introspecting->scheduler); } - return labcomm_writer_start(w, action_context->next, index, signature, value); + return labcomm2014_writer_start(w, action_context->next, index, signature, value); } static int wrap_writer_ioctl( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int index, const struct labcomm_signature *signature, + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int index, const struct labcomm2014_signature *signature, uint32_t ioctl_action, va_list args) { struct introspecting_private *introspecting = action_context->context; @@ -253,20 +253,20 @@ static int wrap_writer_ioctl( struct local *local; int result; - labcomm_scheduler_data_lock(introspecting->scheduler); + labcomm2014_scheduler_data_lock(introspecting->scheduler); local = get_local(introspecting, index, signature); result = local->status; - labcomm_scheduler_data_unlock(introspecting->scheduler); + labcomm2014_scheduler_data_unlock(introspecting->scheduler); return result; } default: { - return labcomm_writer_ioctl(w, action_context->next, index, signature, + return labcomm2014_writer_ioctl(w, action_context->next, index, signature, ioctl_action, args); } break; } } -struct labcomm_writer_action introspecting_writer_action = { +struct labcomm2014_writer_action introspecting_writer_action = { .alloc = wrap_writer_alloc, .free = NULL, .start = wrap_writer_start, @@ -276,11 +276,11 @@ struct labcomm_writer_action introspecting_writer_action = { }; extern struct introspecting *introspecting_new( - struct labcomm_reader *reader, - struct labcomm_writer *writer, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler) + struct labcomm2014_reader *reader, + struct labcomm2014_writer *writer, + struct labcomm2014_error_handler *error, + struct labcomm2014_memory *memory, + struct labcomm2014_scheduler *scheduler) { struct introspecting_private *result; diff --git a/examples/twoway/introspecting.h b/examples/twoway/introspecting.h index 984670d..bcd3be7 100644 --- a/examples/twoway/introspecting.h +++ b/examples/twoway/introspecting.h @@ -23,22 +23,22 @@ #ifndef __INTROSPECTING_H__ #define __INTROSPECTING_H__ -#include <labcomm.h> -#include <labcomm_ioctl.h> -#include <labcomm_fd_reader.h> -#include <labcomm_fd_writer.h> +#include <labcomm2014.h> +#include <labcomm2014_ioctl.h> +#include <labcomm2014_fd_reader.h> +#include <labcomm2014_fd_writer.h> struct introspecting { - struct labcomm_reader *reader; - struct labcomm_writer *writer; + struct labcomm2014_reader *reader; + struct labcomm2014_writer *writer; }; extern struct introspecting *introspecting_new( - struct labcomm_reader *reader, - struct labcomm_writer *writer, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler); + struct labcomm2014_reader *reader, + struct labcomm2014_writer *writer, + struct labcomm2014_error_handler *error, + struct labcomm2014_memory *memory, + struct labcomm2014_scheduler *scheduler); #define HAS_SIGNATURE LABCOMM_IOS('i',2) enum introspecting_status { introspecting_unknown, diff --git a/examples/twoway/server.c b/examples/twoway/server.c index e6eaac0..152f8a9 100644 --- a/examples/twoway/server.c +++ b/examples/twoway/server.c @@ -33,11 +33,11 @@ #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> -#include <labcomm_default_error_handler.h> -#include <labcomm_default_memory.h> -#include <labcomm_pthread_scheduler.h> -#include <labcomm_fd_reader.h> -#include <labcomm_fd_writer.h> +#include <labcomm2014_default_error_handler.h> +#include <labcomm2014_default_memory.h> +#include <labcomm2014_pthread_scheduler.h> +#include <labcomm2014_fd_reader.h> +#include <labcomm2014_fd_writer.h> #include "decimating.h" #include "introspecting.h" #include "gen/types.h" @@ -49,9 +49,9 @@ struct client { struct sockaddr_in adr; unsigned int adrlen; int32_t A, B, Sum, Diff, Product; - struct labcomm_decoder *decoder; - struct labcomm_encoder *encoder; - struct labcomm_scheduler *scheduler; + struct labcomm2014_decoder *decoder; + struct labcomm2014_encoder *encoder; + struct labcomm2014_scheduler *scheduler; }; static void handle_A(int32_t *value, void *context) @@ -67,22 +67,22 @@ static void handle_B(int32_t *value, void *context) int status; client->B = *value; - status = labcomm_encoder_ioctl_types_Product(client->encoder, HAS_SIGNATURE); + status = labcomm2014_encoder_ioctl_types_Product(client->encoder, HAS_SIGNATURE); switch (status) { case introspecting_unregistered: - labcomm_encoder_register_types_Product(client->encoder); + labcomm2014_encoder_register_types_Product(client->encoder); /* fall through */ case introspecting_registered: client->Product = client->A * client->B; - labcomm_encode_types_Product(client->encoder, &client->Product); + labcomm2014_encode_types_Product(client->encoder, &client->Product); break; default: break; } client->Sum = client->A + client->B; client->Diff = client->A - client->B; - labcomm_encode_types_Sum(client->encoder, &client->Sum); - labcomm_encode_types_Diff(client->encoder, &client->Diff); + labcomm2014_encode_types_Sum(client->encoder, &client->Sum); + labcomm2014_encode_types_Diff(client->encoder, &client->Diff); } static void handle_Terminate(types_Terminate *value, void *context) @@ -95,14 +95,14 @@ static void *run_decoder(void *arg) struct client *client = arg; int result; - labcomm_decoder_register_types_A(client->decoder, handle_A, client); - labcomm_decoder_register_types_B(client->decoder, handle_B, client); - labcomm_decoder_register_types_Terminate(client->decoder, handle_Terminate, + labcomm2014_decoder_register_types_A(client->decoder, handle_A, client); + labcomm2014_decoder_register_types_B(client->decoder, handle_B, client); + labcomm2014_decoder_register_types_Terminate(client->decoder, handle_Terminate, NULL); do { - result = labcomm_decoder_decode_one(client->decoder); + result = labcomm2014_decoder_decode_one(client->decoder); } while (result >= 0); - labcomm_scheduler_wakeup(client->scheduler); + labcomm2014_scheduler_wakeup(client->scheduler); return NULL; } @@ -115,13 +115,13 @@ static void *run_client(void *arg) printf("Client start\n"); client->A = 0; client->B = 0; - client->scheduler = labcomm_pthread_scheduler_new(labcomm_default_memory); - decimating = decimating_new(labcomm_fd_reader_new(labcomm_default_memory, + client->scheduler = labcomm2014_pthread_scheduler_new(labcomm2014_default_memory); + decimating = decimating_new(labcomm2014_fd_reader_new(labcomm2014_default_memory, client->fd, 1), - labcomm_fd_writer_new(labcomm_default_memory, + labcomm2014_fd_writer_new(labcomm2014_default_memory, client->fd, 0), - labcomm_default_error_handler, - labcomm_default_memory, + labcomm2014_default_error_handler, + labcomm2014_default_memory, client->scheduler); if (decimating == NULL) { /* Warning: might leak reader and writer at this point */ @@ -129,26 +129,26 @@ static void *run_client(void *arg) } introspecting = introspecting_new(decimating->reader, decimating->writer, - labcomm_default_error_handler, - labcomm_default_memory, + labcomm2014_default_error_handler, + labcomm2014_default_memory, client->scheduler); if (introspecting == NULL) { /* Warning: might leak reader and writer at this point */ goto out; } - client->decoder = labcomm_decoder_new(introspecting->reader, - labcomm_default_error_handler, - labcomm_default_memory, + client->decoder = labcomm2014_decoder_new(introspecting->reader, + labcomm2014_default_error_handler, + labcomm2014_default_memory, client->scheduler); - client->encoder = labcomm_encoder_new(introspecting->writer, - labcomm_default_error_handler, - labcomm_default_memory, + client->encoder = labcomm2014_encoder_new(introspecting->writer, + labcomm2014_default_error_handler, + labcomm2014_default_memory, client->scheduler); pthread_t rdt; pthread_create(&rdt, NULL, run_decoder, client); - labcomm_encoder_register_types_Sum(client->encoder); - labcomm_encoder_register_types_Diff(client->encoder); - labcomm_scheduler_sleep(client->scheduler, NULL); + labcomm2014_encoder_register_types_Sum(client->encoder); + labcomm2014_encoder_register_types_Diff(client->encoder); + labcomm2014_scheduler_sleep(client->scheduler, NULL); printf("Awoken\n"); pthread_join(rdt, NULL); out: diff --git a/examples/user_types/example_decoder.c b/examples/user_types/example_decoder.c index b727f8a..5d6062e 100644 --- a/examples/user_types/example_decoder.c +++ b/examples/user_types/example_decoder.c @@ -1,10 +1,10 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <labcomm_fd_reader.h> -#include <labcomm_default_error_handler.h> -#include <labcomm_default_memory.h> -#include <labcomm_default_scheduler.h> +#include <labcomm2014_fd_reader.h> +#include <labcomm2014_default_error_handler.h> +#include <labcomm2014_default_memory.h> +#include <labcomm2014_default_scheduler.h> #include "gen/test.h" #include <stdio.h> @@ -28,11 +28,11 @@ static void handle_test_theSecondInt(int *v,void *context) { printf("Got theSecondInt. (%d) \n", *v); } -static void handle_type_def(struct labcomm_raw_type_def *v,void *context) { +static void handle_type_def(struct labcomm2014_raw_type_def *v,void *context) { printf("Got type_def. (0x%x) %s\n", v->index, v->name); } -static void handle_type_binding(struct labcomm_type_binding *v,void *context) { +static void handle_type_binding(struct labcomm2014_type_binding *v,void *context) { printf("Got type binding. 0x%x --> 0x%x\n", v->sample_index, v->type_index); } @@ -45,37 +45,37 @@ static void handle_test_twoLines(test_twoLines *v,void *context) { int main(int argc, char *argv[]) { int fd; - struct labcomm_decoder *decoder; + struct labcomm2014_decoder *decoder; void *context = NULL; char *filename = argv[1]; printf("C decoder reading from %s\n", filename); fd = open(filename, O_RDONLY); - decoder = labcomm_decoder_new(labcomm_fd_reader_new( - labcomm_default_memory, fd, 1), - labcomm_default_error_handler, - labcomm_default_memory, - labcomm_default_scheduler); + decoder = labcomm2014_decoder_new(labcomm2014_fd_reader_new( + labcomm2014_default_memory, fd, 1), + labcomm2014_default_error_handler, + labcomm2014_default_memory, + labcomm2014_default_scheduler); if (!decoder) { printf("Failed to allocate decoder %s:%d\n", __FUNCTION__, __LINE__); return 1; } - labcomm_decoder_register_test_doavoid(decoder, handle_test_doavoid, context); - labcomm_decoder_register_test_intAndRef(decoder, handle_test_intAndRef, context); - labcomm_decoder_sample_ref_register(decoder,labcomm_signature_test_doavoid ); + labcomm2014_decoder_register_test_doavoid(decoder, handle_test_doavoid, context); + labcomm2014_decoder_register_test_intAndRef(decoder, handle_test_intAndRef, context); + labcomm2014_decoder_sample_ref_register(decoder,labcomm2014_signature_test_doavoid ); - labcomm_decoder_register_test_twoInts(decoder, handle_test_twoInts, context); - labcomm_decoder_register_test_theFirstInt(decoder, handle_test_theFirstInt, context); - labcomm_decoder_register_test_theSecondInt(decoder, handle_test_theSecondInt, context); - labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context); - labcomm_decoder_register_labcomm_type_def(decoder, handle_type_def, context); - labcomm_decoder_register_labcomm_type_binding(decoder, handle_type_binding, context); + labcomm2014_decoder_register_test_twoInts(decoder, handle_test_twoInts, context); + labcomm2014_decoder_register_test_theFirstInt(decoder, handle_test_theFirstInt, context); + labcomm2014_decoder_register_test_theSecondInt(decoder, handle_test_theSecondInt, context); + labcomm2014_decoder_register_test_twoLines(decoder, handle_test_twoLines, context); + labcomm2014_decoder_register_labcomm2014_type_def(decoder, handle_type_def, context); + labcomm2014_decoder_register_labcomm2014_type_binding(decoder, handle_type_binding, context); printf("Decoding:\n"); - labcomm_decoder_run(decoder); + labcomm2014_decoder_run(decoder); printf("--- End Of File ---:\n"); - labcomm_decoder_free(decoder); + labcomm2014_decoder_free(decoder); return 0; } diff --git a/examples/user_types/example_encoder.c b/examples/user_types/example_encoder.c index 3c76dcd..6c1d1ef 100644 --- a/examples/user_types/example_encoder.c +++ b/examples/user_types/example_encoder.c @@ -1,26 +1,26 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <labcomm_fd_writer.h> -#include <labcomm_default_error_handler.h> -#include <labcomm_default_memory.h> -#include <labcomm_default_scheduler.h> +#include <labcomm2014_fd_writer.h> +#include <labcomm2014_default_error_handler.h> +#include <labcomm2014_default_memory.h> +#include <labcomm2014_default_scheduler.h> #include "gen/test.h" #include <stdio.h> int main(int argc, char *argv[]) { int fd; - struct labcomm_encoder *encoder; + struct labcomm2014_encoder *encoder; char *filename = argv[1]; printf("C encoder writing to %s\n", filename); fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644); - encoder = labcomm_encoder_new(labcomm_fd_writer_new( - labcomm_default_memory, fd, 1), - labcomm_default_error_handler, - labcomm_default_memory, - labcomm_default_scheduler); - labcomm_encoder_register_test_twoLines(encoder); + encoder = labcomm2014_encoder_new(labcomm2014_fd_writer_new( + labcomm2014_default_memory, fd, 1), + labcomm2014_default_error_handler, + labcomm2014_default_memory, + labcomm2014_default_scheduler); + labcomm2014_encoder_register_test_twoLines(encoder); test_twoLines tl; @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) { tl.l2.end.y.val = 23; printf("Encoding twoLines...\n"); - labcomm_encode_test_twoLines(encoder, &tl); + labcomm2014_encode_test_twoLines(encoder, &tl); return 0; } diff --git a/examples/wiki_example/example_encoder.c b/examples/wiki_example/example_encoder.c index 3983a13..ee82c7a 100644 --- a/examples/wiki_example/example_encoder.c +++ b/examples/wiki_example/example_encoder.c @@ -1,24 +1,24 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <labcomm.h> -#include <labcomm_default_memory.h> -#include <labcomm_fd_reader.h> -#include <labcomm_fd_writer.h> +#include <labcomm2014.h> +#include <labcomm2014_default_memory.h> +#include <labcomm2014_fd_reader.h> +#include <labcomm2014_fd_writer.h> #include "example.h" int main(int argc, char *argv[]) { int fd; - struct labcomm_encoder *encoder; - struct labcomm_writer *labcomm_fd_writer; + struct labcomm2014_encoder *encoder; + struct labcomm2014_writer *labcomm2014_fd_writer; int i, j; fd = open("example.encoded", O_WRONLY|O_CREAT|O_TRUNC, 0644); - labcomm_fd_writer = labcomm_fd_writer_new(labcomm_default_memory, fd, 1); - encoder = labcomm_encoder_new(labcomm_fd_writer, NULL, - labcomm_default_memory, NULL); - labcomm_encoder_register_example_log_message(encoder); - labcomm_encoder_register_example_data(encoder); + labcomm2014_fd_writer = labcomm2014_fd_writer_new(labcomm2014_default_memory, fd, 1); + encoder = labcomm2014_encoder_new(labcomm2014_fd_writer, NULL, + labcomm2014_default_memory, NULL); + labcomm2014_encoder_register_example_log_message(encoder); + labcomm2014_encoder_register_example_data(encoder); for (i = 0 ; i < argc ; i++) { example_log_message message; @@ -29,12 +29,12 @@ int main(int argc, char *argv[]) { message.line.a[j].last = (j == message.line.n_0 - 1); message.line.a[j].data = argv[j + 1]; } - labcomm_encode_example_log_message(encoder, &message); + labcomm2014_encode_example_log_message(encoder, &message); free(message.line.a); } for (i = 0 ; i < argc ; i++) { float f = i; - labcomm_encode_example_data(encoder, &f); + labcomm2014_encode_example_data(encoder, &f); } return 0; } diff --git a/lib/c/2014/Makefile b/lib/c/2014/Makefile index f5a9f10..0e7aca5 100644 --- a/lib/c/2014/Makefile +++ b/lib/c/2014/Makefile @@ -1,5 +1,5 @@ ## Macros -VERSION= +VERSION=2014 LIBVERSION=2014 include ../os_compat.mk diff --git a/lib/c/2014/labcomm.h b/lib/c/2014/labcomm.h deleted file mode 100644 index fa62e7d..0000000 --- a/lib/c/2014/labcomm.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - labcomm.h -- user interface for handling encoding and decoding of - labcomm samples. - - Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> - - This file is part of LabComm. - - LabComm is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - LabComm is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __LABCOMM_H__ -#define __LABCOMM_H__ - -#include <stdarg.h> - -#ifdef LABCOMM_COMPAT - #include LABCOMM_COMPAT -#else - #include <stdint.h> - #include <unistd.h> -#endif - -#include "labcomm_error.h" -#include "labcomm_scheduler.h" - -/* Forward declaration */ -struct labcomm_encoder; -struct labcomm_decoder; - -#include "labcomm_type_signature.h" -/* - * Error handling. - */ - -/* The callback prototype for error handling. - * First parameter is the error ID. - * The second paramters is the number of va_args that comes after this - * one. If none it should be 0. - * Optionaly other paramters can be supplied depending on what is needed - * for this error ID. - */ -typedef void (*labcomm_error_handler_callback)(enum labcomm_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 labcomm2014_on_error_fprintf(enum labcomm_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); - -/* 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); - -/* Get a string describing the supplied standrad labcomm error. */ -const char *labcomm_error_get_str(enum labcomm_error error_id); - -typedef int (*labcomm_handle_new_datatype_callback)( - struct labcomm_decoder *decoder, - struct labcomm_signature *sig); - -/* - * Dynamic memory handling - * lifetime == 0 memory that will live for as long as the - * encoder/decoder or that are allocated/deallocated - * during the communication setup phase - * otherwise memory will live for approximately this number of - * sent/received samples - */ -struct labcomm_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 *ptr, size_t size); -void labcomm_memory_free(struct labcomm_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); -int labcomm_decoder_sample_ref_register( - struct labcomm_decoder *decoder, - const struct labcomm_signature *signature); - -/* See labcomm_ioctl.h for predefined ioctl_action values */ -int labcomm_decoder_ioctl(struct labcomm_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); -int labcomm_encoder_sample_ref_register( - struct labcomm_encoder *encoder, - const struct labcomm_signature *signature); - -/* See labcomm_ioctl.h for predefined ioctl_action values */ -int labcomm_encoder_ioctl(struct labcomm_encoder *encoder, - uint32_t ioctl_action, - ...); - -#define LABCOMM_VOID ((void*)1) - -#endif diff --git a/lib/c/2014/labcomm.c b/lib/c/2014/labcomm2014.c similarity index 54% rename from lib/c/2014/labcomm.c rename to lib/c/2014/labcomm2014.c index a01c96b..41d6f1a 100644 --- a/lib/c/2014/labcomm.c +++ b/lib/c/2014/labcomm2014.c @@ -1,6 +1,6 @@ /* - labcomm.c -- runtime for handling encoding and decoding of - labcomm samples. + labcomm2014.c -- runtime for handling encoding and decoding of + labcomm2014 samples. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -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 "labcomm2014.h" +#include "labcomm2014_private.h" +#include "labcomm2014_ioctl.h" +#include "labcomm2014_dynamic_buffer_writer.h" /* Unwrapping reader/writer functions */ #define UNWRAP_ac(rw, ac, ...) ac @@ -47,85 +47,85 @@ UNWRAP_ac( __VA_ARGS__) = UNWRAP_ac(__VA_ARGS__)->next; \ } -int labcomm_reader_alloc(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +int labcomm2014_reader_alloc(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context) { UNWRAP(alloc, r, action_context); } -int labcomm_reader_free(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +int labcomm2014_reader_free(struct labcomm2014_reader *r, + struct labcomm2014_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 labcomm2014_reader_start(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context, int local_index, int remote_index, - const struct labcomm_signature *signature, + const struct labcomm2014_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 labcomm2014_reader_end(struct labcomm2014_reader *r, + struct labcomm2014_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 labcomm2014_reader_fill(struct labcomm2014_reader *r, + struct labcomm2014_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 labcomm2014_reader_ioctl(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context, int local_index, int remote_index, - const struct labcomm_signature *signature, + const struct labcomm2014_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) +int labcomm2014_writer_alloc(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { UNWRAP(alloc, w, action_context); } -int labcomm_writer_free(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +int labcomm2014_writer_free(struct labcomm2014_writer *w, + struct labcomm2014_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, const struct labcomm_signature *signature, +int labcomm2014_writer_start(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int index, const struct labcomm2014_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 labcomm2014_writer_end(struct labcomm2014_writer *w, + struct labcomm2014_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 labcomm2014_writer_flush(struct labcomm2014_writer *w, + struct labcomm2014_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 labcomm2014_writer_ioctl(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, int index, - const struct labcomm_signature *signature, + const struct labcomm2014_signature *signature, uint32_t ioctl_action, va_list args) { UNWRAP(ioctl, w, action_context, index, signature, ioctl_action, args); @@ -137,29 +137,29 @@ int labcomm_writer_ioctl(struct labcomm_writer *w, -static const char *labcomm_error_string[] = { +static const char *labcomm2014_error_string[] = { #define LABCOMM_ERROR(name, description) description , -#include "labcomm_error.h" +#include "labcomm2014_error.h" #undef LABCOMM_ERROR }; -static const int labcomm_error_string_count = (sizeof(labcomm_error_string) / - sizeof(labcomm_error_string[0])); +static const int labcomm2014_error_string_count = (sizeof(labcomm2014_error_string) / + sizeof(labcomm2014_error_string[0])); -const char *labcomm_error_get_str(enum labcomm_error error_id) +const char *labcomm2014_error_get_str(enum labcomm2014_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 < labcomm2014_error_string_count) { + error_str = labcomm2014_error_string[error_id]; } return error_str; } -void labcomm2014_on_error_fprintf(enum labcomm_error error_id, size_t nbr_va_args, ...) +void labcomm20142014_on_error_fprintf(enum labcomm2014_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 = labcomm2014_error_get_str(error_id); // The final string to print. if (err_msg == NULL) { err_msg = "Error with an unknown error ID occured."; } @@ -177,7 +177,7 @@ void labcomm2014_on_error_fprintf(enum labcomm_error error_id, size_t nbr_va_arg va_end(arg_pointer); } #else - ; // If labcomm can't be compiled with stdio the user will have to make an own error callback functionif he/she needs error reporting. + ; // If labcomm2014 can't be compiled with stdio the user will have to make an own error callback functionif he/she needs error reporting. #endif } @@ -199,14 +199,14 @@ static void dump(void *p, int size, int first, int last) } #endif -void *labcomm_signature_array_ref(struct labcomm_memory *memory, +void *labcomm2014_signature_array_ref(struct labcomm2014_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 = labcomm2014_memory_alloc(memory, 0, size); if (*data) { memset(*data, 0, size); } @@ -218,7 +218,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 = labcomm2014_memory_alloc(memory, 0, n * size); if (*data) { memset(*data, 0, n * size); memcpy(*data + (old_first - *first) * size, @@ -226,7 +226,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); + labcomm2014_memory_free(memory, 0, old_data); } if (*data) { // dump(*data, size, *first, *last); @@ -238,36 +238,36 @@ void *labcomm_signature_array_ref(struct labcomm_memory *memory, static int local_index = LABCOMM_USER; -void labcomm_set_local_index(struct labcomm_signature *signature) +void labcomm2014_set_local_index(struct labcomm2014_signature *signature) { if (signature->index != 0) { - labcomm_error_fatal_global(LABCOMM_ERROR_SIGNATURE_ALREADY_SET, + labcomm2014_error_fatal_global(LABCOMM_ERROR_SIGNATURE_ALREADY_SET, "Signature already set: %s\n", signature->name); } signature->index = local_index; local_index++; } -int labcomm_get_local_index(const struct labcomm_signature *signature) +int labcomm2014_get_local_index(const struct labcomm2014_signature *signature) { if (signature->index == 0) { - labcomm_error_fatal_global(LABCOMM_ERROR_SIGNATURE_NOT_SET, + labcomm2014_error_fatal_global(LABCOMM_ERROR_SIGNATURE_NOT_SET, "Signature not set: %s\n", signature->name); } return signature->index; } -int labcomm_get_local_type_index(const struct labcomm_signature *signature) +int labcomm2014_get_local_type_index(const struct labcomm2014_signature *signature) { - return labcomm_get_local_index(signature); + return labcomm2014_get_local_index(signature); } -int labcomm_internal_sizeof(const struct labcomm_signature *signature, +int labcomm2014_internal_sizeof(const struct labcomm2014_signature *signature, void *v) { int length = signature->encoded_size(v); - return (labcomm_size_packed32(signature->index) + - labcomm_size_packed32(length) + + return (labcomm2014_size_packed32(signature->index) + + labcomm2014_size_packed32(length) + length); } diff --git a/lib/c/2014/labcomm2014.h b/lib/c/2014/labcomm2014.h new file mode 100644 index 0000000..5492b1e --- /dev/null +++ b/lib/c/2014/labcomm2014.h @@ -0,0 +1,138 @@ +/* + labcomm2014.h -- user interface for handling encoding and decoding of + labcomm2014 samples. + + Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> + + This file is part of LabComm. + + LabComm is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LabComm is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __LABCOMM_H__ +#define __LABCOMM_H__ + +#include <stdarg.h> + +#ifdef LABCOMM_COMPAT + #include LABCOMM_COMPAT +#else + #include <stdint.h> + #include <unistd.h> +#endif + +#include "labcomm2014_error.h" +#include "labcomm2014_scheduler.h" + +/* Forward declaration */ +struct labcomm2014_encoder; +struct labcomm2014_decoder; + +#include "labcomm2014_type_signature.h" +/* + * Error handling. + */ + +/* The callback prototype for error handling. + * First parameter is the error ID. + * The second paramters is the number of va_args that comes after this + * one. If none it should be 0. + * Optionaly other paramters can be supplied depending on what is needed + * for this error ID. + */ +typedef void (*labcomm2014_error_handler_callback)(enum labcomm2014_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 labcomm20142014_on_error_fprintf(enum labcomm2014_error error_id, size_t nbr_va_args, ...); + +/* Register a callback for the error handler for this encoder. */ +void labcomm2014_register_error_handler_encoder(struct labcomm2014_encoder *encoder, labcomm2014_error_handler_callback callback); + +/* Register a callback for the error handler for this decoder. */ +void labcomm2014_register_error_handler_decoder(struct labcomm2014_decoder *decoder, labcomm2014_error_handler_callback callback); + +/* Get a string describing the supplied standrad labcomm2014 error. */ +const char *labcomm2014_error_get_str(enum labcomm2014_error error_id); + +typedef int (*labcomm2014_handle_new_datatype_callback)( + struct labcomm2014_decoder *decoder, + struct labcomm2014_signature *sig); + +/* + * Dynamic memory handling + * lifetime == 0 memory that will live for as long as the + * encoder/decoder or that are allocated/deallocated + * during the communication setup phase + * otherwise memory will live for approximately this number of + * sent/received samples + */ +struct labcomm2014_memory; + +void *labcomm2014_memory_alloc(struct labcomm2014_memory *m, int lifetime, size_t size); +void *labcomm2014_memory_realloc(struct labcomm2014_memory *m, int lifetime, + void *ptr, size_t size); +void labcomm2014_memory_free(struct labcomm2014_memory *m, int lifetime, void *ptr); + +/* + * Decoder + */ +struct labcomm2014_reader; + +struct labcomm2014_decoder *labcomm2014_decoder_new( + struct labcomm2014_reader *reader, + struct labcomm2014_error_handler *error, + struct labcomm2014_memory *memory, + struct labcomm2014_scheduler *scheduler); +void labcomm2014_decoder_free( + struct labcomm2014_decoder *decoder); +int labcomm2014_decoder_decode_one( + struct labcomm2014_decoder *decoder); +void labcomm2014_decoder_run( + struct labcomm2014_decoder *decoder); +int labcomm2014_decoder_sample_ref_register( + struct labcomm2014_decoder *decoder, + const struct labcomm2014_signature *signature); + +/* See labcomm2014_ioctl.h for predefined ioctl_action values */ +int labcomm2014_decoder_ioctl(struct labcomm2014_decoder *decoder, + uint32_t ioctl_action, + ...); + +/* + * Encoder + */ +struct labcomm2014_writer; + +struct labcomm2014_encoder *labcomm2014_encoder_new( + struct labcomm2014_writer *writer, + struct labcomm2014_error_handler *error, + struct labcomm2014_memory *memory, + struct labcomm2014_scheduler *scheduler); +void labcomm2014_encoder_free( + struct labcomm2014_encoder *encoder); +int labcomm2014_encoder_sample_ref_register( + struct labcomm2014_encoder *encoder, + const struct labcomm2014_signature *signature); + +/* See labcomm2014_ioctl.h for predefined ioctl_action values */ +int labcomm2014_encoder_ioctl(struct labcomm2014_encoder *encoder, + uint32_t ioctl_action, + ...); + +#define LABCOMM_VOID ((void*)1) + +#endif diff --git a/lib/c/2014/labcomm_compat_arm_cortexm3.h b/lib/c/2014/labcomm2014_compat_arm_cortexm3.h similarity index 100% rename from lib/c/2014/labcomm_compat_arm_cortexm3.h rename to lib/c/2014/labcomm2014_compat_arm_cortexm3.h diff --git a/lib/c/2014/labcomm_compat_osx.h b/lib/c/2014/labcomm2014_compat_osx.h similarity index 100% rename from lib/c/2014/labcomm_compat_osx.h rename to lib/c/2014/labcomm2014_compat_osx.h diff --git a/lib/c/2014/labcomm_compat_vxworks.h b/lib/c/2014/labcomm2014_compat_vxworks.h similarity index 100% rename from lib/c/2014/labcomm_compat_vxworks.h rename to lib/c/2014/labcomm2014_compat_vxworks.h diff --git a/lib/c/2014/labcomm_decoder.c b/lib/c/2014/labcomm2014_decoder.c similarity index 63% rename from lib/c/2014/labcomm_decoder.c rename to lib/c/2014/labcomm2014_decoder.c index cac035f..8d3f79b 100644 --- a/lib/c/2014/labcomm_decoder.c +++ b/lib/c/2014/labcomm2014_decoder.c @@ -1,5 +1,5 @@ /* - labcomm_decoder.c -- runtime for handling decoding of labcomm samples. + labcomm2014_decoder.c -- runtime for handling decoding of labcomm2014 samples. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -21,10 +21,10 @@ #define CURRENT_VERSION "LabComm2014" #include <errno.h> -#include "labcomm.h" -#include "labcomm_private.h" -#include "labcomm_ioctl.h" -#include "labcomm_dynamic_buffer_writer.h" +#include "labcomm2014.h" +#include "labcomm2014_private.h" +#include "labcomm2014_ioctl.h" +#include "labcomm2014_dynamic_buffer_writer.h" #ifdef DEBUG #define DEBUG_FPRINTF(str, ...) fprintf(str, ##__VA_ARGS__) @@ -40,36 +40,36 @@ struct sample_entry { int remote_index; - const struct labcomm_signature *signature; - labcomm_decoder_function decode; - labcomm_handler_function handler; + const struct labcomm2014_signature *signature; + labcomm2014_decoder_function decode; + labcomm2014_handler_function handler; void *context; }; -struct labcomm_decoder { - struct labcomm_reader *reader; +struct labcomm2014_decoder { + struct labcomm2014_reader *reader; int reader_allocated; int version_ok; - 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 labcomm2014_error_handler *error; + struct labcomm2014_memory *memory; + struct labcomm2014_scheduler *scheduler; + labcomm2014_error_handler_callback on_error; + labcomm2014_handle_new_datatype_callback on_new_datatype; LABCOMM_SIGNATURE_ARRAY_DEF(local, struct sample_entry); LABCOMM_SIGNATURE_ARRAY_DEF(remote_to_local, int); - LABCOMM_SIGNATURE_ARRAY_DEF(local_ref, const struct labcomm_signature *); + LABCOMM_SIGNATURE_ARRAY_DEF(local_ref, const struct labcomm2014_signature *); LABCOMM_SIGNATURE_ARRAY_DEF(remote_to_local_ref, 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 labcomm2014_decoder *labcomm2014_decoder_new( + struct labcomm2014_reader *reader, + struct labcomm2014_error_handler *error, + struct labcomm2014_memory *memory, + struct labcomm2014_scheduler *scheduler) { - struct labcomm_decoder *result; + struct labcomm2014_decoder *result; - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); + result = labcomm2014_memory_alloc(memory, 0, sizeof(*result)); if (result) { result->reader = reader; result->reader->decoder = result; @@ -83,38 +83,38 @@ struct labcomm_decoder *labcomm_decoder_new( result->error = error; result->memory = memory; result->scheduler = scheduler; - result->on_error = labcomm2014_on_error_fprintf; + result->on_error = labcomm20142014_on_error_fprintf; LABCOMM_SIGNATURE_ARRAY_INIT(result->local, struct sample_entry); LABCOMM_SIGNATURE_ARRAY_INIT(result->remote_to_local, int); LABCOMM_SIGNATURE_ARRAY_INIT(result->local_ref, - const struct labcomm_signature*); + const struct labcomm2014_signature*); LABCOMM_SIGNATURE_ARRAY_INIT(result->remote_to_local_ref, int); } return result; } -void labcomm_decoder_free(struct labcomm_decoder* d) +void labcomm2014_decoder_free(struct labcomm2014_decoder* d) { - struct labcomm_memory *memory = d->memory; + struct labcomm2014_memory *memory = d->memory; - labcomm_reader_free(d->reader, d->reader->action_context); + labcomm2014_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_SIGNATURE_ARRAY_FREE(memory, d->local_ref, - const struct labcomm_signature*); + const struct labcomm2014_signature*); LABCOMM_SIGNATURE_ARRAY_FREE(memory, d->remote_to_local_ref, int); - labcomm_memory_free(memory, 0, d); + labcomm2014_memory_free(memory, 0, d); } -static int handle_sample_def(struct labcomm_decoder *d, int remote_index, - const struct labcomm_signature *signature) +static int handle_sample_def(struct labcomm2014_decoder *d, int remote_index, + const struct labcomm2014_signature *signature) { int result; int i; - const struct labcomm_signature *local_signature = NULL; + const struct labcomm2014_signature *local_signature = NULL; int local_index = 0; - labcomm_scheduler_data_lock(d->scheduler); + labcomm2014_scheduler_data_lock(d->scheduler); LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local, struct sample_entry, i) { struct sample_entry *s; int *remote_to_local; @@ -138,29 +138,29 @@ static int handle_sample_def(struct labcomm_decoder *d, int remote_index, break; } } - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2014_scheduler_data_unlock(d->scheduler); if (local_signature) { - labcomm_reader_start(d->reader, d->reader->action_context, + labcomm2014_reader_start(d->reader, d->reader->action_context, local_index, remote_index, local_signature, NULL); - labcomm_reader_end(d->reader, d->reader->action_context); + labcomm2014_reader_end(d->reader, d->reader->action_context); } return result; } -static int handle_sample_ref(struct labcomm_decoder *d, int remote_index, - const struct labcomm_signature *signature) +static int handle_sample_ref(struct labcomm2014_decoder *d, int remote_index, + const struct labcomm2014_signature *signature) { int result; int i; - labcomm_scheduler_data_lock(d->scheduler); - LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local_ref, const struct labcomm_signature *, i) { - const struct labcomm_signature *s; + labcomm2014_scheduler_data_lock(d->scheduler); + LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local_ref, const struct labcomm2014_signature *, i) { + const struct labcomm2014_signature *s; int *remote_to_local_ref; result = -ENOENT; - s = LABCOMM_SIGNATURE_ARRAY_GET(d->local_ref, const struct labcomm_signature *, i, 0); + s = LABCOMM_SIGNATURE_ARRAY_GET(d->local_ref, const struct labcomm2014_signature *, i, 0); if (s && s->signature && s->size == signature->size && @@ -174,17 +174,17 @@ static int handle_sample_ref(struct labcomm_decoder *d, int remote_index, break; } } - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2014_scheduler_data_unlock(d->scheduler); return result; } -static int decoder_skip(struct labcomm_decoder *d, int len, int tag) +static int decoder_skip(struct labcomm2014_decoder *d, int len, int tag) { int i; DECODER_DEBUG_FPRINTF(stdout, "got tag 0x%x, skipping %d bytes\n", tag, len); for(i = 0; i <len; i++){ DECODER_DEBUG_FPRINTF(stderr, "."); - labcomm_read_byte(d->reader); + labcomm2014_read_byte(d->reader); if (d->reader->error < 0) { DECODER_DEBUG_FPRINTF(stderr, "\nerror while skipping: %d\n", d->reader->error); return d->reader->error; @@ -194,34 +194,34 @@ static int decoder_skip(struct labcomm_decoder *d, int len, int tag) return tag; } -static int decode_sample_def_or_ref(struct labcomm_decoder *d, int kind) +static int decode_sample_def_or_ref(struct labcomm2014_decoder *d, int kind) { int result; - struct labcomm_signature signature; + struct labcomm2014_signature signature; int i, remote_index; - remote_index = labcomm_read_packed32(d->reader); + remote_index = labcomm2014_read_packed32(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto out; } - signature.name = labcomm_read_string(d->reader); + signature.name = labcomm2014_read_string(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto out; } - signature.size = labcomm_read_packed32(d->reader); + signature.size = labcomm2014_read_packed32(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto free_signature_name; } - signature.signature = labcomm_memory_alloc(d->memory, 1, signature.size); + signature.signature = labcomm2014_memory_alloc(d->memory, 1, signature.size); if (d->reader->error < 0) { result = d->reader->error; goto free_signature_name; } for (i = 0 ; i < signature.size ; i++) { - signature.signature[i] = labcomm_read_byte(d->reader); + signature.signature[i] = labcomm2014_read_byte(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto free_signature_signature; @@ -244,19 +244,19 @@ static int decode_sample_def_or_ref(struct labcomm_decoder *d, int kind) result = -EINVAL; } free_signature_signature: - labcomm_memory_free(d->memory, 1, signature.signature); + labcomm2014_memory_free(d->memory, 1, signature.signature); free_signature_name: - labcomm_memory_free(d->memory, 0, signature.name); + labcomm2014_memory_free(d->memory, 0, signature.name); out: return result; } struct call_handler_context { - struct labcomm_reader *reader; + struct labcomm2014_reader *reader; int local_index; int remote_index; - const struct labcomm_signature *signature; - labcomm_handler_function handler; + const struct labcomm2014_signature *signature; + labcomm2014_handler_function handler; void *context; }; @@ -265,52 +265,52 @@ 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, + labcomm2014_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); + labcomm2014_reader_end(wrap->reader, wrap->reader->action_context); } } -static void reader_alloc(struct labcomm_decoder *d) +static void reader_alloc(struct labcomm2014_decoder *d) { if (!d->reader_allocated) { d->reader_allocated = 1; - labcomm_reader_alloc(d->reader, d->reader->action_context); + labcomm2014_reader_alloc(d->reader, d->reader->action_context); } } /* d - decoder to read from registry - decoder to lookup signatures (registry != d only if nesting decoders, e.g., when decoding pragma) - len - length of the labcomm packet ) + len - length of the labcomm2014 packet ) */ -static int decode_pragma(struct labcomm_decoder *d, - struct labcomm_decoder *registry, +static int decode_pragma(struct labcomm2014_decoder *d, + struct labcomm2014_decoder *registry, int len) { char *pragma_type; int result; - pragma_type = labcomm_read_string(d->reader); + pragma_type = labcomm2014_read_string(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto out; } - int bytes = labcomm_size_string(pragma_type); + int bytes = labcomm2014_size_string(pragma_type); int psize = len-bytes; result = decoder_skip(d, psize, LABCOMM_PRAGMA); out: return result; } -static labcomm_decoder_function lookup_h(struct labcomm_decoder *d, +static labcomm2014_decoder_function lookup_h(struct labcomm2014_decoder *d, struct call_handler_context *wrap, int remote_index, int **local_index) { - labcomm_decoder_function do_decode = NULL; - labcomm_scheduler_data_lock(d->scheduler); + labcomm2014_decoder_function do_decode = NULL; + labcomm2014_scheduler_data_lock(d->scheduler); *local_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, d->remote_to_local, int, remote_index); @@ -326,7 +326,7 @@ static labcomm_decoder_function lookup_h(struct labcomm_decoder *d, wrap->context = entry->context; do_decode = entry->decode; } - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2014_scheduler_data_unlock(d->scheduler); return do_decode; } /* d - decoder to read from @@ -334,8 +334,8 @@ static labcomm_decoder_function lookup_h(struct labcomm_decoder *d, nesting decoders, e.g., when decoding pragma) remote_index - received type index ) */ -static int decode_and_handle(struct labcomm_decoder *d, - struct labcomm_decoder *registry, +static int decode_and_handle(struct labcomm2014_decoder *d, + struct labcomm2014_decoder *registry, int remote_index) { int result; @@ -347,7 +347,7 @@ static int decode_and_handle(struct labcomm_decoder *d, .handler = NULL, .context = NULL, }; - labcomm_decoder_function do_decode = lookup_h(registry, &wrap, remote_index, &local_index); + labcomm2014_decoder_function do_decode = lookup_h(registry, &wrap, remote_index, &local_index); result = *local_index; if (do_decode) { do_decode(d->reader, call_handler, &wrap); @@ -359,23 +359,23 @@ static int decode_and_handle(struct labcomm_decoder *d, } return result; } -int labcomm_decoder_decode_one(struct labcomm_decoder *d) +int labcomm2014_decoder_decode_one(struct labcomm2014_decoder *d) { int result, remote_index, length; reader_alloc(d); - remote_index = labcomm_read_packed32(d->reader); + remote_index = labcomm2014_read_packed32(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto out; } - length = labcomm_read_packed32(d->reader); + length = labcomm2014_read_packed32(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto out; } if (remote_index == LABCOMM_VERSION) { - char *version = labcomm_read_string(d->reader); + char *version = labcomm2014_read_string(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto out; @@ -386,7 +386,7 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d) } else { result = -ECONNRESET; } - labcomm_memory_free(d->memory, 1, version); + labcomm2014_memory_free(d->memory, 1, version); } else if (! d->version_ok) { DEBUG_FPRINTF(stderr, "No VERSION %d %d\n", remote_index, length); result = -ECONNRESET; @@ -418,13 +418,13 @@ out: return result; } -void labcomm_decoder_run(struct labcomm_decoder *d) +void labcomm2014_decoder_run(struct labcomm2014_decoder *d) { - while (labcomm_decoder_decode_one(d) > 0) { + while (labcomm2014_decoder_decode_one(d) > 0) { } } -int labcomm_decoder_ioctl(struct labcomm_decoder *d, +int labcomm2014_decoder_ioctl(struct labcomm2014_decoder *d, uint32_t action, ...) { @@ -432,26 +432,26 @@ int labcomm_decoder_ioctl(struct labcomm_decoder *d, va_list va; va_start(va, action); - result = labcomm_reader_ioctl(d->reader, + result = labcomm2014_reader_ioctl(d->reader, d->reader->action_context, 0, 0, NULL, action, va); va_end(va); return result; } -int labcomm_decoder_sample_ref_register( - struct labcomm_decoder *d, - const struct labcomm_signature *signature) +int labcomm2014_decoder_sample_ref_register( + struct labcomm2014_decoder *d, + const struct labcomm2014_signature *signature) { int local_index, *remote_to_local_ref; - const struct labcomm_signature **s; + const struct labcomm2014_signature **s; - local_index = labcomm_get_local_index(signature); + local_index = labcomm2014_get_local_index(signature); if (local_index <= 0) { goto out; } - labcomm_scheduler_data_lock(d->scheduler); + labcomm2014_scheduler_data_lock(d->scheduler); s = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, d->local_ref, - const struct labcomm_signature*, local_index); + const struct labcomm2014_signature*, local_index); if (s == NULL) { local_index = -ENOMEM; goto unlock; }; if (*s) { goto unlock; } *s = signature; @@ -460,26 +460,26 @@ int labcomm_decoder_sample_ref_register( int, local_index); *remote_to_local_ref = 0; unlock: - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2014_scheduler_data_unlock(d->scheduler); out: return local_index; } -int labcomm_internal_decoder_ioctl(struct labcomm_decoder *d, - const struct labcomm_signature *signature, +int labcomm2014_internal_decoder_ioctl(struct labcomm2014_decoder *d, + const struct labcomm2014_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 = labcomm2014_get_local_index(signature); + labcomm2014_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, + labcomm2014_scheduler_data_unlock(d->scheduler); + result = labcomm2014_reader_ioctl(d->reader, d->reader->action_context, local_index, remote_index, signature, action, va); return result; @@ -490,41 +490,41 @@ int labcomm_internal_decoder_ioctl(struct labcomm_decoder *d, //// (should perhaps be moved to another file) static void decode_raw_type_def( - struct labcomm_reader *r, + struct labcomm2014_reader *r, void (*handle)( - struct labcomm_raw_type_def *v, + struct labcomm2014_raw_type_def *v, void *context ), void *context ) { - struct labcomm_raw_type_def v; - v.index = labcomm_read_packed32(r); + struct labcomm2014_raw_type_def v; + v.index = labcomm2014_read_packed32(r); if (r->error < 0) { goto out; } - v.name = labcomm_read_string(r); + v.name = labcomm2014_read_string(r); if (r->error < 0) { goto free_name; } - v.length = labcomm_read_packed32(r); + v.length = labcomm2014_read_packed32(r); if (r->error < 0) { goto free_name; } int i; - v.signature_data = labcomm_memory_alloc(r->memory, 1, v.length); + v.signature_data = labcomm2014_memory_alloc(r->memory, 1, v.length); if(v.signature_data) { for(i=0; i<v.length; i++) { - v.signature_data[i] = labcomm_read_byte(r); + v.signature_data[i] = labcomm2014_read_byte(r); if (r->error < 0) { goto free_sig; } } handle(&v, context); } free_sig: - labcomm_memory_free(r->memory, 1, v.signature_data); + labcomm2014_memory_free(r->memory, 1, v.signature_data); free_name: - labcomm_memory_free(r->memory, 1, v.name); + labcomm2014_memory_free(r->memory, 1, v.name); out: return; } -int labcomm_decoder_register_labcomm_type_def( - struct labcomm_decoder *d, +int labcomm2014_decoder_register_labcomm2014_type_def( + struct labcomm2014_decoder *d, void (*handler)( - struct labcomm_raw_type_def *v, + struct labcomm2014_raw_type_def *v, void *context ), void *context @@ -534,15 +534,15 @@ int labcomm_decoder_register_labcomm_type_def( struct sample_entry *entry; int *remote_to_local; - labcomm_scheduler_data_lock(d->scheduler); + labcomm2014_scheduler_data_lock(d->scheduler); entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, d->local, struct sample_entry, tag); if (entry == NULL) { tag = -ENOMEM; goto unlock; } entry->remote_index = tag; entry->signature = NULL; - entry->decode = (labcomm_decoder_function) decode_raw_type_def; - entry->handler =(labcomm_handler_function) handler; + entry->decode = (labcomm2014_decoder_function) decode_raw_type_def; + entry->handler =(labcomm2014_handler_function) handler; entry->context = context; remote_to_local = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, @@ -550,35 +550,35 @@ int labcomm_decoder_register_labcomm_type_def( tag); *remote_to_local = tag; unlock: - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2014_scheduler_data_unlock(d->scheduler); return tag; } static void decode_type_binding( - struct labcomm_reader *r, + struct labcomm2014_reader *r, void (*handle)( - struct labcomm_type_binding *v, + struct labcomm2014_type_binding *v, void *context ), void *context ) { - struct labcomm_type_binding v; - v.sample_index = labcomm_read_packed32(r); + struct labcomm2014_type_binding v; + v.sample_index = labcomm2014_read_packed32(r); if (r->error < 0) { goto out; } - v.type_index = labcomm_read_packed32(r); + v.type_index = labcomm2014_read_packed32(r); if (r->error < 0) { goto out; } handle(&v, context); out: return; } -int labcomm_decoder_register_labcomm_type_binding( - struct labcomm_decoder *d, +int labcomm2014_decoder_register_labcomm2014_type_binding( + struct labcomm2014_decoder *d, void (*handler)( - struct labcomm_type_binding *v, + struct labcomm2014_type_binding *v, void *context ), void *context @@ -588,15 +588,15 @@ int labcomm_decoder_register_labcomm_type_binding( struct sample_entry *entry; int *remote_to_local; - labcomm_scheduler_data_lock(d->scheduler); + labcomm2014_scheduler_data_lock(d->scheduler); entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, d->local, struct sample_entry, tag); if (entry == NULL) { tag = -ENOMEM; goto unlock; } entry->remote_index = tag; entry->signature = NULL; - entry->decode = (labcomm_decoder_function) decode_type_binding; - entry->handler =(labcomm_handler_function) handler; + entry->decode = (labcomm2014_decoder_function) decode_type_binding; + entry->handler =(labcomm2014_handler_function) handler; entry->context = context; remote_to_local = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, @@ -604,7 +604,7 @@ int labcomm_decoder_register_labcomm_type_binding( tag); *remote_to_local = tag; unlock: - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2014_scheduler_data_unlock(d->scheduler); return tag; } @@ -612,25 +612,25 @@ unlock: //// End type_def handling #endif -int labcomm_internal_decoder_register( - struct labcomm_decoder *d, - const struct labcomm_signature *signature, - labcomm_decoder_function decode, - labcomm_handler_function handler, +int labcomm2014_internal_decoder_register( + struct labcomm2014_decoder *d, + const struct labcomm2014_signature *signature, + labcomm2014_decoder_function decode, + labcomm2014_handler_function handler, void *context) { int local_index; struct sample_entry *entry; reader_alloc(d); - local_index = labcomm_get_local_index(signature); + local_index = labcomm2014_get_local_index(signature); if (local_index <= 0) { goto out; } - labcomm_reader_start(d->reader, d->reader->action_context, + labcomm2014_reader_start(d->reader, d->reader->action_context, local_index, 0, signature, NULL); - labcomm_reader_end(d->reader, d->reader->action_context); + labcomm2014_reader_end(d->reader, d->reader->action_context); - labcomm_scheduler_data_lock(d->scheduler); + labcomm2014_scheduler_data_lock(d->scheduler); entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, d->local, struct sample_entry, local_index); @@ -641,25 +641,25 @@ int labcomm_internal_decoder_register( entry->handler = handler; entry->context = context; unlock: - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2014_scheduler_data_unlock(d->scheduler); out: return local_index; } -const struct labcomm_signature *labcomm_internal_decoder_index_to_signature( - struct labcomm_decoder *d, int index) +const struct labcomm2014_signature *labcomm2014_internal_decoder_index_to_signature( + struct labcomm2014_decoder *d, int index) { - const struct labcomm_signature *result = 0; + const struct labcomm2014_signature *result = 0; int local_index; - labcomm_scheduler_data_lock(d->scheduler); + labcomm2014_scheduler_data_lock(d->scheduler); local_index = LABCOMM_SIGNATURE_ARRAY_GET(d->remote_to_local_ref, int, index, 0); if (local_index) { result = LABCOMM_SIGNATURE_ARRAY_GET(d->local_ref, - const struct labcomm_signature*, + const struct labcomm2014_signature*, local_index, 0); } - labcomm_scheduler_data_unlock(d->scheduler); + labcomm2014_scheduler_data_unlock(d->scheduler); return result; } diff --git a/lib/c/2014/labcomm_default_error_handler.c b/lib/c/2014/labcomm2014_default_error_handler.c similarity index 88% rename from lib/c/2014/labcomm_default_error_handler.c rename to lib/c/2014/labcomm2014_default_error_handler.c index 61e04dd..ae9fe30 100644 --- a/lib/c/2014/labcomm_default_error_handler.c +++ b/lib/c/2014/labcomm2014_default_error_handler.c @@ -19,6 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "labcomm.h" +#include "labcomm2014.h" -struct labcomm_error_handler *labcomm_default_error_handler = NULL; +struct labcomm2014_error_handler *labcomm2014_default_error_handler = NULL; diff --git a/lib/c/2014/labcomm_default_error_handler.h b/lib/c/2014/labcomm2014_default_error_handler.h similarity index 80% rename from lib/c/2014/labcomm_default_error_handler.h rename to lib/c/2014/labcomm2014_default_error_handler.h index 8f479a0..420cb40 100644 --- a/lib/c/2014/labcomm_default_error_handler.h +++ b/lib/c/2014/labcomm2014_default_error_handler.h @@ -18,11 +18,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_DEFAULT_ERROR_HANDLER_H__ -#define __LABCOMM_DEFAULT_ERROR_HANDLER_H__ +#ifndef __LABCOMM2014_DEFAULT_ERROR_HANDLER_H__ +#define __LABCOMM2014_DEFAULT_ERROR_HANDLER_H__ -#include "labcomm.h" +#include "labcomm2014.h" -extern struct labcomm_error_handler *labcomm_default_error_handler; +extern struct labcomm2014_error_handler *labcomm2014_default_error_handler; #endif diff --git a/lib/c/2014/labcomm_default_memory.c b/lib/c/2014/labcomm2014_default_memory.c similarity index 73% rename from lib/c/2014/labcomm_default_memory.c rename to lib/c/2014/labcomm2014_default_memory.c index d6b13c5..17dee8a 100644 --- a/lib/c/2014/labcomm_default_memory.c +++ b/lib/c/2014/labcomm2014_default_memory.c @@ -20,30 +20,30 @@ */ #include <stdlib.h> -#include "labcomm.h" -#include "labcomm_private.h" +#include "labcomm2014.h" +#include "labcomm2014_private.h" -void *default_alloc(struct labcomm_memory *m, int lifetime, size_t size) +void *default_alloc(struct labcomm2014_memory *m, int lifetime, size_t size) { return malloc(size); } -void *default_realloc(struct labcomm_memory *m, int lifetime, +void *default_realloc(struct labcomm2014_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_free(struct labcomm2014_memory *m, int lifetime, void *ptr) { free(ptr); } -struct labcomm_memory memory = { +struct labcomm2014_memory memory = { .alloc = default_alloc, .realloc = default_realloc, .free = default_free, .context = NULL }; -struct labcomm_memory *labcomm_default_memory = &memory; +struct labcomm2014_memory *labcomm2014_default_memory = &memory; diff --git a/lib/c/2014/labcomm_default_memory.h b/lib/c/2014/labcomm2014_default_memory.h similarity index 82% rename from lib/c/2014/labcomm_default_memory.h rename to lib/c/2014/labcomm2014_default_memory.h index f00b226..57947fb 100644 --- a/lib/c/2014/labcomm_default_memory.h +++ b/lib/c/2014/labcomm2014_default_memory.h @@ -18,12 +18,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_DEFAULT_MEMORY_H__ -#define __LABCOMM_DEFAULT_MEMORY_H__ +#ifndef __LABCOMM2014_DEFAULT_MEMORY_H__ +#define __LABCOMM2014_DEFAULT_MEMORY_H__ #include <stdlib.h> -#include "labcomm.h" +#include "labcomm2014.h" -extern struct labcomm_memory *labcomm_default_memory; +extern struct labcomm2014_memory *labcomm2014_default_memory; #endif diff --git a/lib/c/2014/labcomm_default_scheduler.c b/lib/c/2014/labcomm2014_default_scheduler.c similarity index 67% rename from lib/c/2014/labcomm_default_scheduler.c rename to lib/c/2014/labcomm2014_default_scheduler.c index a567b61..f1fd3d6 100644 --- a/lib/c/2014/labcomm_default_scheduler.c +++ b/lib/c/2014/labcomm2014_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 "labcomm2014_default_scheduler.h" +#include "labcomm2014_scheduler.h" +#include "labcomm2014_scheduler_private.h" -static int scheduler_free(struct labcomm_scheduler *s) +static int scheduler_free(struct labcomm2014_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 labcomm2014_scheduler *s) { return 0; } -static int scheduler_writer_unlock(struct labcomm_scheduler *s) +static int scheduler_writer_unlock(struct labcomm2014_scheduler *s) { return 0; } -static int scheduler_data_lock(struct labcomm_scheduler *s) +static int scheduler_data_lock(struct labcomm2014_scheduler *s) { return 0; } -static int scheduler_data_unlock(struct labcomm_scheduler *s) +static int scheduler_data_unlock(struct labcomm2014_scheduler *s) { return 0; } -static struct labcomm_time *scheduler_now(struct labcomm_scheduler *s) +static struct labcomm2014_time *scheduler_now(struct labcomm2014_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 labcomm2014_scheduler *s, + struct labcomm2014_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 labcomm2014_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 labcomm2014_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 labcomm2014_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 labcomm2014_scheduler scheduler = { .action = &scheduler_action, .context = NULL }; -struct labcomm_scheduler *labcomm_default_scheduler = &scheduler; +struct labcomm2014_scheduler *labcomm2014_default_scheduler = &scheduler; diff --git a/lib/c/2014/labcomm_default_scheduler.h b/lib/c/2014/labcomm2014_default_scheduler.h similarity index 81% rename from lib/c/2014/labcomm_default_scheduler.h rename to lib/c/2014/labcomm2014_default_scheduler.h index 7ec579b..db416f3 100644 --- a/lib/c/2014/labcomm_default_scheduler.h +++ b/lib/c/2014/labcomm2014_default_scheduler.h @@ -18,11 +18,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_DEFAULT_SCHEDULER_H__ -#define __LABCOMM_DEFAULT_SCHEDULER_H__ +#ifndef __LABCOMM2014_DEFAULT_SCHEDULER_H__ +#define __LABCOMM2014_DEFAULT_SCHEDULER_H__ -#include "labcomm.h" +#include "labcomm2014.h" -extern struct labcomm_scheduler *labcomm_default_scheduler; +extern struct labcomm2014_scheduler *labcomm2014_default_scheduler; #endif diff --git a/lib/c/2014/labcomm_dynamic_buffer_writer.c b/lib/c/2014/labcomm2014_dynamic_buffer_writer.c similarity index 57% rename from lib/c/2014/labcomm_dynamic_buffer_writer.c rename to lib/c/2014/labcomm2014_dynamic_buffer_writer.c index 32501e1..c209862 100644 --- a/lib/c/2014/labcomm_dynamic_buffer_writer.c +++ b/lib/c/2014/labcomm2014_dynamic_buffer_writer.c @@ -1,5 +1,5 @@ /* - labcomm_dynamic_buffer_writer.c -- LabComm dynamic memory writer. + labcomm2014_dynamic_buffer_writer.c -- LabComm dynamic memory writer. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,17 +22,17 @@ #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" +#include "labcomm2014.h" +#include "labcomm2014_private.h" +#include "labcomm2014_ioctl.h" +#include "labcomm2014_dynamic_buffer_writer.h" -static int dyn_alloc(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +static int dyn_alloc(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { w->data_size = 1000; w->count = w->data_size; - w->data = labcomm_memory_alloc(w->memory, 1, w->data_size); + w->data = labcomm2014_memory_alloc(w->memory, 1, w->data_size); if (w->data == NULL) { w->error = -ENOMEM; } @@ -41,29 +41,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 labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { - labcomm_memory_free(w->memory, 1, w->data); + labcomm2014_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); + labcomm2014_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 labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, int index, - const struct labcomm_signature *signature, + const struct labcomm2014_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 = labcomm2014_memory_realloc(w->memory, 1, w->data, w->data_size); if (tmp != NULL) { w->data = tmp; w->error = 0; @@ -75,20 +75,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 labcomm2014_writer *w, + struct labcomm2014_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 labcomm2014_writer *w, + struct labcomm2014_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 = labcomm2014_memory_realloc(w->memory, 1, w->data, w->data_size); if (tmp != NULL) { w->data = tmp; w->error = 0; @@ -100,10 +100,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 labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, int signature_index, - const struct labcomm_signature *signature, + const struct labcomm2014_signature *signature, uint32_t action, va_list arg) { int result = -ENOTSUP; @@ -122,7 +122,7 @@ static int dyn_ioctl(struct labcomm_writer *w, return result; } -static const struct labcomm_writer_action action = { +static const struct labcomm2014_writer_action action = { .alloc = dyn_alloc, .free = dyn_free, .start = dyn_start, @@ -130,18 +130,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 labcomm2014_writer_action *labcomm2014_dynamic_buffer_writer_action = &action; -struct labcomm_writer *labcomm_dynamic_buffer_writer_new( - struct labcomm_memory *memory) +struct labcomm2014_writer *labcomm2014_dynamic_buffer_writer_new( + struct labcomm2014_memory *memory) { struct result { - struct labcomm_writer writer; - struct labcomm_writer_action_context action_context; + struct labcomm2014_writer writer; + struct labcomm2014_writer_action_context action_context; } *result; - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); + result = labcomm2014_memory_alloc(memory, 0, sizeof(*result)); if (result != NULL) { result->action_context.next = NULL; result->action_context.context = result; diff --git a/lib/c/2014/labcomm_dynamic_buffer_writer.h b/lib/c/2014/labcomm2014_dynamic_buffer_writer.h similarity index 65% rename from lib/c/2014/labcomm_dynamic_buffer_writer.h rename to lib/c/2014/labcomm2014_dynamic_buffer_writer.h index 9fea8ed..ce19d73 100644 --- a/lib/c/2014/labcomm_dynamic_buffer_writer.h +++ b/lib/c/2014/labcomm2014_dynamic_buffer_writer.h @@ -1,5 +1,5 @@ /* - labcomm_dynamic_buffer_writer.h -- LabComm dynamic memory writer. + labcomm2014_dynamic_buffer_writer.h -- LabComm dynamic memory writer. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -19,14 +19,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_DYNAMIC_BUFFER_READER_WRITER_H__ -#define __LABCOMM_DYNAMIC_BUFFER_READER_WRITER_H__ +#ifndef __LABCOMM2014_DYNAMIC_BUFFER_READER_WRITER_H__ +#define __LABCOMM2014_DYNAMIC_BUFFER_READER_WRITER_H__ -#include "labcomm.h" +#include "labcomm2014.h" -extern const struct labcomm_writer_action *labcomm_dynamic_buffer_writer_action; +extern const struct labcomm2014_writer_action *labcomm2014_dynamic_buffer_writer_action; -struct labcomm_writer *labcomm_dynamic_buffer_writer_new( - struct labcomm_memory *memory); +struct labcomm2014_writer *labcomm2014_dynamic_buffer_writer_new( + struct labcomm2014_memory *memory); #endif diff --git a/lib/c/2014/labcomm2014_encoder.c b/lib/c/2014/labcomm2014_encoder.c new file mode 100644 index 0000000..864ff3f --- /dev/null +++ b/lib/c/2014/labcomm2014_encoder.c @@ -0,0 +1,398 @@ +/* + labcomm2014_encoder.c -- handling encoding of labcomm2014 samples. + + Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> + + This file is part of LabComm. + + LabComm is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LabComm is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#define CURRENT_VERSION "LabComm2014" + +#include <errno.h> +#include "labcomm2014.h" +#include "labcomm2014_private.h" +#include "labcomm2014_ioctl.h" +#include "labcomm2014_dynamic_buffer_writer.h" + +//define the following to disable encoding of typedefs +#undef LABCOMM_WITHOUT_TYPE_DEFS + +struct labcomm2014_encoder { + struct labcomm2014_writer *writer; + struct labcomm2014_error_handler *error; + struct labcomm2014_memory *memory; + struct labcomm2014_scheduler *scheduler; + LABCOMM_SIGNATURE_ARRAY_DEF(registered, int); + LABCOMM_SIGNATURE_ARRAY_DEF(sample_ref, int); + LABCOMM_SIGNATURE_ARRAY_DEF(typedefs, int); +}; + +static struct labcomm2014_encoder *internal_encoder_new( + struct labcomm2014_writer *writer, + struct labcomm2014_error_handler *error, + struct labcomm2014_memory *memory, + struct labcomm2014_scheduler *scheduler, + labcomm2014_bool outputVer) +{ + struct labcomm2014_encoder *result; + + result = labcomm2014_memory_alloc(memory, 0, sizeof(*result)); + if (result) { + int length; + + result->writer = writer; + result->writer->encoder = result; + result->writer->data = NULL; + result->writer->data_size = 0; + result->writer->count = 0; + result->writer->pos = 0; + result->writer->error = 0; + result->error = error; + result->memory = memory; + result->scheduler = scheduler; + LABCOMM_SIGNATURE_ARRAY_INIT(result->registered, int); + LABCOMM_SIGNATURE_ARRAY_INIT(result->sample_ref, int); + LABCOMM_SIGNATURE_ARRAY_INIT(result->typedefs, int); + labcomm2014_writer_alloc(result->writer, + result->writer->action_context); + if(outputVer) { + labcomm2014_writer_start(result->writer, + result->writer->action_context, + LABCOMM_VERSION, NULL, CURRENT_VERSION); + labcomm2014_write_packed32(result->writer, LABCOMM_VERSION); + length = labcomm2014_size_string(CURRENT_VERSION); + labcomm2014_write_packed32(result->writer, length); + labcomm2014_write_string(result->writer, CURRENT_VERSION); + labcomm2014_writer_end(result->writer, result->writer->action_context); + } + } + return result; +} + +struct labcomm2014_encoder *labcomm2014_encoder_new( + struct labcomm2014_writer *writer, + struct labcomm2014_error_handler *error, + struct labcomm2014_memory *memory, + struct labcomm2014_scheduler *scheduler) +{ + return internal_encoder_new(writer,error,memory,scheduler,TRUE); +} +void labcomm2014_encoder_free(struct labcomm2014_encoder* e) +{ + struct labcomm2014_memory *memory = e->memory; + + labcomm2014_writer_free(e->writer, e->writer->action_context); + LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, e->registered, int); + LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, e->sample_ref, int); + LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, e->typedefs, int); + labcomm2014_memory_free(memory, 0, e); +} + +int labcomm2014_internal_encoder_register( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature, + labcomm2014_encoder_function encode) +{ + int result = -EINVAL; + int index, *done, err, i, length; + + index = labcomm2014_get_local_index(signature); + labcomm2014_scheduler_writer_lock(e->scheduler); + if (index <= 0) { goto out; } + done = LABCOMM_SIGNATURE_ARRAY_REF(e->memory, e->registered, int, index); + if (*done) { + goto out; } + *done = 1; + err = labcomm2014_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; } + labcomm2014_write_packed32(e->writer, LABCOMM_SAMPLE_DEF); + length = (labcomm2014_size_packed32(index) + + labcomm2014_size_string(signature->name) + + labcomm2014_size_packed32(signature->size) + + signature->size); + labcomm2014_write_packed32(e->writer, length); + labcomm2014_write_packed32(e->writer, index); + labcomm2014_write_string(e->writer, signature->name); + labcomm2014_write_packed32(e->writer, signature->size); + for (i = 0 ; i < signature->size ; i++) { + if (e->writer->pos >= e->writer->count) { + labcomm2014_writer_flush(e->writer, e->writer->action_context); + } + e->writer->data[e->writer->pos] = signature->signature[i]; + e->writer->pos++; + } + labcomm2014_writer_end(e->writer, e->writer->action_context); + result = e->writer->error; +out: + labcomm2014_scheduler_writer_unlock(e->scheduler); + return result; +} + +int labcomm2014_internal_encode( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature, + labcomm2014_encoder_function encode, + void *value) +{ + int result, index, length; + + index = labcomm2014_get_local_index(signature); + length = (signature->encoded_size(value)); + labcomm2014_scheduler_writer_lock(e->scheduler); + if (! LABCOMM_SIGNATURE_ARRAY_GET(e->registered, int, index, 0)) { + result = -EINVAL; + goto no_end; + } + result = labcomm2014_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 = labcomm2014_write_packed32(e->writer, index); + result = labcomm2014_write_packed32(e->writer, length); + if (result != 0) { goto out; } + result = encode(e->writer, value); +out: + labcomm2014_writer_end(e->writer, e->writer->action_context); +no_end: + labcomm2014_scheduler_writer_unlock(e->scheduler); + return result; +} + +int labcomm2014_encoder_sample_ref_register( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature) +{ + int result = -EINVAL; + int index, *done, err, i, length; + + index = labcomm2014_get_local_index(signature); + labcomm2014_scheduler_writer_lock(e->scheduler); + if (index <= 0) { goto out; } + + done = LABCOMM_SIGNATURE_ARRAY_REF(e->memory, e->sample_ref, int, index); + if (*done) { goto out; } + *done = 1; + err = labcomm2014_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; } + labcomm2014_write_packed32(e->writer, LABCOMM_SAMPLE_REF); + length = (labcomm2014_size_packed32(index) + + labcomm2014_size_string(signature->name) + + labcomm2014_size_packed32(signature->size) + + signature->size); + labcomm2014_write_packed32(e->writer, length); + labcomm2014_write_packed32(e->writer, index); + labcomm2014_write_string(e->writer, signature->name); + labcomm2014_write_packed32(e->writer, signature->size); + for (i = 0 ; i < signature->size ; i++) { + if (e->writer->pos >= e->writer->count) { + labcomm2014_writer_flush(e->writer, e->writer->action_context); + } + e->writer->data[e->writer->pos] = signature->signature[i]; + e->writer->pos++; + } + labcomm2014_writer_end(e->writer, e->writer->action_context); + result = e->writer->error; +out: + labcomm2014_scheduler_writer_unlock(e->scheduler); + return result; +} + +int labcomm2014_encoder_ioctl(struct labcomm2014_encoder *encoder, + uint32_t action, + ...) +{ + int result; + va_list va; + + if (LABCOMM_IOC_SIG(action) != LABCOMM_IOC_NOSIG) { + result = -EINVAL; + goto out; + } + + va_start(va, action); + result = labcomm2014_writer_ioctl(encoder->writer, + encoder->writer->action_context, + 0, NULL, action, va); + va_end(va); + +out: + return result; +} + +int labcomm2014_internal_encoder_ioctl(struct labcomm2014_encoder *encoder, + const struct labcomm2014_signature *signature, + uint32_t action, va_list va) +{ + int result = -ENOTSUP; + int index; + + index = labcomm2014_get_local_index(signature); + result = labcomm2014_writer_ioctl(encoder->writer, + encoder->writer->action_context, + index, signature, action, va); + return result; +} + +int labcomm2014_internal_encoder_signature_to_index( + struct labcomm2014_encoder *e, const struct labcomm2014_signature *signature) +{ + /* writer_lock should be held at this point */ + int index = 0; + if (signature != NULL) { + index = labcomm2014_get_local_index(signature); + if (! LABCOMM_SIGNATURE_ARRAY_GET(e->sample_ref, int, index, 0)) { + index = 0; + } + } + return index; +} + + +/********************************************************** + * Start of code related to sending (hierarchical) + * typedefs. Define LABCOMM_WITHOUT_TYPEDEFS to disable + **********************************************************/ +#ifndef LABCOMM_WITHOUT_TYPE_DEFS + +static void write_sig_tree_byte(char b, const struct labcomm2014_signature *signature, + void *context) +{ + struct labcomm2014_encoder *e = context; + if(signature) { + labcomm2014_write_packed32(e->writer, labcomm2014_get_local_index(signature)); + }else { + if (e->writer->pos >= e->writer->count) { + labcomm2014_writer_flush(e->writer, e->writer->action_context); + } + e->writer->data[e->writer->pos] = b; + e->writer->pos++; + } +} + +static void do_write_signature(struct labcomm2014_encoder * e, + const struct labcomm2014_signature *signature, + unsigned char flatten) +{ + map_signature(write_sig_tree_byte, e, signature, flatten); +} + +static void sig_size(char b, const struct labcomm2014_signature *signature, + void *context) +{ + int *result = context; + int diff; + if(signature) { + int idx = labcomm2014_get_local_index(signature); + diff = labcomm2014_size_packed32(idx); + }else { + diff = 1; + } + (*result)+=diff; +} + +static int calc_sig_encoded_size(struct labcomm2014_encoder *e, + const struct labcomm2014_signature *sig) +{ + int result=0; + map_signature(sig_size, &result, sig, FALSE); + return result; +} + +static int internal_reg_type( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature, + labcomm2014_bool flatten) +{ + int result = -EINVAL; + int index, *done, err; + + index = labcomm2014_get_local_index(signature); + labcomm2014_scheduler_writer_lock(e->scheduler); + if (index <= 0) { goto out; } + done = LABCOMM_SIGNATURE_ARRAY_REF(e->memory, e->typedefs, int, index); + if (*done) { goto out; } + *done = 1; + err = labcomm2014_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; } + + int sig_size = calc_sig_encoded_size(e, signature); + int len = labcomm2014_size_packed32(index) + + labcomm2014_size_string(signature->name) + + labcomm2014_size_packed32(sig_size) + + sig_size; + + labcomm2014_write_packed32(e->writer, LABCOMM_TYPE_DEF); + labcomm2014_write_packed32(e->writer, len); + labcomm2014_write_packed32(e->writer, index); + labcomm2014_write_string(e->writer, signature->name); + labcomm2014_write_packed32(e->writer, sig_size); + do_write_signature(e, signature, FALSE); + + labcomm2014_writer_end(e->writer, e->writer->action_context); + result = e->writer->error; +out: + labcomm2014_scheduler_writer_unlock(e->scheduler); + return result; +} +#endif + +int labcomm2014_internal_encoder_type_register( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature) +{ +#ifndef LABCOMM_WITHOUT_TYPE_DEFS + return internal_reg_type(e, signature, FALSE); +#else + return 0; +#endif +} +int labcomm2014_internal_encoder_type_bind( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature, + char has_deps) +{ +#ifndef LABCOMM_WITHOUT_TYPE_DEFS + int result = -EINVAL; + int err; + int sindex = labcomm2014_get_local_index(signature); + int tindex = has_deps ? labcomm2014_get_local_type_index(signature) : LABCOMM_BIND_SELF; + labcomm2014_scheduler_writer_lock(e->scheduler); + if(sindex <= 0 || (has_deps && tindex <= 0)) {goto out;} + err = labcomm2014_writer_start(e->writer, e->writer->action_context, + LABCOMM_TYPE_BINDING, signature, NULL); + if (err == -EALREADY) { result = 0; goto out; } + if (err != 0) { result = err; goto out; } + int length = (labcomm2014_size_packed32(sindex) + + labcomm2014_size_packed32(tindex)); + labcomm2014_write_packed32(e->writer, LABCOMM_TYPE_BINDING); + labcomm2014_write_packed32(e->writer, length); + labcomm2014_write_packed32(e->writer, sindex); + labcomm2014_write_packed32(e->writer, tindex); + labcomm2014_writer_end(e->writer, e->writer->action_context); + result = e->writer->error; + +out: + labcomm2014_scheduler_writer_unlock(e->scheduler); + return result; +#else + return 0; +#endif +} diff --git a/lib/c/2014/labcomm_error.c b/lib/c/2014/labcomm2014_error.c similarity index 86% rename from lib/c/2014/labcomm_error.c rename to lib/c/2014/labcomm2014_error.c index 5bfea6e..9ea193b 100644 --- a/lib/c/2014/labcomm_error.c +++ b/lib/c/2014/labcomm2014_error.c @@ -1,5 +1,5 @@ /* - labcomm_error.c -- labcomm error handling + labcomm2014_error.c -- labcomm2014 error handling Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,9 +22,9 @@ #include <stdlib.h> #include <stdio.h> #include <stdarg.h> -#include "labcomm_error.h" +#include "labcomm2014_error.h" -void labcomm_error_fatal_global(enum labcomm_error error, +void labcomm2014_error_fatal_global(enum labcomm2014_error error, char *format, ...) { diff --git a/lib/c/2014/labcomm_error.h b/lib/c/2014/labcomm2014_error.h similarity index 81% rename from lib/c/2014/labcomm_error.h rename to lib/c/2014/labcomm2014_error.h index 5ad344b..0b06ec2 100644 --- a/lib/c/2014/labcomm_error.h +++ b/lib/c/2014/labcomm2014_error.h @@ -1,5 +1,5 @@ /* - labcomm_error.h -- labcomm error declarations + labcomm2014_error.h -- labcomm2014 error declarations Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -19,23 +19,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_ERROR_H___ -#define __LABCOMM_ERROR_H___ +#ifndef __LABCOMM2014_ERROR_H___ +#define __LABCOMM2014_ERROR_H___ -enum labcomm_error { +enum labcomm2014_error { #define LABCOMM_ERROR(name, description) name , -#include "labcomm_error.h" +#include "labcomm2014_error.h" #undef LABCOMM_ERROR }; -struct labcomm_error_handler; +struct labcomm2014_error_handler; -void labcomm_error_warning(struct labcomm_error_handler *e, - enum labcomm_error, +void labcomm2014_error_warning(struct labcomm2014_error_handler *e, + enum labcomm2014_error, char *format, ...); -void labcomm_error_fatal_global(enum labcomm_error error, +void labcomm2014_error_fatal_global(enum labcomm2014_error error, char *format, ...); @@ -51,7 +51,7 @@ LABCOMM_ERROR(LABCOMM_ERROR_SIGNATURE_NOT_SET, LABCOMM_ERROR(LABCOMM_ERROR_ENC_NO_REG_SIGNATURE, "Encoder has no registration for this signature") LABCOMM_ERROR(LABCOMM_ERROR_ENC_BUF_FULL, - "The labcomm buffer is full") + "The labcomm2014 buffer is full") LABCOMM_ERROR(LABCOMM_ERROR_DEC_UNKNOWN_DATATYPE, "Decoder: Unknown datatype") LABCOMM_ERROR(LABCOMM_ERROR_DEC_INDEX_MISMATCH, diff --git a/lib/c/2014/labcomm_fd_reader.c b/lib/c/2014/labcomm2014_fd_reader.c similarity index 64% rename from lib/c/2014/labcomm_fd_reader.c rename to lib/c/2014/labcomm2014_fd_reader.c index eaa59f9..ad2d222 100644 --- a/lib/c/2014/labcomm_fd_reader.c +++ b/lib/c/2014/labcomm2014_fd_reader.c @@ -1,5 +1,5 @@ /* - labcomm_fd_reader.c -- LabComm reader for Unix file descriptors. + labcomm2014_fd_reader.c -- LabComm reader for Unix file descriptors. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -23,26 +23,26 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> -#include "labcomm_private.h" -#include "labcomm_fd_reader.h" +#include "labcomm2014_private.h" +#include "labcomm2014_fd_reader.h" #define BUFFER_SIZE 2048 -struct labcomm_fd_reader { - struct labcomm_reader reader; - struct labcomm_reader_action_context action_context; +struct labcomm2014_fd_reader { + struct labcomm2014_reader reader; + struct labcomm2014_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 labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context) { int result = 0; r->count = 0; r->pos = 0; - r->data = labcomm_memory_alloc(r->memory, 0, BUFFER_SIZE); + r->data = labcomm2014_memory_alloc(r->memory, 0, BUFFER_SIZE); if (! r->data) { r->data_size = 0; result = -ENOMEM; @@ -54,13 +54,13 @@ static int fd_alloc(struct labcomm_reader *r, return result; } -static int fd_free(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +static int fd_free(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context) { - struct labcomm_fd_reader *fd_reader = action_context->context; - struct labcomm_memory *memory = r->memory; + struct labcomm2014_fd_reader *fd_reader = action_context->context; + struct labcomm2014_memory *memory = r->memory; - labcomm_memory_free(memory, 0, r->data); + labcomm2014_memory_free(memory, 0, r->data); r->data = 0; r->data_size = 0; r->count = 0; @@ -69,16 +69,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); + labcomm2014_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 labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context) { int result = 0; - struct labcomm_fd_reader *fd_reader = action_context->context; + struct labcomm2014_fd_reader *fd_reader = action_context->context; if (r->pos < r->count) { result = r->count - r->pos; @@ -99,7 +99,7 @@ static int fd_fill(struct labcomm_reader *r, return result; } -static const struct labcomm_reader_action action = { +static const struct labcomm2014_reader_action action = { .alloc = fd_alloc, .free = fd_free, .start = NULL, @@ -108,12 +108,12 @@ static const struct labcomm_reader_action action = { .ioctl = NULL }; -struct labcomm_reader *labcomm_fd_reader_new(struct labcomm_memory *memory, +struct labcomm2014_reader *labcomm2014_fd_reader_new(struct labcomm2014_memory *memory, int fd, int close_fd_on_free) { - struct labcomm_fd_reader *result; + struct labcomm2014_fd_reader *result; - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); + result = labcomm2014_memory_alloc(memory, 0, sizeof(*result)); if (result == NULL) { return NULL; } else { diff --git a/lib/c/2014/labcomm_fd_reader.h b/lib/c/2014/labcomm2014_fd_reader.h similarity index 75% rename from lib/c/2014/labcomm_fd_reader.h rename to lib/c/2014/labcomm2014_fd_reader.h index a00fe98..0391c6c 100644 --- a/lib/c/2014/labcomm_fd_reader.h +++ b/lib/c/2014/labcomm2014_fd_reader.h @@ -1,5 +1,5 @@ /* - labcomm_fd_reader.c -- a reader for unix style file-descriptors + labcomm2014_fd_reader.c -- a reader for unix style file-descriptors Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -19,12 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_FD_READER_H__ -#define __LABCOMM_FD_READER_H__ +#ifndef __LABCOMM2014_FD_READER_H__ +#define __LABCOMM2014_FD_READER_H__ -#include "labcomm.h" +#include "labcomm2014.h" -struct labcomm_reader *labcomm_fd_reader_new(struct labcomm_memory *memory, +struct labcomm2014_reader *labcomm2014_fd_reader_new(struct labcomm2014_memory *memory, int fd, int close_fd_on_free); #endif diff --git a/lib/c/2014/labcomm_fd_writer.c b/lib/c/2014/labcomm2014_fd_writer.c similarity index 60% rename from lib/c/2014/labcomm_fd_writer.c rename to lib/c/2014/labcomm2014_fd_writer.c index 5833acc..42c9dbc 100644 --- a/lib/c/2014/labcomm_fd_writer.c +++ b/lib/c/2014/labcomm2014_fd_writer.c @@ -1,5 +1,5 @@ /* - labcomm_fd_writer.c -- LabComm writer for Unix file descriptors. + labcomm2014_fd_writer.c -- LabComm writer for Unix file descriptors. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -24,25 +24,25 @@ #include <string.h> #include <stdlib.h> #include <stdarg.h> -#include "labcomm_private.h" -#include "labcomm_fd_writer.h" +#include "labcomm2014_private.h" +#include "labcomm2014_fd_writer.h" #define BUFFER_SIZE 2048 -struct labcomm_fd_writer { - struct labcomm_writer writer; - struct labcomm_writer_action_context action_context; +struct labcomm2014_fd_writer { + struct labcomm2014_writer writer; + struct labcomm2014_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 labcomm2014_writer *w, + struct labcomm2014_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 labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { - w->data = labcomm_memory_alloc(w->memory, 0, BUFFER_SIZE); + w->data = labcomm2014_memory_alloc(w->memory, 0, BUFFER_SIZE); if (! w->data) { w->error = -ENOMEM; w->data_size = 0; @@ -57,13 +57,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 labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { - struct labcomm_fd_writer *fd_writer = action_context->context; - struct labcomm_memory *memory = w->memory; + struct labcomm2014_fd_writer *fd_writer = action_context->context; + struct labcomm2014_memory *memory = w->memory; - labcomm_memory_free(memory, 0, w->data); + labcomm2014_memory_free(memory, 0, w->data); w->data = 0; w->data_size = 0; w->count = 0; @@ -72,14 +72,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); + labcomm2014_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 labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, int index, - const struct labcomm_signature *signature, + const struct labcomm2014_signature *signature, void *value) { w->pos = 0; @@ -87,10 +87,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 labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { - struct labcomm_fd_writer *fd_context = action_context->context; + struct labcomm2014_fd_writer *fd_context = action_context->context; int start, err; start = 0; @@ -112,7 +112,7 @@ static int fd_flush(struct labcomm_writer *w, return w->error; } -static const struct labcomm_writer_action action = { +static const struct labcomm2014_writer_action action = { .alloc = fd_alloc, .free = fd_free, .start = fd_start, @@ -121,12 +121,12 @@ static const struct labcomm_writer_action action = { .ioctl = NULL }; -struct labcomm_writer *labcomm_fd_writer_new(struct labcomm_memory *memory, +struct labcomm2014_writer *labcomm2014_fd_writer_new(struct labcomm2014_memory *memory, int fd, int close_fd_on_free) { - struct labcomm_fd_writer *result; + struct labcomm2014_fd_writer *result; - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); + result = labcomm2014_memory_alloc(memory, 0, sizeof(*result)); if (result == NULL) { return NULL; } else { diff --git a/lib/c/2014/labcomm_fd_writer.h b/lib/c/2014/labcomm2014_fd_writer.h similarity index 75% rename from lib/c/2014/labcomm_fd_writer.h rename to lib/c/2014/labcomm2014_fd_writer.h index 3fbf42a..92145a5 100644 --- a/lib/c/2014/labcomm_fd_writer.h +++ b/lib/c/2014/labcomm2014_fd_writer.h @@ -1,5 +1,5 @@ /* - labcomm_fd_writer.c -- a writer for unix style file-descriptors + labcomm2014_fd_writer.c -- a writer for unix style file-descriptors Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -19,12 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_FD_WRITER_H__ -#define __LABCOMM_FD_WRITER_H__ +#ifndef __LABCOMM2014_FD_WRITER_H__ +#define __LABCOMM2014_FD_WRITER_H__ -#include "labcomm.h" +#include "labcomm2014.h" -struct labcomm_writer *labcomm_fd_writer_new(struct labcomm_memory *memory, +struct labcomm2014_writer *labcomm2014_fd_writer_new(struct labcomm2014_memory *memory, int fd, int close_on_free); #endif diff --git a/lib/c/2014/labcomm_ioctl.h b/lib/c/2014/labcomm2014_ioctl.h similarity index 95% rename from lib/c/2014/labcomm_ioctl.h rename to lib/c/2014/labcomm2014_ioctl.h index a00a6a8..bb321ed 100644 --- a/lib/c/2014/labcomm_ioctl.h +++ b/lib/c/2014/labcomm2014_ioctl.h @@ -1,5 +1,5 @@ /* - labcomm_ioctl.h -- labcomm ioctl declarations + labcomm2014_ioctl.h -- labcomm2014 ioctl declarations Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -19,10 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_IOCTL_H___ -#define __LABCOMM_IOCTL_H___ +#ifndef __LABCOMM2014_IOCTL_H___ +#define __LABCOMM2014_IOCTL_H___ -#include "labcomm.h" +#include "labcomm2014.h" /* * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -35,7 +35,7 @@ * | +----------------------------------------------- direction (2) * +------------------------------------------------- signature (1) * - * type 0-31 are reserved for labcomm library use + * type 0-31 are reserved for labcomm2014 library use */ diff --git a/lib/c/2014/labcomm_memory.c b/lib/c/2014/labcomm2014_memory.c similarity index 74% rename from lib/c/2014/labcomm_memory.c rename to lib/c/2014/labcomm2014_memory.c index 62bc9ac..757640a 100644 --- a/lib/c/2014/labcomm_memory.c +++ b/lib/c/2014/labcomm2014_memory.c @@ -1,5 +1,5 @@ /* - labcomm_memory.c -- dynamic memory handlig dispatcher + labcomm2014_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 "labcomm2014_private.h" -void *labcomm_memory_alloc(struct labcomm_memory *m, int lifetime, +void *labcomm2014_memory_alloc(struct labcomm2014_memory *m, int lifetime, size_t size) { return m->alloc(m, lifetime, size); } -void *labcomm_memory_realloc(struct labcomm_memory *m, int lifetime, +void *labcomm2014_memory_realloc(struct labcomm2014_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 labcomm2014_memory_free(struct labcomm2014_memory *m, int lifetime, void *ptr) { m->free(m, lifetime, ptr); diff --git a/lib/c/2014/labcomm_private.h b/lib/c/2014/labcomm2014_private.h similarity index 52% rename from lib/c/2014/labcomm_private.h rename to lib/c/2014/labcomm2014_private.h index 6422a90..42615c1 100644 --- a/lib/c/2014/labcomm_private.h +++ b/lib/c/2014/labcomm2014_private.h @@ -1,6 +1,6 @@ /* - labcomm_private.h -- semi private declarations for handling encoding and - decoding of labcomm samples. + labcomm2014_private.h -- semi private declarations for handling encoding and + decoding of labcomm2014 samples. Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -20,8 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_PRIVATE_H__ -#define __LABCOMM_PRIVATE_H__ +#ifndef __LABCOMM2014_PRIVATE_H__ +#define __LABCOMM2014_PRIVATE_H__ #ifdef LABCOMM_COMPAT #include LABCOMM_COMPAT @@ -34,7 +34,7 @@ //#include <stdlib.h> #include <string.h> -#include "labcomm.h" +#include "labcomm2014.h" /* * Allowed packet tags @@ -74,7 +74,7 @@ /* * Macro to automagically call constructors in modules compiled - * with the labcomm compiler. If __attribute__((constructor)) is + * with the labcomm2014 compiler. If __attribute__((constructor)) is * not supported, these calls has to be done first in main program. */ #ifndef LABCOMM_CONSTRUCTOR @@ -85,36 +85,36 @@ * 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 labcomm2014_memory { + void *(*alloc)(struct labcomm2014_memory *m, int lifetime, size_t size); + void *(*realloc)(struct labcomm2014_memory *m, int lifetime, void *ptr, size_t size); - void (*free)(struct labcomm_memory *m, int lifetime, void *ptr); + void (*free)(struct labcomm2014_memory *m, int lifetime, void *ptr); void *context; }; /* * Semi private decoder declarations */ -typedef void (*labcomm_handler_function)(void *value, void *context); +typedef void (*labcomm2014_handler_function)(void *value, void *context); -typedef void (*labcomm_decoder_function)( - struct labcomm_reader *r, - labcomm_handler_function handler, +typedef void (*labcomm2014_decoder_function)( + struct labcomm2014_reader *r, + labcomm2014_handler_function handler, void *context); -struct labcomm_reader_action_context; +struct labcomm2014_reader_action_context; -struct labcomm_reader_action { - /* 'alloc' is called at the first invocation of 'labcomm_decoder_decode_one' +struct labcomm2014_reader_action { + /* 'alloc' is called at the first invocation of 'labcomm2014_decoder_decode_one' on the decoder containing the reader. Returned value: > 0 Number of bytes allocated for buffering <= 0 Error */ - int (*alloc)(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context); + int (*alloc)(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context); /* 'free' returns the resources claimed by 'alloc' and might have other reader specific side-effects as well. @@ -122,8 +122,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 labcomm2014_reader *r, + struct labcomm2014_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) @@ -132,33 +132,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 labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context, int local_index, int remote_index, - const struct labcomm_signature *signature, + const struct labcomm2014_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 labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context); + int (*fill)(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context); + int (*ioctl)(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context, int local_index, int remote_index, - const struct labcomm_signature *signature, + const struct labcomm2014_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 labcomm2014_reader_action_context { + struct labcomm2014_reader_action_context *next; + const struct labcomm2014_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 labcomm2014_reader { + struct labcomm2014_reader_action_context *action_context; + struct labcomm2014_memory *memory; + /* The following fields are initialized by labcomm2014_decoder_new */ + struct labcomm2014_decoder *decoder; unsigned char *data; int data_size; int count; @@ -166,51 +166,51 @@ struct labcomm_reader { int error; }; -int labcomm_reader_alloc(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context); -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 labcomm2014_reader_alloc(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context); +int labcomm2014_reader_free(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context); +int labcomm2014_reader_start(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context, int local_index, int remote_index, - const struct labcomm_signature *signature, + const struct labcomm2014_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 labcomm2014_reader_end(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context); +int labcomm2014_reader_fill(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context); +int labcomm2014_reader_ioctl(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context, int local_index, int remote_index, - const struct labcomm_signature *signature, + const struct labcomm2014_signature *signature, uint32_t ioctl_action, va_list args); /* * Non typesafe registration function to be called from - * generated labcomm_decoder_register_* functions. + * generated labcomm2014_decoder_register_* functions. */ -int labcomm_internal_decoder_register( - struct labcomm_decoder *d, - const struct labcomm_signature *s, - labcomm_decoder_function decoder, - labcomm_handler_function handler, +int labcomm2014_internal_decoder_register( + struct labcomm2014_decoder *d, + const struct labcomm2014_signature *s, + labcomm2014_decoder_function decoder, + labcomm2014_handler_function handler, void *context); -int labcomm_internal_decoder_ioctl(struct labcomm_decoder *decoder, - const struct labcomm_signature *signature, +int labcomm2014_internal_decoder_ioctl(struct labcomm2014_decoder *decoder, + const struct labcomm2014_signature *signature, uint32_t ioctl_action, va_list args); -const struct labcomm_signature *labcomm_internal_decoder_index_to_signature( - struct labcomm_decoder *decoder, int index); +const struct labcomm2014_signature *labcomm2014_internal_decoder_index_to_signature( + struct labcomm2014_decoder *decoder, int index); #if __BYTE_ORDER == __LITTLE_ENDIAN #define LABCOMM_DECODE(name, type) \ - static inline type labcomm_read_##name(struct labcomm_reader *r) { \ + static inline type labcomm2014_read_##name(struct labcomm2014_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); \ + labcomm2014_reader_fill(r, r->action_context); \ if (r->error < 0) { \ return 0; \ } \ @@ -224,11 +224,11 @@ const struct labcomm_signature *labcomm_internal_decoder_index_to_signature( #else #define LABCOMM_DECODE(name, type) \ - static inline type labcomm_read_##name(struct labcomm_reader *r) { \ + static inline type labcomm2014_read_##name(struct labcomm2014_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); \ + labcomm2014_reader_fille(r, r->action_context); \ if (r->error < 0) { \ return 0; \ } \ @@ -249,7 +249,7 @@ LABCOMM_DECODE(long, long long) LABCOMM_DECODE(float, float) LABCOMM_DECODE(double, double) -static inline unsigned int labcomm_read_packed32(struct labcomm_reader *r) +static inline unsigned int labcomm2014_read_packed32(struct labcomm2014_reader *r) { unsigned int result = 0; @@ -257,7 +257,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); + labcomm2014_reader_fill(r, r->action_context); if (r->error != 0) { goto out; } @@ -273,21 +273,21 @@ out: return result; } -static inline char *labcomm_read_string(struct labcomm_reader *r) +static inline char *labcomm2014_read_string(struct labcomm2014_reader *r) { char *result = NULL; int length, pos; - length = labcomm_read_packed32(r); - result = labcomm_memory_alloc(r->memory, 1, length + 1); + length = labcomm2014_read_packed32(r); + result = labcomm2014_memory_alloc(r->memory, 1, length + 1); if (!result) { - labcomm2014_on_error_fprintf(LABCOMM_ERROR_MEMORY, 4, "%d byte at %s:%d", + labcomm20142014_on_error_fprintf(LABCOMM_ERROR_MEMORY, 4, "%d byte at %s:%d", length+1, __FUNCTION__, __LINE__); return NULL; } for (pos = 0 ; pos < length ; pos++) { if (r->pos >= r->count) { - labcomm_reader_fill(r, r->action_context); + labcomm2014_reader_fill(r, r->action_context); if (r->error < 0) { goto out; } @@ -303,15 +303,15 @@ out: /* * Semi private encoder declarations */ -typedef int (*labcomm_encoder_function)(struct labcomm_writer *, +typedef int (*labcomm2014_encoder_function)(struct labcomm2014_writer *, void *value); -struct labcomm_writer_action_context; +struct labcomm2014_writer_action_context; -struct labcomm_writer_action { - int (*alloc)(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); - int (*free)(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); +struct labcomm2014_writer_action { + int (*alloc)(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context); + int (*free)(struct labcomm2014_writer *w, + struct labcomm2014_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. @@ -321,31 +321,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, const struct labcomm_signature *signature, + int (*start)(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int index, const struct labcomm2014_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, const struct labcomm_signature *signature, + int (*end)(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context); + int (*flush)(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context); + int (*ioctl)(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int index, const struct labcomm2014_signature *signature, uint32_t ioctl_action, va_list args); }; -struct labcomm_writer_action_context { - struct labcomm_writer_action_context *next; - const struct labcomm_writer_action *action; +struct labcomm2014_writer_action_context { + struct labcomm2014_writer_action_context *next; + const struct labcomm2014_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 labcomm2014_writer { + struct labcomm2014_writer_action_context *action_context; + struct labcomm2014_memory *memory; + /* The following fields are initialized by labcomm2014_encoder_new */ + struct labcomm2014_encoder *encoder; unsigned char *data; int data_size; int count; @@ -353,63 +353,63 @@ struct labcomm_writer { int error; }; -int labcomm_writer_alloc(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context); -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, const struct labcomm_signature *signature, +int labcomm2014_writer_alloc(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context); +int labcomm2014_writer_free(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context); +int labcomm2014_writer_start(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int index, const struct labcomm2014_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, const struct labcomm_signature *signature, +int labcomm2014_writer_end(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context); +int labcomm2014_writer_flush(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context); +int labcomm2014_writer_ioctl(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int index, const struct labcomm2014_signature *signature, uint32_t ioctl_action, va_list args); -int labcomm_internal_encoder_type_register( - struct labcomm_encoder *e, - const struct labcomm_signature *signature); +int labcomm2014_internal_encoder_type_register( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature); -int labcomm_internal_encoder_type_bind( - struct labcomm_encoder *e, - const struct labcomm_signature *signature, +int labcomm2014_internal_encoder_type_bind( + struct labcomm2014_encoder *e, + const struct labcomm2014_signature *signature, char has_deps); -int labcomm_internal_encoder_register( - struct labcomm_encoder *encoder, - const struct labcomm_signature *signature, - labcomm_encoder_function encode); +int labcomm2014_internal_encoder_register( + struct labcomm2014_encoder *encoder, + const struct labcomm2014_signature *signature, + labcomm2014_encoder_function encode); -int labcomm_internal_encode( - struct labcomm_encoder *encoder, - const struct labcomm_signature *signature, - labcomm_encoder_function encode, +int labcomm2014_internal_encode( + struct labcomm2014_encoder *encoder, + const struct labcomm2014_signature *signature, + labcomm2014_encoder_function encode, void *value); -int labcomm_internal_encoder_ioctl(struct labcomm_encoder *encoder, - const struct labcomm_signature *signature, +int labcomm2014_internal_encoder_ioctl(struct labcomm2014_encoder *encoder, + const struct labcomm2014_signature *signature, uint32_t ioctl_action, va_list args); -int labcomm_internal_encoder_signature_to_index( - struct labcomm_encoder *encoder, const struct labcomm_signature *signature); +int labcomm2014_internal_encoder_signature_to_index( + struct labcomm2014_encoder *encoder, const struct labcomm2014_signature *signature); -int labcomm_internal_sizeof(const struct labcomm_signature *signature, +int labcomm2014_internal_sizeof(const struct labcomm2014_signature *signature, void *v); #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 labcomm2014_write_##name(struct labcomm2014_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 = labcomm2014_writer_flush(w, w->action_context); \ if (err != 0) { return err; } \ } \ w->data[w->pos] = ((unsigned char*)(&data))[i]; \ @@ -421,12 +421,12 @@ int labcomm_internal_sizeof(const struct labcomm_signature *signature, #else #define LABCOMM_ENCODE(name, type) \ - static inline int labcomm_write_##name(struct labcomm_writer *w, type data) { \ + static inline int labcomm2014_write_##name(struct labcomm2014_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 = labcomm2014_writer_flush(w, w->action_context); \ if (err != 0) { return err; } \ } \ w->data[w->pos] = ((unsigned char*)(&data))[i]; \ @@ -445,7 +445,7 @@ LABCOMM_ENCODE(long, long long) LABCOMM_ENCODE(float, float) LABCOMM_ENCODE(double, double) -static inline int labcomm_write_packed32(struct labcomm_writer *w, +static inline int labcomm2014_write_packed32(struct labcomm2014_writer *w, unsigned int data) { unsigned char tmp[5]; @@ -457,7 +457,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 = labcomm2014_writer_flush(w, w->action_context); if (err != 0) { return err; } } w->data[w->pos++] = tmp[i] | (i?0x80:0x00); @@ -465,17 +465,17 @@ static inline int labcomm_write_packed32(struct labcomm_writer *w, return 0; } -static inline int labcomm_write_string(struct labcomm_writer *w, char *s) +static inline int labcomm2014_write_string(struct labcomm2014_writer *w, char *s) { int length, i, err; length = strlen(s); - err = labcomm_write_packed32(w, length); + err = labcomm2014_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 = labcomm2014_writer_flush(w, w->action_context); if (err != 0) { return err; } } w->data[w->pos] = s[i]; @@ -485,7 +485,7 @@ static inline int labcomm_write_string(struct labcomm_writer *w, char *s) } /* Size of packed32 variable */ -static inline int labcomm_size_packed32(unsigned int data) +static inline int labcomm2014_size_packed32(unsigned int data) { int result = 0; int i; @@ -497,11 +497,11 @@ static inline int labcomm_size_packed32(unsigned int data) } -static inline int labcomm_size_string(char *s) +static inline int labcomm2014_size_string(char *s) { int length = strlen(s); - return labcomm_size_packed32(length) + length; + return labcomm2014_size_packed32(length) + length; } /* @@ -523,10 +523,10 @@ static inline int labcomm_size_string(char *s) 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) { labcomm2014_memory_free(memory, 0, name.data); } \ name.data = (kind *)NULL; /* typechecking */ -void *labcomm_signature_array_ref(struct labcomm_memory * memory, +void *labcomm2014_signature_array_ref(struct labcomm2014_memory * memory, int *first, int *last, void **data, int size, int index); /* @@ -538,7 +538,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 *)(labcomm2014_signature_array_ref(memory, \ &name.first, &name.last, \ (void **)&name.data, \ sizeof(kind), index))) @@ -553,11 +553,11 @@ 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 labcomm2014_set_local_index(struct labcomm2014_signature *signature); /* Get the local index for a signature */ -int labcomm_get_local_index(const struct labcomm_signature *s); +int labcomm2014_get_local_index(const struct labcomm2014_signature *s); -int labcomm_get_local_type_index(const struct labcomm_signature *s); +int labcomm2014_get_local_type_index(const struct labcomm2014_signature *s); #endif diff --git a/lib/c/2014/labcomm_pthread_scheduler.c b/lib/c/2014/labcomm2014_pthread_scheduler.c similarity index 75% rename from lib/c/2014/labcomm_pthread_scheduler.c rename to lib/c/2014/labcomm2014_pthread_scheduler.c index a9b516a..e2f5a21 100644 --- a/lib/c/2014/labcomm_pthread_scheduler.c +++ b/lib/c/2014/labcomm2014_pthread_scheduler.c @@ -1,5 +1,5 @@ /* - labcomm_pthread_scheduler.c -- labcomm pthread based task coordination + labcomm2014_pthread_scheduler.c -- labcomm2014 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 "labcomm2014.h" +#include "labcomm2014_scheduler.h" +#include "labcomm2014_scheduler_private.h" +#include "labcomm2014_pthread_scheduler.h" #ifdef LABCOMM_COMPAT #include LABCOMM_COMPAT #endif struct pthread_time { - struct labcomm_time time; - struct labcomm_memory *memory; + struct labcomm2014_time time; + struct labcomm2014_memory *memory; struct timespec abstime; }; @@ -47,8 +47,8 @@ struct pthread_deferred { }; struct pthread_scheduler { - struct labcomm_scheduler scheduler; - struct labcomm_memory *memory; + struct labcomm2014_scheduler scheduler; + struct labcomm2014_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 labcomm2014_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 labcomm2014_time *time_new(struct labcomm2014_memory *memory) { struct pthread_time *time; - time = labcomm_memory_alloc(memory, 0, sizeof(*time)); + time = labcomm2014_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 labcomm2014_time *t) { struct pthread_time *time = t->context; - struct labcomm_memory *memory = time->memory; + struct labcomm2014_memory *memory = time->memory; - labcomm_memory_free(memory, 0, time); + labcomm2014_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 labcomm2014_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 labcomm2014_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); + labcomm2014_scheduler_data_unlock(&scheduler->scheduler); element->action(element->context); - labcomm_memory_free(scheduler->memory, 1, element); - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2014_memory_free(scheduler->memory, 1, element); + labcomm2014_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 labcomm2014_scheduler *s) { struct pthread_scheduler *scheduler = s->context; - struct labcomm_memory *memory = scheduler->memory; + struct labcomm2014_memory *memory = scheduler->memory; - labcomm_memory_free(memory, 0, scheduler); + labcomm2014_memory_free(memory, 0, scheduler); return 0; } -static int scheduler_writer_lock(struct labcomm_scheduler *s) +static int scheduler_writer_lock(struct labcomm2014_scheduler *s) { struct pthread_scheduler *scheduler = s->context; - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2014_scheduler_data_lock(&scheduler->scheduler); run_deferred(scheduler); /* Run deferred tasks before taking lock */ - labcomm_scheduler_data_unlock(&scheduler->scheduler); + labcomm2014_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 labcomm2014_scheduler *s) { struct pthread_scheduler *scheduler = s->context; if (pthread_mutex_unlock(&scheduler->writer_mutex) != 0) { return -errno; } - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2014_scheduler_data_lock(&scheduler->scheduler); run_deferred(scheduler); /* Run deferred tasks after releasing lock */ - labcomm_scheduler_data_unlock(&scheduler->scheduler); + labcomm2014_scheduler_data_unlock(&scheduler->scheduler); return 0; } -static int scheduler_data_lock(struct labcomm_scheduler *s) +static int scheduler_data_lock(struct labcomm2014_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 labcomm2014_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 labcomm2014_time *scheduler_now(struct labcomm2014_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 labcomm2014_scheduler *s, + struct labcomm2014_time *t) { struct pthread_scheduler *scheduler = s->context; struct pthread_time *time = t?t->context:NULL; - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2014_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); + labcomm2014_scheduler_data_unlock(&scheduler->scheduler); return 0; } -static int scheduler_wakeup(struct labcomm_scheduler *s) +static int scheduler_wakeup(struct labcomm2014_scheduler *s) { struct pthread_scheduler *scheduler = s->context; - labcomm_scheduler_data_lock(&scheduler->scheduler); + labcomm2014_scheduler_data_lock(&scheduler->scheduler); scheduler->wakeup = 1; pthread_cond_signal(&scheduler->data_cond); - labcomm_scheduler_data_unlock(&scheduler->scheduler); + labcomm2014_scheduler_data_unlock(&scheduler->scheduler); return 0; } -static int scheduler_enqueue(struct labcomm_scheduler *s, +static int scheduler_enqueue(struct labcomm2014_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 = labcomm2014_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); + labcomm2014_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); + labcomm2014_scheduler_data_unlock(&scheduler->scheduler); out: return result; } -static const struct labcomm_scheduler_action scheduler_action = { +static const struct labcomm2014_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 labcomm2014_scheduler *labcomm2014_pthread_scheduler_new( + struct labcomm2014_memory *memory) { - struct labcomm_scheduler *result = NULL; + struct labcomm2014_scheduler *result = NULL; struct pthread_scheduler *scheduler; - scheduler = labcomm_memory_alloc(memory, 0, sizeof(*scheduler)); + scheduler = labcomm2014_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); + labcomm2014_memory_free(memory, 0, scheduler); out: return result; diff --git a/lib/c/2014/labcomm_pthread_scheduler.h b/lib/c/2014/labcomm2014_pthread_scheduler.h similarity index 71% rename from lib/c/2014/labcomm_pthread_scheduler.h rename to lib/c/2014/labcomm2014_pthread_scheduler.h index 64ace83..e8e5a1b 100644 --- a/lib/c/2014/labcomm_pthread_scheduler.h +++ b/lib/c/2014/labcomm2014_pthread_scheduler.h @@ -1,5 +1,5 @@ /* - labcomm_pthread_scheduler.h -- labcomm pthread based task coordination + labcomm2014_pthread_scheduler.h -- labcomm2014 pthread based task coordination Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -19,13 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_PTHREAD_SCHEDULER_H__ -#define __LABCOMM_PTHREAD_SCHEDULER_H__ +#ifndef __LABCOMM2014_PTHREAD_SCHEDULER_H__ +#define __LABCOMM2014_PTHREAD_SCHEDULER_H__ -#include "labcomm.h" +#include "labcomm2014.h" -struct labcomm_scheduler *labcomm_pthread_scheduler_new( - struct labcomm_memory *memory); +struct labcomm2014_scheduler *labcomm2014_pthread_scheduler_new( + struct labcomm2014_memory *memory); #endif diff --git a/lib/c/2014/labcomm_scheduler.c b/lib/c/2014/labcomm2014_scheduler.c similarity index 66% rename from lib/c/2014/labcomm_scheduler.c rename to lib/c/2014/labcomm2014_scheduler.c index 3ef62f3..4028820 100644 --- a/lib/c/2014/labcomm_scheduler.c +++ b/lib/c/2014/labcomm2014_scheduler.c @@ -1,5 +1,5 @@ /* - labcomm_scheduler.c -- labcomm task coordination + labcomm2014_scheduler.c -- labcomm2014 task coordination Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -20,7 +20,7 @@ */ #include <errno.h> -#include "labcomm_scheduler_private.h" +#include "labcomm2014_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 labcomm2014_scheduler_free(struct labcomm2014_scheduler *s) { SCHEDULER(free, s); } -int labcomm_scheduler_writer_lock(struct labcomm_scheduler *s) +int labcomm2014_scheduler_writer_lock(struct labcomm2014_scheduler *s) { SCHEDULER(writer_lock, s); } -int labcomm_scheduler_writer_unlock(struct labcomm_scheduler *s) +int labcomm2014_scheduler_writer_unlock(struct labcomm2014_scheduler *s) { SCHEDULER(writer_unlock, s); } -int labcomm_scheduler_data_lock(struct labcomm_scheduler *s) +int labcomm2014_scheduler_data_lock(struct labcomm2014_scheduler *s) { SCHEDULER(data_lock, s); } -int labcomm_scheduler_data_unlock(struct labcomm_scheduler *s) +int labcomm2014_scheduler_data_unlock(struct labcomm2014_scheduler *s) { SCHEDULER(data_unlock, s); } -struct labcomm_time *labcomm_scheduler_now(struct labcomm_scheduler *s) +struct labcomm2014_time *labcomm2014_scheduler_now(struct labcomm2014_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 labcomm2014_scheduler_sleep(struct labcomm2014_scheduler *s, + struct labcomm2014_time *wakeup) { SCHEDULER(sleep, s, wakeup); } -int labcomm_scheduler_wakeup(struct labcomm_scheduler *s) +int labcomm2014_scheduler_wakeup(struct labcomm2014_scheduler *s) { SCHEDULER(wakeup, s); } -int labcomm_scheduler_enqueue(struct labcomm_scheduler *s, +int labcomm2014_scheduler_enqueue(struct labcomm2014_scheduler *s, uint32_t delay, void (*func)(void *context), void *context) diff --git a/lib/c/2014/labcomm_scheduler.h b/lib/c/2014/labcomm2014_scheduler.h similarity index 50% rename from lib/c/2014/labcomm_scheduler.h rename to lib/c/2014/labcomm2014_scheduler.h index b96b1ca..8d7e332 100644 --- a/lib/c/2014/labcomm_scheduler.h +++ b/lib/c/2014/labcomm2014_scheduler.h @@ -1,5 +1,5 @@ /* - labcomm_scheduler.h -- labcomm task coordination + labcomm2014_scheduler.h -- labcomm2014 task coordination Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -19,8 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LABCOMM_SCHEDULER_H__ -#define __LABCOMM_SCHEDULER_H__ +#ifndef __LABCOMM2014_SCHEDULER_H__ +#define __LABCOMM2014_SCHEDULER_H__ #ifdef LABCOMM_COMPAT #include LABCOMM_COMPAT @@ -29,29 +29,29 @@ #include <stdint.h> #endif -struct labcomm_time; +struct labcomm2014_time; -int labcomm_time_free(struct labcomm_time *t); -int labcomm_time_add_usec(struct labcomm_time *t, uint32_t usec); +int labcomm2014_time_free(struct labcomm2014_time *t); +int labcomm2014_time_add_usec(struct labcomm2014_time *t, uint32_t usec); -struct labcomm_scheduler; +struct labcomm2014_scheduler; -int labcomm_scheduler_free(struct labcomm_scheduler *s); +int labcomm2014_scheduler_free(struct labcomm2014_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 labcomm2014_scheduler_writer_lock(struct labcomm2014_scheduler *s); +int labcomm2014_scheduler_writer_unlock(struct labcomm2014_scheduler *s); +int labcomm2014_scheduler_data_lock(struct labcomm2014_scheduler *s); +int labcomm2014_scheduler_data_unlock(struct labcomm2014_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 labcomm2014_time *labcomm2014_scheduler_now(struct labcomm2014_scheduler *s); +int labcomm2014_scheduler_sleep(struct labcomm2014_scheduler *s, + struct labcomm2014_time *wakeup); +int labcomm2014_scheduler_wakeup(struct labcomm2014_scheduler *s); /* Deferred action handling */ -int labcomm_scheduler_enqueue(struct labcomm_scheduler *s, +int labcomm2014_scheduler_enqueue(struct labcomm2014_scheduler *s, uint32_t delay, void (*deferred)(void *context), void *context); diff --git a/lib/c/2014/labcomm2014_scheduler_private.h b/lib/c/2014/labcomm2014_scheduler_private.h new file mode 100644 index 0000000..31f4cda --- /dev/null +++ b/lib/c/2014/labcomm2014_scheduler_private.h @@ -0,0 +1,60 @@ +/* + labcomm2014_scheduler.h -- labcomm2014 task coordination, semi-private part + + Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> + + This file is part of LabComm. + + LabComm is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LabComm is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __LABCOMM2014_SCHEDULER_PRIVATE_H__ +#define __LABCOMM2014_SCHEDULER_PRIVATE_H__ + +#ifdef LABCOMM_COMPAT + #include LABCOMM_COMPAT +#else + #include <unistd.h> +#endif + +#include "labcomm2014_scheduler.h" + +struct labcomm2014_time { + const struct labcomm2014_time_action { + int (*free)(struct labcomm2014_time *t); + int (*add_usec)(struct labcomm2014_time *t, uint32_t usec); + } *action; + void *context; +}; + +struct labcomm2014_scheduler { + const struct labcomm2014_scheduler_action { + int (*free)(struct labcomm2014_scheduler *s); + int (*writer_lock)(struct labcomm2014_scheduler *s); + int (*writer_unlock)(struct labcomm2014_scheduler *s); + int (*data_lock)(struct labcomm2014_scheduler *s); + int (*data_unlock)(struct labcomm2014_scheduler *s); + struct labcomm2014_time *(*now)(struct labcomm2014_scheduler *s); + int (*sleep)(struct labcomm2014_scheduler *s, + struct labcomm2014_time *wakeup); + int (*wakeup)(struct labcomm2014_scheduler *s); + int (*enqueue)(struct labcomm2014_scheduler *s, + uint32_t delay, + void (*deferred)(void *context), + void *context); + } *action; + void *context; +}; + +#endif diff --git a/lib/c/2014/labcomm_time.c b/lib/c/2014/labcomm2014_time.c similarity index 82% rename from lib/c/2014/labcomm_time.c rename to lib/c/2014/labcomm2014_time.c index a1a5235..eb5e1f5 100644 --- a/lib/c/2014/labcomm_time.c +++ b/lib/c/2014/labcomm2014_time.c @@ -1,5 +1,5 @@ /* - labcomm_time.c -- labcomm time handling + labcomm2014_time.c -- labcomm2014 time handling Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -20,7 +20,7 @@ */ #include <errno.h> -#include "labcomm_scheduler_private.h" +#include "labcomm2014_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 labcomm2014_time_free(struct labcomm2014_time *s) { TIME(free, s); } -int labcomm_time_add_usec(struct labcomm_time *s, uint32_t usec) +int labcomm2014_time_add_usec(struct labcomm2014_time *s, uint32_t usec) { TIME(add_usec, s, usec); } diff --git a/lib/c/2014/labcomm_type_signature.c b/lib/c/2014/labcomm2014_type_signature.c similarity index 70% rename from lib/c/2014/labcomm_type_signature.c rename to lib/c/2014/labcomm2014_type_signature.c index 3cb9cc3..abc95a3 100644 --- a/lib/c/2014/labcomm_type_signature.c +++ b/lib/c/2014/labcomm2014_type_signature.c @@ -1,13 +1,13 @@ -#include "labcomm.h" +#include "labcomm2014.h" #include <string.h> // for memcmp #include <stdio.h> // for debug printf /* Dump signature bytes on stdout */ -void labcomm_signature_print(struct labcomm_signature_data *signature) +void labcomm2014_signature_print(struct labcomm2014_signature_data *signature) { - struct labcomm_signature_data *p = signature ; + struct labcomm2014_signature_data *p = signature ; while (p->length != -1) { if (p->length) { int i; @@ -15,7 +15,7 @@ void labcomm_signature_print(struct labcomm_signature_data *signature) printf("%02x ", p->u.bytes[i]); } } else if(p->u.signature){ - labcomm_signature_print(p->u.signature->treedata); + labcomm2014_signature_print(p->u.signature->treedata); } else { printf("neither data nor ref, bailing out.\n"); return; @@ -24,7 +24,7 @@ void labcomm_signature_print(struct labcomm_signature_data *signature) } printf("\n"); } -static labcomm_bool sig_dump_checked(struct labcomm_signature_data *signature, +static labcomm2014_bool sig_dump_checked(struct labcomm2014_signature_data *signature, char *buf, int *len, int buflen); /* buf (out) : byte array to write signature into @@ -32,7 +32,7 @@ static labcomm_bool sig_dump_checked(struct labcomm_signature_data *signature, return TRUE if aborted due to overrun */ -labcomm_bool labcomm_signature_dump(struct labcomm_signature_data *signature, +labcomm2014_bool labcomm2014_signature_dump(struct labcomm2014_signature_data *signature, char *buf, int *len) { int buflen = *len; @@ -43,10 +43,10 @@ labcomm_bool labcomm_signature_dump(struct labcomm_signature_data *signature, /* internal function with bounds checking for buf. * buflen: capacity of buf */ -static labcomm_bool sig_dump_checked(struct labcomm_signature_data *signature, +static labcomm2014_bool sig_dump_checked(struct labcomm2014_signature_data *signature, char *buf, int *len, int buflen) { - struct labcomm_signature_data *p = signature; + struct labcomm2014_signature_data *p = signature; while ( (p->length != -1) && (*len < buflen)) { if (p->length) { int i; @@ -72,16 +72,16 @@ static labcomm_bool sig_dump_checked(struct labcomm_signature_data *signature, /* compare signature (flattened, if needed) to other return TRUE if equal */ -labcomm_bool labcomm_signature_cmp( struct labcomm_signature_data *s1, - struct labcomm_signature_data *s2) +labcomm2014_bool labcomm2014_signature_cmp( struct labcomm2014_signature_data *s1, + struct labcomm2014_signature_data *s2) { int buflen=512; char buf1[buflen]; int len1=buflen; char buf2[buflen]; int len2=buflen; - labcomm_bool res1 = labcomm_signature_dump(s1, buf1, &len1); - labcomm_bool res2 = labcomm_signature_dump(s2, buf2, &len2); + labcomm2014_bool res1 = labcomm2014_signature_dump(s1, buf1, &len1); + labcomm2014_bool res2 = labcomm2014_signature_dump(s2, buf2, &len2); if(res1 || res2) { printf("WARNING: OVERRUN\n"); return FALSE; @@ -89,7 +89,7 @@ labcomm_bool labcomm_signature_cmp( struct labcomm_signature_data *s1, return(len1 == len2 && memcmp(buf1, buf2, len1)==0); } } -/* maps a function f(char b, struct labcomm_signature *s, void *context) +/* maps a function f(char b, struct labcomm2014_signature *s, void *context) * on each byte (or type ref) in the signature. * * If flatten, the signature is flattened to a byte array, and the @@ -100,11 +100,11 @@ labcomm_bool labcomm_signature_cmp( struct labcomm_signature_data *s1, * * The context parameter is passed on, unaltered, to f */ -void map_signature( void(*f)(char, const struct labcomm_signature *, void *), +void map_signature( void(*f)(char, const struct labcomm2014_signature *, void *), void *context, - const struct labcomm_signature *signature, labcomm_bool flatten) + const struct labcomm2014_signature *signature, labcomm2014_bool flatten) { - struct labcomm_signature_data* p = signature->treedata; + struct labcomm2014_signature_data* p = signature->treedata; while (p->length != -1) { //fprintf(stderr, "%p %x\n", p, p->length); if (p->length) { diff --git a/lib/c/2014/labcomm_type_signature.h b/lib/c/2014/labcomm2014_type_signature.h similarity index 67% rename from lib/c/2014/labcomm_type_signature.h rename to lib/c/2014/labcomm2014_type_signature.h index e556589..1d77640 100644 --- a/lib/c/2014/labcomm_type_signature.h +++ b/lib/c/2014/labcomm2014_type_signature.h @@ -1,9 +1,9 @@ -#ifndef LABCOMM_TYPE_SIGNATURE_H -#define LABCOMM_TYPE_SIGNATURE_H +#ifndef __LABCOMM2014_TYPE_SIGNATURE_H__ +#define __LABCOMM2014_TYPE_SIGNATURE_H__ //XXX move to common.h -#ifndef labcomm_bool -#define labcomm_bool char +#ifndef labcomm2014_bool +#define labcomm2014_bool char #define TRUE 1 #define FALSE 0 #endif @@ -19,7 +19,7 @@ #define LABCOMM_SIGDEF_BYTES_OR_SIGNATURE \ union { \ char *bytes; \ - struct labcomm_signature* signature; \ + struct labcomm2014_signature* signature; \ } u; #define LABCOMM_SIGDEF_BYTES(l, b) { l, .u.bytes=b } @@ -31,7 +31,7 @@ #define LABCOMM_SIGDEF_BYTES_OR_SIGNATURE \ struct { \ char *bytes; \ - const struct labcomm_signature *signature; \ + const struct labcomm2014_signature *signature; \ } u; #define LABCOMM_SIGDEF_BYTES(l, b) { l, { b, 0 } } @@ -40,13 +40,13 @@ #endif -struct labcomm_signature_data { +struct labcomm2014_signature_data { int length; LABCOMM_SIGDEF_BYTES_OR_SIGNATURE }; #endif -struct labcomm_signature { +struct labcomm2014_signature { char *name; int (*encoded_size)(void *); /* void* refers to sample_data */ int size; @@ -54,7 +54,7 @@ struct labcomm_signature { int index; #ifndef LABCOMM_NO_TYPEDECL int tdsize; - struct labcomm_signature_data *treedata; + struct labcomm2014_signature_data *treedata; #endif #ifdef LABCOMM_EXPERIMENTAL_CACHED_ENCODED_SIZE int cached_encoded_size; // -1 if not initialized or type is variable size @@ -65,7 +65,7 @@ struct labcomm_signature { * between decoder and signature parser */ -struct labcomm_raw_type_def { +struct labcomm2014_raw_type_def { char *name; int index; int length; @@ -75,7 +75,7 @@ struct labcomm_raw_type_def { /* a struct for type bindings */ -struct labcomm_type_binding { +struct labcomm2014_type_binding { int sample_index; int type_index; }; @@ -88,19 +88,19 @@ struct labcomm_type_binding { /* register a handler for type_defs and type bindings */ -int labcomm_decoder_register_labcomm_type_def( - struct labcomm_decoder *d, +int labcomm2014_decoder_register_labcomm2014_type_def( + struct labcomm2014_decoder *d, void (*handler)( - struct labcomm_raw_type_def *v, + struct labcomm2014_raw_type_def *v, void *context ), void *context ); -int labcomm_decoder_register_labcomm_type_binding( - struct labcomm_decoder *d, +int labcomm2014_decoder_register_labcomm2014_type_binding( + struct labcomm2014_decoder *d, void (*handler)( - struct labcomm_type_binding *v, + struct labcomm2014_type_binding *v, void *context ), void *context @@ -109,13 +109,13 @@ int labcomm_decoder_register_labcomm_type_binding( /* Dump signature bytes on stdout */ -void labcomm_signature_print(struct labcomm_signature_data *signature); +void labcomm2014_signature_print(struct labcomm2014_signature_data *signature); /* compare signatures (flattened, if needed) to other * return TRUE if equal */ -labcomm_bool labcomm_signature_cmp( struct labcomm_signature_data *s2, - struct labcomm_signature_data *s1); +labcomm2014_bool labcomm2014_signature_cmp( struct labcomm2014_signature_data *s2, + struct labcomm2014_signature_data *s1); /* flatten and dump signature to a byte array. * buf (out) : byte array to write signature into @@ -123,7 +123,7 @@ labcomm_bool labcomm_signature_cmp( struct labcomm_signature_data *s2, * * return TRUE if aborted due to overrun */ -labcomm_bool labcomm_signature_dump(struct labcomm_signature_data *signature, +labcomm2014_bool labcomm2014_signature_dump(struct labcomm2014_signature_data *signature, char *buf, int *len); /* maps function f on each byte in the signature @@ -132,8 +132,8 @@ labcomm_bool labcomm_signature_dump(struct labcomm_signature_data *signature, * otherwise, when a type ref is encountered, f is called with the first * argument zero and the type ref as the second argument. */ -void map_signature( void(*f)(char, const struct labcomm_signature *, void *), +void map_signature( void(*f)(char, const struct labcomm2014_signature *, void *), void *context, - const struct labcomm_signature *signature, labcomm_bool flatten); + const struct labcomm2014_signature *signature, labcomm2014_bool flatten); #endif diff --git a/lib/c/2014/labcomm_encoder.c b/lib/c/2014/labcomm_encoder.c deleted file mode 100644 index 4b71ed0..0000000 --- a/lib/c/2014/labcomm_encoder.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - labcomm_encoder.c -- handling encoding of labcomm samples. - - Copyright 2006-2013 Anders Blomdell <anders.blomdell@control.lth.se> - - This file is part of LabComm. - - LabComm is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - LabComm is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ -#define CURRENT_VERSION "LabComm2014" - -#include <errno.h> -#include "labcomm.h" -#include "labcomm_private.h" -#include "labcomm_ioctl.h" -#include "labcomm_dynamic_buffer_writer.h" - -//define the following to disable encoding of typedefs -#undef LABCOMM_WITHOUT_TYPE_DEFS - -struct labcomm_encoder { - struct labcomm_writer *writer; - struct labcomm_error_handler *error; - struct labcomm_memory *memory; - struct labcomm_scheduler *scheduler; - LABCOMM_SIGNATURE_ARRAY_DEF(registered, int); - LABCOMM_SIGNATURE_ARRAY_DEF(sample_ref, int); - LABCOMM_SIGNATURE_ARRAY_DEF(typedefs, int); -}; - -static struct labcomm_encoder *internal_encoder_new( - struct labcomm_writer *writer, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler, - labcomm_bool outputVer) -{ - struct labcomm_encoder *result; - - result = labcomm_memory_alloc(memory, 0, sizeof(*result)); - if (result) { - int length; - - result->writer = writer; - result->writer->encoder = result; - result->writer->data = NULL; - result->writer->data_size = 0; - result->writer->count = 0; - result->writer->pos = 0; - result->writer->error = 0; - result->error = error; - result->memory = memory; - result->scheduler = scheduler; - LABCOMM_SIGNATURE_ARRAY_INIT(result->registered, int); - LABCOMM_SIGNATURE_ARRAY_INIT(result->sample_ref, int); - LABCOMM_SIGNATURE_ARRAY_INIT(result->typedefs, int); - labcomm_writer_alloc(result->writer, - result->writer->action_context); - if(outputVer) { - labcomm_writer_start(result->writer, - result->writer->action_context, - LABCOMM_VERSION, NULL, CURRENT_VERSION); - labcomm_write_packed32(result->writer, LABCOMM_VERSION); - length = labcomm_size_string(CURRENT_VERSION); - labcomm_write_packed32(result->writer, length); - labcomm_write_string(result->writer, CURRENT_VERSION); - labcomm_writer_end(result->writer, result->writer->action_context); - } - } - return result; -} - -struct labcomm_encoder *labcomm_encoder_new( - struct labcomm_writer *writer, - struct labcomm_error_handler *error, - struct labcomm_memory *memory, - struct labcomm_scheduler *scheduler) -{ - return internal_encoder_new(writer,error,memory,scheduler,TRUE); -} -void labcomm_encoder_free(struct labcomm_encoder* e) -{ - struct labcomm_memory *memory = e->memory; - - labcomm_writer_free(e->writer, e->writer->action_context); - LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, e->registered, int); - LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, e->sample_ref, int); - LABCOMM_SIGNATURE_ARRAY_FREE(e->memory, e->typedefs, int); - labcomm_memory_free(memory, 0, e); -} - -int labcomm_internal_encoder_register( - struct labcomm_encoder *e, - const struct labcomm_signature *signature, - labcomm_encoder_function encode) -{ - int result = -EINVAL; - int index, *done, err, i, length; - - index = labcomm_get_local_index(signature); - labcomm_scheduler_writer_lock(e->scheduler); - 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, - index, signature, NULL); - if (err == -EALREADY) { result = 0; goto out; } - if (err != 0) { result = err; goto out; } - labcomm_write_packed32(e->writer, LABCOMM_SAMPLE_DEF); - length = (labcomm_size_packed32(index) + - labcomm_size_string(signature->name) + - labcomm_size_packed32(signature->size) + - signature->size); - labcomm_write_packed32(e->writer, length); - labcomm_write_packed32(e->writer, index); - labcomm_write_string(e->writer, signature->name); - labcomm_write_packed32(e->writer, signature->size); - for (i = 0 ; i < signature->size ; i++) { - if (e->writer->pos >= e->writer->count) { - labcomm_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); - result = e->writer->error; -out: - labcomm_scheduler_writer_unlock(e->scheduler); - return result; -} - -int labcomm_internal_encode( - struct labcomm_encoder *e, - const struct labcomm_signature *signature, - labcomm_encoder_function encode, - void *value) -{ - int result, index, length; - - index = labcomm_get_local_index(signature); - length = (signature->encoded_size(value)); - labcomm_scheduler_writer_lock(e->scheduler); - if (! LABCOMM_SIGNATURE_ARRAY_GET(e->registered, int, index, 0)) { - result = -EINVAL; - goto no_end; - } - result = labcomm_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 = labcomm_write_packed32(e->writer, length); - if (result != 0) { goto out; } - result = encode(e->writer, value); -out: - labcomm_writer_end(e->writer, e->writer->action_context); -no_end: - labcomm_scheduler_writer_unlock(e->scheduler); - return result; -} - -int labcomm_encoder_sample_ref_register( - struct labcomm_encoder *e, - const struct labcomm_signature *signature) -{ - int result = -EINVAL; - int index, *done, err, i, length; - - index = labcomm_get_local_index(signature); - labcomm_scheduler_writer_lock(e->scheduler); - if (index <= 0) { goto out; } - - done = LABCOMM_SIGNATURE_ARRAY_REF(e->memory, e->sample_ref, int, index); - if (*done) { goto out; } - *done = 1; - err = labcomm_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, LABCOMM_SAMPLE_REF); - length = (labcomm_size_packed32(index) + - labcomm_size_string(signature->name) + - labcomm_size_packed32(signature->size) + - signature->size); - labcomm_write_packed32(e->writer, length); - labcomm_write_packed32(e->writer, index); - labcomm_write_string(e->writer, signature->name); - labcomm_write_packed32(e->writer, signature->size); - for (i = 0 ; i < signature->size ; i++) { - if (e->writer->pos >= e->writer->count) { - labcomm_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); - result = e->writer->error; -out: - labcomm_scheduler_writer_unlock(e->scheduler); - return result; -} - -int labcomm_encoder_ioctl(struct labcomm_encoder *encoder, - uint32_t action, - ...) -{ - int result; - va_list va; - - if (LABCOMM_IOC_SIG(action) != LABCOMM_IOC_NOSIG) { - result = -EINVAL; - goto out; - } - - va_start(va, action); - result = labcomm_writer_ioctl(encoder->writer, - encoder->writer->action_context, - 0, NULL, action, va); - va_end(va); - -out: - return result; -} - -int labcomm_internal_encoder_ioctl(struct labcomm_encoder *encoder, - const struct labcomm_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, - encoder->writer->action_context, - index, signature, action, va); - return result; -} - -int labcomm_internal_encoder_signature_to_index( - struct labcomm_encoder *e, const struct labcomm_signature *signature) -{ - /* writer_lock should be held at this point */ - int index = 0; - if (signature != NULL) { - index = labcomm_get_local_index(signature); - if (! LABCOMM_SIGNATURE_ARRAY_GET(e->sample_ref, int, index, 0)) { - index = 0; - } - } - return index; -} - - -/********************************************************** - * Start of code related to sending (hierarchical) - * typedefs. Define LABCOMM_WITHOUT_TYPEDEFS to disable - **********************************************************/ -#ifndef LABCOMM_WITHOUT_TYPE_DEFS - -static void write_sig_tree_byte(char b, const struct labcomm_signature *signature, - void *context) -{ - struct labcomm_encoder *e = context; - if(signature) { - labcomm_write_packed32(e->writer, labcomm_get_local_index(signature)); - }else { - if (e->writer->pos >= e->writer->count) { - labcomm_writer_flush(e->writer, e->writer->action_context); - } - e->writer->data[e->writer->pos] = b; - e->writer->pos++; - } -} - -static void do_write_signature(struct labcomm_encoder * e, - const struct labcomm_signature *signature, - unsigned char flatten) -{ - map_signature(write_sig_tree_byte, e, signature, flatten); -} - -static void sig_size(char b, const struct labcomm_signature *signature, - void *context) -{ - int *result = context; - int diff; - if(signature) { - int idx = labcomm_get_local_index(signature); - diff = labcomm_size_packed32(idx); - }else { - diff = 1; - } - (*result)+=diff; -} - -static int calc_sig_encoded_size(struct labcomm_encoder *e, - const struct labcomm_signature *sig) -{ - int result=0; - map_signature(sig_size, &result, sig, FALSE); - return result; -} - -static int internal_reg_type( - struct labcomm_encoder *e, - const struct labcomm_signature *signature, - labcomm_bool flatten) -{ - int result = -EINVAL; - int index, *done, err; - - index = labcomm_get_local_index(signature); - labcomm_scheduler_writer_lock(e->scheduler); - if (index <= 0) { goto out; } - done = LABCOMM_SIGNATURE_ARRAY_REF(e->memory, e->typedefs, int, index); - if (*done) { goto out; } - *done = 1; - err = labcomm_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; } - - int sig_size = calc_sig_encoded_size(e, signature); - int len = labcomm_size_packed32(index) + - labcomm_size_string(signature->name) + - labcomm_size_packed32(sig_size) + - sig_size; - - labcomm_write_packed32(e->writer, LABCOMM_TYPE_DEF); - labcomm_write_packed32(e->writer, len); - labcomm_write_packed32(e->writer, index); - labcomm_write_string(e->writer, signature->name); - labcomm_write_packed32(e->writer, sig_size); - do_write_signature(e, signature, FALSE); - - labcomm_writer_end(e->writer, e->writer->action_context); - result = e->writer->error; -out: - labcomm_scheduler_writer_unlock(e->scheduler); - return result; -} -#endif - -int labcomm_internal_encoder_type_register( - struct labcomm_encoder *e, - const struct labcomm_signature *signature) -{ -#ifndef LABCOMM_WITHOUT_TYPE_DEFS - return internal_reg_type(e, signature, FALSE); -#else - return 0; -#endif -} -int labcomm_internal_encoder_type_bind( - struct labcomm_encoder *e, - const struct labcomm_signature *signature, - char has_deps) -{ -#ifndef LABCOMM_WITHOUT_TYPE_DEFS - int result = -EINVAL; - int err; - int sindex = labcomm_get_local_index(signature); - int tindex = has_deps ? labcomm_get_local_type_index(signature) : LABCOMM_BIND_SELF; - labcomm_scheduler_writer_lock(e->scheduler); - if(sindex <= 0 || (has_deps && tindex <= 0)) {goto out;} - err = labcomm_writer_start(e->writer, e->writer->action_context, - LABCOMM_TYPE_BINDING, signature, NULL); - if (err == -EALREADY) { result = 0; goto out; } - if (err != 0) { result = err; goto out; } - int length = (labcomm_size_packed32(sindex) + - labcomm_size_packed32(tindex)); - labcomm_write_packed32(e->writer, LABCOMM_TYPE_BINDING); - labcomm_write_packed32(e->writer, length); - labcomm_write_packed32(e->writer, sindex); - labcomm_write_packed32(e->writer, tindex); - labcomm_writer_end(e->writer, e->writer->action_context); - result = e->writer->error; - -out: - labcomm_scheduler_writer_unlock(e->scheduler); - return result; -#else - return 0; -#endif -} diff --git a/lib/c/2014/labcomm_scheduler_private.h b/lib/c/2014/labcomm_scheduler_private.h deleted file mode 100644 index 46b108d..0000000 --- a/lib/c/2014/labcomm_scheduler_private.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - labcomm_scheduler.h -- labcomm task coordination, semi-private part - - Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> - - This file is part of LabComm. - - LabComm is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - LabComm is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __LABCOMM_SCHEDULER_PRIVATE_H__ -#define __LABCOMM_SCHEDULER_PRIVATE_H__ - -#ifdef LABCOMM_COMPAT - #include LABCOMM_COMPAT -#else - #include <unistd.h> -#endif - -#include "labcomm_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); - } *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, - uint32_t delay, - void (*deferred)(void *context), - void *context); - } *action; - void *context; -}; - -#endif diff --git a/lib/c/2014/test/test_labcomm.c b/lib/c/2014/test/test_labcomm.c index c852677..de36a7f 100644 --- a/lib/c/2014/test/test_labcomm.c +++ b/lib/c/2014/test/test_labcomm.c @@ -1,5 +1,5 @@ /* - test_labcomm.c -- Various labcomm tests + test_labcomm2014.c -- Various labcomm2014 tests Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -24,19 +24,19 @@ #include <string.h> #include <stdlib.h> #include <errno.h> -#include "labcomm_private.h" -#include "labcomm_default_error_handler.h" -#include "labcomm_default_memory.h" -#include "labcomm_default_scheduler.h" +#include "labcomm2014_private.h" +#include "labcomm2014_default_error_handler.h" +#include "labcomm2014_default_memory.h" +#include "labcomm2014_default_scheduler.h" #include "test/gen/test_sample.h" -static struct labcomm_writer writer; +static struct labcomm2014_writer writer; static struct expect { char *description; int result; - int (*trampoline)(struct labcomm_decoder *context); - struct labcomm_decoder *context; + int (*trampoline)(struct labcomm2014_decoder *context); + struct labcomm2014_decoder *context; } *expect; static void check_expect() @@ -70,8 +70,8 @@ static void check_expect() static unsigned char buffer[512]; -static int writer_alloc(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) +static int writer_alloc(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { w->data = buffer; w->data_size = sizeof(buffer); @@ -80,35 +80,35 @@ static int writer_alloc(struct labcomm_writer *w, return 0; } -static int writer_start(struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int index, const struct labcomm_signature *signature, +static int writer_start(struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int index, const struct labcomm2014_signature *signature, void *value) { return 0; } static int buf_writer_end( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { check_expect(); return 0; } -const struct labcomm_writer_action writer_action = { +const struct labcomm2014_writer_action writer_action = { .alloc = writer_alloc, .start = writer_start, .end = buf_writer_end, }; -static struct labcomm_writer_action_context writer_action_context = { +static struct labcomm2014_writer_action_context writer_action_context = { .next = NULL, .action = &writer_action, .context = NULL }; -static struct labcomm_writer writer = { +static struct labcomm2014_writer writer = { .action_context = &writer_action_context, .data = buffer, .data_size = sizeof(buffer), @@ -117,36 +117,36 @@ static struct labcomm_writer writer = { .error = 0, }; -static int reader_alloc(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +static int reader_alloc(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context) { r->data = buffer; r->data_size = sizeof(buffer); r->count = 0; - r->memory = labcomm_default_memory; + r->memory = labcomm2014_default_memory; return 0; } -static int reader_fill(struct labcomm_reader *r, - struct labcomm_reader_action_context *action_context) +static int reader_fill(struct labcomm2014_reader *r, + struct labcomm2014_reader_action_context *action_context) { r->error = -ENOMEM; return r->error; } -const struct labcomm_reader_action reader_action = { +const struct labcomm2014_reader_action reader_action = { .alloc = reader_alloc, .fill = reader_fill, }; -static struct labcomm_reader_action_context reader_action_context = { +static struct labcomm2014_reader_action_context reader_action_context = { .next = NULL, .action = &reader_action, .context = NULL }; -static struct labcomm_reader reader = { +static struct labcomm2014_reader reader = { .action_context = &reader_action_context, .data = buffer, .data_size = sizeof(buffer), @@ -174,14 +174,14 @@ void handle_test_var(test_sample_test_var *v, void *ctx) decoder_var.a[0] = v->a[0]; } -int test_decode_one(struct labcomm_decoder *decoder) +int test_decode_one(struct labcomm2014_decoder *decoder) { int result; for (reader.count = 0 ; reader.count < writer.pos ; reader.count++) { reader.error = 0; reader.pos = 0; - result = labcomm_decoder_decode_one(decoder); + result = labcomm2014_decoder_decode_one(decoder); if (result >= 0 ) { fprintf(stderr, "Got result from buffer with bogus length (%d, %d != %d)\n", @@ -192,7 +192,7 @@ int test_decode_one(struct labcomm_decoder *decoder) reader.error = 0; reader.pos = 0; reader.count = writer.pos; - result = labcomm_decoder_decode_one(decoder); + result = labcomm2014_decoder_decode_one(decoder); if (result < 0) { fprintf(stderr, "Got no result from buffer with correct length (%d)\n", result); @@ -201,8 +201,8 @@ int test_decode_one(struct labcomm_decoder *decoder) return result; } -static void test_encode_decode(struct labcomm_encoder *encoder, - struct labcomm_decoder *decoder, +static void test_encode_decode(struct labcomm2014_encoder *encoder, + struct labcomm2014_decoder *decoder, int expected, uint32_t n_0, uint32_t n_2) { int err; @@ -211,14 +211,14 @@ static void test_encode_decode(struct labcomm_encoder *encoder, encoder_var.n_0 = n_0; encoder_var.n_2 = n_2; encoder_var.a[0] = 314; - labcomm_encode_test_sample_test_var(encoder, &encoder_var); + labcomm2014_encode_test_sample_test_var(encoder, &encoder_var); err = test_decode_one(decoder); fprintf(stderr, "decode of sample %u * 2 * %u -> size=%d err=%d\n", n_0, n_2, writer.pos, err); - if (writer.pos != labcomm_sizeof_test_sample_test_var(&encoder_var)) { + if (writer.pos != labcomm2014_sizeof_test_sample_test_var(&encoder_var)) { fprintf(stderr, "Incorrect sizeof %u * 2 * %u (%d != %d)\n", n_0, n_2, - writer.pos, labcomm_sizeof_test_sample_test_var(&encoder_var)); + writer.pos, labcomm2014_sizeof_test_sample_test_var(&encoder_var)); exit(1); } if (writer.pos != expected) { @@ -232,22 +232,22 @@ static void test_encode_decode(struct labcomm_encoder *encoder, int main(void) { int i; - struct labcomm_decoder *decoder = labcomm_decoder_new( + struct labcomm2014_decoder *decoder = labcomm2014_decoder_new( &reader, - labcomm_default_error_handler, - labcomm_default_memory, - labcomm_default_scheduler); + labcomm2014_default_error_handler, + labcomm2014_default_memory, + labcomm2014_default_scheduler); struct expect expect_version[] = { { "Version", 1, test_decode_one, decoder }, { 0, 0, 0 } }; expect = expect_version; - struct labcomm_encoder *encoder = labcomm_encoder_new( + struct labcomm2014_encoder *encoder = labcomm2014_encoder_new( &writer, - labcomm_default_error_handler, - labcomm_default_memory, - labcomm_default_scheduler); - labcomm_decoder_register_test_sample_test_var(decoder, + labcomm2014_default_error_handler, + labcomm2014_default_memory, + labcomm2014_default_scheduler); + labcomm2014_decoder_register_test_sample_test_var(decoder, handle_test_var, NULL); struct expect expect_registration[] = { @@ -259,7 +259,7 @@ int main(void) { 0, 0, 0 } }; expect = expect_registration; - labcomm_encoder_register_test_sample_test_var(encoder); + labcomm2014_encoder_register_test_sample_test_var(encoder); test_encode_decode(encoder, decoder, 12, 1, 1); if (decoder_var.a[0] != encoder_var.a[0]) { fprintf(stderr, "Failed to decode correct value %d != %d\n", diff --git a/lib/c/2014/test/test_labcomm_basic_type_encoding.c b/lib/c/2014/test/test_labcomm_basic_type_encoding.c index b964c98..29079df 100644 --- a/lib/c/2014/test/test_labcomm_basic_type_encoding.c +++ b/lib/c/2014/test/test_labcomm_basic_type_encoding.c @@ -1,5 +1,5 @@ /* - test_labcomm_basic_type_encoding.c -- LabComm tests of basic encoding + test_labcomm2014_basic_type_encoding.c -- LabComm tests of basic encoding Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -23,13 +23,13 @@ #include <inttypes.h> #include <string.h> #include <stdlib.h> -#include "labcomm_private.h" +#include "labcomm2014_private.h" static int line; static unsigned char buffer[128]; -static struct labcomm_writer writer = { +static struct labcomm2014_writer writer = { .action_context = NULL, .data = buffer, .data_size = sizeof(buffer), @@ -38,7 +38,7 @@ static struct labcomm_writer writer = { .error = 0, }; -static struct labcomm_reader reader = { +static struct labcomm2014_reader reader = { .action_context = NULL, .data = buffer, .data_size = sizeof(buffer), @@ -53,11 +53,11 @@ typedef uint32_t packed32; type decoded; \ line = __LINE__; \ writer.pos = 0; \ - labcomm_write_##ltype(&writer, value); \ + labcomm2014_write_##ltype(&writer, value); \ writer_assert(#ltype, expect_count, (uint8_t*)expect_bytes); \ reader.count = writer.pos; \ reader.pos = 0; \ - decoded = labcomm_read_##ltype(&reader); \ + decoded = labcomm2014_read_##ltype(&reader); \ if (decoded != value) { \ fprintf(stderr, "Decode error" format " != " format " @%s:%d \n", \ value, decoded, __FILE__, __LINE__); \ diff --git a/lib/c/2014/test/test_labcomm_copy.c b/lib/c/2014/test/test_labcomm_copy.c index 9261e66..d26ef96 100644 --- a/lib/c/2014/test/test_labcomm_copy.c +++ b/lib/c/2014/test/test_labcomm_copy.c @@ -7,13 +7,13 @@ #include <assert.h> #include <err.h> -#include "labcomm.h" -#include "labcomm_private.h" -#include "labcomm_default_error_handler.h" -#include "labcomm_default_memory.h" -#include "labcomm_default_scheduler.h" -#include "labcomm_fd_writer.h" -#include "labcomm_fd_reader.h" +#include "labcomm2014.h" +#include "labcomm2014_private.h" +#include "labcomm2014_default_error_handler.h" +#include "labcomm2014_default_memory.h" +#include "labcomm2014_default_scheduler.h" +#include "labcomm2014_fd_writer.h" +#include "labcomm2014_fd_reader.h" #include "test/gen/generated_encoding.h" #include "test/gen/test_sample.h" #include "test/gen/more_types.h" @@ -22,58 +22,58 @@ static void handle_s1(generated_encoding_S1 *v, void *context) { - labcomm_copy_generated_encoding_S1(labcomm_default_memory, context, v); + labcomm2014_copy_generated_encoding_S1(labcomm2014_default_memory, context, v); } static void handle_b(generated_encoding_B *v, void *context) { - labcomm_copy_generated_encoding_B(labcomm_default_memory, context, v); + labcomm2014_copy_generated_encoding_B(labcomm2014_default_memory, context, v); } static void handle_i(generated_encoding_I *v, void *context) { - labcomm_copy_generated_encoding_I(labcomm_default_memory, context, v); + labcomm2014_copy_generated_encoding_I(labcomm2014_default_memory, context, v); } static void handle_p(generated_encoding_P *v, void *context) { - labcomm_copy_generated_encoding_P(labcomm_default_memory, context, v); + labcomm2014_copy_generated_encoding_P(labcomm2014_default_memory, context, v); } static void handle_r(generated_encoding_R *v, void *context) { - labcomm_copy_generated_encoding_R(labcomm_default_memory, context, v); + labcomm2014_copy_generated_encoding_R(labcomm2014_default_memory, context, v); } static void handle_test_var(test_sample_test_var *v, void *context) { - labcomm_copy_test_sample_test_var(labcomm_default_memory, context, v); + labcomm2014_copy_test_sample_test_var(labcomm2014_default_memory, context, v); } static void handle_a(more_types_A *v, void *context) { - labcomm_copy_more_types_A(labcomm_default_memory, context, v); + labcomm2014_copy_more_types_A(labcomm2014_default_memory, context, v); } static void handle_s(more_types_S *v, void *context) { - labcomm_copy_more_types_S(labcomm_default_memory, context, v); + labcomm2014_copy_more_types_S(labcomm2014_default_memory, context, v); } static void handle_ns(more_types_NS *v, void *context) { - labcomm_copy_more_types_NS(labcomm_default_memory, context, v); + labcomm2014_copy_more_types_NS(labcomm2014_default_memory, context, v); } static void handle_as(more_types_AS *v, void *context) { - labcomm_copy_more_types_AS(labcomm_default_memory, context, v); + labcomm2014_copy_more_types_AS(labcomm2014_default_memory, context, v); } int main(int argc, char **argv) { - struct labcomm_encoder *encoder; - struct labcomm_decoder *decoder; + struct labcomm2014_encoder *encoder; + struct labcomm2014_decoder *decoder; int fd; generated_encoding_S1 s1; generated_encoding_S1 cache_s1; @@ -100,35 +100,35 @@ int main(int argc, char **argv) if (fd == -1) err(1, "open()"); encoder = - labcomm_encoder_new(labcomm_fd_writer_new(labcomm_default_memory, fd, 0), - labcomm_default_error_handler, - labcomm_default_memory, - labcomm_default_scheduler); + labcomm2014_encoder_new(labcomm2014_fd_writer_new(labcomm2014_default_memory, fd, 0), + labcomm2014_default_error_handler, + labcomm2014_default_memory, + labcomm2014_default_scheduler); - labcomm_encoder_register_generated_encoding_S1(encoder); + labcomm2014_encoder_register_generated_encoding_S1(encoder); s1.i = 1; - labcomm_encode_generated_encoding_S1(encoder, &s1); + labcomm2014_encode_generated_encoding_S1(encoder, &s1); - labcomm_encoder_register_generated_encoding_B(encoder); + labcomm2014_encoder_register_generated_encoding_B(encoder); b = 2; - labcomm_encode_generated_encoding_B(encoder, &b); + labcomm2014_encode_generated_encoding_B(encoder, &b); - labcomm_encoder_register_generated_encoding_I(encoder); + labcomm2014_encoder_register_generated_encoding_I(encoder); I.n_0 = 3; I.a = calloc(I.n_0, sizeof(I.a[0])); I.a[0] = 4; I.a[1] = 5; I.a[2] = 6; - labcomm_encode_generated_encoding_I(encoder, &I); + labcomm2014_encode_generated_encoding_I(encoder, &I); - labcomm_encoder_register_generated_encoding_P(encoder); + labcomm2014_encoder_register_generated_encoding_P(encoder); p.n_0 = 7; p.a = calloc(p.n_0, sizeof(p.a[0])); for (int i = 0; i < p.n_0; i++) p.a[i].i = 8 + i; - labcomm_encode_generated_encoding_P(encoder, &p); + labcomm2014_encode_generated_encoding_P(encoder, &p); - labcomm_encoder_register_test_sample_test_var(encoder); + labcomm2014_encoder_register_test_sample_test_var(encoder); test_var.n_0 = 2; test_var.n_2 = 7; test_var.a = calloc(test_var.n_0 * 2 * test_var.n_2, sizeof(*test_var.a)); @@ -137,67 +137,67 @@ int main(int argc, char **argv) for (int k = 0; k < test_var.n_2; k++) { test_var.a[(((i) * 2 + j) * test_var.n_2) + k] = 100 * i + 10 * j + k; } - labcomm_encode_test_sample_test_var(encoder, &test_var); + labcomm2014_encode_test_sample_test_var(encoder, &test_var); - labcomm_encoder_register_more_types_A(encoder); + labcomm2014_encoder_register_more_types_A(encoder); for (int i = 0; i < sizeof(a.a) / sizeof(a.a[0]); i++) a.a[i] = i; - labcomm_encode_more_types_A(encoder, &a); + labcomm2014_encode_more_types_A(encoder, &a); - labcomm_encoder_register_more_types_S(encoder); + labcomm2014_encoder_register_more_types_S(encoder); s = "this is a string"; - labcomm_encode_more_types_S(encoder, &s); + labcomm2014_encode_more_types_S(encoder, &s); - labcomm_encoder_register_more_types_NS(encoder); + labcomm2014_encoder_register_more_types_NS(encoder); ns.s1 = "this is a string"; ns.s2 = "this is a another string"; - labcomm_encode_more_types_NS(encoder, &ns); + labcomm2014_encode_more_types_NS(encoder, &ns); - labcomm_encoder_register_more_types_AS(encoder); + labcomm2014_encoder_register_more_types_AS(encoder); as.n_0 = 3; as.a = calloc(as.n_0, sizeof(as.a[0])); as.a[0] = "string 0"; as.a[1] = "string 1"; as.a[2] = "string 2"; - labcomm_encode_more_types_AS(encoder, &as); - - labcomm_encoder_register_generated_encoding_R(encoder); - labcomm_encoder_sample_ref_register(encoder, labcomm_signature_generated_encoding_V); - labcomm_encoder_sample_ref_register(encoder, - labcomm_signature_generated_encoding_UnusedD); - labcomm_encoder_sample_ref_register(encoder, labcomm_signature_generated_encoding_R); - r.a[0] = labcomm_signature_generated_encoding_V; - r.a[1] = labcomm_signature_generated_encoding_UnusedE; - r.a[2] = labcomm_signature_generated_encoding_UnusedD; - r.a[3] = labcomm_signature_generated_encoding_R; - labcomm_encode_generated_encoding_R(encoder, &r); - - labcomm_encoder_free(encoder); + labcomm2014_encode_more_types_AS(encoder, &as); + + labcomm2014_encoder_register_generated_encoding_R(encoder); + labcomm2014_encoder_sample_ref_register(encoder, labcomm2014_signature_generated_encoding_V); + labcomm2014_encoder_sample_ref_register(encoder, + labcomm2014_signature_generated_encoding_UnusedD); + labcomm2014_encoder_sample_ref_register(encoder, labcomm2014_signature_generated_encoding_R); + r.a[0] = labcomm2014_signature_generated_encoding_V; + r.a[1] = labcomm2014_signature_generated_encoding_UnusedE; + r.a[2] = labcomm2014_signature_generated_encoding_UnusedD; + r.a[3] = labcomm2014_signature_generated_encoding_R; + labcomm2014_encode_generated_encoding_R(encoder, &r); + + labcomm2014_encoder_free(encoder); encoder = NULL; lseek(fd, 0, SEEK_SET); decoder = - labcomm_decoder_new(labcomm_fd_reader_new(labcomm_default_memory, fd, 0), - labcomm_default_error_handler, - labcomm_default_memory, - labcomm_default_scheduler); - - labcomm_decoder_register_generated_encoding_S1(decoder, handle_s1, &cache_s1); - labcomm_decoder_register_generated_encoding_B(decoder, handle_b, &cache_b); - labcomm_decoder_register_generated_encoding_I(decoder, handle_i, &cache_I); - labcomm_decoder_register_generated_encoding_P(decoder, handle_p, &cache_p); - labcomm_decoder_register_test_sample_test_var(decoder, handle_test_var, + labcomm2014_decoder_new(labcomm2014_fd_reader_new(labcomm2014_default_memory, fd, 0), + labcomm2014_default_error_handler, + labcomm2014_default_memory, + labcomm2014_default_scheduler); + + labcomm2014_decoder_register_generated_encoding_S1(decoder, handle_s1, &cache_s1); + labcomm2014_decoder_register_generated_encoding_B(decoder, handle_b, &cache_b); + labcomm2014_decoder_register_generated_encoding_I(decoder, handle_i, &cache_I); + labcomm2014_decoder_register_generated_encoding_P(decoder, handle_p, &cache_p); + labcomm2014_decoder_register_test_sample_test_var(decoder, handle_test_var, &cache_test_var); - labcomm_decoder_register_more_types_A(decoder, handle_a, &cache_a); - labcomm_decoder_register_more_types_S(decoder, handle_s, &cache_s); - labcomm_decoder_register_more_types_NS(decoder, handle_ns, &cache_ns); - labcomm_decoder_register_more_types_AS(decoder, handle_as, &cache_as); - labcomm_decoder_register_generated_encoding_R(decoder, handle_r, &cache_r); - labcomm_decoder_sample_ref_register(decoder, labcomm_signature_generated_encoding_V); - labcomm_decoder_sample_ref_register(decoder, - labcomm_signature_generated_encoding_UnusedE); - labcomm_decoder_sample_ref_register(decoder, labcomm_signature_generated_encoding_R); - - while (labcomm_decoder_decode_one(decoder) > 0) ; + labcomm2014_decoder_register_more_types_A(decoder, handle_a, &cache_a); + labcomm2014_decoder_register_more_types_S(decoder, handle_s, &cache_s); + labcomm2014_decoder_register_more_types_NS(decoder, handle_ns, &cache_ns); + labcomm2014_decoder_register_more_types_AS(decoder, handle_as, &cache_as); + labcomm2014_decoder_register_generated_encoding_R(decoder, handle_r, &cache_r); + labcomm2014_decoder_sample_ref_register(decoder, labcomm2014_signature_generated_encoding_V); + labcomm2014_decoder_sample_ref_register(decoder, + labcomm2014_signature_generated_encoding_UnusedE); + labcomm2014_decoder_sample_ref_register(decoder, labcomm2014_signature_generated_encoding_R); + + while (labcomm2014_decoder_decode_one(decoder) > 0) ; printf("cache_s1.i = %d, s1.i = %d\n", cache_s1.i, s1.i); assert(cache_s1.i == s1.i); @@ -258,26 +258,26 @@ int main(int argc, char **argv) assert(cache_r.a[3] == r.a[3]); puts("R copied ok"); - labcomm_decoder_free(decoder); + labcomm2014_decoder_free(decoder); close(fd); unlink(DATA_FILE); - labcomm_copy_free_generated_encoding_S1(labcomm_default_memory, &cache_s1); + labcomm2014_copy_free_generated_encoding_S1(labcomm2014_default_memory, &cache_s1); puts("S1 deallocated ok"); - labcomm_copy_free_generated_encoding_B(labcomm_default_memory, &cache_b); + labcomm2014_copy_free_generated_encoding_B(labcomm2014_default_memory, &cache_b); puts("B deallocated ok"); - labcomm_copy_free_generated_encoding_I(labcomm_default_memory, &cache_I); + labcomm2014_copy_free_generated_encoding_I(labcomm2014_default_memory, &cache_I); puts("I deallocated ok"); - labcomm_copy_free_generated_encoding_P(labcomm_default_memory, &cache_p); + labcomm2014_copy_free_generated_encoding_P(labcomm2014_default_memory, &cache_p); puts("P deallocated ok"); - labcomm_copy_free_test_sample_test_var(labcomm_default_memory, &cache_test_var); + labcomm2014_copy_free_test_sample_test_var(labcomm2014_default_memory, &cache_test_var); puts("test_var deallocated ok"); - labcomm_copy_free_more_types_A(labcomm_default_memory, &cache_a); + labcomm2014_copy_free_more_types_A(labcomm2014_default_memory, &cache_a); puts("A deallocated ok"); - labcomm_copy_free_more_types_S(labcomm_default_memory, &cache_s); + labcomm2014_copy_free_more_types_S(labcomm2014_default_memory, &cache_s); puts("S deallocated ok"); - labcomm_copy_free_more_types_NS(labcomm_default_memory, &cache_ns); + labcomm2014_copy_free_more_types_NS(labcomm2014_default_memory, &cache_ns); puts("NS deallocated ok"); - labcomm_copy_free_more_types_AS(labcomm_default_memory, &cache_as); + labcomm2014_copy_free_more_types_AS(labcomm2014_default_memory, &cache_as); puts("AS deallocated ok"); } diff --git a/lib/c/2014/test/test_labcomm_generated_encoding.c b/lib/c/2014/test/test_labcomm_generated_encoding.c index 11f9d7c..f728ac0 100644 --- a/lib/c/2014/test/test_labcomm_generated_encoding.c +++ b/lib/c/2014/test/test_labcomm_generated_encoding.c @@ -1,5 +1,5 @@ /* - test_labcomm_generated_encoding.c -- LabComm tests of generated encoding + test_labcomm2014_generated_encoding.c -- LabComm tests of generated encoding Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -23,19 +23,19 @@ #include <stdlib.h> #include <string.h> #include <errno.h> -#include "labcomm_private.h" -#include "labcomm_default_error_handler.h" -#include "labcomm_default_memory.h" -#include "labcomm_pthread_scheduler.h" +#include "labcomm2014_private.h" +#include "labcomm2014_default_error_handler.h" +#include "labcomm2014_default_memory.h" +#include "labcomm2014_pthread_scheduler.h" #include "test/gen/generated_encoding.h" #define IOCTL_WRITER_ASSERT_BYTES 4096 #define IOCTL_WRITER_RESET 4097 #define EXPECT(...) \ - { \ + { \ int expected[] = __VA_ARGS__; \ - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_ASSERT_BYTES, \ + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_ASSERT_BYTES, \ __LINE__, \ sizeof(expected)/sizeof(expected[0]), \ expected); \ @@ -45,12 +45,12 @@ #define IS_VARIABLE(i) (i < 0) static unsigned char buffer[128]; -struct labcomm_writer *writer; +struct labcomm2014_writer *writer; static int seen_variable[1024]; static int buf_writer_alloc( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { writer = w; /* Hack */ w->data_size = sizeof(buffer); @@ -62,32 +62,32 @@ static int buf_writer_alloc( } static int buf_writer_free( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { return 0; } static int buf_writer_start( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, int index, - const struct labcomm_signature *signature, + const struct labcomm2014_signature *signature, void *value) { return 0; } static int buf_writer_end( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { return 0; } static int buf_writer_flush( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context) + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context) { fprintf(stderr, "Should not come here %s:%d\n", __FILE__, __LINE__); exit(1); @@ -96,9 +96,9 @@ static int buf_writer_flush( } static int buf_writer_ioctl( - struct labcomm_writer *w, - struct labcomm_writer_action_context *action_context, - int signature_index, const struct labcomm_signature *signature, + struct labcomm2014_writer *w, + struct labcomm2014_writer_action_context *action_context, + int signature_index, const struct labcomm2014_signature *signature, uint32_t action, va_list arg) { int result = -ENOTSUP; @@ -157,7 +157,7 @@ static int buf_writer_ioctl( return result; } -const struct labcomm_writer_action writer_action = { +const struct labcomm2014_writer_action writer_action = { .alloc = buf_writer_alloc, .free = buf_writer_free, .start = buf_writer_start, @@ -166,12 +166,12 @@ const struct labcomm_writer_action writer_action = { .ioctl = buf_writer_ioctl }; -static struct labcomm_writer_action_context action_context = { +static struct labcomm2014_writer_action_context action_context = { .next = NULL, .action = &writer_action, .context = NULL }; -static struct labcomm_writer buffer_writer = { +static struct labcomm2014_writer buffer_writer = { .action_context = &action_context, .data = buffer, .data_size = sizeof(buffer), @@ -180,7 +180,7 @@ static struct labcomm_writer buffer_writer = { .error = 0, }; -void dump_encoder(struct labcomm_encoder *encoder) +void dump_encoder(struct labcomm2014_encoder *encoder) { int i; @@ -194,83 +194,83 @@ int main(void) { generated_encoding_B B = 1; generated_encoding_R R; - struct labcomm_encoder *encoder; + struct labcomm2014_encoder *encoder; int i; for (i = 0 ; i < sizeof(seen_variable)/sizeof(seen_variable[0]) ; i++) { seen_variable[i] = -1; } - encoder = labcomm_encoder_new( + encoder = labcomm2014_encoder_new( &buffer_writer, - labcomm_default_error_handler, - labcomm_default_memory, - labcomm_pthread_scheduler_new(labcomm_default_memory)); + labcomm2014_default_error_handler, + labcomm2014_default_memory, + labcomm2014_pthread_scheduler_new(labcomm2014_default_memory)); EXPECT({ 0x01, 0x0c, 0x0b, 'L', 'a', 'b', 'C', 'o', 'm', 'm', '2','0', '1', '4' }); - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); /* Register twice to make sure that only one registration gets encoded */ - labcomm_encoder_register_generated_encoding_V(encoder); - labcomm_encoder_register_generated_encoding_V(encoder); + labcomm2014_encoder_register_generated_encoding_V(encoder); + labcomm2014_encoder_register_generated_encoding_V(encoder); EXPECT({ 0x02, 0x06, VARIABLE(0), 0x01, 'V', 0x02, 0x11, 0x00, 0x04, 0x08, VARIABLE(1), 0x03, 'v', '_', 't', 0x02, 0x11, 0x00, 0x04, 0x05, VARIABLE(2), 0x01, 'V', 0x01, VARIABLE(1), 0x05, 0x02, VARIABLE(0), VARIABLE(2) }); - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); /* Register twice to make sure that only one registration gets encoded */ - labcomm_encoder_register_generated_encoding_B(encoder); - labcomm_encoder_register_generated_encoding_B(encoder); + labcomm2014_encoder_register_generated_encoding_B(encoder); + labcomm2014_encoder_register_generated_encoding_B(encoder); EXPECT({ 0x02, 0x05, VARIABLE(3), 0x01, 'B', 0x01, 0x21, 0x05, 0x02, VARIABLE(3), LABCOMM_BIND_SELF }); - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); /* Register twice to make sure that only one registration gets encoded */ - labcomm_encoder_register_generated_encoding_R(encoder); - labcomm_encoder_register_generated_encoding_R(encoder); + labcomm2014_encoder_register_generated_encoding_R(encoder); + labcomm2014_encoder_register_generated_encoding_R(encoder); EXPECT({ 0x02, 0x08, VARIABLE(4), 0x01, 'R', 0x04, 0x10, 0x01, 0x04, 0x28, 0x05, 0x02, VARIABLE(4), LABCOMM_BIND_SELF }); - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); /* Register twice to make sure that only one registration gets encoded */ - labcomm_encoder_sample_ref_register(encoder, - labcomm_signature_generated_encoding_V); - labcomm_encoder_sample_ref_register(encoder, - labcomm_signature_generated_encoding_V); + labcomm2014_encoder_sample_ref_register(encoder, + labcomm2014_signature_generated_encoding_V); + labcomm2014_encoder_sample_ref_register(encoder, + labcomm2014_signature_generated_encoding_V); EXPECT({0x03, 0x06, VARIABLE(5), 0x01, 'V', 0x02, 0x11, 0x00}); - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); /* Register twice to make sure that only one registration gets encoded */ - labcomm_encoder_sample_ref_register(encoder, - labcomm_signature_generated_encoding_B); - labcomm_encoder_sample_ref_register(encoder, - labcomm_signature_generated_encoding_B); + labcomm2014_encoder_sample_ref_register(encoder, + labcomm2014_signature_generated_encoding_B); + labcomm2014_encoder_sample_ref_register(encoder, + labcomm2014_signature_generated_encoding_B); EXPECT({0x03, 0x05, VARIABLE(6), 0x01, 'B', 0x01, 0x21}); - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); /* Register twice to make sure that only one registration gets encoded */ - labcomm_encoder_sample_ref_register(encoder, - labcomm_signature_generated_encoding_R); - labcomm_encoder_sample_ref_register(encoder, - labcomm_signature_generated_encoding_R); + labcomm2014_encoder_sample_ref_register(encoder, + labcomm2014_signature_generated_encoding_R); + labcomm2014_encoder_sample_ref_register(encoder, + labcomm2014_signature_generated_encoding_R); EXPECT({0x03, 0x08, VARIABLE(7), 0x01, 'R', 0x04, 0x10, 0x01, 0x04, 0x28}); - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); - // was: labcomm_encode_generated_encoding_V(encoder, &V); - labcomm_encode_generated_encoding_V(encoder); + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); + // was: labcomm2014_encode_generated_encoding_V(encoder, &V); + labcomm2014_encode_generated_encoding_V(encoder); EXPECT({VARIABLE(10), 0x00 }); - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); - labcomm_encode_generated_encoding_B(encoder, &B); + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); + labcomm2014_encode_generated_encoding_B(encoder, &B); EXPECT({VARIABLE(20), 0x01, 1}); - labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET); - R.a[0] = labcomm_signature_generated_encoding_V; - R.a[1] = labcomm_signature_generated_encoding_B; - R.a[2] = labcomm_signature_generated_encoding_UnusedE; - R.a[3] = labcomm_signature_generated_encoding_R; - labcomm_encode_generated_encoding_R(encoder, &R); + labcomm2014_encoder_ioctl(encoder, IOCTL_WRITER_RESET); + R.a[0] = labcomm2014_signature_generated_encoding_V; + R.a[1] = labcomm2014_signature_generated_encoding_B; + R.a[2] = labcomm2014_signature_generated_encoding_UnusedE; + R.a[3] = labcomm2014_signature_generated_encoding_R; + labcomm2014_encode_generated_encoding_R(encoder, &R); EXPECT({VARIABLE(4), 0x10, 0x00, 0x00, 0x00, VARIABLE(5), 0x00, 0x00, 0x00, VARIABLE(6), 0x00, 0x00, 0x00, 0x00, diff --git a/lib/c/2014/test/test_labcomm_pthread_scheduler.c b/lib/c/2014/test/test_labcomm_pthread_scheduler.c index 718293d..aa7c5f0 100644 --- a/lib/c/2014/test/test_labcomm_pthread_scheduler.c +++ b/lib/c/2014/test/test_labcomm_pthread_scheduler.c @@ -1,5 +1,5 @@ /* - test_labcomm_pthread_scheduler.c -- test labcomm pthread based task + test_labcomm2014_pthread_scheduler.c -- test labcomm2014 pthread based task coordination Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se> @@ -22,13 +22,13 @@ #include <stdio.h> #include <stdlib.h> -#include "labcomm_default_memory.h" -#include "labcomm_scheduler.h" -#include "labcomm_pthread_scheduler.h" +#include "labcomm2014_default_memory.h" +#include "labcomm2014_scheduler.h" +#include "labcomm2014_pthread_scheduler.h" #define TICK 100000 struct func_arg { - struct labcomm_scheduler *scheduler; + struct labcomm2014_scheduler *scheduler; int i; }; @@ -38,11 +38,11 @@ static void func(void *arg) printf("%p %d\n", arg, func_arg->i); if (func_arg->i == 999) { - labcomm_scheduler_wakeup(func_arg->scheduler); + labcomm2014_scheduler_wakeup(func_arg->scheduler); } } -void enqueue(struct labcomm_scheduler *scheduler, +void enqueue(struct labcomm2014_scheduler *scheduler, int first, int last) { int i; @@ -52,16 +52,16 @@ void enqueue(struct labcomm_scheduler *scheduler, tmp->scheduler = scheduler; tmp->i = i; - labcomm_scheduler_enqueue(scheduler, i*TICK, func, tmp); + labcomm2014_scheduler_enqueue(scheduler, i*TICK, func, tmp); } } int main(int argc, char *argv[]) { - struct labcomm_scheduler *scheduler; - struct labcomm_time *time; + struct labcomm2014_scheduler *scheduler; + struct labcomm2014_time *time; - scheduler = labcomm_pthread_scheduler_new(labcomm_default_memory); + scheduler = labcomm2014_pthread_scheduler_new(labcomm2014_default_memory); enqueue(scheduler, 0, 5); enqueue(scheduler, 0, 1); enqueue(scheduler, 1, 3); @@ -71,12 +71,12 @@ int main(int argc, char *argv[]) tmp->scheduler = scheduler; tmp->i = 999; - labcomm_scheduler_enqueue(scheduler, 6*TICK, func, tmp); + labcomm2014_scheduler_enqueue(scheduler, 6*TICK, func, tmp); } - time = labcomm_scheduler_now(scheduler); - labcomm_time_add_usec(time, 12*TICK); - labcomm_scheduler_sleep(scheduler, NULL); - labcomm_scheduler_sleep(scheduler, time); + time = labcomm2014_scheduler_now(scheduler); + labcomm2014_time_add_usec(time, 12*TICK); + labcomm2014_scheduler_sleep(scheduler, NULL); + labcomm2014_scheduler_sleep(scheduler, time); return 0; } diff --git a/lib/c/2014/test/test_signature_numbers.c b/lib/c/2014/test/test_signature_numbers.c index 675088a..c540f81 100644 --- a/lib/c/2014/test/test_signature_numbers.c +++ b/lib/c/2014/test/test_signature_numbers.c @@ -1,14 +1,14 @@ #include <stdlib.h> #include <stdio.h> -#include "labcomm_private.h" +#include "labcomm2014_private.h" #include "test/gen/another_encoding.h" #include "test/gen/generated_encoding.h" static void info(char *name, char *full_name, - const struct labcomm_signature *signature) { + const struct labcomm2014_signature *signature) { printf("%s %s %p -> %d\n", name, full_name, signature, - labcomm_get_local_index(signature)); - if (labcomm_get_local_index(signature) < 0x40) { + labcomm2014_get_local_index(signature)); + if (labcomm2014_get_local_index(signature) < 0x40) { exit(1); } }; @@ -16,7 +16,7 @@ static void info(char *name, char *full_name, int main(int argc, char *argv[]) { #define FUNC(name, full_name) \ - info( #name, #full_name, labcomm_signature_##full_name) + info( #name, #full_name, labcomm2014_signature_##full_name) LABCOMM_FORALL_SAMPLES_generated_encoding(FUNC, ;); LABCOMM_FORALL_SAMPLES_another_encoding(FUNC, ;); diff --git a/lib/c/version_compare.py b/lib/c/version_compare.py index 47d016b..ad2c1b1 100755 --- a/lib/c/version_compare.py +++ b/lib/c/version_compare.py @@ -9,7 +9,9 @@ class File: def __init__(self, path, match, replacement): def replace(s): - return re.sub('[ \t]+', ' ', s).replace(match, replacement).strip() + r = re.sub('[ \t]+', ' ', s).replace(match, replacement) + r = r.strip() + '\n' + return r self.name = path.replace(match, replacement) self.path = path with open(path) as f: @@ -50,7 +52,7 @@ if __name__ == '__main__': else: equal = True for l in difflib.unified_diff(a.lines, b.lines, a.path, b.path): - print l + print l, equal = False if equal: print "Identical", a.path, b.path diff --git a/test/relay_gen_c.py b/test/relay_gen_c.py index dd3f894..4d05064 100755 --- a/test/relay_gen_c.py +++ b/test/relay_gen_c.py @@ -27,32 +27,26 @@ if __name__ == '__main__': |#include <sys/types.h> |#include <sys/stat.h> |#include <fcntl.h> - |#include <labcomm.h> - |#include <labcomm_default_error_handler.h> - |#include <labcomm_default_memory.h> - |#include <labcomm_default_scheduler.h> - |#include <labcomm_fd_reader.h> - |#include <labcomm_fd_writer.h> + |#include <labcomm2014.h> + |#include <labcomm2014_default_error_handler.h> + |#include <labcomm2014_default_memory.h> + |#include <labcomm2014_default_scheduler.h> + |#include <labcomm2014_fd_reader.h> + |#include <labcomm2014_fd_writer.h> |#include "c_code.h" """)) for func,arg,stype in sample: result.extend(split_match('^[^|]*\|(.*)$', """ |void handle_%(func)s(%(arg)s *v, void *context) |{ - | struct labcomm_encoder *e = context; - | labcomm_encode_%(func)s(e%(valargstr)s); + | struct labcomm2014_encoder *e = context; + | labcomm2014_encode_%(func)s(e%(valargstr)s); |}""" % { 'func': func, 'arg': arg, 'valargstr': '' if stype == "void" else', v' })) -# result.extend(split_match('^[^|]*\|(.*)$', """ -# |void handle_%(func)s(%(arg)s *v, void *context) -# |{ -# | struct labcomm_encoder *e = context; -# | labcomm_encode_%(func)s(e, v); -# |}""" % { 'func': func, 'arg': arg })) pass result.extend(split_match('^[^|]*\|(.*)$', """ |int main(int argc, char *argv[]) { - | struct labcomm_encoder *e; - | struct labcomm_decoder *d; + | struct labcomm2014_encoder *e; + | struct labcomm2014_decoder *d; | int in, out; | | if (argc < 3) { return 1; } @@ -60,26 +54,26 @@ if __name__ == '__main__': | if (in < 0) { return 1; } | out = open(argv[2], O_WRONLY); | if (out < 0) { return 1; } - | e = labcomm_encoder_new(labcomm_fd_writer_new( - | labcomm_default_memory, out, 1), - | labcomm_default_error_handler, - | labcomm_default_memory, - | labcomm_default_scheduler); - | d = labcomm_decoder_new(labcomm_fd_reader_new( - | labcomm_default_memory, in, 1), - | labcomm_default_error_handler, - | labcomm_default_memory, - | labcomm_default_scheduler); + | e = labcomm2014_encoder_new(labcomm2014_fd_writer_new( + | labcomm2014_default_memory, out, 1), + | labcomm2014_default_error_handler, + | labcomm2014_default_memory, + | labcomm2014_default_scheduler); + | d = labcomm2014_decoder_new(labcomm2014_fd_reader_new( + | labcomm2014_default_memory, in, 1), + | labcomm2014_default_error_handler, + | labcomm2014_default_memory, + | labcomm2014_default_scheduler); """)) for func,arg,stype in sample: result.extend(split_match('^[^|]*\|(.*)$', """ - | labcomm_encoder_register_%(func)s(e); - | labcomm_encoder_sample_ref_register(e, labcomm_signature_%(func)s); - | labcomm_decoder_register_%(func)s(d, handle_%(func)s, e); - | labcomm_decoder_sample_ref_register(d, labcomm_signature_%(func)s); + | labcomm2014_encoder_register_%(func)s(e); + | labcomm2014_encoder_sample_ref_register(e, labcomm2014_signature_%(func)s); + | labcomm2014_decoder_register_%(func)s(d, handle_%(func)s, e); + | labcomm2014_decoder_sample_ref_register(d, labcomm2014_signature_%(func)s); """ % { 'func': func, 'arg': arg })) result.extend(split_match('^[^|]*\|(.*)$', """ - | labcomm_decoder_run(d); + | labcomm2014_decoder_run(d); | return 0; |} """)) -- GitLab