Commit ed94e814 authored by René Schöne's avatar René Schöne
Browse files

Simple logging for reads and writes (untested).

parent e8eaab35
aspect Configuration {
public static boolean ASTNode.loggingEnabledForReads = false;
public static boolean ASTNode.loggingEnabledForWrites = false;
}
...@@ -162,6 +162,11 @@ aspect AspectGeneration { ...@@ -162,6 +162,11 @@ aspect AspectGeneration {
.append(connectMethod()).append("(String topic) {\n"); .append(connectMethod()).append("(String topic) {\n");
sb.append(ind(2)).append(mqttUpdaterAttribute()).append("().newConnection(topic, message -> {\n"); sb.append(ind(2)).append(mqttUpdaterAttribute()).append("().newConnection(topic, message -> {\n");
String lastResult = generateMappingApplication(sb, 3, "message"); String lastResult = generateMappingApplication(sb, 3, "message");
if (loggingEnabledForReads) {
sb.append(ind(3)).append("System.out.println(\"[Read] \" + topic + \" -> ")
.append(getToken().getName()).append(" = \" + ").append(lastResult)
.append(");\n");
}
sb.append(ind(3)).append("set").append(getToken().getName()).append("(").append(lastResult).append(");\n"); sb.append(ind(3)).append("set").append(getToken().getName()).append("(").append(lastResult).append(");\n");
sb.append(ind(2)).append("});\n"); sb.append(ind(2)).append("});\n");
sb.append(ind(1)).append("}\n\n"); sb.append(ind(1)).append("}\n\n");
...@@ -198,6 +203,10 @@ aspect AspectGeneration { ...@@ -198,6 +203,10 @@ aspect AspectGeneration {
// write method // write method
sb.append(ind(1)).append("protected void ").append(parentTypeName).append(".") sb.append(ind(1)).append("protected void ").append(parentTypeName).append(".")
.append(writeMethod()).append("() {\n"); .append(writeMethod()).append("() {\n");
if (loggingEnabledForWrites) {
sb.append(ind(2)).append("System.out.println(\"[Write] ").append(getToken().getName())
.append(" = \" + ").append(lastValue()).append(" + \" -> ").append(writeTopic()).append("\");\n");
}
// _mqttUpdater().publish(${writeTopic()}, ${lastValue()}); // _mqttUpdater().publish(${writeTopic()}, ${lastValue()});
sb.append(ind(2)).append(mqttUpdaterAttribute()).append("().publish(") sb.append(ind(2)).append(mqttUpdaterAttribute()).append("().publish(")
.append(writeTopic()).append(", ").append(lastValue()).append(");\n"); .append(writeTopic()).append(", ").append(lastValue()).append(");\n");
......
...@@ -25,6 +25,8 @@ public class Compiler { ...@@ -25,6 +25,8 @@ public class Compiler {
private StringOption optionInputRos2Rag; private StringOption optionInputRos2Rag;
private FlagOption optionHelp; private FlagOption optionHelp;
private FlagOption optionVerbose; private FlagOption optionVerbose;
private FlagOption optionLogReads;
private FlagOption optionLogWrites;
private ArrayList<Option<?>> options; private ArrayList<Option<?>> options;
private CommandLine commandLine; private CommandLine commandLine;
...@@ -143,7 +145,9 @@ public class Compiler { ...@@ -143,7 +145,9 @@ public class Compiler {
optionRootNode = addOption(new StringOption("rootNode", "root node in the base grammar.")); optionRootNode = addOption(new StringOption("rootNode", "root node in the base grammar."));
optionInputRos2Rag = addOption(new StringOption("inputRos2Rag", "ros2rag definition file.")); optionInputRos2Rag = addOption(new StringOption("inputRos2Rag", "ros2rag definition file."));
optionHelp = addOption(new FlagOption("help", "Print usage and exit.")); optionHelp = addOption(new FlagOption("help", "Print usage and exit."));
optionVerbose = addOption(new FlagOption("verbose", "Print more messages.")); optionVerbose = addOption(new FlagOption("verbose", "Print more messages while compiling."));
optionLogReads = addOption(new FlagOption("logReads", "Enable logging for every read."));
optionLogWrites = addOption(new FlagOption("logWrites", "Enable logging for every write."));
} }
private <OptionType extends Option<?>> OptionType addOption(OptionType option) { private <OptionType extends Option<?>> OptionType addOption(OptionType option) {
...@@ -179,6 +183,8 @@ public class Compiler { ...@@ -179,6 +183,8 @@ public class Compiler {
} }
ros2Rag.treeResolveAll(); ros2Rag.treeResolveAll();
ros2Rag.additionalRelations().forEach(inputGrammar::addDeclaration); ros2Rag.additionalRelations().forEach(inputGrammar::addDeclaration);
ASTNode.loggingEnabledForReads = optionLogReads.isSet();
ASTNode.loggingEnabledForWrites = optionLogWrites.isSet();
return ros2Rag; return ros2Rag;
} }
......
Supports Markdown
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