Search in sources :

Example 26 with ConnectionReference

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

the class ConnectionInfo method createConnectionInstance.

public ConnectionInstance createConnectionInstance(final String name, final ConnectionInstanceEnd dst) {
    ConnectionInstance conni = InstanceFactory.eINSTANCE.createConnectionInstance();
    conni.setName(name);
    Iterator<Connection> connIter = connections.iterator();
    Iterator<ComponentInstance> ctxIter = contexts.iterator();
    // Iterator<ConnectionInstanceEnd> srcIter = sources.iterator();
    Iterator<ConnectionInstanceEnd> dstIter = destinations.iterator();
    Iterator<Boolean> oppIter = opposites.iterator();
    ConnectionInstanceEnd dosrc = src;
    ConnectionInstanceEnd dodst = null;
    while (connIter.hasNext() && dstIter.hasNext()) {
        ConnectionReference connRef = conni.createConnectionReference();
        connRef.setConnection(connIter.next());
        connRef.setContext(ctxIter.next());
        connRef.setSource(dosrc);
        dodst = resolveFeatureInstance(dosrc, dstIter.next());
        connRef.setDestination(dodst);
        dosrc = dodst;
        connRef.setReverse(oppIter.next());
    }
    conni.setSource(src);
    conni.setDestination(dst);
    conni.setComplete(across);
    kind = getKind(dst);
    conni.setKind(kind);
    return conni;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) Connection(org.osate.aadl2.Connection) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Example 27 with ConnectionReference

use of org.osate.aadl2.instance.ConnectionReference 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 28 with ConnectionReference

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

the class InstantiateModel method createNewConnection.

/**
 * create a copy of the connection instance with the specified indices for the source and the destination
 * @param conni
 * @param srcIndices
 * @param dstIndices
 */
private void createNewConnection(ConnectionInstance conni, List<Long> srcIndices, List<Long> dstIndices) {
    LinkedList<String> names = new LinkedList<String>();
    LinkedList<Integer> dims = new LinkedList<Integer>();
    LinkedList<Integer> sizes = new LinkedList<Integer>();
    ConnectionInstance newConn = EcoreUtil.copy(conni);
    conni.getContainingComponentInstance().getConnectionInstances().add(newConn);
    ConnectionReference topConnRef = Aadl2InstanceUtil.getTopConnectionReference(newConn);
    analyzePath(conni.getContainingComponentInstance(), conni.getSource(), names, dims, sizes);
    if (srcIndices.size() != sizes.size() && // filter out one side being an element without index (array of 1) (many to one mapping)
    !(sizes.size() == 0 && dstIndices.size() == 1)) {
        errManager.error(newConn, "Source indices " + srcIndices + " do not match source dimension " + sizes.size());
    }
    InstanceObject src = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, srcIndices, true);
    names.clear();
    dims.clear();
    sizes.clear();
    analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), names, dims, sizes);
    if (dstIndices.size() != sizes.size() && // filter out one side being an element without index (array of 1) (many to one mapping)
    !(sizes.size() == 0 && dstIndices.size() == 1)) {
        errManager.error(newConn, "For " + newConn.getConnectionReferences().get(0).getFullName() + " : " + newConn.getFullName() + ", destination indices " + dstIndices + " do not match destination dimension " + sizes.size());
    }
    InstanceObject dst = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, dstIndices, false);
    if (src == null) {
        errManager.error(newConn, "Connection source not found");
    }
    if (dst == null) {
        errManager.error(newConn, "Connection destination not found");
    }
    String containerPath = conni.getContainingComponentInstance().getInstanceObjectPath();
    int len = containerPath.length() + 1;
    String srcPath = (src != null) ? src.getInstanceObjectPath() : "Source end not found";
    StringBuffer sb = new StringBuffer();
    int i = (srcPath.startsWith(containerPath)) ? len : 0;
    sb.append(srcPath.substring(i));
    sb.append(" --> ");
    String dstPath = (dst != null) ? dst.getInstanceObjectPath() : "Destination end not found";
    i = (dstPath.startsWith(containerPath)) ? len : 0;
    sb.append(dstPath.substring(i));
    ConnectionInstance duplicate = (ConnectionInstance) AadlUtil.findNamedElementInList(conni.getContainingComponentInstance().getConnectionInstances(), sb.toString());
    if (duplicate != null && duplicate != conni) {
        // conni will be removed later
        errManager.warning(newConn, "There is already another connection between the same endpoints");
    }
    newConn.setSource((ConnectionInstanceEnd) src);
    newConn.setDestination((ConnectionInstanceEnd) dst);
    newConn.setName(sb.toString());
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) LinkedList(java.util.LinkedList)

