Commit 98bf8658 authored by Georg Vinogradov's avatar Georg Vinogradov
Browse files

Start implementing classes/ftl files

parent 4cba0feb
Pipeline #152086 passed with stage
in 57 seconds
package de.monticore.lang.monticar.generator.mqtt;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import java.util.List;
public class GeneratorMqtt {
private String generationTargetPath;
private boolean generateCMake = false;
private boolean mqtt2Mode = false;
public boolean isMqtt2Mode() {
return mqtt2Mode;
public void setMqtt2Mode(boolean mqtt2Mode) {
this.mqtt2Mode = mqtt2Mode;
public void setGenerateCMake(boolean generateCMake) {
this.generateCMake = generateCMake;
public String getGenerationTargetPath() {
return generationTargetPath;
public void setGenerationTargetPath(String generationTargetPath) {
this.generationTargetPath = generationTargetPath.endsWith("/") ? generationTargetPath : generationTargetPath + "/";
// Those methods use ROS specific fileContent and need to be rewritten
public List<File> generateFiles(EMAComponentInstanceSymbol component, TaggingResolver symtab) throws IOException {
return null;
// public List<FileContent> generateStrings(EMAComponentInstanceSymbol component) {}
// private List<FileContent> generateMqttAdapter(EMAComponentInstanceSymbol component) {}
// public List<FileContent> generateCMakeFiles(EMAComponentInstanceSymbol component, List<MqttInterface> mqttInterfaces, boolean mqtt2Mode) {}
package de.monticore.lang.monticar.generator.mqtt.template;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import de.se_rwth.commons.logging.Log;
import java.util.Map;
import java.util.HashMap;
public class MqttTemplates {
private static final Template Mqtt_CMAKELISTS;
private static final Template Mqtt_ADAPTER;
// Choosing ftl files for templates
static {
Configuration conf = new Configuration(Configuration.VERSION_2_3_23);
conf.setClassForTemplateLoading(MqttTemplates.class, "");
try {
Mqtt_CMAKELISTS = conf.getTemplate("CMakeLists.ftl");
Mqtt_ADAPTER = conf.getTemplate("Adapter.ftl");
} catch (IOException e) {
String msg = "could not load template";
Log.error(msg, e);
throw new RuntimeException(msg, e);
/*public static String generateMqttCMakeLists(MqttCMakeListsModel model) {
HashMap<String, Object> data = new HashMap<>();
data.put("model", model);
return generate(Mqtt_CMAKELISTS, data);
/*public static String generateMqttAdapter(MqttAdapterModel model) {
HashMap<String, Object> data = new HashMap<>();
data.put("model", model);
return generate(Mqtt_ADAPTER, data);
private static String generate(Template template, Map dataForTemplate) {
StringWriter sw = new StringWriter();
try {
template.process(dataForTemplate, sw);
} catch (TemplateException | IOException e) {
Log.error("template generation failed, template: " + template.getName(), e);
return sw.toString();
<#-- Creating header file for the adapter -->
<#-- We dont need if else case as with ROS/ROS2 - import MqttMacros.ftl directly -->
<#import "MqttMacros.ftl" as m>
#pragma once
<#-- Include IAdapter of component and component, that was set in a model -->
#include "IAdapter_${model.getCompName()}.h"
#include "${model.getCompName()}.h"
<#-- Import the list of addtional includes from model -->
<#list model.getIncludes() as incl>
<@m.mwMsgInclude incl=incl/>
<#-- Construct class name and generics from model -->
class <@m.mwIdent/>Adapter_${model.getCompName()}: public IAdapter_${model.getCompName()}{
<#list model.getGenerics() as gen>
<#-- Create pointers to component, subscribers and publishers instances -->
${model.getCompName()}* component;
<#list model.getSubscribers() as sub>
<@m.fieldSubscriber type="${sub.getTypeNameInTargetLanguage()}" name="${sub.getNameInTargetLanguage()}"/>
<#list model.getPublishers() as pub>
<@m.fieldPublisher type="${pub.getTypeNameInTargetLanguage()}" name="${pub.getNameInTargetLanguage()}"/>
<#-- Describing public methods, attributes -->
<#-- Since our implementations are not in header files, we also need to generate a .cpp -->
<#-- To be continued -->
<#-- Create a CMakeLists file for Mqtt -->
cmake_minimum_required(VERSION 3.1...3.14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
project (${})
<#-- To be continued -->
\ No newline at end of file
<#-- In FreeMarker, macros are template fragments associated with variables that are called with @ e.g. <@m.mwIdent/> where mwIdent is the name of a variable -->
<#-- Macros are then used in other .ftl files -->
<#macro mwIdent>Mqtt</#macro>
<#-- To be continued -->
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