blob: 5f58af8c0ff9749b8d0cc3e5c28278255dfd1b28 [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.linux.generators;
import org.eclipse.app4mc.slg.config.ConfigModel;
import org.eclipse.app4mc.transformation.util.OutputBuffer;
public class LinuxTicksUtilsTranslationUnit extends LinuxSyntheticTranslationUnit {
public static String getModulePathStatic() {
return getBasePathStatic() + "/" + getModuleNameStatic();
}
public static String getMakeFilePathStatic() {
return getModulePathStatic() + "/" + getMakeFileName();
}
public static String getModuleNameStatic() {
return "ticksUtils";
}
public static String getLibName() {
return "TICKS_UTILS";
}
@Override
public String getModuleName() {
return getModuleNameStatic();
}
public CharSequence getExecCall(final String params) {
return "burnTicks(" + params + ")";
}
/**
* '''executeTicks_«valueClass.toString.split("\\.").last»(«params»)'''
*/
@Override
public String getIncFile() {
return this.getModuleName() + ".h";
}
private final ConfigModel configModel;
private final Object valueClass;
public LinuxTicksUtilsTranslationUnit(final OutputBuffer outputBuffer, final ConfigModel configModel,
final Object valueClass) {
super(outputBuffer);
this.configModel = configModel;
this.valueClass = valueClass;
this.genFiles();
}
public void genFiles() {
if (isIncFileEmpty()) {
toH();
}
if (isSrcFileEmpty()) {
toCPP();
}
srcAppend(LinuxTicksUtilsGenerator.generateTicks(valueClass));
incAppend(LinuxTicksUtilsGenerator.generateTicksDecleration(valueClass));
}
private void toCPP() {
srcAppend("#include \"" + this.getIncFile() + "\"\n");
final String ticksCodeSnippet = this.configModel.getCustomTickImpl().getValue();
final String burnTicksBody = this.configModel.getCustomTickImpl().isEnable() ? ticksCodeSnippet : LinuxTicksUtilsGenerator.burnTicksDefault();
srcAppend(LinuxTicksUtilsGenerator.burnTicks(burnTicksBody));
srcAppend(LinuxTicksUtilsGenerator.burnTicksStatistics(this.configModel));
}
private void toH() {
incAppend(LinuxTicksUtilsGenerator.burnTicksDecleration());
incAppend(LinuxTicksUtilsGenerator.burnTicksStatisticsDecleration());
}
}