Skip to main content
Sign in
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
  • anders.blomdell
  • typeref
  • pragma
  • compiler-refactoring
  • labcomm2013
  • v2013.0
  • v2014.0
  • v2014.1
9 results

Target

Select target project
  • Anders Blomdell / LabComm
  • Anton Klarén / LabComm
  • Tommy Olofsson / LabComm
  • Erik Jansson / LabComm
  • Sven Gestegård Robertz / LabComm
5 results
Select Git revision
  • labcomm2014
  • labcomm2006
  • master
  • python_sig_hash
  • typedefs
  • anders.blomdell
  • typeref
  • pragma
  • compiler-refactoring
  • labcomm2013
  • v2006.0
  • v2013.0
  • v2014.0
  • v2014.1
  • v2014.2
  • v2014.3
  • v2014.4
  • v2014.5
  • v2014.6
  • v2015.0
20 results
Show changes

Commits on Source 30

125 files
+ 2295
1338
Compare changes
  • Side-by-side
  • Inline

Files

+7 −3
Original line number Original line Diff line number Diff line
@@ -6,9 +6,9 @@ lib/c/liblabcomm.so.1
lib/c/liblabcomm2006.so.1
lib/c/liblabcomm2006.so.1
lib/c/liblabcomm2006.so
lib/c/liblabcomm2006.so
lib/c/liblabcomm2006.a
lib/c/liblabcomm2006.a
lib/c/liblabcomm2013.so.1
lib/c/liblabcomm20141009.so.1
lib/c/liblabcomm2013.so
lib/c/liblabcomm20141009.so
lib/c/liblabcomm2013.a
lib/c/liblabcomm20141009.a
lib/c/test/test_labcomm
lib/c/test/test_labcomm
lib/c/test/test_labcomm_basic_type_encoding
lib/c/test/test_labcomm_basic_type_encoding
lib/c/test/test_labcomm_copy
lib/c/test/test_labcomm_copy
@@ -26,3 +26,7 @@ examples/twoway/gen/
lib/csharp/labcomm.dll
lib/csharp/labcomm.dll
lib/java/gen/
lib/java/gen/
lib/java/labcomm*.jar
lib/java/labcomm*.jar
examples/simple/example_decoder
examples/simple/example_decoder06
examples/simple/example_encoder
examples/simple/example_encoder06
+1 −1
Original line number Original line Diff line number Diff line
SUBDIRS=compiler lib test examples
SUBDIRS=compiler lib test examples
export LABCOMM_JAR=$(shell pwd)/compiler/labComm.jar
export LABCOMM_JAR=$(shell pwd)/compiler/labcomm_compiler.jar
export LABCOMM=java -jar $(LABCOMM_JAR) 
export LABCOMM=java -jar $(LABCOMM_JAR) 


