| /** |
| * 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.HashSet; |
| import java.util.LinkedList; |
| import java.util.List; |
| |
| import org.eclipse.app4mc.amalthea.model.Amalthea; |
| import org.eclipse.app4mc.amalthea.model.Tag; |
| import org.eclipse.app4mc.amalthea.model.Task; |
| import org.eclipse.app4mc.slg.commons.m2t.generators.TranslationUnit; |
| import org.eclipse.app4mc.slg.ros2.transformers.sw.RosTaskTransformer; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| |
| public class RosTagTranslationUnit extends TranslationUnit { |
| private RosTaskTransformer rosTaskTransformer; |
| private Tag tag; |
| private Amalthea model; |
| |
| private HashSet<String> header = new HashSet<>(); |
| private List<String> declaration = new LinkedList<>(); |
| private List<String> initialization = new LinkedList<>(); |
| private List<String> calls = new LinkedList<>(); |
| private List<String> serviceCallbacks = new LinkedList<>(); |
| private OutputBuffer outputBuffer; |
| |
| public RosTagTranslationUnit(final OutputBuffer outputBuffer, final RosTaskTransformer rosTaskTransformer, |
| final Tag tag, final Amalthea model) { |
| super(); |
| this.tag = tag; |
| this.model = model; |
| this.rosTaskTransformer = rosTaskTransformer; |
| this.outputBuffer = outputBuffer; |
| |
| this.genFiles(); |
| } |
| |
| public void genFiles() { |
| if (model != null && model.getSwModel() != null) { |
| for (Task task : model.getSwModel().getTasks()) { |
| if (task.getTags().contains(tag)) { |
| final RosTaskTranslationUnit tu = (RosTaskTranslationUnit) rosTaskTransformer.transform(task, null); |
| header.add(tu.getHeaders()); |
| declaration.add(tu.getDeclaration()); |
| initialization.add(tu.getInitialisation(this.getModuleName())); |
| calls.add(tu.getCallback()); |
| serviceCallbacks.add(tu.getServiceCallback()); |
| } |
| } |
| } |
| srcAppend(RosTagGenerator.toCpp(tag, getModuleName(), header, declaration, initialization, calls, serviceCallbacks)); |
| } |
| |
| public String getBasePath() { |
| return ""; |
| } |
| |
| public String getModuleName() { |
| return tag.getName(); |
| } |
| |
| public String getModulePath() { |
| return getBasePath() + "/" + getModuleName(); |
| } |
| |
| @Override |
| public String getIncFile() { |
| return getModuleName() + ".hpp"; |
| } |
| |
| @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("INC", getModulePath() + "/_inc/" + getModuleName()); |
| } |
| |
| public boolean isSrcFileEmpty() { |
| return !outputBuffer.bufferExists("SRC", getModulePath() + "/_src/" + getModuleName()); |
| } |
| |
| public boolean incAppend(final String str) { |
| return outputBuffer.appendTo("INC", getModulePath() + "/_inc/" + getModuleName(), str); |
| } |
| |
| public boolean srcAppend(final String str) { |
| return outputBuffer.appendTo("SRC", getModulePath() + "/_src/" + getModuleName(), str); |
| } |
| |
| } |