| /** |
| * ******************************************************************************* |
| * Copyright (c) 2019-2020 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.amlt2systemc.m2t.transformers.stimuli |
| |
| import com.google.inject.Inject |
| import com.google.inject.Singleton |
| import org.eclipse.app4mc.amalthea.model.InterProcessStimulus |
| import org.eclipse.app4mc.amlt2systemc.m2t.module.BaseTransformer |
| import org.eclipse.app4mc.amlt2systemc.m2t.transformers.AmaltheaTransformer |
| import org.eclipse.app4mc.amlt2systemc.m2t.transformers.TranslationUnit |
| import org.eclipse.app4mc.transformation.util.OutputBuffer |
| |
| @Singleton |
| class InterProcessStimulusTransformer extends BaseTransformer { |
| |
| @Inject OutputBuffer outputBuffer |
| |
| static def getModulePath(InterProcessStimulus interProcessStimulus) { |
| return AmaltheaTransformer.getModulePath() + "/stimuliModel/" + interProcessStimulus.name |
| } |
| |
| def getFunctionDef(InterProcessStimulus interProcessStimulus) { |
| return "get_" + interProcessStimulus.name + "()" |
| } |
| |
| def create new TranslationUnit transform(InterProcessStimulus interProcessStimulus) { |
| if (interProcessStimulus === null) { |
| it.module = "UNSPECIFIED_PERIODICSTIMULUS" |
| it.call = it.module |
| return |
| } |
| |
| it.module = getModulePath(interProcessStimulus) |
| it.call = getFunctionDef(interProcessStimulus) |
| |
| // write header file |
| outputBuffer.appendTo("INC", it.module, toH(interProcessStimulus)) |
| |
| // write implementation file |
| outputBuffer.appendTo("SRC", it.module, toCpp(interProcessStimulus)) |
| } |
| |
| private def String toH(InterProcessStimulus interProcessStimulus) ''' |
| #include "Common.h" |
| #include "SoftwareModel/Trigger.h" |
| |
| //InterProcessStimulus runnableA---- |
| std::shared_ptr<InterProcessStimulus> «getFunctionDef(interProcessStimulus)»; |
| ''' |
| |
| private def String toCpp(InterProcessStimulus interProcessStimulus) ''' |
| // This code was generated for simulation with app4mc.sim |
| |
| #include "../../«getModulePath(interProcessStimulus)».h" |
| |
| std::shared_ptr<InterProcessStimulus> «interProcessStimulus.name» = nullptr; |
| |
| std::shared_ptr<InterProcessStimulus> «getFunctionDef(interProcessStimulus)» { |
| |
| if («interProcessStimulus.name» == nullptr) { |
| //initialize |
| «interProcessStimulus.name» = std::make_shared<InterProcessStimulus>("«interProcessStimulus.name»"); |
| } |
| return «interProcessStimulus.name»; |
| } |
| |
| ''' |
| |
| def getCache() { return this._createCache_transform } |
| |
| } |