all: $(SUBDIRS:%=make-%)
all: $(SUBDIRS:%=make-%)
+10 −10
Original line number Original line Diff line number Diff line
@@ -268,7 +268,7 @@ aspect CS_Class {
      pp(env.getPrintStream());
      pp(env.getPrintStream());
      env.println("*/");
      env.println("*/");
      env.println();
      env.println();
      env.println("public class " + getName() + " : LabCommType {");
      env.println("public class " + getName() + " : SampleType {");
      env.println();
      env.println();
      env.indent();
      env.indent();
      getType().CS_emitInstance(env);
      getType().CS_emitInstance(env);
@@ -284,11 +284,11 @@ aspect CS_Class {
    pp(env.getPrintStream());
    pp(env.getPrintStream());
    env.println("*/");
    env.println("*/");
    env.println();
    env.println();
    env.println("public class " + getName() + " : LabCommSample {");
    env.println("public class " + getName() + " : Sample {");
    env.println();
    env.println();
    env.indent();
    env.indent();
    getType().CS_emitInstance(env);
    getType().CS_emitInstance(env);
    env.println("public interface Handler : LabCommHandler {");
    env.println("public interface Handler : SampleHandler {");
    env.print("  void handle(");
    env.print("  void handle(");
    if (!isVoid()) {
    if (!isVoid()) {
      getType().CS_emitType(env);
      getType().CS_emitType(env);
@@ -297,21 +297,21 @@ aspect CS_Class {
    env.println(");");
    env.println(");");
    env.println("}");
    env.println("}");
    env.println();
    env.println();
    env.println("public static void register(LabCommDecoder d, Handler h) {");
    env.println("public static void register(Decoder d, Handler h) {");
    env.indent();
    env.indent();
    env.println("d.register(new Dispatcher(), h);");
    env.println("d.register(new Dispatcher(), h);");
    env.unindent();
    env.unindent();
    env.println("}");
    env.println("}");
    env.println();
    env.println();


    env.println("public static void register(LabCommEncoder e) {");
    env.println("public static void register(Encoder e) {");
    env.indent();
    env.indent();
    env.println("e.register(new Dispatcher());");
    env.println("e.register(new Dispatcher());");
    env.unindent();
    env.unindent();
    env.println("}");
    env.println("}");
    env.println(); 
    env.println(); 


    env.println("private class Dispatcher : LabCommDispatcher {");
    env.println("private class Dispatcher : SampleDispatcher {");
    env.indent();
    env.indent();
    env.println(); 
    env.println(); 
    env.println("public Type getSampleClass() {");
    env.println("public Type getSampleClass() {");
@@ -332,7 +332,7 @@ aspect CS_Class {
    env.unindent();
    env.unindent();
    env.println("}");
    env.println("}");
    env.println(); 
    env.println(); 
    env.println("public void decodeAndHandle(LabCommDecoder d, LabCommHandler h) {");
    env.println("public void decodeAndHandle(Decoder d, SampleHandler h) {");
    env.indent();
    env.indent();
    if (isVoid()) {
    if (isVoid()) {
      env.println(getName() + ".decode(d);");
      env.println(getName() + ".decode(d);");
@@ -374,7 +374,7 @@ aspect CS_Class {
  }
  }


  public void TypeDecl.CS_emitEncoder(CS_env env) {
  public void TypeDecl.CS_emitEncoder(CS_env env) {
    env.print("public static void encode(LabCommEncoder e");
    env.print("public static void encode(Encoder e");
    if (!isVoid()) {
    if (!isVoid()) {
      env.print(", ");
      env.print(", ");
      getType().CS_emitType(env);
      getType().CS_emitType(env);
@@ -389,7 +389,7 @@ aspect CS_Class {
  }
  }


  public void SampleDecl.CS_emitEncoder(CS_env env) {
  public void SampleDecl.CS_emitEncoder(CS_env env) {
    env.print("public static void encode(LabCommEncoder e");
    env.print("public static void encode(Encoder e");
    if (!isVoid()) {
    if (!isVoid()) {
      env.print(", ");
      env.print(", ");
      getType().CS_emitType(env);
      getType().CS_emitType(env);
@@ -485,7 +485,7 @@ aspect CS_Class {
  public void Decl.CS_emitDecoder(CS_env env) {
  public void Decl.CS_emitDecoder(CS_env env) {
    env.print("public static ");
    env.print("public static ");
    getType().CS_emitType(env);
    getType().CS_emitType(env);
    env.println(" decode(LabCommDecoder d) {");
    env.println(" decode(Decoder d) {");
    env.indent();
    env.indent();
    if (!isVoid()) {
    if (!isVoid()) {
      getType().CS_emitType(env);
      getType().CS_emitType(env);
+26 −10
Original line number Original line Diff line number Diff line
@@ -1188,12 +1188,12 @@ aspect C_Signature {
      }
      }
    }
    }
    env.println("};");
    env.println("};");
    C_emitSizeofValue(env);
    env.println("struct labcomm"+env.verStr+"_signature labcomm"+env.verStr+"_signature_" + 
    env.println("struct labcomm"+env.verStr+"_signature labcomm"+env.verStr+"_signature_" + 
		env.prefix + getName() + " = {");
		env.prefix + getName() + " = {");
    env.indent();
    env.indent();
    env.println("LABCOMM_SAMPLE, \"" + getName() + "\",");
    env.println("\"" + getName() + "\",");
    env.println("(int (*)(struct labcomm"+env.verStr+"_signature *, void *))labcomm"+env.verStr+"_sizeof_" + 
    env.println("sizeof_" + env.prefix + getName() + ",");
		env.prefix + getName() + ",");
    env.println("sizeof(signature_bytes_" + env.prefix + getName() + "),");
    env.println("sizeof(signature_bytes_" + env.prefix + getName() + "),");
    env.println("signature_bytes_" + env.prefix + getName() + ",");
    env.println("signature_bytes_" + env.prefix + getName() + ",");
    env.println("0");
    env.println("0");
@@ -1260,6 +1260,22 @@ aspect C_Sizeof {
    return getType().C_fixedSizeof();
    return getType().C_fixedSizeof();
  }
  }


  public void Decl.C_emitSizeof(C_env env) {
  }

  public void SampleDecl.C_emitSizeof(C_env env) {
    env = env.nestStruct("(*v)");
    env.println("int labcomm"+env.verStr+"_sizeof_" + env.prefix + getName() +
		"(" + env.prefix + getName() + " *v)");
    env.println("{");
    env.indent();
    env.println("return labcomm"+env.verStr+"_internal_sizeof(" +
                "&labcomm" + env.verStr+"_signature_" + env.prefix + getName() +
                ", v);");
    env.unindent();
    env.println("}");
  }

  public int Type.C_fixedSizeof() {
  public int Type.C_fixedSizeof() {
    throw new Error(this.getClass().getName() + 
    throw new Error(this.getClass().getName() + 
		    ".C_fixedSizeof()" + 
		    ".C_fixedSizeof()" + 
@@ -1308,18 +1324,17 @@ aspect C_Sizeof {
    return getType().C_fixedSizeof() * elements;
    return getType().C_fixedSizeof() * elements;
  }
  }


  public void Decl.C_emitSizeof(C_env env) {
  public void Decl.C_emitSizeofValue(C_env env) {
  }
  }


  public void SampleDecl.C_emitSizeof(C_env env) {
  public void SampleDecl.C_emitSizeofValue(C_env env) {
    env = env.nestStruct("(*v)");
    env = env.nestStruct("(*v)");
    env.println("int labcomm"+env.verStr+"_sizeof_" + env.prefix + getName() +
    env.println("static int sizeof_" + env.prefix + getName() + "(void *vv)");
		"(" + env.prefix + getName() + " *v)");
    env.println("{");
    env.println("{");
    env.indent();
    env.indent();
    env.println("int result = labcomm"+env.verStr+"_size_packed32(labcomm"+env.verStr+"_signature_" + 
    env.println("int result = 0;");
                env.prefix + getName() +".index);");
    if (C_isDynamic()) {
    if (C_isDynamic()) {
      env.println(env.prefix + getName() + " *v = vv;");
      getType().C_emitSizeof(env);
      getType().C_emitSizeof(env);
    } else {
    } else {
      env.println("result += " + C_fixedSizeof() + ";");
      env.println("result += " + C_fixedSizeof() + ";");
@@ -1338,7 +1353,8 @@ aspect C_Sizeof {
  public void PrimType.C_emitSizeof(C_env env) {
  public void PrimType.C_emitSizeof(C_env env) {
    switch (getToken()) {
    switch (getToken()) {
      case LABCOMM_STRING: { 
      case LABCOMM_STRING: { 
	env.println("result += 0 + strlen(" + env.qualid + ");"); 
        env.print("{ int l = strlen(" + env.qualid + "); ");
	env.println("result += labcomm"+env.verStr+"_size_packed32(l) + l; }"); 
      } break;
      } break;
      default: { 
      default: { 
	throw new Error(this.getClass().getName() + 
	throw new Error(this.getClass().getName() + 
+19 −81
Original line number Original line Diff line number Diff line
@@ -206,21 +206,6 @@ aspect Java_CodeGen {


  public void Program.J_gen(PrintStream ps, String pack, int version) throws IOException {
  public void Program.J_gen(PrintStream ps, String pack, int version) throws IOException {
    Java_env env;
    Java_env env;
/*
    // Registration class
    env = new Java_env(version, ps);
    if (pack != null && pack.length() > 0) {
      env.println("package " + pack + ";");
    }
    env.println("public class LabCommRegister {");
    env.println();
    env.indent();
    Java_emitTypeRegister(env);
    env.unindent();
    env.println();
    env.println("}");
//    env.close();
*/
    env = new Java_env(version, ps);
    env = new Java_env(version, ps);
    for (int i = 0; i < getNumDecl(); i++) {
    for (int i = 0; i < getNumDecl(); i++) {
      Decl d = getDecl(i);
      Decl d = getDecl(i);
@@ -236,21 +221,6 @@ aspect Java_CodeGen {


  public void Program.J_gen(String dir, String pack, int version) throws IOException {
  public void Program.J_gen(String dir, String pack, int version) throws IOException {
    Java_env env;
    Java_env env;
/*
    // Registration class
    env = new Java_env(version, new File(dir, "LabCommRegister.java"));
    if (pack != null && pack.length() > 0) {
      env.println("package " + pack + ";");
    }
    env.println("public class LabCommRegister {");
    env.println();
    env.indent();
    Java_emitTypeRegister(env);
    env.unindent();
    env.println();
    env.println("}");
    env.close();
*/
    for (int i = 0; i < getNumDecl(); i++) {
    for (int i = 0; i < getNumDecl(); i++) {
      Decl d = getDecl(i);
      Decl d = getDecl(i);
      try {
      try {
@@ -286,38 +256,6 @@ aspect Java_CodeGen {
      }
      }
    }
    }
  }
  }

}

aspect Java_Register {

  public void Program.Java_emitTypeRegister(Java_env env) {
    /*
    env.println("static void register(LabCommChannel c) {");
    env.indent();
    for (int i = 0; i < getNumDecl(); i++) {
      getDecl(i).Java_emitTypeRegister(env);
    }
    env.unindent();
    env.println("}");
*/

  }

  public void Decl.Java_emitTypeRegister(Java_env env) {
    throw new Error(this.getClass().getName() + 
		    ".Java_emitTypeRegister(Java_env env)" + 
		    " not declared");
  }

  public void SampleDecl.Java_emitTypeRegister(Java_env env) {
    env.println(getName() + ".register(c);");
  }

  public void TypeDecl.Java_emitTypeRegister(Java_env env) {
    // TODO
  }

}
}


aspect Java_Class {
aspect Java_Class {
@@ -340,11 +278,11 @@ aspect Java_Class {
      }
      }


      env.println("import java.io.IOException;");
      env.println("import java.io.IOException;");
      env.println("import se.lth.control.labcomm"+env.verStr+".LabCommType;");
      env.println("import se.lth.control.labcomm"+env.verStr+".SampleType;");
      env.println("import se.lth.control.labcomm"+env.verStr+".LabCommEncoder;");
      env.println("import se.lth.control.labcomm"+env.verStr+".Encoder;");
      env.println("import se.lth.control.labcomm"+env.verStr+".LabCommDecoder;");
      env.println("import se.lth.control.labcomm"+env.verStr+".Decoder;");
      env.println();
      env.println();
      env.println("public class " + getName() + " implements LabCommType {");
      env.println("public class " + getName() + " implements SampleType {");
      env.println();
      env.println();
      env.indent();
      env.indent();
      getType().Java_emitInstance(env);
      getType().Java_emitInstance(env);
@@ -380,21 +318,21 @@ aspect Java_Class {
    }
    }


    env.println("import java.io.IOException;");
    env.println("import java.io.IOException;");
    env.println("import se.lth.control.labcomm"+env.verStr+".LabCommDecoder;");
    env.println("import se.lth.control.labcomm"+env.verStr+".Decoder;");
    env.println("import se.lth.control.labcomm"+env.verStr+".LabCommDispatcher;");
    env.println("import se.lth.control.labcomm"+env.verStr+".SampleDispatcher;");
    env.println("import se.lth.control.labcomm"+env.verStr+".LabCommEncoder;");
    env.println("import se.lth.control.labcomm"+env.verStr+".Encoder;");
    env.println("import se.lth.control.labcomm"+env.verStr+".LabCommHandler;");
    env.println("import se.lth.control.labcomm"+env.verStr+".SampleHandler;");
    env.println("import se.lth.control.labcomm"+env.verStr+".LabCommSample;");
    env.println("import se.lth.control.labcomm"+env.verStr+".Sample;");
    env.println();
    env.println();
    env.print("public class " + getName());
    env.print("public class " + getName());
//    if(getType().isUserType()) {
//    if(getType().isUserType()) {
//        env.print(" extends "+getType().getTypeName());
//        env.print(" extends "+getType().getTypeName());
//    }
//    }
    env.println(" implements LabCommSample {");
    env.println(" implements Sample {");
    env.println();
    env.println();
    env.indent();
    env.indent();
    getType().Java_emitInstance(env);
    getType().Java_emitInstance(env);
    env.println("public interface Handler extends LabCommHandler {");
    env.println("public interface Handler extends SampleHandler {");
    env.print("  public void handle_" + getName() + "(");
    env.print("  public void handle_" + getName() + "(");
    if (!isVoid()) {
    if (!isVoid()) {
      getType().Java_emitType(env);
      getType().Java_emitType(env);
@@ -403,21 +341,21 @@ aspect Java_Class {
    env.println(") throws Exception;");
    env.println(") throws Exception;");
    env.println("}");
    env.println("}");
    env.println();
    env.println();
    env.println("public static void register(LabCommDecoder d, Handler h) throws IOException {");
    env.println("public static void register(Decoder d, SampleHandler h) throws IOException {");
    env.indent();
    env.indent();
    env.println("d.register(new Dispatcher(), h);");
    env.println("d.register(new Dispatcher(), h);");
    env.unindent();
    env.unindent();
    env.println("}");
    env.println("}");
    env.println();
    env.println();


    env.println("public static void register(LabCommEncoder e) throws IOException {");
    env.println("public static void register(Encoder e) throws IOException {");
    env.indent();
    env.indent();
    env.println("e.register(new Dispatcher());");
    env.println("e.register(new Dispatcher());");
    env.unindent();
    env.unindent();
    env.println("}");
    env.println("}");
    env.println(); 
    env.println(); 


    env.println("private static class Dispatcher implements LabCommDispatcher {");
    env.println("private static class Dispatcher implements SampleDispatcher {");
    env.indent();
    env.indent();
    env.println(); 
    env.println(); 
    env.println("public Class getSampleClass() {");
    env.println("public Class getSampleClass() {");
@@ -438,8 +376,8 @@ aspect Java_Class {
    env.unindent();
    env.unindent();
    env.println("}");
    env.println("}");
    env.println(); 
    env.println(); 
    env.println("public void decodeAndHandle(LabCommDecoder d,");
    env.println("public void decodeAndHandle(Decoder d,");
    env.println("                            LabCommHandler h) throws Exception {");
    env.println("                            SampleHandler h) throws Exception {");
    env.indent();
    env.indent();
    if (isVoid()) {
    if (isVoid()) {
      env.println(getName() + ".decode(d);");
      env.println(getName() + ".decode(d);");
@@ -481,7 +419,7 @@ aspect Java_Class {
  }
  }


  public void TypeDecl.Java_emitEncoder(Java_env env) {
  public void TypeDecl.Java_emitEncoder(Java_env env) {
    env.print("public static void encode(LabCommEncoder e");
    env.print("public static void encode(Encoder e");
    if (!isVoid()) {
    if (!isVoid()) {
      env.print(", ");
      env.print(", ");
      getType().Java_emitType(env);
      getType().Java_emitType(env);
@@ -496,7 +434,7 @@ aspect Java_Class {
  }
  }


  public void SampleDecl.Java_emitEncoder(Java_env env) {
  public void SampleDecl.Java_emitEncoder(Java_env env) {
    env.print("public static void encode(LabCommEncoder e");
    env.print("public static void encode(Encoder e");
    if (!isVoid()) {
    if (!isVoid()) {
      env.print(", ");
      env.print(", ");
      getType().Java_emitType(env);
      getType().Java_emitType(env);
@@ -588,7 +526,7 @@ aspect Java_Class {
  public void Decl.Java_emitDecoder(Java_env env) {
  public void Decl.Java_emitDecoder(Java_env env) {
    env.print("public static ");
    env.print("public static ");
    getType().Java_emitType(env);
    getType().Java_emitType(env);
    env.println(" decode(LabCommDecoder d) throws IOException {");
    env.println(" decode(Decoder d) throws IOException {");
    env.indent();
    env.indent();
    if (!isVoid()) {
    if (!isVoid()) {
      getType().Java_emitType(env);
      getType().Java_emitType(env);
+12 −4
Original line number Original line Diff line number Diff line
@@ -83,6 +83,7 @@ aspect Python_CodeGen {
    env.println("import labcomm");
    env.println("import labcomm");
    env.println();
    env.println();
    Python_genTypes(env);
    Python_genTypes(env);
/* Typedefs curenntly disabled
    env.println("typedef = [");
    env.println("typedef = [");
    env.indent();
    env.indent();
    for (int i = 0 ; i < getNumDecl() ; i++) {
    for (int i = 0 ; i < getNumDecl() ; i++) {
@@ -90,6 +91,7 @@ aspect Python_CodeGen {
    }
    }
    env.unindent();
    env.unindent();
    env.println("]");
    env.println("]");
*/
    env.println("sample = [");
    env.println("sample = [");
    env.indent();
    env.indent();
    for (int i = 0 ; i < getNumDecl() ; i++) {
    for (int i = 0 ; i < getNumDecl() ; i++) {
@@ -105,11 +107,7 @@ aspect PythonTypes {
  
  
  public void Program.Python_genTypes(Python_env env) {
  public void Program.Python_genTypes(Python_env env) {
    for (int i = 0 ; i < getNumDecl() ; i++) {
    for (int i = 0 ; i < getNumDecl() ; i++) {
      env.println("class " + getDecl(i).getName() + "(object):");
      env.indent();
      getDecl(i).Python_genSignature(env);
      getDecl(i).Python_genSignature(env);
      env.unindent();
      env.println();
    }
    }
  }
  }


@@ -120,19 +118,29 @@ aspect PythonTypes {
  }
  }


  public void TypeDecl.Python_genSignature(Python_env env) {
  public void TypeDecl.Python_genSignature(Python_env env) {
/*
    env.println("class " + getName() + "(object):");
    env.indent();
    env.println("signature = labcomm.typedef('" + getName() + "',");
    env.println("signature = labcomm.typedef('" + getName() + "',");
    env.indent();
    env.indent();
    getType().Python_genSignature(env);
    getType().Python_genSignature(env);
    env.unindent();
    env.unindent();
    env.println(")");
    env.println(")");
    env.unindent();
    env.println();
*/
  }
  }


  public void SampleDecl.Python_genSignature(Python_env env) {
  public void SampleDecl.Python_genSignature(Python_env env) {
    env.println("class " + getName() + "(object):");
    env.indent();
    env.println("signature = labcomm.sample('" + getName() + "', ");
    env.println("signature = labcomm.sample('" + getName() + "', ");
    env.indent();
    env.indent();
    getType().Python_genSignature(env);
    getType().Python_genSignature(env);
    env.unindent();
    env.unindent();
    env.println(")");
    env.println(")");
    env.unindent();
    env.println();
  }
  }


  public void UserType.Python_genSignature(Python_env env) {
  public void UserType.Python_genSignature(Python_env env) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -90,7 +90,7 @@ classpath="tools/jastadd2.jar"/>




<target name="jar" depends="build">
<target name="jar" depends="build">
  <jar destfile="labComm.jar">
  <jar destfile="labcomm_compiler.jar">
    <fileset dir="." includes="LabComm*.class"/>
    <fileset dir="." includes="LabComm*.class"/>
    <fileset dir="." includes="AST/*.class"/>
    <fileset dir="." includes="AST/*.class"/>
    <zipfileset src="tools/beaver-rt.jar" includes="beaver/*.class"/>
    <zipfileset src="tools/beaver-rt.jar" includes="beaver/*.class"/>

doc/pragma-skiss.txt

0 → 100644
+141 −0
Original line number Original line Diff line number Diff line
Discussion 141023

TODO:

*** new labcomm packet types:
    TYPE_DEF = 0x03     // for (possibly) hierarchical type definitions
    TYPE_BINDING = 0x04 // binding a sample def to a type def

*** rewrite malloc of received samples to utilize the packet length field
    to allocate a single object before parsing the sample byte stream

*** labcomm language: add type for type_ref to facilitate references to
    labcomm sample_defs (and type_defs) in (primarily) pragmas
    E.g.,  sample ... foo;
         sample ... bar;

         sample struct {
             ...
             type[2] some_refs;
         } some_pragma;

	my_lc_some_pragma sp;

	sp.some_refs = {&labcomm_signature_my_lc_foo,
                        &labcomm_signature_my_lc_bar};

 	labcomm_encode_my_lc_some_pragma(enc, &sp);

    This is to avoid exposing local_to_remote and remote_to_local

*** refactor {encoder,decoder}registry to separate the actual encoder
    from the registry

    - currently, the assignment of local indices is done in the "constructor"
      which means that the registries will be very thin

*** labcomm_pragma_builder(struct labcomm_encoder *enc);

    - looks like an encoder to enable reuse of the generated encode functions
    - allocates memory in the enclosing encoder, enc.
    - deallocates memory when packet is sent

*** Pragma handler
    - is a decoder, to which the user registers handlers for pragma samples
    - has/gets a byte_array_reader in the context
    - the "surrounding" decoder will deallocate the pragma packet when the
      pragma handler returns




______________________________________________________________
______________preliminary sketch of pragma____________________


A pragma "packet" is a sequence of fields, where each field is
a labcomm sample (in order to keep labcomm in-band self-describing).

A pragma packet has a type, which is a globally unique string
(e.g., java package-like name, URI, or UUID)

One predefined pragma sample type is labcomm_type_ref, which is used to refer
to labcomm sample types in a way that is unique on a given encoder/channel.

Sending:

/* create a pragma packet for pragma type type
   allocated in e->memory */
// (or, if that is visible to user code, should
// the parameter be a struct labcomm_memory*?)
struct labcom_pragma_packet * = labcomm_pragma_new(struct labcomm_encoder e*,
                                                   char *type);

/* add type reference field*/
void labcomm_pragma_add_ref(struct labcomm_signature sig);

// the semantics if more than one type reference field is undefined
// (as far as labcomm is concerned).
// One possible (pragma-type defined) semantic is that the latest type
// reference applies to the fields following it.

A pragma packet is (under the hood) a struct labcomm_encoder, so that we
can reuse the sample_type_encode() function for adding pragma fields.


// an example session
struct labcom_pragma_packet pp = labcomm_pragma_new(enc, some_type));
labcomm_pragma_add_ref(some_sig);
some_pragma_type_encode(pp, some_pragma_instance);
another_pragma_type_encode(pp, another_pragma_instance);
labcomm_pragma_send(pp, enc);


#define labcomm_pragma_add_field(some_pragma_sample_type, value) \
	labcomm_encode_#some_pragma_sample_type, value)

int labcomm_encode_test_twoLines( struct labcomm_encoder *e,
                                  test_twoLines *v)
{
return labcomm_internal_encode(e,
                               &labcomm_signature_test_twoLines,
                               (labcomm_enc oder_function) encode_test_twoLines,
                                v);
}



receiving:

alt 1. standard handlers, parameter pragma_type to handle function
	-- this means adding a parameter to all handlers
           (where null means not pragma)

void handle_some_pragma(some_pragma *v, void *context, char * pragma_type);

alt 2. standard handlers, but separate register_pragma_handler function
       use the handler context to store and communicate pragma-specific data.

	-- this means that the decoder interface needs to be extended,
           and that the handler context for pragmas need to be specified
           (by labcomm)

alt 3  have a single handler for pragma packets as the interface upwards
       from the labcomm lib. That handler is then responsible for managing
       and multiplexing pragma types based on the type field in the pragma
       packet.

       The labcomm libraries can provide a default implementation of a
       pragma_handler, to facilitate the common cases and reduce the
       amount of boilerplate code.

struct pragma_packet {
	char *pragma_type;
	char *packed_data;
}

void handle_pragma(struct pragma_packet *p, void *context);



+1 −1
Original line number Original line Diff line number Diff line
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM_JAR=../../compiler/labcomm_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR) 
LABCOMM=java -jar $(LABCOMM_JAR) 


all: gen/animal.py
all: gen/animal.py
+15 −15
Original line number Original line Diff line number Diff line
@@ -18,12 +18,12 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map;


import se.lth.control.labcomm.LabCommDecoder;
import se.lth.control.labcomm.Decoder;
import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoder;
import se.lth.control.labcomm.Encoder;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import AST.LabCommParser;
import AST.Parser;
import AST.LabCommScanner;
import AST.Scanner;
import AST.Program;
import AST.Program;
import beaver.Parser.Exception;
import beaver.Parser.Exception;


@@ -160,8 +160,8 @@ public class DynamicPart {
	public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) {
	public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) {
		Program ast = null;
		Program ast = null;
		InputStream in = new ByteArrayInputStream(lcDecl.getBytes());
		InputStream in = new ByteArrayInputStream(lcDecl.getBytes());
		LabCommScanner scanner = new LabCommScanner(in);
		Scanner scanner = new Scanner(in);
		LabCommParser parser = new LabCommParser();
		Parser parser = new Parser();
		Collection errors = new LinkedList();
		Collection errors = new LinkedList();


		InRAMCompiler irc = null;
		InRAMCompiler irc = null;
@@ -272,7 +272,7 @@ public class DynamicPart {
	private void decodeTest(InRAMCompiler irc, HandlerContext ctxt, String tmpFile, String... sampleNames) {
	private void decodeTest(InRAMCompiler irc, HandlerContext ctxt, String tmpFile, String... sampleNames) {
		try {
		try {
			FileInputStream in = new FileInputStream(tmpFile);
			FileInputStream in = new FileInputStream(tmpFile);
			LabCommDecoderChannel dec = new LabCommDecoderChannel(in);
			DecoderChannel dec = new DecoderChannel(in);
			Class handlerClass =  irc.load(handlerClassName);
			Class handlerClass =  irc.load(handlerClassName);
			Constructor hcc = handlerClass.getDeclaredConstructor(Object.class);
			Constructor hcc = handlerClass.getDeclaredConstructor(Object.class);
			Object handler = hcc.newInstance(ctxt);
			Object handler = hcc.newInstance(ctxt);
@@ -282,7 +282,7 @@ public class DynamicPart {
				Class sampleClass = irc.load(sampleName);
				Class sampleClass = irc.load(sampleName);
				Class handlerInterface = irc.load(sampleName+"$Handler");
				Class handlerInterface = irc.load(sampleName+"$Handler");


				Method reg = sampleClass.getDeclaredMethod("register", LabCommDecoder.class, handlerInterface);
				Method reg = sampleClass.getDeclaredMethod("register", Decoder.class, handlerInterface);
				reg.invoke(sampleClass, dec, handler);
				reg.invoke(sampleClass, dec, handler);
			}
			}


@@ -324,20 +324,20 @@ public class DynamicPart {




			FileOutputStream out = new FileOutputStream(tmpFile);
			FileOutputStream out = new FileOutputStream(tmpFile);
			LabCommEncoderChannel enc = new LabCommEncoderChannel(out);
			EncoderChannel enc = new EncoderChannel(out);


			/* register and send foo */
			/* register and send foo */
			Method regFoo = fc.getDeclaredMethod("register", LabCommEncoder.class);
			Method regFoo = fc.getDeclaredMethod("register", Encoder.class);
			regFoo.invoke(fc, enc);
			regFoo.invoke(fc, enc);


			Method doEncodeFoo = fc.getDeclaredMethod("encode", LabCommEncoder.class, ft);
			Method doEncodeFoo = fc.getDeclaredMethod("encode", Encoder.class, ft);
			doEncodeFoo.invoke(fc, enc, fv);
			doEncodeFoo.invoke(fc, enc, fv);


			/* register and send bar (NB! uses primitive type int) */
			/* register and send bar (NB! uses primitive type int) */
			Method regBar = bc.getDeclaredMethod("register", LabCommEncoder.class);
			Method regBar = bc.getDeclaredMethod("register", Encoder.class);
			regBar.invoke(bc, enc);
			regBar.invoke(bc, enc);


			Method doEncodeBar = bc.getDeclaredMethod("encode", LabCommEncoder.class, Integer.TYPE);
			Method doEncodeBar = bc.getDeclaredMethod("encode", Encoder.class, Integer.TYPE);
			doEncodeBar.invoke(bc, enc, ctxt.bar);
			doEncodeBar.invoke(bc, enc, ctxt.bar);


			out.close();
			out.close();
+3 −3
Original line number Original line Diff line number Diff line
@@ -6,16 +6,16 @@ import gen.bar;
import java.io.File;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStream;
import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;




public class StaticDecoder implements foo.Handler, bar.Handler
public class StaticDecoder implements foo.Handler, bar.Handler
{
{


  LabCommDecoderChannel decoder;
  DecoderChannel decoder;


  public StaticDecoder(InputStream in) throws Exception {
  public StaticDecoder(InputStream in) throws Exception {
    decoder = new LabCommDecoderChannel(in);
    decoder = new DecoderChannel(in);
    foo.register(decoder, this);
    foo.register(decoder, this);
    bar.register(decoder, this);
    bar.register(decoder, this);


+3 −3
Original line number Original line Diff line number Diff line
@@ -2,19 +2,19 @@ package test;
import java.io.File;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStream;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;


import gen.foo;
import gen.foo;
import gen.bar;
import gen.bar;


public class StaticEncoder {
public class StaticEncoder {


  LabCommEncoderChannel encoder;
  EncoderChannel encoder;


  public StaticEncoder(OutputStream out) 
  public StaticEncoder(OutputStream out) 
    throws Exception 
    throws Exception 
  {
  {
    encoder = new LabCommEncoderChannel(out);
    encoder = new EncoderChannel(out);
    foo.register(encoder);
    foo.register(encoder);
    bar.register(encoder);
    bar.register(encoder);
  }
  }
+14 −14
Original line number Original line Diff line number Diff line
@@ -16,18 +16,18 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map;


import se.lth.control.labcomm.LabCommDecoder;
import se.lth.control.labcomm.Decoder;
import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoder;
import se.lth.control.labcomm.Encoder;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import AST.LabCommParser;
import AST.Parser;
import AST.LabCommScanner;
import AST.Scanner;
import AST.Program;
import AST.Program;
import beaver.Parser.Exception;
import beaver.Parser.Exception;






public class TestLabCommCompiler {
public class TestCompiler {


	private static final String BAR = "bar";
	private static final String BAR = "bar";
	private static final String FOO = "foo";
	private static final String FOO = "foo";
@@ -73,7 +73,7 @@ public class TestLabCommCompiler {
	private static void decodeTest(InRAMCompiler irc, String tmpFile) {
	private static void decodeTest(InRAMCompiler irc, String tmpFile) {
		try {
		try {
			FileInputStream in = new FileInputStream(tmpFile);
			FileInputStream in = new FileInputStream(tmpFile);
			LabCommDecoderChannel dec = new LabCommDecoderChannel(in);
			DecoderChannel dec = new DecoderChannel(in);
	
	
			Class fc = irc.load(FOO);
			Class fc = irc.load(FOO);
			Class hc = irc.load("gen_"+FOO+"Handler");
			Class hc = irc.load("gen_"+FOO+"Handler");
@@ -81,7 +81,7 @@ public class TestLabCommCompiler {


			Object h = hc.newInstance(); 
			Object h = hc.newInstance(); 
		
		
			Method reg = fc.getDeclaredMethod("register", LabCommDecoder.class, hi);
			Method reg = fc.getDeclaredMethod("register", Decoder.class, hi);
			reg.invoke(fc, dec, h);
			reg.invoke(fc, dec, h);
			
			
			dec.runOne();
			dec.runOne();
@@ -106,11 +106,11 @@ public class TestLabCommCompiler {
			z.setInt(f, 12);
			z.setInt(f, 12);
			
			
			FileOutputStream out = new FileOutputStream(tmpFile);
			FileOutputStream out = new FileOutputStream(tmpFile);
			LabCommEncoderChannel enc = new LabCommEncoderChannel(out);
			EncoderChannel enc = new EncoderChannel(out);
			Method reg = fc.getDeclaredMethod("register", LabCommEncoder.class);
			Method reg = fc.getDeclaredMethod("register", Encoder.class);
			reg.invoke(fc, enc);
			reg.invoke(fc, enc);
			
			
			Method doEncode = fc.getDeclaredMethod("encode", LabCommEncoder.class, fc);
			Method doEncode = fc.getDeclaredMethod("encode", Encoder.class, fc);
			doEncode.invoke(fc, enc, f);
			doEncode.invoke(fc, enc, f);
			
			
			out.close();
			out.close();
@@ -123,8 +123,8 @@ public class TestLabCommCompiler {
	public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) {
	public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) {
		Program ast = null;
		Program ast = null;
		InputStream in = new ByteArrayInputStream(lcDecl.getBytes());
		InputStream in = new ByteArrayInputStream(lcDecl.getBytes());
		LabCommScanner scanner = new LabCommScanner(in);
		Scanner scanner = new Scanner(in);
		LabCommParser parser = new LabCommParser();
		Parser parser = new Parser();
		Collection errors = new LinkedList();
		Collection errors = new LinkedList();


		InRAMCompiler irc = null;
		InRAMCompiler irc = null;
+17 −17
Original line number Original line Diff line number Diff line
@@ -18,12 +18,12 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map;


import se.lth.control.labcomm.LabCommDecoder;
import se.lth.control.labcomm.Decoder;
import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoder;
import se.lth.control.labcomm.Encoder;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import AST.LabCommParser;
import AST.Parser;
import AST.LabCommScanner;
import AST.Scanner;
import AST.Program;
import AST.Program;
import beaver.Parser.Exception;
import beaver.Parser.Exception;


@@ -163,8 +163,8 @@ public class TestLabcommGen {
	public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) {
	public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) {
		Program ast = null;
		Program ast = null;
		InputStream in = new ByteArrayInputStream(lcDecl.getBytes());
		InputStream in = new ByteArrayInputStream(lcDecl.getBytes());
		LabCommScanner scanner = new LabCommScanner(in);
		Scanner scanner = new Scanner(in);
		LabCommParser parser = new LabCommParser();
		Parser parser = new Parser();
		Collection errors = new LinkedList();
		Collection errors = new LinkedList();


		InRAMCompiler irc = null;
		InRAMCompiler irc = null;
@@ -332,7 +332,7 @@ public class TestLabcommGen {
	private static void decodeTest(InRAMCompiler irc, String tmpFile, String... sampleNames) {
	private static void decodeTest(InRAMCompiler irc, String tmpFile, String... sampleNames) {
		try {
		try {
			FileInputStream in = new FileInputStream(tmpFile);
			FileInputStream in = new FileInputStream(tmpFile);
			LabCommDecoderChannel dec = new LabCommDecoderChannel(in);
			DecoderChannel dec = new DecoderChannel(in);
			Class handlerClass =  irc.load(handlerClassName);
			Class handlerClass =  irc.load(handlerClassName);
			Constructor hcc = handlerClass.getDeclaredConstructor(Object.class);
			Constructor hcc = handlerClass.getDeclaredConstructor(Object.class);
//			Object handler = handlerClass.newInstance(); 
//			Object handler = handlerClass.newInstance(); 
@@ -344,7 +344,7 @@ public class TestLabcommGen {
				Class sampleClass = irc.load(sampleName);
				Class sampleClass = irc.load(sampleName);
				Class handlerInterface = irc.load(sampleName+"$Handler");
				Class handlerInterface = irc.load(sampleName+"$Handler");


				Method reg = sampleClass.getDeclaredMethod("register", LabCommDecoder.class, handlerInterface);
				Method reg = sampleClass.getDeclaredMethod("register", Decoder.class, handlerInterface);
				reg.invoke(sampleClass, dec, handler);
				reg.invoke(sampleClass, dec, handler);
			}
			}


@@ -389,20 +389,20 @@ public class TestLabcommGen {




			FileOutputStream out = new FileOutputStream(tmpFile);
			FileOutputStream out = new FileOutputStream(tmpFile);
			LabCommEncoderChannel enc = new LabCommEncoderChannel(out);
			EncoderChannel enc = new EncoderChannel(out);


			/* register and send foo */
			/* register and send foo */
			Method regFoo = fc.getDeclaredMethod("register", LabCommEncoder.class);
			Method regFoo = fc.getDeclaredMethod("register", Encoder.class);
			regFoo.invoke(fc, enc);
			regFoo.invoke(fc, enc);


			Method doEncodeFoo = fc.getDeclaredMethod("encode", LabCommEncoder.class, ft);
			Method doEncodeFoo = fc.getDeclaredMethod("encode", Encoder.class, ft);
			doEncodeFoo.invoke(fc, enc, f);
			doEncodeFoo.invoke(fc, enc, f);


			/* register and send bar (NB! uses primitive type int) */
			/* register and send bar (NB! uses primitive type int) */
			Method regBar = bc.getDeclaredMethod("register", LabCommEncoder.class);
			Method regBar = bc.getDeclaredMethod("register", Encoder.class);
			regBar.invoke(bc, enc);
			regBar.invoke(bc, enc);


			Method doEncodeBar = bc.getDeclaredMethod("encode", LabCommEncoder.class, Integer.TYPE);
			Method doEncodeBar = bc.getDeclaredMethod("encode", Encoder.class, Integer.TYPE);
			doEncodeBar.invoke(bc, enc, 42);
			doEncodeBar.invoke(bc, enc, 42);


			out.close();
			out.close();
@@ -475,7 +475,7 @@ public class TestLabcommGen {
	private static void decodeTestSeparate(InRAMCompiler irc, String tmpFile, String... sampleNames) {
	private static void decodeTestSeparate(InRAMCompiler irc, String tmpFile, String... sampleNames) {
		try {
		try {
			FileInputStream in = new FileInputStream(tmpFile);
			FileInputStream in = new FileInputStream(tmpFile);
			LabCommDecoderChannel dec = new LabCommDecoderChannel(in);
			DecoderChannel dec = new DecoderChannel(in);
			for (String sampleName : sampleNames) {
			for (String sampleName : sampleNames) {
				System.out.println("registering handler for "+sampleName);
				System.out.println("registering handler for "+sampleName);
				Class sampleClass = irc.load(sampleName);
				Class sampleClass = irc.load(sampleName);
@@ -484,7 +484,7 @@ public class TestLabcommGen {


				Object handler = handlerClass.newInstance(); 
				Object handler = handlerClass.newInstance(); 


				Method reg = sampleClass.getDeclaredMethod("register", LabCommDecoder.class, handlerInterface);
				Method reg = sampleClass.getDeclaredMethod("register", Decoder.class, handlerInterface);
				reg.invoke(sampleClass, dec, handler);
				reg.invoke(sampleClass, dec, handler);
			}
			}


+1 −2
Original line number Original line Diff line number Diff line
LCDIR=../..
LCDIR=../..
LCC=java -jar ${LCDIR}/compiler/labComm.jar
LCC=java -jar ${LCDIR}/compiler/labcomm_compiler.jar
CLASSPATH=.:${LCDIR}/lib/java/labcomm.jar
CLASSPATH=.:${LCDIR}/lib/java/labcomm.jar
JAVA_PKG=labcommTCPtest
JAVA_PKG=labcommTCPtest
SAMPLENAME=foo
SAMPLENAME=foo
LCC=java -jar ${LCDIR}/compiler/labComm.jar
LCLIBDIR=${LCDIR}/lib/c
LCLIBDIR=${LCDIR}/lib/c


LCFILE=jg
LCFILE=jg
+4 −4
Original line number Original line Diff line number Diff line
@@ -6,8 +6,8 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.UnknownHostException;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import labcommTCPtest.gen.foo;
import labcommTCPtest.gen.foo;
import labcommTCPtest.gen.foo.Handler;
import labcommTCPtest.gen.foo.Handler;


@@ -25,7 +25,7 @@ public class TestClient implements Handler {
	public void test() {
	public void test() {
		
		
		try {
		try {
			LabCommEncoderChannel e = new LabCommEncoderChannel(out );
			EncoderChannel e = new EncoderChannel(out );
			foo.register(e);
			foo.register(e);
			foo sample = new foo();
			foo sample = new foo();
			sample.c = 17;
			sample.c = 17;
@@ -36,7 +36,7 @@ public class TestClient implements Handler {
			printSample("Client sending", sample);
			printSample("Client sending", sample);
			foo.encode(e, sample);
			foo.encode(e, sample);


			LabCommDecoderChannel c = new LabCommDecoderChannel(in);
			DecoderChannel c = new DecoderChannel(in);
			foo.register(c,this);
			foo.register(c,this);
			c.run();
			c.run();
		} catch (Exception e) {
		} catch (Exception e) {
+4 −4
Original line number Original line Diff line number Diff line
@@ -6,8 +6,8 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.UnknownHostException;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample.Handler;
import labcommTCPtest.gen.FooSample.Handler;


@@ -25,7 +25,7 @@ public class TestClientSingleshot implements Handler {
	public void test() {
	public void test() {
		
		
		try {
		try {
			LabCommEncoderChannel e = new LabCommEncoderChannel(out );
			EncoderChannel e = new EncoderChannel(out );
			FooSample.register(e);
			FooSample.register(e);
			FooSample sample = new FooSample();
			FooSample sample = new FooSample();
			sample.x = 17;
			sample.x = 17;
@@ -35,7 +35,7 @@ public class TestClientSingleshot implements Handler {
			printSample("Client sending", sample);
			printSample("Client sending", sample);
			FooSample.encode(e, sample);
			FooSample.encode(e, sample);


			LabCommDecoderChannel c = new LabCommDecoderChannel(in);
			DecoderChannel c = new DecoderChannel(in);
			FooSample.register(c,this);
			FooSample.register(c,this);
			c.runOne();
			c.runOne();
		} catch (Exception e) {
		} catch (Exception e) {
+4 −4
Original line number Original line Diff line number Diff line
@@ -8,8 +8,8 @@ import java.lang.reflect.Method;
import java.net.ServerSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.Socket;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import labcommTCPtest.gen.foo;
import labcommTCPtest.gen.foo;
import labcommTCPtest.gen.foo.Handler;
import labcommTCPtest.gen.foo.Handler;


@@ -38,7 +38,7 @@ public class TestServer implements Handler {
	public void runOne() {
	public void runOne() {
		
		
		try {
		try {
			LabCommDecoderChannel c = new LabCommDecoderChannel(in);
			DecoderChannel c = new DecoderChannel(in);
			foo.register(c,this);
			foo.register(c,this);
			c.runOne();
			c.runOne();
		} catch (Exception e) {
		} catch (Exception e) {
@@ -47,7 +47,7 @@ public class TestServer implements Handler {
	}
	}


	public void handle_foo(foo sample) throws Exception {
	public void handle_foo(foo sample) throws Exception {
		LabCommEncoderChannel e = new LabCommEncoderChannel(out );
		EncoderChannel e = new EncoderChannel(out );
		foo.register(e);
		foo.register(e);
		System.out.println("TestServer.handle_foo...");
		System.out.println("TestServer.handle_foo...");
		sample.b *= 2;
		sample.b *= 2;
+1 −1
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@ namespace RobotCtrl
            try
            try
            {
            {
                client.Connect(serverEndPoint);
                client.Connect(serverEndPoint);
                LabCommEncoder enc = new LabCommEncoderChannel(client.GetStream(), true);
                Encoder enc = new EncoderChannel(client.GetStream(), true);
                jointtarget.register(enc);
                jointtarget.register(enc);
                jointtarget.encode(enc, val);
                jointtarget.encode(enc, val);
                for (int i = 0; i < 10; i++)
                for (int i = 0; i < 10; i++)
+3 −3
Original line number Original line Diff line number Diff line
@@ -2,19 +2,19 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStream;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;


public class Decoder
public class Decoder
  implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler, doavoid.Handler
  implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler, doavoid.Handler


{
{


  LabCommDecoderChannel decoder;
  DecoderChannel decoder;


  public Decoder(InputStream in) 
  public Decoder(InputStream in) 
    throws Exception 
    throws Exception 
  {
  {
    decoder = new LabCommDecoderChannel(in);
    decoder = new DecoderChannel(in);
    theTwoInts.register(decoder, this);
    theTwoInts.register(decoder, this);
    anotherTwoInts.register(decoder, this);
    anotherTwoInts.register(decoder, this);
    IntString.register(decoder, this);
    IntString.register(decoder, this);
+3 −3
Original line number Original line Diff line number Diff line
@@ -2,19 +2,19 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStream;


import se.lth.control.labcomm2006.LabCommDecoderChannel;
import se.lth.control.labcomm2006.DecoderChannel;


public class Decoder06
public class Decoder06
  implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler
  implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler


{
{


  LabCommDecoderChannel decoder;
  DecoderChannel decoder;


  public Decoder06(InputStream in) 
  public Decoder06(InputStream in) 
    throws Exception 
    throws Exception 
  {
  {
    decoder = new LabCommDecoderChannel(in);
    decoder = new DecoderChannel(in);
    theTwoInts.register(decoder, this);
    theTwoInts.register(decoder, this);
    anotherTwoInts.register(decoder, this);
    anotherTwoInts.register(decoder, this);
    IntString.register(decoder, this);
    IntString.register(decoder, this);
+3 −3
Original line number Original line Diff line number Diff line
@@ -2,7 +2,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStream;


import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;


/**
/**
 * Simple encoder 
 * Simple encoder 
@@ -10,12 +10,12 @@ import se.lth.control.labcomm.LabCommEncoderChannel;
public class Encoder 
public class Encoder 
{
{


  LabCommEncoderChannel encoder;
  EncoderChannel encoder;


  public Encoder(OutputStream out) 
  public Encoder(OutputStream out) 
    throws Exception 
    throws Exception 
  {
  {
    encoder = new LabCommEncoderChannel(out);
    encoder = new EncoderChannel(out);
    theTwoInts.register(encoder);
    theTwoInts.register(encoder);
    IntString.register(encoder);
    IntString.register(encoder);
    TwoArrays.register(encoder);
    TwoArrays.register(encoder);
+3 −3
Original line number Original line Diff line number Diff line
@@ -2,7 +2,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStream;


import se.lth.control.labcomm2006.LabCommEncoderChannel;
import se.lth.control.labcomm2006.EncoderChannel;


/**
/**
 * Simple encoder 
 * Simple encoder 
@@ -10,12 +10,12 @@ import se.lth.control.labcomm2006.LabCommEncoderChannel;
public class Encoder06 
public class Encoder06 
{
{


  LabCommEncoderChannel encoder;
  EncoderChannel encoder;


  public Encoder06(OutputStream out) 
  public Encoder06(OutputStream out) 
    throws Exception 
    throws Exception 
  {
  {
    encoder = new LabCommEncoderChannel(out);
    encoder = new EncoderChannel(out);
    theTwoInts.register(encoder);
    theTwoInts.register(encoder);
    IntString.register(encoder);
    IntString.register(encoder);
    TwoArrays.register(encoder);
    TwoArrays.register(encoder);
+7 −0
Original line number Original line Diff line number Diff line
@@ -4,3 +4,10 @@ clean:


distclean:
distclean:
	rm -rf gen
	rm -rf gen
	rm -rf gen06
	rm -f *.class
	rm -f example_encoder
	rm -f example_encoder06
	rm -f example_decoder
	rm -f example_decoder06
	rm -f encoded_data
+5 −5
Original line number Original line Diff line number Diff line
@@ -5,22 +5,22 @@
(cd ../..; make all)
(cd ../..; make all)


mkdir -p gen
mkdir -p gen
java -jar ../../compiler/labComm.jar --java=gen --c=gen/simple.c --h=gen/simple.h  --python=gen/simple.py simple.lc 
java -jar ../../compiler/labcomm_compiler.jar --java=gen --c=gen/simple.c --h=gen/simple.h  --python=gen/simple.py simple.lc 


javac -cp ../../lib/java/labcomm2013.jar:. gen/*.java Encoder.java Decoder.java
javac -cp ../../lib/java/labcomm20141009.jar:. gen/*.java Encoder.java Decoder.java


gcc -Wall -Werror -Wno-unused-function \
gcc -Wall -Werror -Wno-unused-function \
    -I. -I../../lib/c -L../../lib/c \
    -I. -I../../lib/c -L../../lib/c \
    -o example_encoder example_encoder.c gen/simple.c \
    -o example_encoder example_encoder.c gen/simple.c \
    -llabcomm2013 -Tlabcomm.linkscript
    -llabcomm20141009 -Tlabcomm.linkscript
gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
    -o example_decoder example_decoder.c gen/simple.c \
    -o example_decoder example_decoder.c gen/simple.c \
    -llabcomm2013 -Tlabcomm.linkscript
    -llabcomm20141009 -Tlabcomm.linkscript


# For version 2006
# For version 2006


mkdir -p gen06
mkdir -p gen06
java -jar ../../compiler/labComm.jar --ver=2006 --java=gen06 --c=gen06/simple.c --h=gen06/simple.h  --python=gen06/simple.py simple.lc 
java -jar ../../compiler/labcomm_compiler.jar --ver=2006 --java=gen06 --c=gen06/simple.c --h=gen06/simple.h  --python=gen06/simple.py simple.lc 


javac -cp ../../lib/java/labcomm2006.jar:. gen06/*.java Encoder06.java Decoder06.java
javac -cp ../../lib/java/labcomm2006.jar:. gen06/*.java Encoder06.java Decoder06.java


+1 −1
Original line number Original line Diff line number Diff line
@@ -5,7 +5,7 @@ import sys
import simple
import simple


if __name__ == '__main__':
if __name__ == '__main__':
    version = sys.argv[2] if len(sys.argv) == 3 else "LabComm2013"
    version = sys.argv[2] if len(sys.argv) == 3 else "LabComm20141009"
    encoder = labcomm.Encoder(labcomm.StreamWriter(open(sys.argv[1], 'w')), version)
    encoder = labcomm.Encoder(labcomm.StreamWriter(open(sys.argv[1], 'w')), version)
    encoder.add_decl(simple.theTwoInts.signature)
    encoder.add_decl(simple.theTwoInts.signature)
    encoder.add_decl(simple.IntString.signature)
    encoder.add_decl(simple.IntString.signature)
+4 −4
Original line number Original line Diff line number Diff line
@@ -5,17 +5,17 @@ echo "*** Running example for version 2013 ***"
echo "********************************************"
echo "********************************************"
echo
echo


java -cp .:../../lib/java/labcomm2013.jar:gen Encoder encoded_data
java -cp .:../../lib/java/labcomm20141009.jar:gen Encoder encoded_data
./example_decoder encoded_data
./example_decoder encoded_data


PYTHONPATH=../../lib/python:gen ./example_encoder.py encoded_data
PYTHONPATH=../../lib/python:gen ./example_encoder.py encoded_data
java -cp .:../../lib/java/labcomm2013.jar:gen Decoder encoded_data
java -cp .:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data


./example_encoder encoded_data
./example_encoder encoded_data
java -cp .:../../lib/java/labcomm2013.jar:gen Decoder encoded_data
java -cp .:../../lib/java/labcomm20141009.jar:gen Decoder encoded_data


echo "running python decoder (from wiki_example):"
echo "running python decoder (from wiki_example):"
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm2013
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm20141009


echo
echo
echo "*******************************************************"
echo "*******************************************************"
+1 −1
Original line number Original line Diff line number Diff line
LCDIR=../..
LCDIR=../..
LCCJAR=${LCDIR}/compiler/labComm.jar  # the LabComm compiler
LCCJAR=${LCDIR}/compiler/labcomm_compiler.jar  # the LabComm compiler
LCLJAR=${LCDIR}/lib/java/labcomm.jar  # the LabComm library
LCLJAR=${LCDIR}/lib/java/labcomm.jar  # the LabComm library
JAVA_PKG=labcommTCPtest
JAVA_PKG=labcommTCPtest


+4 −4
Original line number Original line Diff line number Diff line
@@ -6,8 +6,8 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.UnknownHostException;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample.Handler;
import labcommTCPtest.gen.FooSample.Handler;


@@ -25,7 +25,7 @@ public class TestClient implements Handler {
	public void test() {
	public void test() {
		
		
		try {
		try {
			LabCommEncoderChannel e = new LabCommEncoderChannel(out );
			EncoderChannel e = new EncoderChannel(out );
			FooSample.register(e);
			FooSample.register(e);
			FooSample sample = new FooSample();
			FooSample sample = new FooSample();
			int a[] = new int[3];
			int a[] = new int[3];
@@ -42,7 +42,7 @@ public class TestClient implements Handler {
			printSample("Client sending", sample);
			printSample("Client sending", sample);
			FooSample.encode(e, sample);
			FooSample.encode(e, sample);


			LabCommDecoderChannel c = new LabCommDecoderChannel(in);
			DecoderChannel c = new DecoderChannel(in);
			FooSample.register(c,this);
			FooSample.register(c,this);
			c.runOne();
			c.runOne();
		} catch (Exception e) {
		} catch (Exception e) {
+4 −4
Original line number Original line Diff line number Diff line
@@ -6,8 +6,8 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.UnknownHostException;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample.Handler;
import labcommTCPtest.gen.FooSample.Handler;


@@ -25,7 +25,7 @@ public class TestClientSingleshot implements Handler {
	public void test() {
	public void test() {
		
		
		try {
		try {
			LabCommEncoderChannel e = new LabCommEncoderChannel(out );
			EncoderChannel e = new EncoderChannel(out );
			FooSample.register(e);
			FooSample.register(e);
			FooSample sample = new FooSample();
			FooSample sample = new FooSample();
			sample.x = 17;
			sample.x = 17;
@@ -35,7 +35,7 @@ public class TestClientSingleshot implements Handler {
			printSample("Client sending", sample);
			printSample("Client sending", sample);
			FooSample.encode(e, sample);
			FooSample.encode(e, sample);


			LabCommDecoderChannel c = new LabCommDecoderChannel(in);
			DecoderChannel c = new DecoderChannel(in);
			FooSample.register(c,this);
			FooSample.register(c,this);
			c.runOne();
			c.runOne();
		} catch (Exception e) {
		} catch (Exception e) {
+3 −3
Original line number Original line Diff line number Diff line
@@ -6,8 +6,8 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.Socket;
import java.net.ServerSocket;
import java.net.ServerSocket;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample;


public class OneShotServer {//implements Handler {
public class OneShotServer {//implements Handler {
@@ -21,7 +21,7 @@ public class OneShotServer {//implements Handler {
	public void test() {
	public void test() {
		
		
		try {
		try {
			LabCommEncoderChannel e = new LabCommEncoderChannel(out );
			EncoderChannel e = new EncoderChannel(out );
			FooSample.register(e);
			FooSample.register(e);
			FooSample sample = new FooSample();
			FooSample sample = new FooSample();
			sample.s = "OneShotServer message";
			sample.s = "OneShotServer message";
+4 −4
Original line number Original line Diff line number Diff line
@@ -8,8 +8,8 @@ import java.lang.reflect.Method;
import java.net.ServerSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.Socket;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample;
import labcommTCPtest.gen.FooSample.Handler;
import labcommTCPtest.gen.FooSample.Handler;


@@ -38,7 +38,7 @@ public class TestServer implements Handler {
	public void runOne() {
	public void runOne() {
		
		
		try {
		try {
			LabCommDecoderChannel c = new LabCommDecoderChannel(in);
			DecoderChannel c = new DecoderChannel(in);
			FooSample.register(c,this);
			FooSample.register(c,this);
			c.runOne();
			c.runOne();
		} catch (Exception e) {
		} catch (Exception e) {
@@ -47,7 +47,7 @@ public class TestServer implements Handler {
	}
	}


	public void handle_FooSample(FooSample sample) throws Exception {
	public void handle_FooSample(FooSample sample) throws Exception {
		LabCommEncoderChannel e = new LabCommEncoderChannel(out );
		EncoderChannel e = new EncoderChannel(out );
		FooSample.register(e);
		FooSample.register(e);
		System.out.println("TestServer.handle_FooSample: "+sample.s);
		System.out.println("TestServer.handle_FooSample: "+sample.s);
		int tmp[] = new int[2*sample.a.length];
		int tmp[] = new int[2*sample.a.length];
+1 −1
Original line number Original line Diff line number Diff line
TARGETS=client server
TARGETS=client server
LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM_JAR=../../compiler/labcomm_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR) 
LABCOMM=java -jar $(LABCOMM_JAR) 


CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I. -Wno-unused-function
CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I. -Wno-unused-function
+18 −18
Original line number Original line Diff line number Diff line
@@ -62,14 +62,13 @@ static void set_decimation(


static int wrap_reader_alloc(
static int wrap_reader_alloc(
  struct labcomm_reader *r, 
  struct labcomm_reader *r, 
  struct labcomm_reader_action_context *action_context, 
  struct labcomm_reader_action_context *action_context)
  char *labcomm_version)
{
{
  struct decimating_private *decimating = action_context->context;
  struct decimating_private *decimating = action_context->context;
  
  
  labcomm_decoder_register_decimating_messages_set_decimation(
  labcomm_decoder_register_decimating_messages_set_decimation(
    r->decoder, set_decimation, decimating);
    r->decoder, set_decimation, decimating);
  return labcomm_reader_alloc(r, action_context->next, labcomm_version);
  return labcomm_reader_alloc(r, action_context->next);
}
}


struct send_set_decimation {
struct send_set_decimation {
@@ -186,14 +185,13 @@ static void register_signatures(void *context)


static int wrap_writer_alloc(
static int wrap_writer_alloc(
  struct labcomm_writer *w, 
  struct labcomm_writer *w, 
  struct labcomm_writer_action_context *action_context, 
  struct labcomm_writer_action_context *action_context)
  char *labcomm_version)
{
{
  struct decimating_private *decimating = action_context->context;
  struct decimating_private *decimating = action_context->context;


  labcomm_scheduler_enqueue(decimating->scheduler, 
  labcomm_scheduler_enqueue(decimating->scheduler, 
			    0, register_signatures, decimating);
			    0, register_signatures, decimating);
  return labcomm_writer_alloc(w, action_context->next, labcomm_version);
  return labcomm_writer_alloc(w, action_context->next);
}
}


static int wrap_writer_start(
static int wrap_writer_start(
@@ -206,8 +204,10 @@ static int wrap_writer_start(
  struct decimation *decimation;
  struct decimation *decimation;
  int result;
  int result;


  if (index < LABCOMM_USER) {
    result = 0;
  } else {
    labcomm_scheduler_data_lock(decimating->scheduler);
    labcomm_scheduler_data_lock(decimating->scheduler);

    decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory, 
    decimation = LABCOMM_SIGNATURE_ARRAY_REF(decimating->memory, 
                                             decimating->writer_decimation, 
                                             decimating->writer_decimation, 
                                             struct decimation, index);
                                             struct decimation, index);
@@ -219,7 +219,7 @@ static int wrap_writer_start(
      result = 0;
      result = 0;
    }
    }
    labcomm_scheduler_data_unlock(decimating->scheduler);
    labcomm_scheduler_data_unlock(decimating->scheduler);

  }
  if (result == 0) {
  if (result == 0) {
    result = labcomm_writer_start(w, action_context->next,
    result = labcomm_writer_start(w, action_context->next,
				 index, signature, value);
				 index, signature, value);
+5 −7
Original line number Original line Diff line number Diff line
@@ -124,15 +124,14 @@ static void handles_signature(


static int wrap_reader_alloc(
static int wrap_reader_alloc(
  struct labcomm_reader *r, 
  struct labcomm_reader *r, 
  struct labcomm_reader_action_context *action_context, 
  struct labcomm_reader_action_context *action_context)
  char *labcomm_version)
{
{
  struct introspecting_private *introspecting = action_context->context;
  struct introspecting_private *introspecting = action_context->context;


  labcomm_decoder_register_introspecting_messages_handles_signature(
  labcomm_decoder_register_introspecting_messages_handles_signature(
    introspecting->introspecting.reader->decoder, 
    introspecting->introspecting.reader->decoder, 
    handles_signature, introspecting);
    handles_signature, introspecting);
  return labcomm_reader_alloc(r, action_context->next, labcomm_version);
  return labcomm_reader_alloc(r, action_context->next);
}
}


struct handles_signature {
struct handles_signature {
@@ -213,14 +212,13 @@ static void register_encoder_signatures(void *context)


static int wrap_writer_alloc(
static int wrap_writer_alloc(
  struct labcomm_writer *w, 
  struct labcomm_writer *w, 
  struct labcomm_writer_action_context *action_context, 
  struct labcomm_writer_action_context *action_context)
  char *labcomm_version)
{
{
  struct introspecting_private *introspecting = action_context->context;
  struct introspecting_private *introspecting = action_context->context;


  labcomm_scheduler_enqueue(introspecting->scheduler, 
  labcomm_scheduler_enqueue(introspecting->scheduler, 
			    0, register_encoder_signatures, introspecting);
			    0, register_encoder_signatures, introspecting);
  return labcomm_writer_alloc(w, action_context->next, labcomm_version);
  return labcomm_writer_alloc(w, action_context->next);
}
}


static int wrap_writer_start(
static int wrap_writer_start(
@@ -231,7 +229,7 @@ static int wrap_writer_start(
{
{
  struct introspecting_private *introspecting = action_context->context;
  struct introspecting_private *introspecting = action_context->context;


  if (value == NULL) {
  if (index >= LABCOMM_USER && value == NULL) {
    struct local *local;
    struct local *local;


    labcomm_scheduler_data_lock(introspecting->scheduler);
    labcomm_scheduler_data_lock(introspecting->scheduler);
+21 −4
Original line number Original line Diff line number Diff line
@@ -2,20 +2,23 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStream;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;


public class Decoder
public class Decoder
  implements twoLines.Handler
  implements twoLines.Handler, theint.Handler, Comment.Handler//, Typedef.Handler


{
{


  LabCommDecoderChannel decoder;
  DecoderChannel decoder;


  public Decoder(InputStream in) 
  public Decoder(InputStream in) 
    throws Exception 
    throws Exception 
  {
  {
    decoder = new LabCommDecoderChannel(in);
    decoder = new DecoderChannel(in);
    twoLines.register(decoder, this);
    twoLines.register(decoder, this);
    theint.register(decoder,this);
    Comment.register(decoder, this);
    //Typedef.register(decoder, this);


    try {
    try {
      System.out.println("Running decoder.");
      System.out.println("Running decoder.");
@@ -39,6 +42,20 @@ public class Decoder
    System.out.println("              Line l2: "+genLine(d.l2));
    System.out.println("              Line l2: "+genLine(d.l2));
  }
  }


  public void handle_theint(int d) throws java.io.IOException {
    System.out.println("Got theint: "+d);
  }

  public void handle_Comment(Comment c) throws java.io.IOException {
    System.out.print("Decoder got Comment: ");
    System.out.println("id: "+c.id);
    System.out.println("comment: "+c.comment);
  }

  //public void handle_Typedef(Typedef t) throws java.io.IOException {
  //  System.out.print("Decoder got Typedef: ");
  //  t.dump();
  //}


  public static void main(String[] arg) throws Exception {
  public static void main(String[] arg) throws Exception {
    Decoder example = new Decoder(
    Decoder example = new Decoder(
+26 −10
Original line number Original line Diff line number Diff line
@@ -2,21 +2,35 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStream;


import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.Encoder;
import se.lth.control.labcomm.EncoderChannel;


/**
/**
 * Simple encoder
 * Simple encoder
 */
 */
public class Encoder 
public class ExampleEncoder
{
{


  LabCommEncoderChannel encoder;
  EncoderChannel encoder;


  public Encoder(OutputStream out) 
  public ExampleEncoder(OutputStream out)
    throws Exception
    throws Exception
  {
  {
    encoder = new LabCommEncoderChannel(out);
    encoder = new EncoderChannel(out);
    twoLines.register(encoder);
    twoLines.register(encoder);
    theint.register(encoder);
    Encoder.PragmaPacketBuilder t = encoder.newPragma("se.lth.cs.sven.pragma");
    Comment.register(t);
    Comment c = new Comment();
    //c.id = encoder.getTypeId(twoLines.class);
    c.id = 42;
    c.comment = "Test comment";
    Comment.encode(t,c);
    t.send();
    t = encoder.newPragma(null);
    afoo.register(t);
    afoo.encode(t, new foo());
    t.send();
  }
  }


  public void doEncode() throws java.io.IOException {
  public void doEncode() throws java.io.IOException {
@@ -74,12 +88,14 @@ public class Encoder


    System.out.println("Encoding theTwoLines");
    System.out.println("Encoding theTwoLines");
    twoLines.encode(encoder, x);
    twoLines.encode(encoder, x);

    theint.encode(encoder, 1337);
  }
  }




  public static void main(String[] arg) throws Exception {
  public static void main(String[] arg) throws Exception {
    FileOutputStream fos = new FileOutputStream(arg[0]);
    FileOutputStream fos = new FileOutputStream(arg[0]);
    Encoder example = new Encoder(fos);
    ExampleEncoder example = new ExampleEncoder(fos);
    example.doEncode();
    example.doEncode();
    fos.close();
    fos.close();
  }
  }
+173 −2
Original line number Original line Diff line number Diff line
all:
LCDIR=../..
LCCJAR=${LCDIR}/compiler/labcomm_compiler.jar  # the LabComm compiler
LCLJAR=${LCDIR}/lib/java/labcomm.jar  # the LabComm library

EXECUTABLES=example_encoder example_decoder ExampleEncoder.class Decoder.class Encoder.exe Decoder.exe
include ${LCDIR}/lib/c/os_compat.mk

GENDIR=gen

.PHONY: all cleanbuild clean distclean build run allall buildcs runwcs

all: cleanbuild run

allall: clean build buildcs runwcs

###############################################
### dependencies and parts ####################
###############################################

LCC=java -jar ${LCCJAR}
CLASSPATH=.:${LCLJAR}

${LCCJAR} :
	$MAKE -C ${LCDIR} make-compiler

${LCLJAR} :
	$MAKE -C ${LCDIR} labcomm.jar


cleanbuild: clean build

labcomm.dll:
	ln -sf ../../lib/csharp/labcomm.dll $@

Encoder.exe: Encoder.cs gen/test.cs labcomm.dll Makefile
	mcs -out:$@ $(filter %.cs, $^) -lib:../../lib/csharp/ -r:labcomm
	chmod a+x $@

Decoder.exe: Decoder.cs gen/test.cs labcomm.dll Makefile
	mcs -out:$@ $(filter %.cs, $^) -lib:../../lib/csharp/ -r:labcomm
	chmod a+x $@

build : 
	mkdir -p ${GENDIR}
	java -jar ${LCDIR}/compiler/labcomm_compiler.jar --java=${GENDIR} --c=${GENDIR}/test.c --h=${GENDIR}/test.h  --python=${GENDIR}/test.py --cs=${GENDIR}/test.cs test.lc 

	javac -cp ${LCDIR}/lib/java/labcomm.jar:. ${GENDIR}/*.java ExampleEncoder.java Decoder.java

	${CC} ${CFLAGS} ${LDFLAGS} -Wall -Werror -Wno-unused-function \
	    -I. -I${LCDIR}/lib/c -L${LCDIR}/lib/c \
	    -o example_encoder example_encoder.c ${GENDIR}/test.c \
	    -llabcomm20141009 

	${CC} ${CFLAGS} ${LDFLAGS} -Wall -Werror -I . -I ${LCDIR}/lib/c -L${LCDIR}/lib/c \
	    -o example_decoder example_decoder.c ${GENDIR}/test.c \
	    -llabcomm20141009 

buildcs: Encoder.exe Decoder.exe

run:
	export LD_LIBRARY_PATH=${LCDIR}/lib/c/
	@echo
	@echo "********************************************"
	@echo "***   ************ running example for version 2014   ***"
	@echo "********************************************"
	@echo

	@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} ExampleEncoder encoded_data_j

	@echo "************ running Java  decoder: *****************"
	@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_j

	@echo "************ running C decoder: *****************"
	@./example_decoder encoded_data_j

	@echo "************ running python decoder (from wiki_example):"
	@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_j LabComm20141009

	@echo "************ running C encoder: *****************"
	@./example_encoder encoded_data_c

	@echo "************ running Java  decoder: *****************"
	@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_c

	@echo "************ running C decoder: *****************"
	@./example_decoder encoded_data_c

	@echo "************ running python decoder (from wiki_example):"
	@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm20141009

	@echo "************ running python encoder: *****************"
	@PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm20141009

	@echo "************ running Java  decoder: *****************"
	@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_p

	@echo "************ running C decoder: *****************"
	@./example_decoder encoded_data_p

	@echo "************ running python decoder (from wiki_example):"
	PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm20141009

runwcs: Encoder.exe Decoder.exe
	export LD_LIBRARY_PATH=${LCDIR}/lib/c/
	@echo
	@echo "********************************************"
	@echo "***   ************ running example for version 2014   ***"
	@echo "********************************************"
	@echo

	@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} ExampleEncoder encoded_data_j

	@echo "************ running Java  decoder: *****************"
	@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_j

	@echo "************ running C decoder: *****************"
	@./example_decoder encoded_data_j

	@echo "************ running python decoder (from wiki_example):"
	@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_j LabComm2014

	@echo "************ running C# decoder: *****************"
	@./Decoder.exe encoded_data_j

	@echo "************ running C encoder: *****************"
	@./example_encoder encoded_data_c

	@echo "************ running Java  decoder: *****************"
	@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_c

	@echo "************ running C decoder: *****************"
	@./example_decoder encoded_data_c

	@echo "************ running python decoder (from wiki_example):"
	@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_c LabComm20141009

	@echo "************ running C# decoder: *****************"
	@./Decoder.exe encoded_data_c

	@echo "************ running python encoder: *****************"
	@PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm20141009

	@echo "************ running Java  decoder: *****************"
	@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_p

	@echo "************ running C decoder: *****************"
	@./example_decoder encoded_data_p

	@echo "************ running python decoder (from wiki_example):"
	PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm20141009

	@echo "************ running C# decoder: *****************"
	@./Decoder.exe encoded_data_p

	@echo "************ running C# encoder: *****************"
	@./Encoder.exe encoded_data_cs

	@echo "************ running Java  decoder: *****************"
	@java -cp .:${LCDIR}/lib/java/labcomm.jar:${GENDIR} Decoder encoded_data_cs

	@echo "************ running C decoder: *****************"
	@./example_decoder encoded_data_cs

	@echo "************ running python decoder (from wiki_example):"
	@PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_cs LabComm20141009

	@echo "************ running C# decoder: *****************"
	@./Decoder.exe encoded_data_cs




clean:
clean:
	rm -rf ${GENDIR}


distclean:
distclean: clean
	rm -f ${EXECUTABLES}

examples/user_types/compile.sh

deleted100644 → 0
+0 −22
Original line number Original line Diff line number Diff line
### Example compile script, showing the steps required to build a labcomm application
### (including compiler and libs).

# For current version (2013)
(cd ../..; make all)

mkdir -p gen
java -jar ../../compiler/labComm.jar --java=gen --c=gen/test.c --h=gen/test.h  --python=gen/test.py test.lc 

javac -cp ../../lib/java/labcomm2013.jar:. gen/*.java Encoder.java Decoder.java

# for macOS, add     -DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
gcc -Wall -Werror -Wno-unused-function \
    -I. -I../../lib/c -L../../lib/c \
    -o example_encoder example_encoder.c gen/test.c \
    -llabcomm2013 

gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
    -o example_decoder example_decoder.c gen/test.c \
    -llabcomm2013 
    #-Tlabcomm.linkscript
+10 −0
Original line number Original line Diff line number Diff line
@@ -15,6 +15,14 @@ static void handle_test_twoLines(test_twoLines *v,void *context) {
                                                                     v->l2.end.x.val, v->l2.end.y.val);    
                                                                     v->l2.end.x.val, v->l2.end.y.val);    
}
}


static void handle_test_theint(test_theint *v,void *context) {
  printf("Got theint. %d\n", *v); 
}

static void handle_test_Comment(test_Comment *v,void *context) {
  printf("Got comment (0x%x): %s\n", v->id, v->comment);
}

int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
  int fd;
  int fd;
  struct labcomm_decoder *decoder;
  struct labcomm_decoder *decoder;
@@ -34,6 +42,8 @@ int main(int argc, char *argv[]) {
  }
  }


  labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context);
  labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context);
  labcomm_decoder_register_test_theint(decoder, handle_test_theint, context);
  labcomm_decoder_register_test_Comment(decoder, handle_test_Comment, context);


  printf("Decoding:\n");
  printf("Decoding:\n");
  labcomm_decoder_run(decoder);
  labcomm_decoder_run(decoder);
+11 −0
Original line number Original line Diff line number Diff line
@@ -8,6 +8,7 @@
#include "gen/test.h"
#include "gen/test.h"
#include <stdio.h>
#include <stdio.h>


extern struct labcomm_signature labcomm_signature_test_twoLines;
int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
  int fd;
  int fd;
  struct labcomm_encoder *encoder;
  struct labcomm_encoder *encoder;
@@ -22,6 +23,16 @@ int main(int argc, char *argv[]) {
				labcomm_default_scheduler);
				labcomm_default_scheduler);
  labcomm_encoder_register_test_twoLines(encoder);
  labcomm_encoder_register_test_twoLines(encoder);


#ifndef WITHOUT_PRAGMA
  struct labcomm_encoder *pb = labcomm_pragma_builder_new(encoder,
		  "se.lth.cs.sven.pragma");
  labcomm_encoder_register_test_Comment(pb);
  test_Comment comment;
  comment.id = 17;
  comment.comment = "This is a metadata comment...";
  labcomm_encode_test_Comment(pb, &comment);
  labcomm_pragma_send(pb);
#endif
  test_twoLines tl;
  test_twoLines tl;


  tl.l1.start.x.val = 11;
  tl.l1.start.x.val = 11;
+1 −1
Original line number Original line Diff line number Diff line
@@ -5,7 +5,7 @@ import sys
import test
import test


if __name__ == '__main__':
if __name__ == '__main__':
    version = sys.argv[2] if len(sys.argv) == 3 else "LabComm2013"
    version = sys.argv[2] if len(sys.argv) == 3 else "LabComm20141009"
    encoder = labcomm.Encoder(labcomm.StreamWriter(open(sys.argv[1], 'w')), version)
    encoder = labcomm.Encoder(labcomm.StreamWriter(open(sys.argv[1], 'w')), version)
    encoder.add_decl(test.twoLines.signature)
    encoder.add_decl(test.twoLines.signature)
    tl = dict(
    tl = dict(

examples/user_types/run.sh

deleted100644 → 0
+0 −39
Original line number Original line Diff line number Diff line
export LD_LIBRARY_PATH=../../lib/c/
echo
echo "********************************************"
echo "***   Running example for version 2013   ***"
echo "********************************************"
echo

java -cp .:../../lib/java/labcomm2013.jar:gen Encoder encoded_data

echo "running Java  decoder:"
java -cp .:../../lib/java/labcomm2013.jar:gen Decoder encoded_data

echo "running C decoder:"
./example_decoder encoded_data

echo "running python decoder (from wiki_example):"
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm2013

echo "running C encoder:"
./example_encoder encoded_data

echo "running Java  decoder:"
java -cp .:../../lib/java/labcomm2013.jar:gen Decoder encoded_data

echo "running C decoder:"
./example_decoder encoded_data

echo "running python decoder (from wiki_example):"
PYTHONPATH=../../lib/python ../wiki_example/example_decoder.py encoded_data LabComm2013

echo "running python encoder:"
PYTHONPATH=../../lib/python:gen ./example_encoder.py encoded_data2

echo "running Java  decoder:"
java -cp .:../../lib/java/labcomm2013.jar:gen Decoder encoded_data2

echo "running C decoder:"
./example_decoder encoded_data2
+22 −2
Original line number Original line Diff line number Diff line
@@ -12,14 +12,34 @@ typedef struct {
  point end;
  point end;
} line;
} line;


typedef int anint;

typedef struct {
typedef struct {
  int a;
  anint a;
  int b;
  anint b;
  boolean c;
  boolean c;
} foo;
} foo;


sample anint theint;

sample struct {
sample struct {
  line l1;
  line l1;
  line l2;
  line l2;
  foo  f;
  foo  f;
} twoLines;
} twoLines;

sample line fixedLineArray[2];

sample line varLineArray[_];

sample struct {
  int x;
  int y;
} structArray[2];

sample struct {
  int id;
  string comment;
} Comment;   // For use in metadata

sample foo afoo; // to test unregistered metadata
+14 −14
Original line number Original line Diff line number Diff line
@@ -2,27 +2,27 @@
sample float data;
sample float data;
*/
*/
import java.io.IOException;
import java.io.IOException;
import se.lth.control.labcomm.LabCommDecoder;
import se.lth.control.labcomm.Decoder;
import se.lth.control.labcomm.LabCommDispatcher;
import se.lth.control.labcomm.Dispatcher;
import se.lth.control.labcomm.LabCommEncoder;
import se.lth.control.labcomm.Encoder;
import se.lth.control.labcomm.LabCommHandler;
import se.lth.control.labcomm.Handler;
import se.lth.control.labcomm.LabCommSample;
import se.lth.control.labcomm.Sample;


public class data implements LabCommSample {
public class data implements Sample {


  public interface Handler extends LabCommHandler {
  public interface Handler extends Handler {
    public void handle_data(float value) throws Exception;
    public void handle_data(float value) throws Exception;
  }
  }
  
  
  public static void register(LabCommDecoder d, Handler h) throws IOException {
  public static void register(Decoder d, Handler h) throws IOException {
    d.register(new Dispatcher(), h);
    d.register(new Dispatcher(), h);
  }
  }
  
  
  public static void register(LabCommEncoder e) throws IOException {
  public static void register(Encoder e) throws IOException {
    e.register(new Dispatcher());
    e.register(new Dispatcher());
  }
  }
  
  
  private static class Dispatcher implements LabCommDispatcher {
  private static class Dispatcher implements Dispatcher {
    
    
    public Class getSampleClass() {
    public Class getSampleClass() {
      return data.class;
      return data.class;
@@ -36,20 +36,20 @@ public class data implements LabCommSample {
      return signature;
      return signature;
    }
    }
    
    
    public void decodeAndHandle(LabCommDecoder d,
    public void decodeAndHandle(Decoder d,
                                LabCommHandler h) throws Exception {
                                Handler h) throws Exception {
      ((Handler)h).handle_data(data.decode(d));
      ((Handler)h).handle_data(data.decode(d));
    }
    }
    
    
  }
  }
  
  
  public static void encode(LabCommEncoder e, float value) throws IOException {
  public static void encode(Encoder e, float value) throws IOException {
    e.begin(data.class);
    e.begin(data.class);
    e.encodeFloat(value);
    e.encodeFloat(value);
    e.end(data.class);
    e.end(data.class);
  }
  }
  
  
  public static float decode(LabCommDecoder d) throws IOException {
  public static float decode(Decoder d) throws IOException {
    float result;
    float result;
    result = d.decodeFloat();
    result = d.decodeFloat();
    return result;
    return result;
+1 −1
Original line number Original line Diff line number Diff line
@@ -4,7 +4,7 @@ import labcomm
import sys
import sys


if __name__ == "__main__":
if __name__ == "__main__":
    version = sys.argv[2] if len(sys.argv) == 3 else "LabComm2013"
    version = sys.argv[2] if len(sys.argv) == 3 else "LabComm20141009"
    d = labcomm.Decoder(labcomm.StreamReader(open(sys.argv[1])), version)
    d = labcomm.Decoder(labcomm.StreamReader(open(sys.argv[1])), version)


    while True:
    while True:
+6 −6
Original line number Original line Diff line number Diff line
@@ -4,24 +4,24 @@ import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStream;


import se.lth.control.labcomm.LabCommDecoderChannel;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.LabCommEncoderChannel;
import se.lth.control.labcomm.EncoderChannel;


public class example_decoder_encoder 
public class example_decoder_encoder 
  implements data.Handler, log_message.Handler 
  implements data.Handler, log_message.Handler 
{
{


  LabCommDecoderChannel decoder;
  DecoderChannel decoder;
  LabCommEncoderChannel encoder;
  EncoderChannel encoder;


  public example_decoder_encoder(InputStream in, OutputStream out) 
  public example_decoder_encoder(InputStream in, OutputStream out) 
    throws Exception 
    throws Exception 
  {
  {
    decoder = new LabCommDecoderChannel(in);
    decoder = new DecoderChannel(in);
    log_message.register(decoder, this);
    log_message.register(decoder, this);
    data.register(decoder, this);
    data.register(decoder, this);


    encoder = new LabCommEncoderChannel(out);
    encoder = new EncoderChannel(out);
    log_message.register(encoder);
    log_message.register(encoder);
    data.register(encoder);
    data.register(encoder);
 
 
+2 −0
Original line number Original line Diff line number Diff line
@@ -10,8 +10,10 @@ clean:
	cd c ; make clean
	cd c ; make clean
	cd csharp ; make clean
	cd csharp ; make clean
	cd java ; make clean
	cd java ; make clean
	$(MAKE) -C python clean


distclean:
distclean:
	cd c ; make distclean
	cd c ; make distclean
	cd csharp ; make clean
	cd csharp ; make clean
	cd java ; make clean
	cd java ; make clean
	$(MAKE) -C python clean
+1 −1
Original line number Original line Diff line number Diff line
@@ -34,7 +34,7 @@ or
	$ VAR Encoder e;
	$ VAR Encoder e;
	$ Init_Encoder e, st;
	$ Init_Encoder e, st;
This will read/write the version of LabComm to ensure compatibility, current
This will read/write the version of LabComm to ensure compatibility, current
version is "LabComm2013".
version is "LabComm20141009".


# Initiate the labcomm samples:
# Initiate the labcomm samples:
LabComm trusts the application to manage each sample. It requests the samples,
LabComm trusts the application to manage each sample. It requests the samples,
Loading