Search in sources :

Example 16 with ModeInstance

use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.

the class CreateConnectionsSwitch method fillInModes.

/**
 * For the given connection instance, identify all connection declarations
 * with "in modes." For all possible mode combinations of those "in modes,"
 * add those SOMs that contain the mode instance combinations.
 *
 * @param conni
 *            the connection instance
 */
private void fillInModes(ConnectionInstance conni) {
    ListIterator<ConnectionReference> refIter = conni.getConnectionReferences().listIterator();
    while (refIter.hasNext()) {
        ConnectionReference connRef = refIter.next();
        Connection conn = connRef.getConnection();
        ComponentInstance ci = connRef.getContext();
        List<ModeInstance> mis = null;
        // source modal
        mis = getComponentModes(conni.getSource().getComponentInstance());
        // conns modal
        if (mis == null) {
            var connModes = conn.getAllInModes();
            if (connModes.isEmpty()) {
                mis = getComponentModes(ci);
            } else {
                mis = connModes.stream().map(ci::findModeInstance).collect(Collectors.toList());
            }
        }
        // destination modal
        if (mis == null) {
            mis = getComponentModes(conni.getDestination().getComponentInstance());
        }
        if (mis != null) {
            for (ModeInstance mi : mis) {
                generateModeCombinations(conni, refIter, new ArrayList<>(Collections.singletonList(mi)));
            }
            if (conni.getInSystemOperationModes().isEmpty()) {
                warning(conni.getContainingComponentInstance(), "Connection " + conni.getName() + " was removed because it is not active in any system operation mode");
                EcoreUtil.delete(conni);
            }
            break;
        }
    }
}
Also used : ModeInstance(org.osate.aadl2.instance.ModeInstance) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ParameterConnection(org.osate.aadl2.ParameterConnection) AccessConnection(org.osate.aadl2.AccessConnection) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) Connection(org.osate.aadl2.Connection) PortConnection(org.osate.aadl2.PortConnection) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Example 17 with ModeInstance

use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.

the class CachePropertyAssociationsSwitch method fillPropertyValue.

