| /** |
| * ******************************************************************************* |
| * Copyright (c) 2019 Robert Bosch GmbH and others. |
| * |
| * 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 templates.m2m.sw |
| |
| import com.google.inject.Inject |
| import com.google.inject.Singleton |
| import com.inchron.realtime.root.model.Component |
| import com.inchron.realtime.root.model.FunctionCall |
| import java.util.Map |
| import org.eclipse.app4mc.amalthea.model.GraphEntryBase |
| import org.eclipse.app4mc.amalthea.model.ModeSwitch |
| import org.eclipse.app4mc.amalthea.model.Process |
| import org.eclipse.app4mc.amalthea.model.RunnableModeSwitch |
| import templates.utils.AmltCacheModel |
| |
| @Singleton |
| class ModeSwitchTransformer extends GraphEntryBaseTransformer { |
| |
| @Inject RunnableItemTransformer runnableItemTransformer |
| @Inject ModeValueDisjunctionTransformer modeValueDisjunctionTransformer |
| @Inject CallGraphTransformer callGraphTransformer |
| |
| var AmltCacheModel cacheModel |
| |
| public def FunctionCall transformRunnableModeSwitch(Component inchronComponent, Process amltTask, |
| RunnableModeSwitch amltRunnableModeSwitch){ |
| |
| cacheModel = customObjsStore.getInstance(AmltCacheModel) |
| |
| val inchronDummyFunction=inchronModelFactory.createFunction |
| |
| inchronDummyFunction.name="Dummy_RunnableModeSwitchFunction_"+amltRunnableModeSwitch.hashCode |
| //Adding Function to Inchron Component |
| inchronComponent.functions.add(inchronDummyFunction) |
| |
| val inchronCallGraph=inchronModelFactory.createCallGraph |
| |
| inchronDummyFunction.callGraph=inchronCallGraph |
| |
| val inchronModeSwitch=inchronModelFactory.createModeSwitch |
| |
| if(amltRunnableModeSwitch.defaultEntry !==null){ |
| |
| val inchronModeSwitchDefault=inchronModelFactory.createModeSwitchDefault |
| //Adding default entry |
| inchronModeSwitch.defaultEntry = inchronModeSwitchDefault |
| |
| val inchronCallSequence=inchronModelFactory.createCallSequence |
| |
| //Adding callSequence to default entry |
| inchronModeSwitchDefault.graphEntries.add(inchronCallSequence) |
| |
| amltRunnableModeSwitch?.defaultEntry?.items?.forEach[amltRunnableModeSwitchRunnableItem| |
| |
| inchronCallSequence.calls.addAll(runnableItemTransformer.transformRunnableItem(inchronComponent,amltTask,amltRunnableModeSwitchRunnableItem)) |
| ] |
| |
| } |
| //Transforming mode entries with condition |
| amltRunnableModeSwitch?.entries?.forEach[amltModeSwitchEntry|{ |
| |
| val inchronModeSwitchEntry=inchronModelFactory.createModeSwitchEntry |
| |
| //Adding entry with condition |
| inchronModeSwitch.entries.add(inchronModeSwitchEntry) |
| |
| var amltCondition=amltModeSwitchEntry.condition |
| if(amltCondition!==null){ |
| var inchronConditon=modeValueDisjunctionTransformer.createModeCondition(amltCondition) |
| |
| inchronModeSwitchEntry.condition = inchronConditon |
| |
| if(inchronConditon.eContainer===null){ |
| //Adding ModeCondition to the Inchron Model |
| getInchronRoot().globalModeConditions.add(inchronConditon) |
| } |
| } |
| |
| |
| val inchronCallSequence=inchronModelFactory.createCallSequence |
| |
| //Adding callSequence to default entry |
| inchronModeSwitchEntry.graphEntries.add(inchronCallSequence) |
| |
| amltModeSwitchEntry?.items?.forEach[amltRunnableModeSwitchRunnableItem| |
| |
| inchronCallSequence.calls.addAll(runnableItemTransformer.transformRunnableItem(inchronComponent,amltTask,amltRunnableModeSwitchRunnableItem)) |
| ] |
| }] |
| |
| |
| /* |
| * Based on the requirement from Inchron to use the latest Mode values: |
| * -- it is required to create a "Dummy CallSequence" and associate ModeConditionEvaluation of each ModeSwitchEntry object |
| */ |
| callGraphTransformer.createDummyCallSequenceWithModeSwitchEvaluation(inchronModeSwitch, inchronCallGraph); |
| |
| //Adding ModeSwitch |
| inchronCallGraph.graphEntries.add(inchronModeSwitch) |
| |
| |
| var FunctionCall inchronFunctionCall=inchronModelFactory.createFunctionCall |
| |
| inchronFunctionCall.function=inchronDummyFunction |
| |
| inchronFunctionCall.name="call_"+inchronDummyFunction.name |
| |
| return inchronFunctionCall |
| } |
| |
| public def create inchronModelFactory.createModeSwitch createModeSwitch(ModeSwitch amltGraphEntry,Process amltTask, |
| Map<Process, com.inchron.realtime.root.model.Process> amltProcess_inchronProcessMap){ |
| |
| cacheModel = customObjsStore.getInstance(AmltCacheModel) |
| |
| var amltDefaultEntry = amltGraphEntry.defaultEntry |
| |
| if (amltDefaultEntry !== null) { |
| it.defaultEntry=inchronModelFactory.createModeSwitchDefault |
| |
| amltDefaultEntry?.items.forEach [ amltEntryItem | |
| var inchronGraphEntryBase=transformGraphEntryBase(amltEntryItem as GraphEntryBase, amltTask, amltProcess_inchronProcessMap) |
| it.defaultEntry.graphEntries.add(inchronGraphEntryBase) |
| ] |
| } |
| |
| amltGraphEntry?.entries?.forEach [ amltEntry | |
| { |
| val inchronModeSwitchEntry=inchronModelFactory.createModeSwitchEntry |
| |
| it.entries.add(inchronModeSwitchEntry) |
| |
| amltEntry?.items?.forEach [ amltEntryItem | |
| { |
| var inchronGraphEntryBase=transformGraphEntryBase(amltEntryItem as GraphEntryBase, amltTask, |
| amltProcess_inchronProcessMap) |
| |
| inchronModeSwitchEntry.graphEntries.add(inchronGraphEntryBase) |
| |
| } |
| |
| ] |
| |
| var amltCondition=amltEntry.condition |
| if(amltCondition!==null){ |
| var inchronConditon=modeValueDisjunctionTransformer.createModeCondition(amltCondition) |
| |
| inchronModeSwitchEntry.condition = inchronConditon |
| |
| if(inchronConditon.eContainer===null){ |
| //Adding ModeCondition to the Inchron Model |
| getInchronRoot().globalModeConditions.add(inchronConditon) |
| } |
| } |
| |
| } |
| ] |
| |
| |
| } |
| |
| |
| } |