Commit 774f9a36 authored by Georg Vinogradov's avatar Georg Vinogradov
Browse files

Extend project to use MqttConnectionSymbol

parent d0f03264
Pipeline #155365 passed with stage
in 2 minutes
......@@ -45,6 +45,14 @@
</properties>
<dependencies>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc</artifactId>
<!-- or newer version -->
<version>0.1.10-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.se_rwth.commons</groupId>
......
......@@ -27,7 +27,7 @@ public class GeneratorMqtt
model.addPorts(ports);
//Generate files
//Generate files and write to project
String content = MqttTemplates.generateRosAdapter(model);
File file = new File("./target/generated-sources/ports.txt");
......
package de.monticore.lang.monticar.generator.mqtt.template;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAPortInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.MiddlewareSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.mqtt.MqttConnectionSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.mqtt.MqttConnectionSymbol.MqttConnectionKind;
import java.util.*;
......@@ -21,12 +24,22 @@ public class MqttAdapterModel {
return compName;
}
// Parse through component to find information about its ports
public void addPorts(Collection<EMAPortInstanceSymbol> ports)
{
for (EMAPortInstanceSymbol port : ports)
{
String kind = port.isIncoming()?"incoming":"outgoing";
this.ports.add(port.getName()+" : "+kind);
String symbolKind = "unknown symbol";
Optional<MiddlewareSymbol> symbol = port.getMiddlewareSymbol();
if(symbol.isPresent() && symbol.get().isKindOf(MqttConnectionKind.INSTANCE))
{
MqttConnectionSymbol sym = (MqttConnectionSymbol) symbol.get();
String topicName = sym.getTopicName().isPresent()?sym.getTopicName().get():"unknown";
symbolKind = "mqtt, topic: "+topicName;
}
this.ports.add(port.getName()+" : "+kind+" ("+symbolKind+")");
}
}
......
......@@ -3,6 +3,7 @@ package de.monticore.lang.monticar.generator.mqtt;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosToEmamTagSchema;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.mqtt.MqttConnectionSymbol;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
......@@ -25,6 +26,9 @@ public class PrettyPrintGenerationTest extends AbstractSymtabTest {
GeneratorMqtt generatorMqtt = new GeneratorMqtt();
// Connect component's ports to topics
componentInstanceSymbol.getPortInstance("portA").orElse(null).setMiddlewareSymbol(new MqttConnectionSymbol("/clock"));
generatorMqtt.generateMqttAdapter(componentInstanceSymbol);
}
......
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