blob: 31e534d26ffa379556c0e4323988d92b31b19bc6 [file] [log] [blame]
/**
* 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 org.eclipse.app4mc.amalthea.model.InterProcessTrigger;
import org.eclipse.app4mc.slg.commons.m2t.generators.TranslationUnit;
import org.eclipse.app4mc.slg.ros2.transformers.utils.Utils;
import org.eclipse.app4mc.transformation.util.OutputBuffer;
import org.eclipse.xtend2.lib.StringConcatenation;
public class RosInterProcessTriggerUtilsTranslationUnit extends TranslationUnit {
private InterProcessTrigger ip;
private OutputBuffer outputBuffer;
public RosInterProcessTriggerUtilsTranslationUnit(final OutputBuffer outputBuffer, final InterProcessTrigger ip) {
super();
this.ip = ip;
this.outputBuffer = outputBuffer;
this.genFiles();
}
public static String getModulePathStatic() {
return "synthetic_gen" + "/" + getModuleNameStatic();
}
public static String getMakeFilePathStatic() {
return getModulePathStatic() + "/" + "CMakeLists.txt";
}
public static String getModuleNameStatic() {
return "interProcessTriggerUtils";
}
public static String getLibName() {
return "INTERPROCESSTRIGGER_UTIL";
}
public String getModuleName() {
return getModuleNameStatic();
}
@Override
public String getIncFile() {
return getModuleName() + ".h";
}
public String getExecCall(final String param) {
return "call_service_" + param + "(" + param + "_client)";
}
public void genFiles() {
if (isSrcFileEmpty()) {
incAppend(RosInterProcessTriggerUtilsGenerator.toHeader());
}
if (isSrcFileEmpty()) {
srcAppend(RosInterProcessTriggerUtilsGenerator.toCPPHead());
}
incAppend(RosInterProcessTriggerUtilsGenerator.toH(ip));
srcAppend(RosInterProcessTriggerUtilsGenerator.toCPP(ip));
}
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);
}
}