private void fillPropertyValue(InstanceObject io, PropertyAssociation pa, List<EvaluatedProperty> values) {
    PropertyExpression lexp;
    List<PropertyExpression> elems;
    final Iterator<EvaluatedProperty> valueIter = values.iterator();
    final EvaluatedProperty value = valueIter.next();
    final List<MpvProxy> proxies = value.getProxies();
    for (MpvProxy proxy : proxies) {
        ModalPropertyValue newVal = Aadl2Factory.eINSTANCE.createModalPropertyValue();
        List<SystemOperationMode> inSOMs = new ArrayList<SystemOperationMode>();
        newVal.setOwnedValue(EcoreUtil.copy(proxy.getValue()));
        // process list appends
        while (valueIter.hasNext()) {
            MpvProxy prx = valueIter.next().getProxies().get(0);
            if (prx.isModal()) {
                throw new InvalidModelException(pa, "Trying to append to a modal list value");
            }
            lexp = EcoreUtil.copy(prx.getValue());
            elems = ((ListValue) lexp).getOwnedListElements();
            ((ListValue) newVal.getOwnedValue()).getOwnedListElements().addAll(0, elems);
        }
        boolean valueIsUsed = false;
        if (!proxy.isModal()) {
            valueIsUsed = true;
            pa.getOwnedValues().add(newVal);
        } else {
            List<Mode> modes = proxy.getModes();
            for (Mode mode : modes) {
                if (mode instanceof SystemOperationMode) {
                    inSOMs.add((SystemOperationMode) mode);
                } else {
                    if (io instanceof ConnectionReference) {
                        List<SystemOperationMode> conniModes = ((ConnectionInstance) io.eContainer()).getInSystemOperationModes();
                        if (conniModes.isEmpty()) {
                            conniModes = io.getSystemInstance().getSystemOperationModes();
                        }
                        List<ModeInstance> holderModes = ((ConnectionReference) io).getContext().getModeInstances();
                        for (ModeInstance mi : holderModes) {
                            if (mi.getMode() == mode) {
                                for (SystemOperationMode som : conniModes) {
                                    if (som.getCurrentModes().contains(mi)) {
                                        inSOMs.add(som);
                                    }
                                }
                                break;
                            }
                        }
                    } else {
                        List<ModeInstance> holderModes = (io instanceof ComponentInstance) ? ((ComponentInstance) io).getModeInstances() : io.getContainingComponentInstance().getModeInstances();
                        for (ModeInstance mi : holderModes) {
                            if (mi.getMode() == mode) {
                                if (mode2som.containsKey(mi)) {
                                    inSOMs.addAll(mode2som.get(mi));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            for (SystemOperationMode som : inSOMs) {
                if (io.isActive(som)) {
                    newVal.getInModes().add(som);
                }
            }
            if (!newVal.getInModes().isEmpty()) {
                valueIsUsed = true;
                pa.getOwnedValues().add(newVal);
            }
        }
        if (valueIsUsed) {
            // replace reference values in the context of the contained PA's owner
            for (Iterator<Element> content = EcoreUtil.getAllProperContents(newVal, false); content.hasNext(); ) {
                Element elem = content.next();
                if (elem instanceof ReferenceValue) {
                    try {
                        PropertyExpression irv = ((ReferenceValue) elem).instantiate(io);
                        if (irv != null) {
                            EcoreUtil.replace(elem, irv);
                        }
                    } catch (InvalidModelException e) {
                        error(io, e.getMessage());
                    }
                }
            }
        }
    }
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ModeInstance(org.osate.aadl2.instance.ModeInstance) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) ReferenceValue(org.osate.aadl2.ReferenceValue) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Element(org.osate.aadl2.Element) ArrayList(java.util.ArrayList) EvaluatedProperty(org.osate.aadl2.properties.EvaluatedProperty) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) MpvProxy(org.osate.aadl2.properties.EvaluatedProperty.MpvProxy) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) PropertyExpression(org.osate.aadl2.PropertyExpression)

Example 18 with ModeInstance

use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.

the class CreateConnectionsSwitch method generateModeCombinations.

private void generateModeCombinations(ConnectionInstance conni, ListIterator<ConnectionReference> refIter, List<ModeInstance> mis) {
    if (!refIter.hasNext()) {
        // add SOMs based on mis
        SystemInstance si = (SystemInstance) conni.getElementRoot();
        List<SystemOperationMode> somList = si.getSystemOperationModesFor(mis);
        // check if all parts of the connection exist
        outer: for (SystemOperationMode som : somList) {
            if (conni.getSource().isActive(som) && conni.getDestination().isActive(som)) {
                for (ConnectionReference cr : conni.getConnectionReferences()) {
                    if (!cr.getContext().isActive(som)) {
                        continue outer;
                    }
                }
                conni.getInSystemOperationModes().add(som);
            }
        }
    } else {
        ConnectionReference connRef = refIter.next();
        Connection conn = connRef.getConnection();
        ComponentInstance ci = connRef.getContext();
        EList<Mode> connModes = conn.getAllInModes();
        List<ModeInstance> nextMis = null;
        if (connModes.isEmpty()) {
            nextMis = getComponentModes(ci);
        } else {
            nextMis = connModes.stream().map(ci::findModeInstance).collect(Collectors.toList());
        }
        if (nextMis != null) {
            for (ModeInstance mi : nextMis) {
                mis.add(mi);
                generateModeCombinations(conni, refIter, mis);
                mis.remove(mi);
            }
        } else {
            generateModeCombinations(conni, refIter, mis);
        }
        refIter.previous();
    }
}
Also used : ModeInstance(org.osate.aadl2.instance.ModeInstance) SystemInstance(org.osate.aadl2.instance.SystemInstance) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) ParameterConnection(org.osate.aadl2.ParameterConnection) AccessConnection(org.osate.aadl2.AccessConnection) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) Connection(org.osate.aadl2.Connection) PortConnection(org.osate.aadl2.PortConnection) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode)

Example 19 with ModeInstance

use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.

the class InstantiateModel method instantiateSubcomponent.

protected void instantiateSubcomponent(final ComponentInstance parent, final ModalElement mm, final Subcomponent sub, Stack<Long> indexStack, int index) throws InterruptedException {
    final ComponentInstance newInstance = InstanceFactory.eINSTANCE.createComponentInstance();
    final ComponentClassifier cc;
    final InstantiatedClassifier ic;
    newInstance.setSubcomponent(sub);
    // Issue 961: Set the category for real later (below); set it here now in case something goes wrong
    newInstance.setCategory(sub.getCategory());
    newInstance.setName(sub.getName());
    newInstance.getIndices().addAll(indexStack);
    newInstance.getIndices().add(Long.valueOf(index));
    parent.getComponentInstances().add(newInstance);
    ic = getInstantiatedClassifier(newInstance);
    if (ic == null) {
        cc = null;
    } else {
        cc = (ComponentClassifier) ic.getClassifier();
    }
    if (cc == null) {
        errManager.warning(newInstance, "Instantiated subcomponent doesn't have a component classifier");
    } else {
        // if (cc instanceof ComponentType) {
        // if (sub instanceof SystemSubcomponent || sub instanceof ProcessSubcomponent
        // || sub instanceof ThreadGroupSubcomponent) {
        // errManager.warning(newInstance, "Instantiated subcomponent has a component type only");
        // }
        // }
        newInstance.setClassifier(cc);
        /*
			 * From Issue 961:
			 *
			 * I think the category can be determined as follows:
			 *
			 * If the classifier is not abstract then use its category (and maybe check that the subcomponent either has the same category or is abstract).
			 * If the classifier is abstract then use the category from the subcomponent.
			 *
			 * Only if both are abstract the component instance should be abstract.
			 * If both are not abstract then they must have the same category. If the categories are different, validation should already have reported an
			 * error, and we don't instantiate models with errors. It can't hurt if the instantiator checks again, though.
			 */
        final ComponentCategory classifierCategory = cc.getCategory();
        final ComponentCategory subcomponentCategory = sub.getCategory();
        if (classifierCategory != ComponentCategory.ABSTRACT) {
            newInstance.setCategory(cc.getCategory());
            if (subcomponentCategory != ComponentCategory.ABSTRACT && subcomponentCategory != classifierCategory) {
                errManager.warning(newInstance, "Subcomponent's category and its classifier's category do not match");
            }
        } else {
            newInstance.setCategory(subcomponentCategory);
        }
    }
    for (Mode mode : mm.getAllInModes()) {
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        ModeInstance mi = parent.findModeInstance(mode);
        if (mi != null) {
            newInstance.getInModes().add(mi);
        }
    }
    populateComponentInstance(newInstance, index);
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ModeInstance(org.osate.aadl2.instance.ModeInstance) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ComponentCategory(org.osate.aadl2.ComponentCategory)

Example 20 with ModeInstance

use of org.osate.aadl2.instance.ModeInstance in project osate2 by osate.

the class CreateEndToEndFlowsSwitch method instantiateEndToEndFlow.

protected void instantiateEndToEndFlow(ComponentInstance ci, EndToEndFlow ete, HashMap<EndToEndFlow, List<ETEInfo>> ete2info) {
    EndToEndFlowInstance etei = InstanceFactory.eINSTANCE.createEndToEndFlowInstance();
    resetETECloneCount();
    created = new ArrayList<ETEInfo>();
    ete2info.put(ete, created);
    this.ete2info = ete2info;
    etei.setName(ete.getName());
    etei.setEndToEndFlow(ete);
    ci.getEndToEndFlows().add(etei);
    addETEI.add(etei);
    created.add(myInfo = new ETEInfo(etei));
    EList<EList<ModeInstance>> ml = etei.getModesList();
    ml.clear();
    ml.add(getModeInstances(ci, ete));
    processETE(ci, etei, ete);
    ml.clear();
}
Also used : BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) EndToEndFlowInstance(org.osate.aadl2.instance.EndToEndFlowInstance)

Aggregations

ModeInstance (org.osate.aadl2.instance.ModeInstance)24 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)12 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)11 Mode (org.osate.aadl2.Mode)9 SystemInstance (org.osate.aadl2.instance.SystemInstance)6 ArrayList (java.util.ArrayList)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)4 Context (org.osate.aadl2.Context)3 FeatureGroup (org.osate.aadl2.FeatureGroup)3 ModeTransition (org.osate.aadl2.ModeTransition)3 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)3 ModeTransitionInstance (org.osate.aadl2.instance.ModeTransitionInstance)3 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)2 NotificationChain (org.eclipse.emf.common.notify.NotificationChain)2 BasicEList (org.eclipse.emf.common.util.BasicEList)2 AccessConnection (org.osate.aadl2.AccessConnection)2 Connection (org.osate.aadl2.Connection)2 Feature (org.osate.aadl2.Feature)2 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)2