| /** |
| * ******************************************************************************* |
| * 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.os |
| |
| import com.google.inject.Inject |
| import com.google.inject.Singleton |
| import org.eclipse.app4mc.amalthea.model.FixedPriorityPreemptive |
| import org.eclipse.app4mc.amalthea.model.TaskScheduler |
| import org.eclipse.app4mc.amalthea.model.TaskSchedulingAlgorithm |
| import org.eclipse.app4mc.amlt2systemc.m2t.module.BaseTransformer |
| import org.eclipse.app4mc.amlt2systemc.m2t.transformers.TranslationUnit |
| import org.eclipse.app4mc.transformation.util.OutputBuffer |
| import org.eclipse.app4mc.amalthea.model.OSEK |
| |
| @Singleton |
| class TaskSchedulerTransformer extends BaseTransformer { |
| |
| @Inject OutputBuffer outputBuffer |
| |
| def getName(TaskScheduler taskScheduler) { |
| return taskScheduler.name + "_" + chooseSchedulerBasedOnAlgorithm(taskScheduler.schedulingAlgorithm).call |
| } |
| |
| private def getModulePath(TaskScheduler taskScheduler) { |
| return OsModelTransformer.getModulePath() + "/tasks/" + getName(taskScheduler) |
| } |
| |
| private def getCall(TaskScheduler taskScheduler) { |
| return "get_" + getName(taskScheduler) |
| } |
| |
| def create new TranslationUnit transform(TaskScheduler taskScheduler) { |
| it.module = getModulePath(taskScheduler) |
| it.call = getCall(taskScheduler) |
| // write header file |
| outputBuffer.appendTo("INC", it.module, toH(taskScheduler)) |
| // write implementation file |
| outputBuffer.appendTo("SRC", it.module, toCpp(taskScheduler)) |
| } |
| |
| private def String toH(TaskScheduler taskScheduler) ''' |
| «val scheduler = chooseSchedulerBasedOnAlgorithm((taskScheduler.schedulingAlgorithm))» |
| #include "SoftwareModel.h" |
| #include "«scheduler.module»" |
| |
| //Task runnableA---- |
| std::shared_ptr<«scheduler.call»> «getCall(taskScheduler)»(); |
| ''' |
| |
| private def String toCpp(TaskScheduler taskScheduler) ''' |
| #include "Common.h" |
| #include "../../../«getModulePath(taskScheduler)».h" |
| «val scheduler = chooseSchedulerBasedOnAlgorithm((taskScheduler.schedulingAlgorithm))» |
| |
| std::shared_ptr<«scheduler.call»> «taskScheduler.name» = nullptr; |
| |
| std::shared_ptr<«scheduler.call»> «getCall(taskScheduler)»() { |
| if («taskScheduler.name» == nullptr) { |
| //initialize |
| «taskScheduler.name» = std::make_shared<«scheduler.call»>("«taskScheduler.name»"); |
| } |
| return «taskScheduler.name»; |
| } |
| ''' |
| |
| private final static def dispatch TranslationUnit chooseSchedulerBasedOnAlgorithm( |
| TaskSchedulingAlgorithm taskSchedulingAlgorithm) { |
| return new TranslationUnit("RandomScheduler.h", "RandomScheduler") |
| } |
| |
| private final static def dispatch TranslationUnit chooseSchedulerBasedOnAlgorithm( |
| FixedPriorityPreemptive fixedPriorityPreemptive) { |
| return new TranslationUnit("PriorityScheduler.h", "PriorityScheduler") |
| } |
| |
| private final static def dispatch TranslationUnit chooseSchedulerBasedOnAlgorithm( |
| OSEK osek) { |
| return new TranslationUnit("PriorityScheduler.h", "PriorityScheduler") |
| } |
| |
| def getCache() { return this._createCache_transform } |
| |
| } |