| /** |
| * ******************************************************************************* |
| * 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.utils |
| |
| import org.eclipse.app4mc.amalthea.model.AbstractEventChain |
| import org.eclipse.app4mc.amalthea.model.Channel |
| import org.eclipse.app4mc.amalthea.model.ChannelAccess |
| import org.eclipse.app4mc.amalthea.model.ChannelEvent |
| import org.eclipse.app4mc.amalthea.model.ChannelEventType |
| import org.eclipse.app4mc.amalthea.model.ChannelReceive |
| import org.eclipse.app4mc.amalthea.model.ChannelSend |
| import org.eclipse.app4mc.amalthea.model.Event |
| import org.eclipse.app4mc.amalthea.model.Process |
| import org.eclipse.app4mc.amalthea.model.Runnable |
| import org.eclipse.app4mc.amalthea.model.RunnableItem |
| |
| class DataFlowUtils { |
| |
| |
| |
| static def boolean testConditionEventChain2DataFlow(AbstractEventChain abstractEventChain){ |
| if (!testConditionChannelEvent(abstractEventChain?.stimulus)) |
| return false |
| if (!testConditionChannelEvent(abstractEventChain?.response)) |
| return false |
| return true |
| } |
| |
| |
| static def dispatch boolean isChannelEvent(Event event){ |
| return false |
| } |
| |
| static def dispatch boolean isChannelEvent(ChannelEvent event){ |
| return true |
| } |
| |
| |
| static def dispatch boolean testConditionChannelEvent(Event event){ |
| return false |
| } |
| |
| static def dispatch boolean testConditionChannelEvent(ChannelEvent event){ |
| if (DataFlowUtils.findChannelAccess(event) !== null){ |
| return true |
| } |
| return false |
| } |
| |
| |
| public static def dispatch ChannelAccess findChannelAccess(Event amltEvent) { |
| //some event not of specialization type ChannelEvent |
| return null |
| } |
| |
| |
| public static def dispatch ChannelAccess findChannelAccess(ChannelEvent amltChannelEvent) { |
| |
| if(amltChannelEvent === null) |
| return null |
| |
| val Channel channel = amltChannelEvent.entity; |
| val ChannelEventType eventType = amltChannelEvent.eventType; |
| val Runnable runnable = amltChannelEvent.runnable |
| val Process task = amltChannelEvent.process |
| |
| if(runnable === null) |
| return null |
| if(task === null) |
| return null |
| |
| if(!runnable.taskRunnableCalls.map[it.containingProcess].contains(task)) |
| return null |
| |
| if (eventType == ChannelEventType.SEND) { |
| return findChannelSend(runnable, channel) |
| } else if (eventType == ChannelEventType.RECEIVE) { |
| return findChannelReceive(runnable, channel) |
| } else { |
| return null; |
| } |
| } |
| |
| private static def ChannelSend findChannelSend(Runnable runnable, Channel channel) { |
| var ChannelSend ret = null |
| for (RunnableItem runnableItem : runnable.runnableItems) { |
| if (runnableItem instanceof ChannelSend){ |
| val channelSend = runnableItem as ChannelSend |
| if (channelSend.data === channel){ |
| if (ret === null){ |
| ret = channelSend |
| } else{ |
| //multiple send accesses to this channel within runnable --> not valid |
| return null |
| } |
| } |
| } |
| } |
| return ret |
| } |
| |
| private static def ChannelReceive findChannelReceive(Runnable runnable, Channel channel) { |
| var ChannelReceive ret = null |
| for (RunnableItem runnableItem : runnable.runnableItems) { |
| if (runnableItem instanceof ChannelReceive){ |
| val channelReceive= runnableItem as ChannelReceive |
| if (channelReceive.data === channel){ |
| if (ret === null){ |
| ret = channelReceive |
| } else{ |
| //multiple receive accesses to this channel within runnable --> not valid |
| return null |
| } |
| } |
| } |
| } |
| return ret |
| } |
| |
| |
| } |