Search in sources :

Example 1 with PropertyNotPresentException

use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.

the class Binpack method getAllowedProcessorBindings.

/**
 * Get the processor components that a given thread is allowed to be bound to
 * based on the thread's ALLOWED_PROCESSOR_BINDING and
 * ALLOWED_PROCESSOR_BINDING_CLASS property values. The processors are
 * search for in the same system instance that the given thread component is
 * a part of.
 *
 * @param thread
 *                 The thread.
 * @return An unmodifiable set of processor ComponentInstances.
 * @exception IllegalArgumentException
 *                      Thrown if the category of the component instance
 *                      referenced by <code>thread</code> is not
 *                      {@link ComponentCategory#THREAD_LITERAL}.
 */
public Set<ComponentInstance> getAllowedProcessorBindings(final ComponentInstance thread) {
    if (thread.getCategory() != ComponentCategory.THREAD) {
        throw new IllegalArgumentException("Component \"" + thread.getName() + "\" is not a thread.");
    }
    List<ComponentInstance> allowedBindingsVals;
    try {
        allowedBindingsVals = GetProperties.getAllowedProcessorBinding(thread);
    } catch (PropertyNotPresentException e) {
        // Ignore this situation and move on.
        allowedBindingsVals = Collections.emptyList();
    }
    List<Classifier> allowedClassVals;
    try {
        allowedClassVals = GetProperties.getAllowedProcessorBindingClass(thread);
    } catch (PropertyNotPresentException e) {
        // Ignore this situation and move on.
        allowedClassVals = Collections.emptyList();
    }
    final Set<ComponentInstance> searchRoots = new HashSet<>();
    if (allowedBindingsVals.isEmpty()) {
        searchRoots.add(thread.getSystemInstance());
    } else {
        for (final Iterator<ComponentInstance> i = allowedBindingsVals.iterator(); i.hasNext(); ) {
            final ComponentInstance rv = i.next();
            searchRoots.add(rv);
        }
    }
    final Set<SystemClassifier> allowedSystemClassifiers = new HashSet<>();
    final Set<ProcessorClassifier> allowedProcClassifiers = new HashSet<>();
    for (final Iterator<Classifier> i = allowedClassVals.iterator(); i.hasNext(); ) {
        final Classifier cc = i.next();
        if (cc instanceof ProcessorClassifier) {
            // ComponentCategory.PROCESSOR) {
            allowedProcClassifiers.add((ProcessorClassifier) cc);
        } else if (cc instanceof SystemClassifier) {
            // cv.getValue() == ComponentCategory.SYSTEM_LITERAL) {
            allowedSystemClassifiers.add((SystemClassifier) cc);
        } else {
            internalError("Ill-formed allowed_processor_binding_class value: got a non-system non-processor component classifier");
        }
    }
    final Set<ComponentInstance> allowedProcs = new HashSet<>();
    for (final Iterator<ComponentInstance> i = searchRoots.iterator(); i.hasNext(); ) {
        final ComponentInstance ci = i.next();
        getAllowedProcessorBindings(ci, allowedProcs, allowedProcClassifiers, allowedSystemClassifiers);
    }
    return Collections.unmodifiableSet(allowedProcs);
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) Classifier(org.osate.aadl2.Classifier) SystemClassifier(org.osate.aadl2.SystemClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) SystemClassifier(org.osate.aadl2.SystemClassifier) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) HashSet(java.util.HashSet)

Example 2 with PropertyNotPresentException

use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.

the class SetInstanceModelBindings method prepare.

public boolean prepare() {
    /*
		 * First get the old processor bindings so we can undo.
		 * We assume that the bindings are NOT modal!
		 */
    try {
        for (Iterator iter = threadsToProc.keySet().iterator(); iter.hasNext(); ) {
            final ComponentInstance thread = (ComponentInstance) iter.next();
            // Get the old val, may not have been set
            PropertyValue oldVal;
            try {
                oldVal = (PropertyValue) thread.getSimplePropertyValue(GetProperties.getActualProcessorBindingProperty(thread));
            } catch (PropertyNotPresentException e) {
                oldVal = null;
            }
            oldThreadsToProc.put(thread, oldVal);
        }
        /*
			 * Next we go through the given thread->proc map and change it to be a
			 * map from theads to InstanceReferenceValues. This way we don't have
			 * to keep recreating reference values.
			 */
        for (Iterator iter = threadsToProc.keySet().iterator(); iter.hasNext(); ) {
            final ComponentInstance thread = (ComponentInstance) iter.next();
            final ComponentInstance proc = (ComponentInstance) threadsToProc.get(thread);
            final InstanceReferenceValue val = InstanceFactory.eINSTANCE.createInstanceReferenceValue();
            val.setReferencedInstanceObject(proc);
            threadsToProc.put(thread, val);
        }
        // always ready to go
        return true;
    } catch (InvalidModelException e) {
        ResourcemanagementPlugin.logErrorMessage(e.getMessage());
        return false;
    }
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) Iterator(java.util.Iterator) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) PropertyValue(org.osate.aadl2.PropertyValue) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue)