Example 29 with ConnectionReference

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

the class InstantiateModel method resolveConnectionReference.

/**
 * resolve downgoing source or destination of the connection reference.
 * we do so by re-retrieving the feature instance based on the existing connection instance end name.
 * If the connection reference is up or down going we also fill in the other end.
 * @param targetConnRef
 * @param result
 * @param name
 * @param doSource
 */
private ConnectionInstanceEnd resolveConnectionReference(ConnectionReference targetConnRef, ConnectionReference outerConnRef, ComponentInstance target, boolean doSource, long idx, long fgidx) {
    ConnectionInstanceEnd src = targetConnRef.getSource();
    ConnectionInstanceEnd dst = targetConnRef.getDestination();
    if (doSource) {
        if (target.getName().equalsIgnoreCase(src.getName())) {
            // we point to a component instance, such as a bus or data component in an access connection
            targetConnRef.setSource(target);
        } else if (src instanceof FeatureInstance) {
            // re-resolve the source feature
            ConnectionInstanceEnd found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), src.getName(), idx);
            if (found == null) {
                Element parent = src.getOwner();
                if (parent instanceof FeatureInstance) {
                    found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), ((FeatureInstance) parent).getName(), fgidx);
                }
            }
            if (found != null) {
                targetConnRef.setSource(found);
            }
        }
        // now we need to resolve the upper end (destination)
        if (targetConnRef != outerConnRef) {
            // we need to fix the context of the connection reference
            ConnectionInstanceEnd outerSrc = outerConnRef.getSource();
            targetConnRef.setContext(outerSrc.getComponentInstance());
            // we are not at the top so we fix up the upper end of the connection reference
            if ((dst.getOwner() instanceof ComponentInstance) && dst.getName().equalsIgnoreCase(outerSrc.getName())) {
                targetConnRef.setDestination(outerSrc);
            } else {
                // the outer source points to the enclosing feature group. reresolve the feature in this feature group
                ConnectionInstanceEnd found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(((FeatureInstance) outerSrc).getFeatureInstances(), dst.getName(), idx);
                if (found == null) {
                    Element parent = dst.getOwner();
                    if (parent instanceof FeatureInstance) {
                        found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), ((FeatureInstance) parent).getName(), fgidx);
                    }
                }
                if (found != null) {
                    targetConnRef.setDestination(found);
                }
            }
        }
        return targetConnRef.getSource();
    } else {
        if (target.getName().equalsIgnoreCase(dst.getName())) {
            // we point to a component instance, such as a bus or data component in an access connection
            targetConnRef.setDestination(target);
        } else if (dst instanceof FeatureInstance) {
            // re-resolve the source feature
            ConnectionInstanceEnd found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), dst.getName(), idx);
            if (found == null) {
                Element parent = dst.getOwner();
                if (parent instanceof FeatureInstance) {
                    found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), ((FeatureInstance) parent).getName(), fgidx);
                }
            }
            if (found != null) {
                targetConnRef.setDestination(found);
            }
        }
        // now we need to resolve the upper end (source)
        if ((outerConnRef != null) && (targetConnRef != outerConnRef)) {
            // we need to fix the context of the connection reference
            ConnectionInstanceEnd outerDst = outerConnRef.getDestination();
            targetConnRef.setContext(outerDst.getComponentInstance());
            // we are not at the top so we fix up the upper end of the connection reference
            if ((src.getOwner() instanceof ComponentInstance) && src.getName().equalsIgnoreCase(outerDst.getName())) {
                targetConnRef.setSource(outerDst);
            } else {
                // the outer source points to the enclosing feature group. reresolve the feature in this feature group
                ConnectionInstanceEnd found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(((FeatureInstance) outerDst).getFeatureInstances(), src.getName(), idx);
                if (found == null) {
                    Element parent = src.getOwner();
                    if (parent instanceof FeatureInstance) {
                        found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), ((FeatureInstance) parent).getName(), fgidx);
                    }
                }
                if (found != null) {
                    targetConnRef.setSource(found);
                }
            }
        }
        return targetConnRef.getDestination();
    }
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ModalElement(org.osate.aadl2.ModalElement) Element(org.osate.aadl2.Element) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Example 30 with ConnectionReference

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

