| /** |
| * Copyright (c) 2020-2021 Robert Bosch GmbH. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| */ |
| |
| package org.eclipse.app4mc.slg.ros2.generators; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.app4mc.amalthea.model.ChannelSend; |
| import org.eclipse.app4mc.slg.commons.m2t.generators.TranslationUnit; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| |
| public class RosChannelSendUtilsTranslationUnit extends TranslationUnit { |
| public static final String LIB_NAME = "CHANNELSEND_UTIL"; |
| public static final String MODULE_NAME = "channelSendUtils"; |
| public static final String MODULE_PATH = "synthetic_gen/" + MODULE_NAME; |
| public static final String MAKEFILE_PATH = MODULE_PATH + "/CMakeLists.txt"; |
| |
| private ChannelSend cs; |
| private OutputBuffer outputBuffer; |
| |
| public RosChannelSendUtilsTranslationUnit(final OutputBuffer outputBuffer, final ChannelSend cs) { |
| super(); |
| this.cs = cs; |
| this.outputBuffer = outputBuffer; |
| |
| this.genFiles(); |
| } |
| |
| private static List<String> topic_list = new ArrayList<>(); |
| |
| public String getModuleName() { |
| return MODULE_NAME; |
| } |
| |
| @Override |
| public String getIncFile() { |
| return (MODULE_NAME + ".h"); |
| } |
| |
| public String getExecCall(final String param) { |
| return "publish_to_" + param + "(" + param + "_publisher)"; |
| } |
| |
| public void genFiles() { |
| |
| if (this.isSrcFileEmpty()) { |
| this.incAppend(RosChannelSendUtilsGenerator.toHeader().toString()); |
| } |
| if (this.isSrcFileEmpty()) { |
| this.srcAppend(RosChannelSendUtilsGenerator.toCPPHead().toString()); |
| } |
| boolean already_defined = false; |
| for (final String topic_name : RosChannelSendUtilsTranslationUnit.topic_list) { |
| if (topic_name.equals(this.cs.getData().getName())) { |
| already_defined = true; |
| } |
| } |
| |
| if ((!already_defined)) { |
| |
| this.incAppend(RosChannelSendUtilsGenerator.toH(cs).toString()); |
| this.srcAppend(RosChannelSendUtilsGenerator.toCPP(cs).toString()); |
| |
| RosChannelSendUtilsTranslationUnit.topic_list.add(this.cs.getData().getName()); |
| } |
| } |
| |
| public String getBasePath() { |
| return "synthetic_gen"; |
| } |
| |
| public String getModulePath() { |
| return getBasePath() + "/" + getModuleName(); |
| } |
| |
| @Override |
| public String getSrcFile() { |
| return getModuleName() + ".cpp"; |
| } |
| |
| public String getIncPath() { |
| return getModulePath() + "/_inc/" + getIncFile(); |
| } |
| |
| public String getSrcPath() { |
| return getModulePath() + "/_src/" + getSrcFile(); |
| } |
| |
| public boolean isIncFileEmpty() { |
| return !outputBuffer.bufferExists("H", getModulePath() + "/_inc/" + getModuleName()); |
| } |
| |
| public boolean isSrcFileEmpty() { |
| return !outputBuffer.bufferExists("C", getModulePath() + "/_src/" + getModuleName()); |
| } |
| |
| public boolean incAppend(final String str) { |
| return outputBuffer.appendTo("H", getModulePath() + "/_inc/" + getModuleName(), str); |
| } |
| |
| public boolean srcAppend(final String str) { |
| return outputBuffer.appendTo("C", getModulePath() + "/_src/" + getModuleName(), str); |
| } |
| |
| } |