Commit 7ef98a98 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Major C# rename spree.

parent a42235a0
...@@ -268,7 +268,7 @@ aspect CS_Class { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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);
......
...@@ -24,7 +24,7 @@ namespace RobotCtrl ...@@ -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++)
......
MODULES=LabCommDispatcher \ MODULES=Constant\
LabCommDecoderRegistry \ Decoder \
LabComm \ DecoderChannel \
LabCommSample \ DecoderRegistry \
LabCommHandler \ Encoder \
LabCommEncoderRegistry \ EncoderChannel \
LabCommDecoder \ EncoderRegistry \
LabCommType \ Sample \
LabCommEncoderChannel \ SampleDispatcher \
LabCommEncoder \ SampleHandler \
LabCommDecoderChannel \ SampleType
all: labcomm.dll all: labcomm.dll
......
namespace se.lth.control.labcomm { namespace se.lth.control.labcomm {
public class LabComm { public class Constant {
public const string VERSION = "LabComm20141009"; public const string VERSION = "LabComm20141009";
......
...@@ -2,10 +2,10 @@ using System; ...@@ -2,10 +2,10 @@ using System;
namespace se.lth.control.labcomm { namespace se.lth.control.labcomm {
public interface LabCommDecoder { public interface Decoder {
void register(LabCommDispatcher dispatcher, void register(SampleDispatcher dispatcher,
LabCommHandler handler); SampleHandler handler);
bool decodeBoolean(); bool decodeBoolean();
byte decodeByte(); byte decodeByte();
......
...@@ -5,18 +5,18 @@ namespace se.lth.control.labcomm { ...@@ -5,18 +5,18 @@ namespace se.lth.control.labcomm {
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
public class LabCommDecoderChannel : LabCommDecoder { public class DecoderChannel : Decoder {
private Stream stream; private Stream stream;
private LabCommDecoderRegistry registry = new LabCommDecoderRegistry(); private DecoderRegistry registry = new DecoderRegistry();
byte[] buf = new byte[8]; byte[] buf = new byte[8];
public LabCommDecoderChannel(Stream stream) { public DecoderChannel(Stream stream) {
this.stream = stream; this.stream = stream;
String version = decodeString(); String version = decodeString();
if (version != LabComm.VERSION) { if (version != Constant.VERSION) {
throw new IOException("LabComm version mismatch " + throw new IOException("LabComm version mismatch " +
version + " != " + LabComm.VERSION); version + " != " + Constant.VERSION);
} }
} }
...@@ -26,7 +26,7 @@ namespace se.lth.control.labcomm { ...@@ -26,7 +26,7 @@ namespace se.lth.control.labcomm {
int tag = decodePacked32(); int tag = decodePacked32();
int length = decodePacked32(); int length = decodePacked32();
switch (tag) { switch (tag) {
case LabComm.SAMPLE: { case Constant.SAMPLE: {
int index = decodePacked32(); int index = decodePacked32();
String name = decodeString(); String name = decodeString();
int signature_length = decodePacked32(); int signature_length = decodePacked32();
...@@ -35,15 +35,15 @@ namespace se.lth.control.labcomm { ...@@ -35,15 +35,15 @@ namespace se.lth.control.labcomm {
registry.add(index, name, signature); registry.add(index, name, signature);
} break; } break;
default: { default: {
LabCommDecoderRegistry.Entry e = registry.get(tag); DecoderRegistry.Entry e = registry.get(tag);
if (e == null) { if (e == null) {
throw new IOException("Unhandled tag " + tag); throw new IOException("Unhandled tag " + tag);
} }
LabCommDispatcher d = e.getDispatcher(); SampleDispatcher d = e.getSampleDispatcher();
if (d == null) { if (d == null) {
throw new IOException("No dispatcher for '" + e.getName() + "'" + e.getSignature()); throw new IOException("No dispatcher for '" + e.getName() + "'" + e.getSignature());
} }
LabCommHandler h = e.getHandler(); SampleHandler h = e.getHandler();
if (h == null) { if (h == null) {
throw new IOException("No handler for '" + e.getName() +"'"); throw new IOException("No handler for '" + e.getName() +"'");
} }
...@@ -60,8 +60,8 @@ namespace se.lth.control.labcomm { ...@@ -60,8 +60,8 @@ namespace se.lth.control.labcomm {
} }
} }
public void register(LabCommDispatcher dispatcher, public void register(SampleDispatcher dispatcher,
LabCommHandler handler) { SampleHandler handler) {
registry.add(dispatcher, handler); registry.add(dispatcher, handler);
} }
......
...@@ -3,18 +3,18 @@ namespace se.lth.control.labcomm { ...@@ -3,18 +3,18 @@ namespace se.lth.control.labcomm {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
public class LabCommDecoderRegistry { public class DecoderRegistry {
public class Entry { public class Entry {
private LabCommDispatcher dispatcher; private SampleDispatcher dispatcher;
private LabCommHandler handler; private SampleHandler handler;
private int index; private int index;
private String name; private String name;
private byte[] signature; private byte[] signature;
public Entry(LabCommDispatcher dispatcher, public Entry(SampleDispatcher dispatcher,
LabCommHandler handler) { SampleHandler handler) {
this.dispatcher = dispatcher; this.dispatcher = dispatcher;
this.name = dispatcher.getName(); this.name = dispatcher.getName();
this.signature = dispatcher.getSignature(); this.signature = dispatcher.getSignature();
...@@ -27,19 +27,19 @@ namespace se.lth.control.labcomm { ...@@ -27,19 +27,19 @@ namespace se.lth.control.labcomm {
this.signature = signature; this.signature = signature;
} }
public LabCommDispatcher getDispatcher() { public SampleDispatcher getSampleDispatcher() {
return dispatcher; return dispatcher;
} }
public void setDispatcher(LabCommDispatcher dispatcher) { public void setSampleDispatcher(SampleDispatcher dispatcher) {
this.dispatcher = dispatcher; this.dispatcher = dispatcher;
} }
public LabCommHandler getHandler() { public SampleHandler getHandler() {
return handler; return handler;
} }
public void setHandler(LabCommHandler handler) { public void setHandler(SampleHandler handler) {
this.handler = handler; this.handler = handler;
} }
...@@ -93,13 +93,13 @@ namespace se.lth.control.labcomm { ...@@ -93,13 +93,13 @@ namespace se.lth.control.labcomm {
private Dictionary<Type, Entry> byClass; private Dictionary<Type, Entry> byClass;
private Dictionary<int, Entry> byIndex; private Dictionary<int, Entry> byIndex;
public LabCommDecoderRegistry() { public DecoderRegistry() {
byClass = new Dictionary<Type, Entry>(); byClass = new Dictionary<Type, Entry>();
byIndex = new Dictionary<int, Entry>(); byIndex = new Dictionary<int, Entry>();
} }
public void add(LabCommDispatcher dispatcher, public void add(SampleDispatcher dispatcher,
LabCommHandler handler) { SampleHandler handler) {
lock(this) { lock(this) {
Entry e; Entry e;
byClass.TryGetValue(dispatcher.getSampleClass(), out e); byClass.TryGetValue(dispatcher.getSampleClass(), out e);
...@@ -109,7 +109,7 @@ namespace se.lth.control.labcomm { ...@@ -109,7 +109,7 @@ namespace se.lth.control.labcomm {
} else { } else {
foreach (Entry e2 in byIndex.Values) { foreach (Entry e2 in byIndex.Values) {
if (e2.match(dispatcher.getName(), dispatcher.getSignature())) { if (e2.match(dispatcher.getName(), dispatcher.getSignature())) {
e2.setDispatcher(dispatcher); e2.setSampleDispatcher(dispatcher);
e2.setHandler(handler); e2.setHandler(handler);
e = e2; e = e2;
break; break;
......
...@@ -2,9 +2,9 @@ namespace se.lth.control.labcomm { ...@@ -2,9 +2,9 @@ namespace se.lth.control.labcomm {
using System; using System;
public interface LabCommEncoder { public interface Encoder {
void register(LabCommDispatcher dispatcher); void register(SampleDispatcher dispatcher);
void begin(Type c); void begin(Type c);
void end(Type c); void end(Type c);
......
...@@ -5,30 +5,30 @@ namespace se.lth.control.labcomm { ...@@ -5,30 +5,30 @@ namespace se.lth.control.labcomm {
using System.Text; using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public class LabCommEncoderChannel : LabCommEncoder { public class EncoderChannel : Encoder {
private Stream writer; private Stream writer;
private MemoryStream bytes = new MemoryStream(); private MemoryStream bytes = new MemoryStream();
private LabCommEncoderRegistry registry = new LabCommEncoderRegistry(); private EncoderRegistry registry = new EncoderRegistry();
byte[] buf = new byte[8]; byte[] buf = new byte[8];
private int current_tag; private int current_tag;
public LabCommEncoderChannel(Stream writer, bool emitVersion) { public EncoderChannel(Stream writer, bool emitVersion) {
this.writer = writer; this.writer = writer;
if (emitVersion) { if (emitVersion) {
encodeString(LabComm.VERSION); encodeString(Constant.VERSION);
bytes.WriteTo(writer); bytes.WriteTo(writer);
bytes.SetLength(0); bytes.SetLength(0);
writer.Flush(); writer.Flush();
} }
} }
public LabCommEncoderChannel(Stream writer) : this(writer, true) { public EncoderChannel(Stream writer) : this(writer, true) {
} }
public void register(LabCommDispatcher dispatcher) { public void register(SampleDispatcher dispatcher) {
int index = registry.add(dispatcher); int index = registry.add(dispatcher);
begin(LabComm.SAMPLE); begin(Constant.SAMPLE);
encodePacked32(index); encodePacked32(index);
encodeString(dispatcher.getName()); encodeString(dispatcher.getName());
byte[] signature = dispatcher.getSignature(); byte[] signature = dispatcher.getSignature();
......
...@@ -3,19 +3,19 @@ namespace se.lth.control.labcomm { ...@@ -3,19 +3,19 @@ namespace se.lth.control.labcomm {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
public class LabCommEncoderRegistry { public class EncoderRegistry {
public class Entry { public class Entry {
private LabCommDispatcher dispatcher; private SampleDispatcher dispatcher;
private int index; private int index;
public Entry(LabCommDispatcher dispatcher, int index) { public Entry(SampleDispatcher dispatcher, int index) {
this.dispatcher = dispatcher; this.dispatcher = dispatcher;
this.index = index; this.index = index;
} }
public LabCommDispatcher getDispatcher() { public SampleDispatcher getSampleDispatcher() {
return dispatcher; return dispatcher;
} }
...@@ -25,14 +25,14 @@ namespace se.lth.control.labcomm { ...@@ -25,14 +25,14 @@ namespace se.lth.control.labcomm {
} }
private int userIndex = LabComm.FIRST_USER_INDEX; private int userIndex = Constant.FIRST_USER_INDEX;
private Dictionary<Type, Entry> byClass; private Dictionary<Type, Entry> byClass;
public LabCommEncoderRegistry() { public EncoderRegistry() {
byClass = new Dictionary<Type, Entry>(); byClass = new Dictionary<Type, Entry>();
} }
public int add(LabCommDispatcher dispatcher) { public int add(SampleDispatcher dispatcher) {
lock(this) { lock(this) {
Entry e; Entry e;
byClass.TryGetValue(dispatcher.getSampleClass(), out e); byClass.TryGetValue(dispatcher.getSampleClass(), out e);
......
...@@ -2,7 +2,7 @@ namespace se.lth.control.labcomm { ...@@ -2,7 +2,7 @@ namespace se.lth.control.labcomm {
using System; using System;
public interface LabCommDispatcher { public interface SampleDispatcher {
Type getSampleClass(); Type getSampleClass();
...@@ -10,8 +10,8 @@ namespace se.lth.control.labcomm { ...@@ -10,8 +10,8 @@ namespace se.lth.control.labcomm {
byte[] getSignature(); byte[] getSignature();
void decodeAndHandle(LabCommDecoder decoder, void decodeAndHandle(Decoder decoder,
LabCommHandler handler); SampleHandler handler);
} }
......
namespace se.lth.control.labcomm { namespace se.lth.control.labcomm {
public interface LabCommHandler { public interface SampleHandler {
} }
} }
\ No newline at end of file
...@@ -35,7 +35,7 @@ if __name__ == '__main__': ...@@ -35,7 +35,7 @@ if __name__ == '__main__':
result.append(' %s.Handler' % sample[-1][0]) result.append(' %s.Handler' % sample[-1][0])
result.extend(split_match('^[^|]*\|(.*)$', """ result.extend(split_match('^[^|]*\|(.*)$', """
|{ |{
| LabCommEncoderChannel encoder; | EncoderChannel encoder;
""")) """))
for func,arg in sample: for func,arg in sample: