Search in sources :

Example 21 with ConnectionInstanceEnd

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

the class ValidateConnectionsSwitch method checkAccessConnectionClassifiers.

private void checkAccessConnectionClassifiers(final ConnectionInstance conni) {
    final ConnectionInstanceEnd srcEnd = conni.getSource();
    final ConnectionInstanceEnd destEnd = conni.getDestination();
    final boolean sourceIsSubcomponent = srcEnd instanceof ComponentInstance;
    final boolean destIsSubcomponent = destEnd instanceof ComponentInstance;
    /*
		 * Here we need to figure out which end of the connection is providing the
		 * shared component.
		 */
    final ConnectionInstanceEnd requiresEnd;
    final ConnectionInstanceEnd providesEnd;
    if (sourceIsSubcomponent) {
        providesEnd = srcEnd;
        requiresEnd = destEnd;
    } else if (destIsSubcomponent) {
        providesEnd = destEnd;
        requiresEnd = srcEnd;
    } else {
        // Both cannot be components -- If we get here, both are FeatureInstances
        final FeatureInstance srcFeature = (FeatureInstance) srcEnd;
        final FeatureInstance destFeature = (FeatureInstance) destEnd;
        final boolean sourceIsProvides = ((Access) srcFeature.getFeature()).getKind() == AccessType.PROVIDES;
        final boolean destIsProvides = ((Access) (destFeature).getFeature()).getKind() == AccessType.PROVIDES;
        if (sourceIsProvides && !destIsProvides) {
            providesEnd = srcEnd;
            requiresEnd = destEnd;
        } else if (!sourceIsProvides && destIsProvides) {
            providesEnd = destEnd;
            requiresEnd = srcEnd;
        } else {
            final ConnectionInstanceEnd outerEnd;
            final ConnectionInstanceEnd innerEnd;
            if (isAncestorOf(srcFeature.getComponentInstance(), destFeature.getComponentInstance())) {
                outerEnd = srcEnd;
                innerEnd = destEnd;
            } else {
                outerEnd = destEnd;
                innerEnd = srcEnd;
            }
            // Remember, both features have the same access type
            if (sourceIsProvides) {
                providesEnd = innerEnd;
                requiresEnd = outerEnd;
            } else {
                providesEnd = outerEnd;
                requiresEnd = innerEnd;
            }
        }
    }
    /* Now we can check the classifier compatibility */
    final Classifier providesClassifier = getConnectionEndClassifier(providesEnd);
    final Classifier requiresClassifier = getConnectionEndClassifier(requiresEnd);
    final boolean providesIsSubcomponent = providesEnd instanceof ComponentInstance;
    final boolean requiresIsSubcomponent = requiresEnd instanceof ComponentInstance;
    if (providesClassifier == null && requiresClassifier != null) {
        if (!isAbstractFeature(providesEnd)) {
            warning(conni, "Expected " + (providesIsSubcomponent ? "subcomponent \'" : "feature \'") + providesEnd.getComponentInstancePath() + "' to have classifier '" + requiresClassifier.getQualifiedName() + '\'');
        }
    } else if (providesClassifier != null && requiresClassifier == null) {
        if (!isAbstractFeature(requiresEnd)) {
            warning(conni, "Expected " + (requiresIsSubcomponent ? "subcomponent \'" : "feature \'") + requiresEnd.getComponentInstancePath() + "' to have classifier '" + providesClassifier.getQualifiedName() + '\'');
        }
    } else {
        checkEndPointClassifierMatching(conni, providesEnd, requiresEnd, providesClassifier, requiresClassifier);
    }
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Access(org.osate.aadl2.Access) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) Classifier(org.osate.aadl2.Classifier)

Example 22 with ConnectionInstanceEnd

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

the class CreateConnectionsSwitch method findSourceFeatureInstance.

