| /** |
| * ******************************************************************************* |
| * 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.DataFlowConnection |
| import com.inchron.realtime.root.model.VariableReadAccessPolicy |
| import com.inchron.realtime.root.model.VariableReadAccessType |
| import com.inchron.realtime.root.model.VariableWriteAccessType |
| import com.inchron.realtime.root.model.memory.DataAccessType |
| import org.eclipse.app4mc.amalthea.model.ChannelReceive |
| import org.eclipse.app4mc.amalthea.model.ChannelSend |
| import org.eclipse.app4mc.amalthea.model.Process |
| import org.eclipse.app4mc.amalthea.model.ReceiveOperation |
| import templates.AbstractAmaltheaInchronTransformer |
| import templates.m2m.sw.ChannelTransformer |
| |
| @Singleton |
| class ChannelAccessTransformer extends AbstractAmaltheaInchronTransformer { |
| |
| @Inject ChannelTransformer channelTransformer |
| @Inject TransmissionPolicyTransformer transmissionPolicyTransformer |
| |
| private static Integer enumeratorRead = 0; |
| private static Integer enumeratorSend = 0 |
| |
| def dispatch create inchronModelFactory.createVariableReadAccess createVariableAccess(Process amltTask, ChannelReceive amltChannelReceive) { |
| //create/get dataflow |
| it.connection = channelTransformer.createDataFlowConnection(amltChannelReceive.data) |
| //set attributes |
| val name = amltTask.name + "_receive_" + it.connection.name + "_" + enumeratorRead |
| it.dataMustBeNew = amltChannelReceive.dataMustBeNew |
| it.index = amltChannelReceive.elementIndex |
| it.name = name |
| it.label = name |
| it.minElements = amltChannelReceive.lowerBound |
| it.elements = amltChannelReceive.elements |
| |
| //set data access policy |
| if (amltChannelReceive.transmissionPolicy !== null){ |
| it.dataAccess = transmissionPolicyTransformer.createExplicitDataAccess(amltTask, amltChannelReceive.transmissionPolicy) |
| } else { |
| it.dataAccess = inchronMemoryFactory.createExplicitDataAccess |
| } |
| it.dataAccess.accessType = DataAccessType.READ; |
| |
| |
| //assign operation type: FIFO, LIFO, TAKE, READ |
| if (amltChannelReceive.receiveOperation === ReceiveOperation.FIFO_READ) { |
| it.policy = VariableReadAccessPolicy.FIFO_READ |
| } |
| else if (amltChannelReceive.receiveOperation === ReceiveOperation.FIFO_TAKE) { |
| it.policy = VariableReadAccessPolicy.FIFO_TAKE |
| } |
| else if (amltChannelReceive.receiveOperation === ReceiveOperation.LIFO_READ) { |
| it.policy = VariableReadAccessPolicy.LIFO_READ |
| } |
| else if (amltChannelReceive.receiveOperation === ReceiveOperation.LIFO_TAKE) { |
| it.policy = VariableReadAccessPolicy.LIFO_TAKE |
| } |
| |
| //assign type |
| it.type = VariableReadAccessType.GENERIC |
| |
| //add read access to dataflow connection's receiver list |
| it.connection.requesters.add(it) |
| |
| enumeratorRead = enumeratorRead + 1 |
| } |
| |
| |
| def dispatch create inchronModelFactory.createVariableWriteAccess createVariableAccess(Process amltTask, ChannelSend amltChannelSend) { |
| //create/get dataflow |
| val DataFlowConnection connectionTmp = channelTransformer.createDataFlowConnection(amltChannelSend.data) |
| //set attributes |
| val name = amltTask.name + "_send_" + connectionTmp.name + "_" + enumeratorSend |
| //issue an error if connection's provider is already set |
| if (connectionTmp.provider !== null){ |
| logger.error("Transformation for Channel to Inchron DataFlowConnection supports only one writer per channel. Updating provider of data flow connection " + connectionTmp.name + |
| ", replacing " + connectionTmp.provider.name + " with " + name) |
| } |
| |
| it.connection = connectionTmp |
| it.name = name |
| it.label = name |
| it.elements = amltChannelSend.elements |
| |
| //set data access policy |
| if (amltChannelSend.transmissionPolicy !== null){ |
| it.dataAccess = transmissionPolicyTransformer.createExplicitDataAccess(amltTask, amltChannelSend.transmissionPolicy) |
| } else { |
| it.dataAccess = inchronMemoryFactory.createExplicitDataAccess |
| } |
| it.dataAccess.accessType = DataAccessType.WRITE; |
| |
| //assign type |
| it.type = VariableWriteAccessType.GENERIC |
| |
| //TODO: assign policy |
| //it.policy = VariableWriteAccessPolicy.ERROR_DROP |
| |
| enumeratorSend = enumeratorSend + 1 |
| } |
| } |