Move msg->h generation to EMAM2RosCpp

parent 696525ee
...@@ -4,6 +4,7 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instance ...@@ -4,6 +4,7 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instance
import de.monticore.lang.monticar.generator.FileContent; import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.helpers.*; import de.monticore.lang.monticar.generator.middleware.helpers.*;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl; import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.monticar.generator.middleware.impls.RclCppGenImpl;
import de.monticore.lang.tagging._symboltable.TaggingResolver; import de.monticore.lang.tagging._symboltable.TaggingResolver;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
...@@ -48,22 +49,10 @@ public class DistributedTargetGenerator extends CMakeGenerator { ...@@ -48,22 +49,10 @@ public class DistributedTargetGenerator extends CMakeGenerator {
subDirs.add(NameHelper.getNameTargetLanguage(comp.getFullName())); subDirs.add(NameHelper.getNameTargetLanguage(comp.getFullName()));
} }
//generate rosMsg CMake iff a .msg file was generated
if(files.stream().anyMatch(f -> f.getName().endsWith(".msg"))){
subDirs.add("rosMsg");
files.add(generateRosMsgGen());
}
files.add(generateCMake(componentInstanceSymbol)); files.add(generateCMake(componentInstanceSymbol));
return files; return files;
} }
private File generateRosMsgGen() throws IOException {
File file = new File(generationTargetPath + "rosMsg/CMakeLists.txt");
FileUtils.write(file, TemplateHelper.getStruct_msgsCmakeTemplate());
return file;
}
private GeneratorImpl createFullGenerator(String subdir) { private GeneratorImpl createFullGenerator(String subdir) {
MiddlewareGenerator res = new MiddlewareGenerator(); MiddlewareGenerator res = new MiddlewareGenerator();
res.setGenerationTargetPath(generationTargetPath + (subdir.endsWith("/") ? subdir : subdir + "/")); res.setGenerationTargetPath(generationTargetPath + (subdir.endsWith("/") ? subdir : subdir + "/"));
...@@ -74,7 +63,7 @@ public class DistributedTargetGenerator extends CMakeGenerator { ...@@ -74,7 +63,7 @@ public class DistributedTargetGenerator extends CMakeGenerator {
} }
private void fixComponentInstance(EMAComponentInstanceSymbol componentInstanceSymbol) { private void fixComponentInstance(EMAComponentInstanceSymbol componentInstanceSymbol) {
RosHelper.fixRosConnectionSymbols(componentInstanceSymbol); RosHelper.fixRosConnectionSymbols(componentInstanceSymbol, this.getGeneratorImpls().stream().anyMatch(g -> g instanceof RclCppGenImpl));
} }
@Override @Override
......
...@@ -16,28 +16,28 @@ public class RosHelper { ...@@ -16,28 +16,28 @@ public class RosHelper {
} }
public static void fixRosConnectionSymbols(EMAComponentInstanceSymbol componentInstanceSymbol) { public static void fixRosConnectionSymbols(EMAComponentInstanceSymbol componentInstanceSymbol, boolean ros2mode) {
componentInstanceSymbol.getConnectorInstances().stream() componentInstanceSymbol.getConnectorInstances().stream()
.filter(connectorSymbol -> connectorSymbol.getSourcePort().isRosPort() && connectorSymbol.getTargetPort().isRosPort()) .filter(connectorSymbol -> connectorSymbol.getSourcePort().isRosPort() && connectorSymbol.getTargetPort().isRosPort())
.forEach(connectorSymbol -> { .forEach(connectorSymbol -> {
if (Objects.equals(connectorSymbol.getSourcePort().getComponentInstance(), componentInstanceSymbol)) { if (Objects.equals(connectorSymbol.getSourcePort().getComponentInstance(), componentInstanceSymbol)) {
//In port of supercomp //In port of supercomp
inferRosConnectionIfPossible(connectorSymbol.getSourcePort(), connectorSymbol.getTargetPort()); inferRosConnectionIfPossible(connectorSymbol.getSourcePort(), connectorSymbol.getTargetPort());
generateRosConnectionIfPossible(connectorSymbol); generateRosConnectionIfPossible(connectorSymbol, ros2mode);
} else if (Objects.equals(connectorSymbol.getTargetPort().getComponentInstance(), componentInstanceSymbol)) { } else if (Objects.equals(connectorSymbol.getTargetPort().getComponentInstance(), componentInstanceSymbol)) {
//out port of supercomp //out port of supercomp
inferRosConnectionIfPossible(connectorSymbol.getTargetPort(), connectorSymbol.getSourcePort()); inferRosConnectionIfPossible(connectorSymbol.getTargetPort(), connectorSymbol.getSourcePort());
generateRosConnectionIfPossible(connectorSymbol); generateRosConnectionIfPossible(connectorSymbol, ros2mode);
} else { } else {
//In between subcomps //In between subcomps
generateRosConnectionIfPossible(connectorSymbol); generateRosConnectionIfPossible(connectorSymbol, ros2mode);
} }
}); });
} }
//Cannot be moved to GeneratorRosCpp: target port name needed for topic name //Cannot be moved to GeneratorRosCpp: target port name needed for topic name
private static void generateRosConnectionIfPossible(EMAConnectorInstanceSymbol connectorSymbol) { private static void generateRosConnectionIfPossible(EMAConnectorInstanceSymbol connectorSymbol, boolean ros2mode) {
MiddlewareSymbol sourceTag = connectorSymbol.getSourcePort().getMiddlewareSymbol().orElse(null); MiddlewareSymbol sourceTag = connectorSymbol.getSourcePort().getMiddlewareSymbol().orElse(null);
MiddlewareSymbol targetTag = connectorSymbol.getTargetPort().getMiddlewareSymbol().orElse(null); MiddlewareSymbol targetTag = connectorSymbol.getTargetPort().getMiddlewareSymbol().orElse(null);
if (sourceTag == null || targetTag == null || !sourceTag.isKindOf(RosConnectionSymbol.KIND) || !targetTag.isKindOf(RosConnectionSymbol.KIND)) { if (sourceTag == null || targetTag == null || !sourceTag.isKindOf(RosConnectionSymbol.KIND) || !targetTag.isKindOf(RosConnectionSymbol.KIND)) {
...@@ -54,8 +54,8 @@ public class RosHelper { ...@@ -54,8 +54,8 @@ public class RosHelper {
//target port name is unique: each in port can only have one connection! //target port name is unique: each in port can only have one connection!
String topicName = NameHelper.getNameTargetLanguage(connectorSymbol.getTargetPort().getFullName()); String topicName = NameHelper.getNameTargetLanguage(connectorSymbol.getTargetPort().getFullName());
RosMsg rosTypeA = GeneratorRosMsg.getRosType("struct_msgs", connectorSymbol.getTargetPort().getTypeReference()); RosMsg rosTypeA = GeneratorRosMsg.getRosType("struct_msgs", connectorSymbol.getTargetPort().getTypeReference(), ros2mode);
RosMsg rosTypeB = GeneratorRosMsg.getRosType("struct_msgs", connectorSymbol.getSourcePort().getTypeReference()); RosMsg rosTypeB = GeneratorRosMsg.getRosType("struct_msgs", connectorSymbol.getSourcePort().getTypeReference(), ros2mode);
if (!rosTypeA.equals(rosTypeB)) { if (!rosTypeA.equals(rosTypeB)) {
Log.error("topicType mismatch! " Log.error("topicType mismatch! "
+ connectorSymbol.getSourcePort().getFullName() + " has " + rosTypeB + " and " + connectorSymbol.getSourcePort().getFullName() + " has " + rosTypeB + " and "
......
...@@ -32,10 +32,6 @@ public class TemplateHelper { ...@@ -32,10 +32,6 @@ public class TemplateHelper {
return getTemplate("coordinatorTemplate.ftl"); return getTemplate("coordinatorTemplate.ftl");
} }
public static String getStruct_msgsCmakeTemplate() {
return getTemplate("struct_msgsCmakeTemplate.ftl");
}
public static String getDummyCmakeTemplate() { public static String getDummyCmakeTemplate() {
return getTemplate("dummyCmakeTemplate.ftl"); return getTemplate("dummyCmakeTemplate.ftl");
} }
......
cmake_minimum_required(VERSION 3.5)
project (struct_msgs)
find_package(genmsg REQUIRED)
FILE(GLOB MSG_FILES_RAW RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ../*/*/struct_msgs/*.msg)
#generate struct_msgs iff .msg files where found
if(MSG_FILES_RAW)
#filter: add each struct msg only once (distinct by filename without path)
foreach(CUR_MSG_FILE ${MSG_FILES_RAW})
get_filename_component(TMP_MSG_NAME ${CUR_MSG_FILE} NAME)
IF(NOT MSG_DEFINED_${TMP_MSG_NAME})
get_filename_component(DIR_${TMP_MSG_NAME} ${CUR_MSG_FILE} DIRECTORY)
add_message_files(DIRECTORY ${DIR_${TMP_MSG_NAME}} FILES ${TMP_MSG_NAME})
SET(MSG_DEFINED_${TMP_MSG_NAME} TRUE)
ENDIF()
endforeach(CUR_MSG_FILE)
generate_messages()
#export the include_dirs, so that other subprojects can use it
set(struct_msgs_INCLUDE_DIRS ${struct_msgs_INCLUDE_DIRS} PARENT_SCOPE)
endif()
\ No newline at end of file
...@@ -43,7 +43,7 @@ public class MiddlewareSymbolTest extends AbstractSymtabTest { ...@@ -43,7 +43,7 @@ public class MiddlewareSymbolTest extends AbstractSymtabTest {
assertNotEquals(rosInRCS, sub1RosInRCS); assertNotEquals(rosInRCS, sub1RosInRCS);
assertNotEquals(rosOutRCS, sub1RosOutRCS); assertNotEquals(rosOutRCS, sub1RosOutRCS);
RosHelper.fixRosConnectionSymbols(componentInstanceSymbol); RosHelper.fixRosConnectionSymbols(componentInstanceSymbol, false);
assertEquals(rosInRCS, sub1RosInRCS); assertEquals(rosInRCS, sub1RosInRCS);
assertEquals(rosOutRCS, sub1RosOutRCS); assertEquals(rosOutRCS, sub1RosOutRCS);
......
package de.monticore.lang.monticar.generator.middleware;
public class Ros2GenerationTest {
}
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