blob: ad098657cb494e90b566b1a0d4c319f5962056b1 [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.transformation.util.OutputBuffer;
public class RosInterProcessTriggerUtilsTranslationUnit extends TranslationUnit {
public static final String LIB_NAME = "INTERPROCESSTRIGGER_UTIL";
public static final String MODULE_NAME = "interProcessTriggerUtils";
public static final String MODULE_PATH = "synthetic_gen/" + MODULE_NAME;
public static final String MAKEFILE_PATH = MODULE_PATH + "/CMakeLists.txt";
private InterProcessTrigger ip;
private OutputBuffer outputBuffer;
public RosInterProcessTriggerUtilsTranslationUnit(final OutputBuffer outputBuffer, final InterProcessTrigger ip) {
super();
this.ip = ip;
this.outputBuffer = outputBuffer;
this.genFiles();
}
public String getModuleName() {
return MODULE_NAME;
}
@Override
public String getIncFile() {
return MODULE_NAME + ".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("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);
}
}