/**
 * Find the feature instance under FGI, whose name matches the the Feature at the other end
 * We do this by finding the connection declaration that goes down at the other end
 * It is found by matching the FGT name and then retrieving the feature instance matching the name
 * @param connInfo
 * @param fgi
 * @return FeatureInstance
 */
FeatureInstance findSourceFeatureInstance(ConnectionInfo connInfo, FeatureInstance fgi) {
    List<ConnectionInstanceEnd> srclist = connInfo.sources;
    List<ConnectionInstanceEnd> dstlist = connInfo.destinations;
    ConnectionInstanceEnd target = null;
    for (int i = srclist.size() - 1; i >= 0; i--) {
        ConnectionInstanceEnd src = srclist.get(i);
        ConnectionInstanceEnd dst = dstlist.get(i);
        if (target != null && target != dst) {
            if (dst == target.eContainer()) {
                // we have a feature in a FG
                FeatureInstance targetFI = findFeatureInstance(fgi, target.getName());
                if (targetFI == null) {
                    // name does not match. We may have an inverse of feature group type with its own set of feature names
                    // In this case it is an index based match
                    int idx = dst.eContents().indexOf(target);
                    if (idx >= 0) {
                        targetFI = fgi.getFeatureInstances().get(idx);
                    }
                }
                return targetFI;
            } else {
                target = src;
            }
        } else {
            target = src;
        }
    }
    return null;
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd)

Example 23 with ConnectionInstanceEnd

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

the class CreateConnectionsSwitch method addConnectionInstance.

protected ConnectionInstance addConnectionInstance(final SystemInstance systemInstance, final ConnectionInfo connInfo, final ConnectionInstanceEnd dstI) {
    // with aggregate data ports will be sources/destinations missing
    int numConns = connInfo.connections.size();
    if (connInfo.sources.size() != numConns || connInfo.destinations.size() != numConns) {
        // happens if conn leaves system to aggregate data port
        warning(connInfo.container, "Connection from " + connInfo.sources.get(0).getInstanceObjectPath() + " to " + dstI.getInstanceObjectPath() + " could not be instantiated.");
        return null;
    }
    // check for duplicate connection instance
    // with arrays we can get duplicates that we don't need
    ComponentInstance container = connInfo.container;
    List<Connection> conns = connInfo.connections;
    if (container == null) {
        container = systemInstance;
    }
    for (ConnectionInstance test : container.getConnectionInstances()) {
        // check for duplicates and do not create
        if (connInfo.src == test.getSource() && dstI == test.getDestination() && conns.size() == test.getConnectionReferences().size()) {
            ListIterator<Connection> i = conns.listIterator();
            boolean isDuplicate = true;
            for (ConnectionReference ref : test.getConnectionReferences()) {
                if (ref.getConnection() != i.next()) {
                    isDuplicate = false;
                    break;
                }
            }
            if (!isDuplicate) {
                // also test reverse direction
                isDuplicate = true;
                i = conns.listIterator(conns.size());
                for (ConnectionReference ref : test.getConnectionReferences()) {
                    if (ref.getConnection() != i.previous()) {
                        isDuplicate = false;
                        break;
                    }
                }
            }
            if (isDuplicate) {
                return null;
            }
        }
    }
    boolean duplicate = false;
    // Generate a name for the connection
    String containerPath = (connInfo.container != null) ? container.getInstanceObjectPath() : systemInstance.getName();
    int len = containerPath.length() + 1;
    String srcPath = connInfo.src.getInstanceObjectPath();
    StringBuffer sb = new StringBuffer();
    String dstPath = "xxx";
    int i = (srcPath.startsWith(containerPath)) ? len : 0;
    srcPath = srcPath.substring(i);
    sb.append(srcPath);
    sb.append(" -> ");
    if (dstI != null) {
        dstPath = dstI.getInstanceObjectPath();
        i = (dstPath.startsWith(containerPath)) ? len : 0;
        dstPath = dstPath.substring(i);
        sb.append(dstPath);
    }
    ConnectionInstance conni = null;
    if (!duplicate) {
        conni = connInfo.createConnectionInstance(sb.toString(), dstI);
        if (conni == null) {
            warning(container, "Connection sequence from " + srcPath + " to " + dstPath + " is only outgoing. No connection instance created.");
            return null;
        } else {
            container.getConnectionInstances().add(conni);
        }
        fillInModes(conni);
        fillInModeTransitions(conni);
    }
    return conni;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) 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)