Example 3 with PropertyNotPresentException

use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.

the class PriorityInversion method checkPriorityInversion.

/**
 * check for priority inversion of threads bound to the given processor
 * @param curProcessor Component Instance of processor
 */
public void checkPriorityInversion(ComponentInstance curProcessor) {
    SystemInstance root = curProcessor.getSystemInstance();
    final ComponentInstance currentProcessor = curProcessor;
    EList<Element> boundThreads = new ForAllElement() {

        @Override
        protected boolean suchThat(Element obj) {
            if (!InstanceModelUtil.isPeriodicThread((ComponentInstance) obj)) {
                return false;
            }
            List<ComponentInstance> boundProcessor;
            try {
                boundProcessor = GetProperties.getActualProcessorBinding((ComponentInstance) obj);
            } catch (PropertyNotPresentException e) {
                return false;
            }
            return boundProcessor.contains(currentProcessor);
        }
    }.processPreOrderComponentInstance(root, ComponentCategory.THREAD);
    // we will sort the thread list by period and
    // check to make sure the assigned priority is monotonically decreasing
    ECollections.sort(boundThreads, (obj1, obj2) -> {
        final double a = PropertyUtils.getScaled(TimingProperties::getPeriod, (ComponentInstance) obj1, TimeUnits.MS).orElse(0.0);
        final double b = PropertyUtils.getScaled(TimingProperties::getPeriod, (ComponentInstance) obj2, TimeUnits.MS).orElse(0.0);
        if (a > b) {
            return 1;
        }
        if (a == b) {
            return 0;
        }
        return -1;
    });
    checkDecreasingPriority(boundThreads);
}
Also used : ForAllElement(org.osate.aadl2.modelsupport.modeltraversal.ForAllElement) PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) SystemInstance(org.osate.aadl2.instance.SystemInstance) Element(org.osate.aadl2.Element) ForAllElement(org.osate.aadl2.modelsupport.modeltraversal.ForAllElement) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) EList(org.eclipse.emf.common.util.EList) List(java.util.List)

Example 4 with PropertyNotPresentException

use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.

the class ModelingProperties method getAcceptableArraySize.

public static Optional<List<IntegerRange>> getAcceptableArraySize(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getAcceptableArraySize_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> {
            PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode);
            return new IntegerRange(resolved1, lookupContext, mode);
        }).collect(Collectors.toList()));
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : IntegerRange(org.osate.pluginsupport.properties.IntegerRange) PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Example 5 with PropertyNotPresentException

use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.

the class ModelingProperties method getImplementedAs.

public static Optional<Classifier> getImplementedAs(NamedElement lookupContext, Optional<Mode> mode) {
    Property property = getImplementedAs_Property(lookupContext);
    try {
        PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
        PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
        return Optional.of(((ClassifierValue) resolved).getClassifier());
    } catch (PropertyNotPresentException e) {
        return Optional.empty();
    }
}
Also used : PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyExpression(org.osate.aadl2.PropertyExpression) Property(org.osate.aadl2.Property)

Aggregations

PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)238 PropertyExpression (org.osate.aadl2.PropertyExpression)236 Property (org.osate.aadl2.Property)233 ListValue (org.osate.aadl2.ListValue)50 TimeUnits (org.osate.aadl2.contrib.aadlproject.TimeUnits)40 SizeUnits (org.osate.aadl2.contrib.aadlproject.SizeUnits)17 InstanceReferenceValue (org.osate.aadl2.instance.InstanceReferenceValue)13 ClassifierValue (org.osate.aadl2.ClassifierValue)7 StringLiteral (org.osate.aadl2.StringLiteral)6 DataRateUnits (org.osate.aadl2.contrib.aadlproject.DataRateUnits)4 IntegerLiteral (org.osate.aadl2.IntegerLiteral)3 RangeValue (org.osate.aadl2.RangeValue)3 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)3 InvalidModelException (org.osate.aadl2.properties.InvalidModelException)3 List (java.util.List)2 BasicProperty (org.osate.aadl2.BasicProperty)2 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)2 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)2 PropertyAssociation (org.osate.aadl2.PropertyAssociation)2 SystemInstance (org.osate.aadl2.instance.SystemInstance)2