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

Simple logging for reads and writes (untested).

parent 07e46089
Pipeline #6832 passed with stage
in 2 minutes and 44 seconds
aspect Configuration {
public static boolean ASTNode.loggingEnabledForReads = false;
public static boolean ASTNode.loggingEnabledForWrites = false;
}
......@@ -162,6 +162,11 @@ aspect AspectGeneration {
.append(connectMethod()).append("(String topic) {\n");
sb.append(ind(2)).append(mqttUpdaterAttribute()).append("().newConnection(topic, message -> {\n");
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(2)).append("});\n");
sb.append(ind(1)).append("}\n\n");
......@@ -198,6 +203,10 @@ aspect AspectGeneration {
// write method
sb.append(ind(1)).append("protected void ").append(parentTypeName).append(".")
.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()});
sb.append(ind(2)).append(mqttUpdaterAttribute()).append("().publish(")
.append(writeTopic()).append(", ").append(lastValue()).append(");\n");
......
......@@ -25,6 +25,8 @@ public class Compiler {
private StringOption optionInputRos2Rag;
private FlagOption optionHelp;
private FlagOption optionVerbose;
private FlagOption optionLogReads;
private FlagOption optionLogWrites;
private ArrayList<Option<?>> options;
private CommandLine commandLine;
......@@ -143,7 +145,9 @@ public class Compiler {
optionRootNode = addOption(new StringOption("rootNode", "root node in the base grammar."));
optionInputRos2Rag = addOption(new StringOption("inputRos2Rag", "ros2rag definition file."));
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) {
......@@ -179,6 +183,8 @@ public class Compiler {
}
ros2Rag.treeResolveAll();
ros2Rag.additionalRelations().forEach(inputGrammar::addDeclaration);
ASTNode.loggingEnabledForReads = optionLogReads.isSet();
ASTNode.loggingEnabledForWrites = optionLogWrites.isSet();
return ros2Rag;
}
......
......@@ -68,7 +68,8 @@ task preprocessExampleTest(type: JavaExec, group: 'verification') {
args '--outputDir=src/test/02-after-ros2rag/example',
'--inputGrammar=src/test/01-input/example/Example.relast',
'--inputRos2Rag=src/test/01-input/example/Example.ros2rag',
'--rootNode=Model'
'--rootNode=Model',
'--logReads', '--logWrites'
}
task compileExampleTest(type: RelastTest) {
......
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