Example 24 with ConnectionInstanceEnd

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

the class CreateConnectionsSwitch method finalizeConnectionInstance.

// ------------------------------------------------------------------------
// Post-process completed connection instance
// ------------------------------------------------------------------------
protected void finalizeConnectionInstance(ComponentInstance parentci, final ConnectionInfo connInfo, ConnectionInstanceEnd dstEnd) {
    FeatureInstance upFi = null;
    if (dstEnd instanceof FeatureInstance) {
        FeatureInstance dstFi = (FeatureInstance) dstEnd;
        EList<FeatureInstance> flist = dstFi.getFeatureInstances();
        if (dstFi.getCategory() == FeatureCategory.FEATURE_GROUP && !upFeature.isEmpty()) {
            upFi = upFeature.pop();
            if (upFi.eContainer() == dstFi) {
                dstFi = upFi;
            } else {
                FeatureGroup upfg = ((FeatureGroup) ((FeatureInstance) upFi.getOwner()).getFeature());
                FeatureGroup downfg = ((FeatureGroup) dstFi.getFeature());
                FeatureGroupType upfgt = upfg.getAllFeatureGroupType();
                FeatureGroupType downfgt = downfg.getAllFeatureGroupType();
                if (downfgt == null) {
                    warning(dstFi.getContainingComponentInstance(), "In " + dstFi.getContainingComponentInstance().getName() + " (classifier " + dstFi.getContainingComponentInstance().getComponentClassifier().getName() + ") feature group " + dstFi.getName() + " has no type");
                }
                if (upfgt != null && downfgt != null && upfg.isInverseOf(downfg) && !upfgt.getAllFeatures().isEmpty() && !downfgt.getAllFeatures().isEmpty()) {
                    dstFi = flist.get(Aadl2InstanceUtil.getFeatureIndex(upFi));
                }
            }
        }
        if (connInfo.src instanceof FeatureInstance) {
            FeatureInstance srcFi = (FeatureInstance) connInfo.src;
            if (srcFi.getFeatureInstances().isEmpty() && dstFi.getFeatureInstances().isEmpty()) {
                addConnectionInstance(parentci.getSystemInstance(), connInfo, dstFi);
            } else {
                // src and/or dst is a feature group
                balanceFeatureGroupEnds(parentci, connInfo, srcFi, dstFi);
            }
        } else if (connInfo.src instanceof ComponentInstance) {
            ComponentInstance srcCi = (ComponentInstance) connInfo.src;
            if (dstFi.getFeatureInstances().isEmpty()) {
                addConnectionInstance(parentci.getSystemInstance(), connInfo, dstFi);
            } else {
                // dst is a feature group
                balanceFeatureGroupEnds(parentci, connInfo, srcCi, dstFi);
            }
        } else {
            error(parentci.getSystemInstance(), "Connection source is neither a feature nor a component: " + connInfo.src.getInstanceObjectPath() + " => " + connInfo.src.getInstanceObjectPath());
        }
        if (upFi != null) {
            upFeature.push(upFi);
        }
    } else {
        // Component Instance
        ComponentInstance dstCi = (ComponentInstance) dstEnd;
        if (connInfo.src instanceof FeatureInstance) {
            FeatureInstance srcFi = (FeatureInstance) connInfo.src;
            if (srcFi.getFeatureInstances().isEmpty()) {
                addConnectionInstance(parentci.getSystemInstance(), connInfo, dstCi);
            } else {
                // src is a feature group
                balanceFeatureGroupEnds(parentci, connInfo, srcFi, dstCi);
            }
        } else if (connInfo.src instanceof ComponentInstance) {
            error(parentci.getSystemInstance(), "Connection source and destination are components: " + connInfo.src.getInstanceObjectPath() + " => " + dstCi.getInstanceObjectPath());
        } else {
            error(parentci.getSystemInstance(), "Connection source is neither a feature nor a component: " + connInfo.src.getInstanceObjectPath() + " => " + dstCi.getInstanceObjectPath());
        }
    }
}
Also used : FeatureGroup(org.osate.aadl2.FeatureGroup) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Example 25 with ConnectionInstanceEnd

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