the class InstantiateModel method createNewConnection.

/**
 * create a copy of the connection instance with the specified indices for the source and the destination
 * @param conni
 * @param srcIndices
 * @param dstIndices
 * @return
 */
private void createNewConnection(ConnectionInstance conni, ComponentInstance targetComponent) {
    LinkedList<Long> indices = new LinkedList<Long>();
    LinkedList<String> names = new LinkedList<String>();
    LinkedList<Integer> dims = new LinkedList<Integer>();
    LinkedList<Integer> sizes = new LinkedList<Integer>();
    ConnectionInstance newConn = EcoreUtil.copy(conni);
    targetComponent.getConnectionInstances().add(newConn);
    ConnectionReference topConnRef = Aadl2InstanceUtil.getTopConnectionReference(newConn);
    analyzePath(conni.getContainingComponentInstance(), conni.getSource(), names, dims, sizes, indices);
    InstanceObject src = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, indices, true);
    names.clear();
    dims.clear();
    sizes.clear();
    indices.clear();
    analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), names, dims, sizes, indices);
    InstanceObject dst = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, indices, false);
    if (src == null) {
        errManager.error(newConn, "Connection source not found");
    }
    if (dst == null) {
        errManager.error(newConn, "Connection destination not found");
    }
    String containerPath = targetComponent.getInstanceObjectPath();
    int len = containerPath.length() + 1;
    String srcPath = (src != null) ? src.getInstanceObjectPath() : "Source end not found";
    StringBuffer sb = new StringBuffer();
    int i = (srcPath.startsWith(containerPath)) ? len : 0;
    sb.append(srcPath.substring(i));
    sb.append(" --> ");
    String dstPath = (dst != null) ? dst.getInstanceObjectPath() : "Destination end not found";
    i = (dstPath.startsWith(containerPath)) ? len : 0;
    sb.append(dstPath.substring(i));
    newConn.setSource((ConnectionInstanceEnd) src);
    newConn.setDestination((ConnectionInstanceEnd) dst);
    newConn.setName(sb.toString());
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) LinkedList(java.util.LinkedList)

Aggregations

ConnectionReference (org.osate.aadl2.instance.ConnectionReference)35 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)20 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)14 Connection (org.osate.aadl2.Connection)12 ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)11 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)7 InstanceObject (org.osate.aadl2.instance.InstanceObject)7 Element (org.osate.aadl2.Element)6 ArrayList (java.util.ArrayList)5 ConnectionEnd (org.osate.aadl2.ConnectionEnd)5 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)5 BasicEList (org.eclipse.emf.common.util.BasicEList)4 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)4 LinkedList (java.util.LinkedList)3 AccessConnection (org.osate.aadl2.AccessConnection)3 Context (org.osate.aadl2.Context)3 Feature (org.osate.aadl2.Feature)3 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)3 Mode (org.osate.aadl2.Mode)3 NamedElement (org.osate.aadl2.NamedElement)3