| /** |
| ******************************************************************************** |
| * Copyright (c) 2018 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.utils; |
| |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.List; |
| import java.util.Map; |
| |
| import org.eclipse.app4mc.amalthea.model.InterruptController; |
| import org.eclipse.app4mc.amalthea.model.MappingModel; |
| import org.eclipse.app4mc.amalthea.model.OperatingSystem; |
| import org.eclipse.app4mc.amalthea.model.Process; |
| import org.eclipse.app4mc.amalthea.model.Scheduler; |
| import org.eclipse.app4mc.amalthea.model.SchedulerAllocation; |
| import org.eclipse.app4mc.amalthea.model.Task; |
| import org.eclipse.app4mc.amalthea.model.TaskAllocation; |
| import org.eclipse.app4mc.amalthea.model.TaskScheduler; |
| import org.eclipse.emf.common.util.EList; |
| |
| import com.inchron.realtime.root.model.Component; |
| import com.inchron.realtime.root.model.ModeGroup; |
| |
| public class AmltCacheModel { |
| |
| private Map<String, ModeGroup> inchronModeGroupsMap = new HashMap<>(); |
| |
| |
| private Map<Process, Component> amltProcess_InchronComponentMap = new HashMap<>(); |
| |
| private Map<Process, com.inchron.realtime.root.model.Process> amltProcess_inchronProcessMap = new HashMap<>(); |
| |
| private Map<com.inchron.realtime.root.model.Scheduler, Scheduler> inchronScheduler_amltSchedulerMap = new HashMap<>(); |
| |
| private Map<Scheduler, SchedulerAllocation> scheduler_schedulerAllocationMap = new HashMap<Scheduler, SchedulerAllocation>(); |
| |
| private Map<Task, List<TaskAllocation>> tasks_TaskAllocationMap = new HashMap<Task, List<TaskAllocation>>(); |
| |
| private Map<TaskScheduler, List<TaskAllocation>> taskScheduler_taskAllocationMap = new HashMap<TaskScheduler, List<TaskAllocation>>(); |
| |
| private Map<String, List<org.eclipse.app4mc.amalthea.model.Process>> amltInterProcessStimuli_processActivationsMap = new HashMap<>(); |
| |
| private Map<String, List<com.inchron.realtime.root.model.Process>> amltStimuliInchronProcessMap = new HashMap<>(); |
| |
| public void cacheAmltStimuliInchronProcessMap(String amltStimuliName, |
| com.inchron.realtime.root.model.Process inchronProcess) { |
| if (amltStimuliName != null) { |
| List<com.inchron.realtime.root.model.Process> processList = amltStimuliInchronProcessMap |
| .get(amltStimuliName); |
| |
| if (processList == null) { |
| processList = new ArrayList<>(); |
| amltStimuliInchronProcessMap.put(amltStimuliName, processList); |
| } |
| processList.add(inchronProcess); |
| } |
| } |
| |
| public Map<String, List<com.inchron.realtime.root.model.Process>> getAmltStimuliInchronProcessElementsMap() { |
| |
| return amltStimuliInchronProcessMap; |
| } |
| |
| public void cacheInterProcessTriggerRelations(String stimuliName, Process amltProcess) { |
| |
| if (stimuliName != null) { |
| List<Process> processList = amltInterProcessStimuli_processActivationsMap.get(stimuliName); |
| |
| if (processList == null) { |
| processList = new ArrayList<>(); |
| amltInterProcessStimuli_processActivationsMap.put(stimuliName, processList); |
| } |
| processList.add(amltProcess); |
| } |
| |
| } |
| |
| public Map<String, List<Process>> getInterProcessTriggerRelationsMap() { |
| return amltInterProcessStimuli_processActivationsMap; |
| } |
| |
| public Map<Scheduler, SchedulerAllocation> getTaskScheduler_schedulerAllocationMap() { |
| return scheduler_schedulerAllocationMap; |
| } |
| |
| public Map<Task, List<TaskAllocation>> getTasks_TaskAllocationMap() { |
| return tasks_TaskAllocationMap; |
| } |
| |
| public Map<TaskScheduler, List<TaskAllocation>> getTaskScheduler_taskAllocationMap() { |
| return taskScheduler_taskAllocationMap; |
| } |
| |
| public void buildProcesses_SchedulerAllocationMap(MappingModel mappingModel) { |
| |
| EList<SchedulerAllocation> schedulerAllocations = mappingModel.getSchedulerAllocation(); |
| |
| for (SchedulerAllocation schedulerAllocation : schedulerAllocations) { |
| |
| scheduler_schedulerAllocationMap.put(schedulerAllocation.getScheduler(), schedulerAllocation); |
| } |
| |
| } |
| |
| public void buildSchedulerAndSchedulerAssociationMap(MappingModel mappingModel) { |
| |
| EList<SchedulerAllocation> schedulerAllocations = mappingModel.getSchedulerAllocation(); |
| |
| for (SchedulerAllocation schedulerAllocation : schedulerAllocations) { |
| |
| Scheduler scheduler = schedulerAllocation.getScheduler(); |
| if (scheduler instanceof TaskScheduler) { |
| scheduler_schedulerAllocationMap.put(scheduler, schedulerAllocation); |
| |
| } else if (scheduler instanceof InterruptController) { |
| // isr_schedulerAllocationMap.put(((InterruptController)scheduler).getISR, schedulerAllocation); |
| } |
| } |
| |
| } |
| |
| public Map<Scheduler, SchedulerAllocation> getScheduler_SchedulerAllocationMap() { |
| return scheduler_schedulerAllocationMap; |
| } |
| |
| public Map<TaskScheduler, List<TaskAllocation>> getTaskScheduler_TaskAllocationMap() { |
| return taskScheduler_taskAllocationMap; |
| } |
| |
| public void buildTaskSchedulerAndTaskAllocationMap(MappingModel mappingModel) { |
| |
| EList<TaskAllocation> taskAllocations = mappingModel.getTaskAllocation(); |
| |
| for (TaskAllocation taskAllocation : taskAllocations) { |
| |
| List<TaskAllocation> listOfTaskAllocations; |
| |
| if (taskScheduler_taskAllocationMap.containsKey(taskAllocation.getScheduler())) { |
| listOfTaskAllocations = taskScheduler_taskAllocationMap.get(taskAllocation.getScheduler()); |
| } else { |
| listOfTaskAllocations = new ArrayList<TaskAllocation>(); |
| taskScheduler_taskAllocationMap.put(taskAllocation.getScheduler(), listOfTaskAllocations); |
| } |
| |
| listOfTaskAllocations.add(taskAllocation); |
| |
| // populating map tasks_TaskAllocationMap |
| |
| List<TaskAllocation> listOftask_TaskAllocations; |
| |
| if (tasks_TaskAllocationMap.containsKey(taskAllocation.getTask())) { |
| listOftask_TaskAllocations = tasks_TaskAllocationMap.get(taskAllocation.getTask()); |
| } else { |
| listOftask_TaskAllocations = new ArrayList<TaskAllocation>(); |
| tasks_TaskAllocationMap.put(taskAllocation.getTask(), listOftask_TaskAllocations); |
| } |
| |
| listOftask_TaskAllocations.add(taskAllocation); |
| |
| } |
| |
| } |
| |
| public Map<OperatingSystem, List<TaskScheduler>> groupTaskSchdulers(Iterable<TaskScheduler> rootTaskSchedulers) { |
| |
| Map<OperatingSystem, List<TaskScheduler>> map = new HashMap<>(); |
| |
| for (TaskScheduler taskScheduler : rootTaskSchedulers) { |
| |
| List<TaskScheduler> list = map.get(taskScheduler.eContainer()); |
| |
| if (list == null) { |
| list = new ArrayList<TaskScheduler>(); |
| map.put((OperatingSystem) taskScheduler.eContainer(), list); |
| } |
| list.add(taskScheduler); |
| } |
| return map; |
| } |
| |
| public Map<Process, com.inchron.realtime.root.model.Process> getAmltProcess_inchronProcessMap() { |
| return amltProcess_inchronProcessMap; |
| } |
| |
| public void setAmltProcess_inchronProcessMap( |
| Map<Process, com.inchron.realtime.root.model.Process> amltProcess_inchronProcessMap) { |
| this.amltProcess_inchronProcessMap = amltProcess_inchronProcessMap; |
| } |
| |
| public void addInchronScheduler_amltSchedulerMap(com.inchron.realtime.root.model.Scheduler inchronScheduler, |
| Scheduler amltScheduler) { |
| inchronScheduler_amltSchedulerMap.put(inchronScheduler, amltScheduler); |
| } |
| |
| public Scheduler getAmltSchedulerFromInchronScheduler(com.inchron.realtime.root.model.Scheduler inchronScheduler) { |
| return inchronScheduler_amltSchedulerMap.get(inchronScheduler); |
| } |
| |
| public Map<com.inchron.realtime.root.model.Scheduler, Scheduler> getInchronScheduler_amltSchedulerMap() { |
| return inchronScheduler_amltSchedulerMap; |
| } |
| |
| |
| public void addInchronModeGroup(ModeGroup modeGroup) { |
| inchronModeGroupsMap.put(modeGroup.getName(), modeGroup); |
| } |
| |
| public ModeGroup getInchronModeGroup(String name) { |
| return inchronModeGroupsMap.get(name); |
| } |
| |
| public Map<String, ModeGroup> getInchronModeGroupMap( ) { |
| return inchronModeGroupsMap ; |
| } |
| |
| public void addAmltProcess_InchronComponent(Process amltProcess, Component inchronComponent) { |
| amltProcess_InchronComponentMap.put(amltProcess, inchronComponent); |
| } |
| |
| public Component getInchronComponent(Process amltProcess) { |
| return amltProcess_InchronComponentMap.get(amltProcess); |
| } |
| |
| } |