the class CreateEndToEndFlowsSwitch method testConnection.

/**
 * @param conni
 * @param etei
 * @param result
 */
private boolean testConnection(ConnectionInstance conni, EndToEndFlowInstance etei) {
    Iterator<ConnectionReference> refIter = conni.getConnectionReferences().iterator();
    boolean match = false;
    while (refIter.hasNext()) {
        String name1 = refIter.next().getConnection().getName();
        String name2 = connections.get(0).getName();
        if (name1.equalsIgnoreCase(name2)) {
            Iterator<Connection> connIter = connections.iterator();
            connIter.next();
            match = true;
            while (match && refIter.hasNext() && connIter.hasNext()) {
                match &= refIter.next().getConnection().getName().equalsIgnoreCase(connIter.next().getName());
            }
            if (!refIter.hasNext() && connIter.hasNext()) {
                match = false;
            }
        }
    }
    if (match && connections.size() == 1) {
        // make sure connection instance goes in the same direction as the flow
        ComponentInstance connci = conni.getSource().getComponentInstance();
        FlowElementInstance fei = etei;
        while (fei instanceof EndToEndFlowInstance) {
            fei = ((EndToEndFlowInstance) fei).getFlowElements().get(((EndToEndFlowInstance) fei).getFlowElements().size() - 1);
        }
        if (fei instanceof FlowSpecificationInstance) {
            fei = fei.getComponentInstance();
        }
        ComponentInstance flowci = (ComponentInstance) fei;
        match = false;
        ComponentInstance ci = connci;
        while (!(ci instanceof SystemInstance)) {
            if (ci == flowci) {
                match = true;
                break;
            }
            ci = ci.getContainingComponentInstance();
        }
    }
    if (match) {
        // test if the connection instance is connected to the end of the ete instance
        // relevant if the flow goes through a port of a feature group and the connection
        // instance comes from an expanded fg connection
        ConnectionInstanceEnd src = conni.getSource();
        if (src instanceof FeatureInstance) {
            FeatureInstance firstFeature = (FeatureInstance) src;
            FeatureInstance lastFeature = getLastFeature(etei);
            if (lastFeature != null) {
                match = isSameorContains(lastFeature, firstFeature);
            }
        }
    }
    return match;
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) Connection(org.osate.aadl2.Connection) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) SystemInstance(org.osate.aadl2.instance.SystemInstance) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) EndToEndFlowInstance(org.osate.aadl2.instance.EndToEndFlowInstance) FlowElementInstance(org.osate.aadl2.instance.FlowElementInstance)

Aggregations

ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)47 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)35 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)33 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)23 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)18 ArrayList (java.util.ArrayList)13 Connection (org.osate.aadl2.Connection)10 Feature (org.osate.aadl2.Feature)9 Subcomponent (org.osate.aadl2.Subcomponent)9 ConnectionEnd (org.osate.aadl2.ConnectionEnd)8 BasicEList (org.eclipse.emf.common.util.BasicEList)7 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 Element (org.osate.aadl2.Element)7 InstanceObject (org.osate.aadl2.instance.InstanceObject)7 HashMap (java.util.HashMap)6 List (java.util.List)6 FeatureGroup (org.osate.aadl2.FeatureGroup)6 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)6 ModeTransitionInstance (org.osate.aadl2.instance.ModeTransitionInstance)6 Map (java.util.Map)5