Commit 1812c7dc authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Removed debugging cruft.

parent 6ac4ee60
......@@ -84,188 +84,77 @@ void labcomm_decoder_free(struct labcomm_decoder* d)
labcomm_memory_free(memory, 0, d);
}
static int collect_flat_signature(
struct labcomm_decoder *decoder,
struct labcomm_writer *writer)
{
int result, type;
type = labcomm_read_packed32(decoder->reader);
result = decoder->reader->error;
if (result < 0) { goto out; }
if (type >= LABCOMM_USER) {
decoder->on_error(LABCOMM_ERROR_UNIMPLEMENTED_FUNC, 3,
"Implement %s ... (1) for type 0x%x\n",
__FUNCTION__, type);
} else {
labcomm_write_packed32(writer, type);
switch (type) {
case LABCOMM_ARRAY: {
int dimensions, i;
dimensions = labcomm_read_packed32(decoder->reader);
labcomm_write_packed32(writer, dimensions);
for (i = 0 ; i < dimensions ; i++) {
int n = labcomm_read_packed32(decoder->reader);
labcomm_write_packed32(writer, n);
}
result = collect_flat_signature(decoder, writer);
if (result < 0) { goto out; }
} break;
case LABCOMM_STRUCT: {
int fields, i;
fields = labcomm_read_packed32(decoder->reader);
labcomm_write_packed32(writer, fields);
for (i = 0 ; i < fields ; i++) {
char *name = labcomm_read_string(decoder->reader);
labcomm_write_string(writer, name);
labcomm_memory_free(decoder->memory, 1, name);
result = collect_flat_signature(decoder, writer);
if (result < 0) { goto out; }
}
} break;
case LABCOMM_BOOLEAN:
case LABCOMM_BYTE:
case LABCOMM_SHORT:
case LABCOMM_INT:
case LABCOMM_LONG:
case LABCOMM_FLOAT:
case LABCOMM_DOUBLE:
case LABCOMM_STRING: {
} break;
default: {
result = -ENOSYS;
decoder->on_error(LABCOMM_ERROR_UNIMPLEMENTED_FUNC, 3,
"Implement %s (2) for type 0x%x...\n",
__FUNCTION__, type);
} break;
}
}
out:
return result;
}
static int writer_ioctl(struct labcomm_writer *writer,
uint32_t action,
...)
{
int result;
va_list va;
if (LABCOMM_IOC_SIG(action) != LABCOMM_IOC_NOSIG) {
result = -EINVAL;
goto out;
}
va_start(va, action);
result = labcomm_writer_ioctl(writer, writer->action_context,
0, NULL, action, va);
va_end(va);
out:
return result;
}
static int decode_sample(struct labcomm_decoder *d, int kind)
{
int result;
/* TODO: should the labcomm_dynamic_buffer_writer be
a permanent part of labcomm_decoder? */
struct labcomm_writer_action_context action_context = {
.next = NULL,
.action = labcomm_dynamic_buffer_writer_action,
.context = NULL
};
struct labcomm_writer writer = {
.action_context = &action_context,
.memory = d->memory,
.data = NULL,
.data_size = 0,
.count = 0,
.pos = 0,
.error = 0,
};
struct labcomm_signature signature, *local_signature;
int remote_index, local_index, err, length;
int remote_index, local_index, i;
local_signature = NULL;
local_index = 0;
labcomm_writer_alloc(&writer, writer.action_context, "");
labcomm_writer_start(&writer, writer.action_context, 0, NULL, NULL);
remote_index = labcomm_read_packed32(d->reader);
if (d->reader->error < 0) {
result = d->reader->error;
goto out;
}
signature.name = labcomm_read_string(d->reader);
length = labcomm_read_packed32(d->reader);
fprintf(stderr, "SIGNATURE_LENGTH=%d\n", length);
collect_flat_signature(d, &writer);
labcomm_writer_end(&writer, writer.action_context);
err = writer_ioctl(&writer,
LABCOMM_IOCTL_WRITER_GET_BYTES_WRITTEN,
&signature.size);
if (err < 0) {
d->on_error(LABCOMM_ERROR_BAD_WRITER, 2,
"Failed to get size: %s\n", strerror(-err));
result = -ENOENT;
goto free_signature_name;
if (d->reader->error < 0) {
result = d->reader->error;
goto out;
}
err = writer_ioctl(&writer,
LABCOMM_IOCTL_WRITER_GET_BYTE_POINTER,
&signature.signature);
if (err < 0) {
d->on_error(LABCOMM_ERROR_BAD_WRITER, 2,
"Failed to get pointer: %s\n", strerror(-err));
result = -ENOENT;
signature.size = labcomm_read_packed32(d->reader);
if (d->reader->error < 0) {
result = d->reader->error;
goto out;
}
signature.signature = labcomm_memory_alloc(d->memory, 1, signature.size);
if (d->reader->error < 0) {
result = d->reader->error;
goto free_signature_name;
}
{
int i;
labcomm_scheduler_data_lock(d->scheduler);
LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local, struct sample_entry, i) {
struct sample_entry *s;
int *remote_to_local;
for (i = 0 ; i < signature.size ; i++) {
signature.signature[i] = labcomm_read_byte(d->reader);
if (d->reader->error < 0) {
result = d->reader->error;
goto free_signature_signature;
}
}
labcomm_scheduler_data_lock(d->scheduler);
LABCOMM_SIGNATURE_ARRAY_FOREACH(d->local, struct sample_entry, i) {
struct sample_entry *s;
int *remote_to_local;
result = -ENOENT;
s = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
result = -ENOENT;
s = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->local, struct sample_entry, i);
if (s->signature &&
s->signature->size == signature.size &&
strcmp(s->signature->name, signature.name) == 0 &&
memcmp((void*)s->signature->signature, (void*)signature.signature,
if (s->signature &&
s->signature->size == signature.size &&
strcmp(s->signature->name, signature.name) == 0 &&
memcmp((void*)s->signature->signature, (void*)signature.signature,
signature.size) == 0) {
s->remote_index = remote_index;
local_signature = s->signature;
local_index = i;
remote_to_local = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local, int,
remote_index);
*remote_to_local = i;
result = remote_index;
break;
}
}
labcomm_scheduler_data_unlock(d->scheduler);
if (local_signature) {
labcomm_reader_start(d->reader, d->reader->action_context,
local_index, remote_index, local_signature,
NULL);
labcomm_reader_end(d->reader, d->reader->action_context);
s->remote_index = remote_index;
local_signature = s->signature;
local_index = i;
remote_to_local = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
d->remote_to_local, int,
remote_index);
*remote_to_local = i;
result = remote_index;
break;
}
}
#if 0
if (! entry) {
/* Unknown datatype, bail out */
d->on_new_datatype(d, &signature);
result = -ENOENT;
} else if (entry->index && entry->index != remote_index) {
d->on_error(LABCOMM_ERROR_DEC_INDEX_MISMATCH, 5,
"%s(): index mismatch '%s' (id=0x%x != 0x%x)\n",
__FUNCTION__, signature.name, entry->index, remote_index);
result = -ENOENT;
#endif
labcomm_scheduler_data_unlock(d->scheduler);
if (local_signature) {
labcomm_reader_start(d->reader, d->reader->action_context,
local_index, remote_index, local_signature,
NULL);
labcomm_reader_end(d->reader, d->reader->action_context);
}
free_signature_signature:
labcomm_memory_free(d->memory, 1, signature.signature);
free_signature_name:
labcomm_memory_free(d->memory, 0, signature.name);
labcomm_writer_free(&writer, writer.action_context);
out:
return result;
}
......@@ -302,7 +191,7 @@ static void reader_alloc(struct labcomm_decoder *d)
int labcomm_decoder_decode_one(struct labcomm_decoder *d)
{
int result, remote_index, length;
int result, remote_index, length __attribute__((__unused__));
reader_alloc(d);
remote_index = labcomm_read_packed32(d->reader);
......@@ -315,7 +204,6 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
result = d->reader->error;
goto out;
}
fprintf(stderr, "LENGTH=%d\n", length);
if (remote_index == LABCOMM_SAMPLE) {
result = decode_sample(d, remote_index);
} else {
......
......@@ -92,17 +92,6 @@ int labcomm_internal_encoder_register(
labcomm_size_string(signature->name) +
labcomm_size_packed32(signature->size) +
signature->size);
{
fprintf(stderr, "LENGTH(%s, %d)=%d %d %d %d -> %d\n",
signature->name, index,
labcomm_size_packed32(index),
labcomm_size_string(signature->name),
labcomm_size_packed32(signature->size),
signature->size,
length);
}
labcomm_write_packed32(e->writer, length);
labcomm_write_packed32(e->writer, index);
labcomm_write_string(e->writer, signature->name);
......@@ -130,15 +119,7 @@ int labcomm_internal_encode(
int result, index, length;
index = labcomm_get_local_index(signature);
/* FIXME: try to gt rid of labcomm_size_packed32(index) in
labcomm_sizeof_* (since that calculation is currently
wrong [length field not accounted for]) */
length = (signature->encoded_size(value));
{
fprintf(stderr, "LENGTH(%s, %d)=%d\n",
signature->name, index,
length);
}
labcomm_scheduler_writer_lock(e->scheduler);
result = labcomm_writer_start(e->writer, e->writer->action_context,
index, signature, value);
......
......@@ -25,20 +25,13 @@ namespace se.lth.control.labcomm {
while (!done) {
int tag = decodePacked32();
int length = decodePacked32();
Console.Error.WriteLine(" tag=" + tag + "length=" + length);
switch (tag) {
case LabComm.SAMPLE: {
int index = decodePacked32();
String name = decodeString();
int signature_length = decodePacked32();
// MemoryStream signature = new MemoryStream();
byte[] signature = new byte[signature_length];
// collectFlatSignature(new LabCommEncoderChannel(signature, false));
ReadBytes(signature, signature_length);
Console.Error.WriteLine("REMOTE:" + name + " " +
signature_length + " " +
signature);
// registry.add(index, name, signature.ToArray());
registry.add(index, name, signature);
} break;
default: {
......@@ -67,42 +60,6 @@ namespace se.lth.control.labcomm {
}
}
private void collectFlatSignature(LabCommEncoder e) {
int type = decodePacked32();
e.encodePacked32(type);
switch (type) {
case LabComm.ARRAY: {
int dimensions = decodePacked32();
e.encodePacked32(dimensions);
for (int i = 0 ; i < dimensions ; i++) {
e.encodePacked32(decodePacked32());
}
collectFlatSignature(e);
} break;
case LabComm.STRUCT: {
int fields = decodePacked32();
e.encodePacked32(fields);
for (int i = 0 ; i < fields ; i++) {
e.encodeString(decodeString());
collectFlatSignature(e);
}
} break;
case LabComm.BOOLEAN:
case LabComm.BYTE:
case LabComm.SHORT:
case LabComm.INT:
case LabComm.LONG:
case LabComm.FLOAT:
case LabComm.DOUBLE:
case LabComm.STRING: {
} break;
default: {
throw new IOException("Unimplemented type=" + type);
}
}
e.end(null);
}
public void register(LabCommDispatcher dispatcher,
LabCommHandler handler) {
registry.add(dispatcher, handler);
......
......@@ -42,8 +42,6 @@ namespace se.lth.control.labcomm {
private void begin(int tag) {
current_tag = tag;
bytes.SetLength(0);
Console.Error.WriteLine("BEGIN CURRENT=" + current_tag + " TAG=" + tag +
"LENGTH=" + bytes.Length);
}
public void begin(Type c) {
......@@ -51,8 +49,6 @@ namespace se.lth.control.labcomm {
}
public void end(Type c) {
Console.Error.WriteLine("END CURRENT=" + current_tag +
"LENGTH=" + bytes.Length);
WritePacked32(writer, current_tag);
WritePacked32(writer, bytes.Length);
bytes.WriteTo(writer);
......@@ -61,7 +57,6 @@ namespace se.lth.control.labcomm {
}
private void WritePacked32(Stream s, Int64 value) {
Console.Error.WriteLine("PACKED=" + value);
Int64 v = value & 0xffffffff;
int i;
......
......@@ -32,11 +32,8 @@ public class LabCommDecoderChannel implements LabCommDecoder {
int index = decodePacked32();
String name = decodeString();
int signature_length = decodePacked32();
// ByteArrayOutputStream signature = new ByteArrayOutputStream();
byte[] signature = new byte[signature_length];
// collectFlatSignature(new LabCommEncoderChannel(signature, false));
ReadBytes(signature, signature_length);
// registry.add(index, name, signature.toByteArray());
registry.add(index, name, signature);
} break;
default: {
......@@ -65,42 +62,6 @@ public class LabCommDecoderChannel implements LabCommDecoder {
}
}
private void collectFlatSignature(LabCommEncoder out) throws IOException {
int type = decodePacked32();
out.encodePacked32(type);
switch (type) {
case LabComm.ARRAY: {
int dimensions = decodePacked32();
out.encodePacked32(dimensions);
for (int i = 0 ; i < dimensions ; i++) {
out.encodePacked32(decodePacked32());
}
collectFlatSignature(out);
} break;
case LabComm.STRUCT: {
int fields = decodePacked32();
out.encodePacked32(fields);
for (int i = 0 ; i < fields ; i++) {
out.encodeString(decodeString());
collectFlatSignature(out);
}
} break;
case LabComm.BOOLEAN:
case LabComm.BYTE:
case LabComm.SHORT:
case LabComm.INT:
case LabComm.LONG:
case LabComm.FLOAT:
case LabComm.DOUBLE:
case LabComm.STRING: {
} break;
default: {
throw new IOException("Unimplemented type=" + type);
}
}
out.end(null);
}
public void register(LabCommDispatcher dispatcher,
LabCommHandler handler) throws IOException {
registry.add(dispatcher, handler);
......
......@@ -56,8 +56,6 @@ public class LabCommEncoderChannel implements LabCommEncoder {
private void begin(int tag) {
current_tag = tag;
bytes.reset();
System.err.println("BEGIN CURRENT=" + current_tag + " TAG=" + tag +
"LENGTH=" + bytes.size());
}
public void begin(Class<? extends LabCommSample> c) throws IOException {
......@@ -66,8 +64,6 @@ public class LabCommEncoderChannel implements LabCommEncoder {
public void end(Class<? extends LabCommSample> c) throws IOException {
data.flush();
System.err.println("END CURRENT=" + current_tag + " " +
"LENGTH=" + bytes.size());
WritePacked32(writer, current_tag);
WritePacked32(writer, bytes.size());
writer.write(bytes.toByteArray());
......
......@@ -123,8 +123,6 @@ class length_encoder:
return Encoder(self)
def __exit__(self, type, value, traceback):
import sys
print>>sys.stderr, [ len(self.data), self.data ]
if usePacketLength(self.version):
self.encoder.encode_packed32(len(self.data))
self.encoder.pack("%ds" % len(self.data), self.data)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment