blob: b233bf409c08fbdad604fc86a7edf3b9e3d7ab7e [file] [log] [blame]
/**
* *******************************************************************************
* 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.runnableItem
import com.google.inject.Inject
import com.google.inject.Singleton
import com.inchron.realtime.root.model.ActivationConnection
import com.inchron.realtime.root.model.CallSequenceItem
import com.inchron.realtime.root.model.Component
import com.inchron.realtime.root.model.FunctionCall
import java.util.LinkedHashMap
import java.util.LinkedList
import java.util.List
import org.eclipse.app4mc.amalthea.model.CustomEventTrigger
import org.eclipse.app4mc.amalthea.model.EventStimulus
import templates.AbstractAmaltheaInchronTransformer
import templates.m2m.stimuli.StimuliTransformer
import templates.utils.AmaltheaModelNagivationUtils
import templates.utils.AmltCacheModel
@Singleton
class CustomEventTriggerTransformer extends AbstractAmaltheaInchronTransformer {
var AmltCacheModel cacheModel
@Inject StimuliTransformer stimuliTransformer
public def List<CallSequenceItem> transformCustomEventTrigger(Component inchronComponent, CustomEventTrigger amltCustomEventTrigger){
cacheModel = customObjsStore.getInstance(AmltCacheModel)
val inchronCallSequenceItems = new LinkedList<CallSequenceItem>
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){
val inchronActivationConnection = stimuliTransformer.createActivationConnection(amltCustomEventBackReference as EventStimulus)
amltStimulusInchronActivationConnectionsMap.put(amltCustomEventBackReference, inchronActivationConnection)
}
}
}
//Transforming mode entries with condition
//############# now creating ActivationItem and associating ActivationConnection objects
amltStimulusInchronActivationConnectionsMap.forEach[amltEventStimulus, inchronActivationConnection|{
val inchronActivationItem=inchronModelFactory.createActivationItem
inchronActivationItem.name = "ActivationItem_"+ amltEventStimulus.name
inchronActivationItem.connection=inchronActivationConnection;
if (amltEventStimulus.enablingModeValueList !== null){
/*
* 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
*/
val inchronDummyFunction=stimuliTransformer.createDummyFunction(amltEventStimulus, inchronActivationItem)
inchronComponent.functions.add(inchronDummyFunction)
var FunctionCall inchronFunctionCall=inchronModelFactory.createFunctionCall
inchronFunctionCall.function=inchronDummyFunction
inchronFunctionCall.name="call_"+inchronDummyFunction.name
inchronCallSequenceItems.add(inchronFunctionCall)
} else {
inchronCallSequenceItems.add(inchronActivationItem)
}
}]
return inchronCallSequenceItems
}
}