| /** |
| * ******************************************************************************* |
| * Copyright (c) 2017 Timing-Architects Embedded Systems GmbH and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Timing-Architects Embedded Systems GmbH - initial API and implementation |
| * |
| * ******************************************************************************* |
| */ |
| package org.eclipse.app4mc.amalthea.generator.ui; |
| |
| import java.util.Arrays; |
| |
| import org.eclipse.app4mc.amalthea.generator.configuration.Generation; |
| import org.eclipse.app4mc.amalthea.generator.configuration.IntegerDistribution; |
| import org.eclipse.app4mc.amalthea.generator.configuration.RTMGC; |
| import org.eclipse.app4mc.amalthea.generator.configuration.RTMGCFactory; |
| import org.eclipse.app4mc.amalthea.generator.configuration.SemaphoreAccessProperties; |
| import org.eclipse.app4mc.amalthea.generator.configuration.SemaphoreAccessType; |
| import org.eclipse.app4mc.amalthea.generator.configuration.SemaphoreProperties; |
| import org.eclipse.app4mc.amalthea.generator.configuration.SemaphoreRequestOrder; |
| import org.eclipse.app4mc.amalthea.generator.configuration.SemaphoreType; |
| import org.eclipse.app4mc.amalthea.generator.configuration.WaitModes; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.custom.ScrolledComposite; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Button; |
| import org.eclipse.swt.widgets.Combo; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.TabFolder; |
| import org.eclipse.swt.widgets.TabItem; |
| |
| public class SemaphoresConfigurationHelper implements IConfigurationHelper { |
| |
| private IntegerDistributionGroup count; |
| private Button pcpButton; |
| private Combo typeCombo; |
| private Combo waitCombo; |
| private IntegerDistributionGroup read; |
| private IntegerDistributionGroup write; |
| private Combo orderCombo; |
| private Combo accessCombo; |
| |
| public void addTabItem(TabFolder parent) { |
| TabItem tab = new TabItem(parent, SWT.NONE); |
| tab.setText("Semaphores"); |
| |
| ScrolledComposite sc = new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL); |
| |
| Composite container = new Composite(sc, SWT.NONE); |
| container.setLayout(new GridLayout()); |
| GridLayout gridLayout = new GridLayout(); |
| container.setLayout(gridLayout); |
| gridLayout.numColumns = 2; |
| |
| sc.setExpandVertical(true); |
| sc.setExpandHorizontal(true); |
| |
| // count |
| this.count = new IntegerDistributionGroup(container, "Number of Semaphores to be Generated"); |
| |
| // priorityCeilingProtocol |
| Label label = new Label(container, SWT.NONE); |
| label.setText("Priority Ceiling Protocol"); |
| label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
| pcpButton = new Button(container, SWT.CHECK); |
| pcpButton.setSelection(true); |
| |
| // type |
| label = new Label(container, SWT.NONE); |
| label.setText("Semaphore Type"); |
| label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
| typeCombo = new Combo(container, SWT.READ_ONLY); |
| typeCombo.setItems(Arrays.stream(SemaphoreType.values()).map(Enum::name).toArray(String[]::new)); |
| typeCombo.select(0); |
| |
| // wait mode |
| label = new Label(container, SWT.NONE); |
| label.setText("Semaphore Wait Mode"); |
| label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
| waitCombo = new Combo(container, SWT.READ_ONLY); |
| waitCombo.setItems(Arrays.stream(WaitModes.values()).map(Enum::name).toArray(String[]::new)); |
| waitCombo.select(0); |
| |
| // SemaphoreAccessProperties |
| label = new Label(container, SWT.NONE); |
| label.setText(""); |
| GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); |
| gridData.horizontalSpan = 2; |
| gridData.heightHint = 30; |
| label.setLayoutData(gridData); |
| label = new Label(container, SWT.NONE); |
| label.setText("Semaphore Access Properties"); |
| gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); |
| gridData.horizontalSpan = 2; |
| label.setLayoutData(gridData); |
| |
| // perUnitReadAccessCount |
| this.read = new IntegerDistributionGroup(container, "Number of Read Accesses per Unit Protected by a Semaphore"); |
| this.write = new IntegerDistributionGroup(container, "Number of Write Accesses per Unit Protected by a Semaphore"); |
| |
| // requestOrder |
| label = new Label(container, SWT.NONE); |
| label.setText("Request Order"); |
| label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
| orderCombo = new Combo(container, SWT.READ_ONLY); |
| orderCombo.setItems(Arrays.stream(SemaphoreRequestOrder.values()).map(Enum::name).toArray(String[]::new)); |
| orderCombo.select(0); |
| |
| // accessType |
| label = new Label(container, SWT.NONE); |
| label.setText("AccessType"); |
| label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
| accessCombo = new Combo(container, SWT.READ_ONLY); |
| accessCombo.setItems(Arrays.stream(SemaphoreAccessType.values()).map(Enum::name).toArray(String[]::new)); |
| accessCombo.select(0); |
| |
| sc.setContent(container); |
| sc.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
| tab.setControl(sc); |
| } |
| |
| @Override |
| public void loadConfiguration(RTMGC rtmgc) { |
| if(null != rtmgc) { |
| Generation generation = rtmgc.getGeneration(); |
| if(null != generation) { |
| SemaphoreProperties semaphores = generation.getSemaphores(); |
| if(null != semaphores) { |
| IntegerDistribution count = semaphores.getCount(); |
| this.count.set(count); |
| this.pcpButton.setSelection(semaphores.isPriorityCeilingProtocol()); |
| this.typeCombo.select(semaphores.getSemaphoreType().getValue()); |
| this.waitCombo.select(semaphores.getWaitMode().getValue()); |
| SemaphoreAccessProperties accessProperties = semaphores.getSemaphoreAccess(); |
| if(null != accessProperties) { |
| IntegerDistribution read = accessProperties.getPerUnitReadAccessCount(); |
| this.read.set(read); |
| IntegerDistribution write = accessProperties.getPerUnitWriteAccessCount(); |
| this.write.set(write); |
| this.accessCombo.select(accessProperties.getAccessType().getValue()); |
| this.orderCombo.select(accessProperties.getRequestOrder().getValue()); |
| } |
| } |
| } |
| } |
| } |
| |
| @Override |
| public void updateConfiguration(RTMGC rtmgc) { |
| if(null != rtmgc) { |
| Generation generation = rtmgc.getGeneration(); |
| if(null == generation) { |
| generation = RTMGCFactory.eINSTANCE.createGeneration(); |
| rtmgc.setGeneration(generation); |
| } |
| SemaphoreProperties semaphores = generation.getSemaphores(); |
| if(null == semaphores) { |
| semaphores = RTMGCFactory.eINSTANCE.createSemaphoreProperties(); |
| generation.setSemaphores(semaphores); |
| } |
| IntegerDistribution count = this.count.get(); |
| semaphores.setCount(count); |
| semaphores.setPriorityCeilingProtocol(this.pcpButton.getSelection()); |
| semaphores.setSemaphoreType(SemaphoreType.get(this.typeCombo.getSelectionIndex())); |
| semaphores.setWaitMode(WaitModes.get(this.waitCombo.getSelectionIndex())); |
| SemaphoreAccessProperties accessProperties = semaphores.getSemaphoreAccess(); |
| if(null == accessProperties) { |
| accessProperties = RTMGCFactory.eINSTANCE.createSemaphoreAccessProperties(); |
| semaphores.setSemaphoreAccess(accessProperties); |
| } |
| IntegerDistribution read = this.read.get(); |
| accessProperties.setPerUnitReadAccessCount(read); |
| IntegerDistribution write = this.write.get(); |
| accessProperties.setPerUnitWriteAccessCount(write); |
| accessProperties.setAccessType(SemaphoreAccessType.get(this.accessCombo.getSelectionIndex())); |
| accessProperties.setRequestOrder(SemaphoreRequestOrder.get(this.orderCombo.getSelectionIndex())); |
| } |
| } |
| |
| @Override |
| public boolean isValid() { |
| return true; |
| } |
| } |