From 6b6da1cec13215b1788bd7c37e545846738b53c1 Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Wed, 26 Nov 2014 10:50:04 +0100
Subject: [PATCH] temporarily unbroke java register: stop sending type defs

---
 .../lth/control/labcomm/EncoderChannel.java   | 21 +++++++++++--------
 .../lth/control/labcomm/SampleDispatcher.java |  6 ++++++
 lib/python/labcomm/LabComm.py                 |  2 +-
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/lib/java/se/lth/control/labcomm/EncoderChannel.java b/lib/java/se/lth/control/labcomm/EncoderChannel.java
index 5949b1a..08f9c87 100644
--- a/lib/java/se/lth/control/labcomm/EncoderChannel.java
+++ b/lib/java/se/lth/control/labcomm/EncoderChannel.java
@@ -27,16 +27,19 @@ public class EncoderChannel implements Encoder {
   }
 
   public void register(SampleDispatcher dispatcher) throws IOException {
-    int index = def_registry.add(dispatcher);
-    begin(Constant.SAMPLE_DEF);
-    encodePacked32(index);
-    encodeString(dispatcher.getName());
-    byte[] signature = dispatcher.getSignature();
-    encodePacked32(signature.length);
-    for (int i = 0 ; i < signature.length ; i++) {
-      encodeByte(signature[i]);
+    if(dispatcher.getTypeDeclTag() == Constant.SAMPLE_DEF) {
+        int index = def_registry.add(dispatcher);
+        //begin(Constant.SAMPLE_DEF);
+        begin(dispatcher.getTypeDeclTag());
+        encodePacked32(index);
+        encodeString(dispatcher.getName());
+        byte[] signature = dispatcher.getSignature();
+        encodePacked32(signature.length);
+        for (int i = 0 ; i < signature.length ; i++) {
+        encodeByte(signature[i]);
+        }
+        end(null);
     }
-    end(null);
   }
 
   public void registerSampleRef(SampleDispatcher dispatcher) throws IOException {
diff --git a/lib/java/se/lth/control/labcomm/SampleDispatcher.java b/lib/java/se/lth/control/labcomm/SampleDispatcher.java
index a878828..8870349 100644
--- a/lib/java/se/lth/control/labcomm/SampleDispatcher.java
+++ b/lib/java/se/lth/control/labcomm/SampleDispatcher.java
@@ -11,5 +11,11 @@ public interface SampleDispatcher <T> {
   public void decodeAndHandle(Decoder decoder,
 			      SampleHandler handler) throws Exception;
 
+  /** return the tag SAMPLE_DEF or TYPE_DEF, for use
+   *  by encoder.register.
+   *  TODO: refactor types, moving this to a super-interface
+   *  applicable to both type and sample defs.
+   */ 
+  public byte getTypeDeclTag();
 }
 
diff --git a/lib/python/labcomm/LabComm.py b/lib/python/labcomm/LabComm.py
index c45e705..c4b353c 100644
--- a/lib/python/labcomm/LabComm.py
+++ b/lib/python/labcomm/LabComm.py
@@ -848,7 +848,7 @@ class Decoder(Codec):
             decl = self.index_to_decl[index].decode_decl(self)
             value = None
         elif index < i_USER:
-            raise exception("Invalid type index %d" % index)
+            raise Exception("Invalid type index %d" % index)
         else:
             decl = self.index_to_decl[index]
             value = decl.decode(self)
-- 
GitLab