| /** |
| ******************************************************************************** |
| * Copyright (c) 2018-2019 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 templates.m2m.sw |
| |
| import com.google.inject.Inject |
| import com.inchron.realtime.root.model.ActivationConnection |
| import com.inchron.realtime.root.model.Component |
| import com.inchron.realtime.root.model.FunctionCall |
| import java.util.LinkedHashMap |
| import org.eclipse.app4mc.amalthea.model.CustomEventTrigger |
| import org.eclipse.app4mc.amalthea.model.EventStimulus |
| import org.eclipse.app4mc.amalthea.model.Process |
| import templates.AbstractAmaltheaInchronTransformer |
| import templates.utils.AmaltheaModelNagivationUtils |
| import templates.utils.AmltCacheModel |
| import com.google.inject.Singleton |
| |
| @Singleton |
| class CustomEventTriggerTransformer extends AbstractAmaltheaInchronTransformer { |
| |
| var AmltCacheModel cacheModel |
| |
| @Inject ModeValueDisjunctionTransformer modeValueDisjunctionTransformer |
| @Inject CallGraphTransformer callGraphTransformer |
| |
| public def FunctionCall transformCustomEventTrigger(Component inchronComponent, Process amltTask, |
| CustomEventTrigger amltCustomEventTrigger){ |
| |
| cacheModel = customObjsStore.getInstance(AmltCacheModel) |
| |
| val amltCustomEvent= amltCustomEventTrigger.event |
| |
| val amltStimulusInchronActivationConnectionsMap=new LinkedHashMap<EventStimulus, ActivationConnection> |
| |
| if(amltCustomEvent !==null){ |
| val amltCustomEventBackReferences=AmaltheaModelNagivationUtils.getBackReferences(amltCustomEvent,true); |
| |
| for (amltCustomEventBackReference : amltCustomEventBackReferences) { |
| |
| if(amltCustomEventBackReference instanceof EventStimulus){ |
| //listing the tasks which are stimulated by EventStimulus |
| val inchronActivationConnection=createActivationConnection(amltCustomEventBackReference) |
| |
| amltStimulusInchronActivationConnectionsMap.put(amltCustomEventBackReference, inchronActivationConnection) |
| |
| } |
| } |
| } |
| |
| |
| val inchronDummyFunction=inchronModelFactory.createFunction |
| |
| inchronDummyFunction.name="Dummy_CustomEventTriggerFunction_"+amltCustomEventTrigger.hashCode |
| //Adding Function to Inchron Component |
| inchronComponent.functions.add(inchronDummyFunction) |
| |
| val inchronCallGraph=inchronModelFactory.createCallGraph |
| |
| inchronDummyFunction.callGraph=inchronCallGraph |
| |
| val inchronModeSwitch=inchronModelFactory.createModeSwitch |
| |
| |
| |
| //Transforming mode entries with condition |
| //############# now creating ActivationItem and associating ActivationConnection objects |
| |
| amltStimulusInchronActivationConnectionsMap.forEach[amltEventStimulus, inchronActivationConnection|{ |
| |
| val inchronModeSwitchEntry=inchronModelFactory.createModeSwitchEntry |
| |
| //Adding entry with condition |
| inchronModeSwitch.entries.add(inchronModeSwitchEntry) |
| |
| var amltCondition=amltEventStimulus.enablingModeValueList |
| |
| if(amltCondition!==null){ |
| var inchronConditon=modeValueDisjunctionTransformer.createModeCondition(amltCondition,amltTask) |
| |
| inchronModeSwitchEntry.condition = inchronConditon |
| |
| if(inchronConditon.eContainer===null){ |
| //Adding ModeCondition to the Inchron Model |
| getInchronRoot().globalModeConditions.add(inchronConditon) |
| } |
| } |
| |
| val inchronCallSequence=inchronModelFactory.createCallSequence |
| |
| val inchronActivationItem=inchronModelFactory.createActivationItem |
| |
| inchronActivationItem.connection=inchronActivationConnection |
| |
| inchronCallSequence.calls.add(inchronActivationItem) |
| |
| //Adding callSequence to default entry |
| inchronModeSwitchEntry.graphEntries.add(inchronCallSequence) |
| |
| }] |
| /* |
| * 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.createDummyCallSequenceWitchModeSwitchEvaluation(inchronModeSwitch, inchronCallGraph); |
| |
| //Adding ModeSwitch |
| inchronCallGraph.graphEntries.add(inchronModeSwitch) |
| |
| var FunctionCall inchronFunctionCall=inchronModelFactory.createFunctionCall |
| |
| inchronFunctionCall.function=inchronDummyFunction |
| |
| inchronFunctionCall.name="call_"+inchronDummyFunction.name |
| |
| return inchronFunctionCall |
| |
| } |
| |
| protected def create inchronModelFactory.createActivationConnection createActivationConnection(EventStimulus amltCustomEventBackReference) { |
| |
| val amltTasks=amltCustomEventBackReference.affectedProcesses |
| |
| it.name = "EventStimulus_"+amltCustomEventBackReference.name |
| |
| getInchronRoot().connections.add(it) |
| |
| amltTasks.forEach[amltStimulatedTask|{ |
| var inchronActivateProcess = inchronModelFactory.createActivateProcess |
| |
| inchronActivateProcess.target = cacheModel.amltProcess_inchronProcessMap.get(amltStimulatedTask) |
| |
| it.activations.add(inchronActivateProcess) |
| }] |
| } |
| |
| |
| |
| |
| } |