Package ptolemy.kernel

Examples of ptolemy.kernel.Port


            // Set up From information.
            String fromType;
            String fromName;
            if (link.from instanceof Port) {
                fromType = "port";
                Port port = (Port) link.from;
                fromName = port.getContainer().getName() + "." + port.getName();
            } else if (link.from instanceof Relation) {
                fromType = "relation";
                Relation relation = (Relation) link.from;
                fromName = relation.getName();
            } else {
                throw new InternalErrorException(
                        "Expected link.from type to be either "
                                + "Port or Relation.");
            }

            // Set up To information.
            String toType;
            String toName;
            if (link.to instanceof Port) {
                toType = "port";
                Port port = (Port) link.to;
                toName = port.getContainer().getName() + "." + port.getName();
            } else if (link.to instanceof Relation) {
                toType = "relation";
                Relation relation = (Relation) link.to;
                toName = relation.getName();
            } else {
View Full Code Here


     */
    protected void createConnection(Xinterface interfaceFrom,
            Xinterface interfaceTo) throws IllegalActionException,
            NameDuplicationException {
        // Find ports connected to interfaces.
        Port portFrom = (Port) _interfaceIOPortTable.get(interfaceFrom);
        Port portTo = (Port) _interfaceIOPortTable.get(interfaceTo);
        if (portFrom == null || portTo == null) {
            throw new InternalErrorException(
                    "Could not find port for From interface: " + interfaceFrom);
        }

        // Determine the From Relation.
        Relation relationFrom;
        if (interfaceFrom.parameters == null) {
            if (_interfaceRelationTable.containsKey(interfaceFrom)) {
                // This is a single (non-parameterized) port, and
                // the relation already exists, so we reuse it.
                Object o = _interfaceRelationTable.get(interfaceFrom);
                if (!(o instanceof Relation)) {
                    throw new InternalErrorException(
                            "Single port should only be connected to a "
                                    + "Relation.");
                }
                relationFrom = (Relation) o;
            } else {
                // This is a single (non-parameterized) port, and
                // the relation does not already exist, so we
                // create a new relation, create a link and a
                // _Link from the port to the new relation, and
                // add the _Link to the list of links.
                String relationName = _relations.getNewRelationName();
                relationFrom = new IORelation(_compositeActor, relationName);
                _interfaceRelationTable.put(interfaceFrom, relationFrom);
                portFrom.link(relationFrom);
                _Link link = new _Link(portFrom, relationFrom);
                _linkList.add(link);
            }
        } else {
            // This is a multi (parameterized) port, so we create
            // a new relation, add it to the relation list of the
            // interface, create a link and a _Link from the port
            // to the new relation, and add the _Link to the list
            // of links.
            String relationName = _relations.getNewRelationName();
            relationFrom = new IORelation(_compositeActor, relationName);
            if (_interfaceRelationTable.containsKey(interfaceFrom)) {
                // If the interface already has a relation list,
                // add the new relation to the list.
                Object o = _interfaceRelationTable.get(interfaceFrom);
                if (!(o instanceof ArrayList)) {
                    throw new InternalErrorException(
                            "Multiport should only be connected to an "
                                    + "ArrayList of Relation.");
                }
                ArrayList arrayList = (ArrayList) o;
                arrayList.add(relationFrom);
            } else {
                // If the interface does not already have a
                // relation list, create it and add the new
                // relation to the list.
                ArrayList arrayList = new ArrayList();
                arrayList.add(relationFrom);
                _interfaceRelationTable.put(interfaceFrom, arrayList);
            }
            portFrom.link(relationFrom);
            _Link link = new _Link(portFrom, relationFrom);
            _linkList.add(link);
        }

        // Determine the To Relation.
        Relation relationTo;
        if (interfaceTo.parameters == null) {
            if (_interfaceRelationTable.containsKey(interfaceTo)) {
                // This is a single (non-parameterized) port, and
                // the relation already exists, so we reuse it.
                Object o = _interfaceRelationTable.get(interfaceTo);
                if (!(o instanceof Relation)) {
                    throw new InternalErrorException(
                            "Single port should only be connected to a "
                                    + "Relation.");
                }
                relationTo = (Relation) o;
            } else {
                // This is a single (non-parameterized) port, and
                // the relation does not already exist, so we
                // create a new relation, create a link and a
                // _Link from the new relation to the port, and
                // add the _Link to the list of links.
                String relationName = _relations.getNewRelationName();
                relationTo = new IORelation(_compositeActor, relationName);
                _interfaceRelationTable.put(interfaceTo, relationTo);
                portTo.link(relationTo);
                _Link link = new _Link(relationTo, portTo);
                _linkList.add(link);
            }
        } else {
            // This is a multi (parameterized) port, so we create
            // a new relation, add it to the relation list of the
            // interface, create a link and a _Link from the new
            // relation to the port, and add the _Link to the list
            // of links.
            String relationName = _relations.getNewRelationName();
            relationTo = new IORelation(_compositeActor, relationName);
            if (_interfaceRelationTable.containsKey(interfaceTo)) {
                // If the interface already has a relation list,
                // add the new relation to the list.
                Object o = _interfaceRelationTable.get(interfaceTo);
                if (!(o instanceof ArrayList)) {
                    throw new InternalErrorException(
                            "Multiport should only be connected to an "
                                    + "ArrayList of Relation.");
                }
                ArrayList arrayList = (ArrayList) o;
                arrayList.add(relationTo);
            } else {
                // If the interface does not already have a
                // relation list, create it and add the new
                // relation to the list.
                ArrayList arrayList = new ArrayList();
                arrayList.add(relationTo);
                _interfaceRelationTable.put(interfaceTo, arrayList);
            }
            portTo.link(relationTo);
            _Link link = new _Link(relationTo, portTo);
            _linkList.add(link);
        }

        // Check for extra connections that might appear/disappear
        // when translating from a nesC graph to a Ptolemy graph.

        {
            // If relationTo is connected to an input port to
            // which relationFrom is not already connected, warn
            // the user the extra connections will be formed.
            List portListTo = ((IORelation) relationTo)
                    .linkedDestinationPortList((IOPort) portTo);
            List portListFrom = ((IORelation) relationFrom)
                    .linkedDestinationPortList();

            for (int i = 0; i < portListTo.size(); i++) {
                Port tempPortTo = (Port) portListTo.get(i);
                if (!portListFrom.contains(tempPortTo)) {
                    System.err.println("Warning: An extra link from "
                            + portFrom.getContainer().getName() + "."
                            + portFrom.getName() + " to "
                            + tempPortTo.getContainer().getName() + "."
                            + tempPortTo.getName() + " will be formed.");
                }
            }
        }

        {
            // If relationTo is already connected to relationFrom,
            // warn the user that this second connection will
            // disappear in the current Ptolemy relation group
            // implementation.
            List portListTo = ((IORelation) relationTo)
                    .linkedDestinationPortList();
            List portListFrom = ((IORelation) relationFrom)
                    .linkedDestinationPortList();
            for (int i = 0; i < portListFrom.size(); i++) {
                Port tempPortFrom = (Port) portListFrom.get(i);
                if (portListTo.contains(tempPortFrom)) {
                    System.err.println("Warning: "
                            + portFrom.getContainer().getName() + "."
                            + portFrom.getName() + " is already connected to "
                            + portTo.getContainer().getName() + "."
View Full Code Here

        // create a link without a vertex for the relation.
        if ((rootVertex == null) && (linkedObjectsCount == 2)
                && (unlinkedPortCount == 2)
                && linkedObjects.get(0) instanceof Port
                && linkedObjects.get(1) instanceof Port) {
            Port port1 = (Port) linkedObjects.get(0);
            Port port2 = (Port) linkedObjects.get(1);
            Object head = null;
            Object tail = null;

            if (port1.getContainer().equals(getRoot())) {
                head = _getLocation(port1);
            } else {
                head = port1;
            }

            if (port2.getContainer().equals(getRoot())) {
                tail = _getLocation(port2);
            } else {
                tail = port2;
            }

            Link link;

            try {
                link = new Link();
                _linkSet.add(link);
            } catch (Exception e) {
                throw new InternalErrorException("Failed to create "
                        + "new link, even though one does not "
                        + "already exist:" + e.getMessage());
            }

            link.setRelation(relation);
            link.setHead(head);
            link.setTail(tail);
        } else {
            // A regular relation with a diamond.
            // Create a vertex if one is not found.
            if (rootVertex == null) {
                try {
                    String name = relation.uniqueName("vertex");
                    rootVertex = new Vertex(relation, name);

                    // Have to manually handle propagation, since
                    // the MoML parser is not involved.
                    // FIXME: This could cause a name collision!
                    // (Unlikely though since auto naming will take
                    // into account subclasses).
                    rootVertex.propagateExistence();
                } catch (Throwable throwable) {
                    throw new InternalErrorException(null, throwable,
                            "Failed to create "
                                    + "new vertex, even though one does not "
                                    + "already exist:" + throwable.getMessage());
                }
            }

            // Create any required links for this relation.
            Iterator linkedObjectsIterator = linkedObjects.iterator();

            while (linkedObjectsIterator.hasNext()) {
                Object portOrRelation = linkedObjectsIterator.next();

                // Set the head to the port or relation. More precisely:
                //   If it is a port belonging to the composite, then
                //   set the head to a Location contained by the port.
                //   If is a port belonging to an actor, then set
                //   the head to the port.
                //   If it is a relation, then set the head to the
                //   root vertex of the relation.
                Object head = null;

                if (portOrRelation instanceof Port) {
                    Port port = (Port) portOrRelation;

                    if (port.getContainer().equals(getRoot())) {
                        head = _getLocation(port);
                    } else {
                        head = port;
                    }
                } else {
View Full Code Here

        Local tempPortLocal = Jimple.v().newLocal("tempPort",
                RefType.v(PtolemyUtilities.componentPortClass));
        body.getLocals().add(tempPortLocal);

        for (Iterator ports = entity.portList().iterator(); ports.hasNext();) {
            Port port = (Port) ports.next();

            //   System.out.println("ModelTransformer: port: " + port);
            String className = port.getClass().getName();

            // FIXME: what about subclasses of TypedIOPort?
            //String portName = port.getName(context);
            String fieldName = getFieldNameForPort(port, context);
            RefType portType = RefType.v(className);
            Local portLocal = Jimple.v().newLocal("port", portType);
            body.getLocals().add(portLocal);

            // Deal with ParameterPorts specially, since they are
            // created by the PortParameter.  Just use the
            // portParameter to get a reference to the ParameterPort.
            if (port instanceof ParameterPort) {
                updateCreatedSet(entity.getFullName() + "." + port.getName(),
                        port, port, objectNameToCreatorName);

                PortParameter parameter = ((ParameterPort) port).getParameter();
                Local parameterLocal = Jimple.v().newLocal("parameter",
                        RefType.v(PtolemyUtilities.portParameterClass));
                body.getLocals().add(parameterLocal);
                body.getUnits().add(
                        Jimple.v().newAssignStmt(
                                parameterLocal,
                                Jimple.v().newVirtualInvokeExpr(
                                        contextLocal,
                                        PtolemyUtilities.getAttributeMethod
                                                .makeRef(),
                                        StringConstant.v(parameter
                                                .getName(context)))));

                // If the class for the object already creates the
                // port, then get a reference to the existing port.
                // First assign to temp
                body
                        .getUnits()
                        .add(
                                Jimple
                                        .v()
                                        .newAssignStmt(
                                                portLocal,
                                                Jimple
                                                        .v()
                                                        .newVirtualInvokeExpr(
                                                                parameterLocal,
                                                                PtolemyUtilities.portParameterGetPortMethod
                                                                        .makeRef())));
            } else if (objectNameToCreatorName.keySet().contains(
                    port.getFullName())) {
                //       System.out.println("already created!");
                // If the class for the object already creates the
                // port, then get a reference to the existing port.
                // First assign to temp
                body.getUnits().add(
                        Jimple.v().newAssignStmt(
                                tempPortLocal,
                                Jimple.v().newVirtualInvokeExpr(
                                        entityLocal,
                                        PtolemyUtilities.getPortMethod
                                                .makeRef(),
                                        StringConstant.v(port.getName()))));

                // and then cast to portLocal
                body.getUnits().add(
                        Jimple.v()
                                .newAssignStmt(
                                        portLocal,
                                        Jimple.v().newCastExpr(tempPortLocal,
                                                portType)));
            } else {
                //     System.out.println("Creating new!");
                // If the class does not create the port
                // then create a new port with the right name.
                Local local = PtolemyUtilities.createNamedObjAndLocal(body,
                        className, entityLocal, port.getName());

                // Record the name of the created port.
                // NOTE: we assume that this is only a TypedIOPort, which
                // contains no other objects!
                //    Port classPort =
                //                     (Port)_findDeferredInstance(port);
                //      updateCreatedSet(entity.getFullName() + "."
                //                         + port.getName(),
                //                         classPort, classPort, objectNameToCreatorName);
                String name = entity.getFullName() + "." + port.getName();
                objectNameToCreatorName.put(name, name);

                // Then assign to portLocal.
                body.getUnits().add(Jimple.v().newAssignStmt(portLocal, local));
            }

            if (port instanceof TypedIOPort) {
                TypedIOPort ioport = (TypedIOPort) port;
                Local ioportLocal = Jimple.v().newLocal(
                        "typed_" + port.getName(), PtolemyUtilities.ioportType);
                body.getLocals().add(ioportLocal);

                Stmt castStmt = Jimple.v().newAssignStmt(
                        ioportLocal,
                        Jimple.v().newCastExpr(portLocal,
View Full Code Here

        if (namedObj instanceof Entity) {
            Entity entity = (Entity) namedObj;

            for (Iterator ports = entity.portList().iterator(); ports.hasNext();) {
                Port port = (Port) ports.next();

                // recurse so that we get all parameters deeply.
                createAttributeComputationFunctions(context, port, theClass,
                        constAnalysis);
            }
View Full Code Here

        if (namedObj instanceof Entity) {
            Entity entity = (Entity) namedObj;

            for (Iterator ports = entity.portList().iterator(); ports.hasNext();) {
                Port port = (Port) ports.next();
                Local portLocal = Jimple.v().newLocal("port",
                        RefType.v(PtolemyUtilities.portClass));
                body.getLocals().add(portLocal);

                String portName = port.getName(context);
                body.getUnits().insertBefore(
                        Jimple.v().newAssignStmt(
                                portLocal,
                                Jimple.v().newVirtualInvokeExpr(
                                        contextLocal,
View Full Code Here

        if (object instanceof Entity) {
            Entity entity = (Entity) object;

            for (Iterator ports = entity.portList().iterator(); ports.hasNext();) {
                Port port = (Port) ports.next();
                updateCreatedSet(prefix, context, port, objectNameToCreatorName);
            }
        }

        for (Iterator attributes = object.attributeList().iterator(); attributes
View Full Code Here

        Local tempPortLocal = Jimple.v().newLocal("tempPort",
                RefType.v(PtolemyUtilities.componentPortClass));
        body.getLocals().add(tempPortLocal);

        for (Iterator ports = entity.portList().iterator(); ports.hasNext();) {
            Port port = (Port) ports.next();

            //System.out.println("ModelTransformer: port: " + port);
            String className = port.getClass().getName();
            //String portName = port.getName(context);
            String fieldName = getFieldNameForPort(port, context);
            RefType portType = RefType.v(className);
            Local portLocal = Jimple.v().newLocal("port", portType);
            body.getLocals().add(portLocal);

            // Ignore ParameterPorts, since they are created by the
            // PortParameter.  Just use the portParameter to get a
            // reference to the ParameterPort.
            if (port instanceof ParameterPort) {
                updateCreatedSet(entity.getFullName() + "." + port.getName(),
                        port, port, objectNameToCreatorName);

                PortParameter parameter = ((ParameterPort) port).getParameter();
                Local parameterLocal = Jimple.v().newLocal("parameter",
                        RefType.v(PtolemyUtilities.portParameterClass));
                body.getLocals().add(parameterLocal);
                body.getUnits().add(
                        Jimple.v().newAssignStmt(
                                parameterLocal,
                                Jimple.v().newVirtualInvokeExpr(
                                        contextLocal,
                                        PtolemyUtilities.getAttributeMethod
                                                .makeRef(),
                                        StringConstant.v(parameter
                                                .getName(context)))));

                // If the class for the object already creates the
                // port, then get a reference to the existing port.
                // First assign to temp
                body
                        .getUnits()
                        .add(
                                Jimple
                                        .v()
                                        .newAssignStmt(
                                                portLocal,
                                                Jimple
                                                        .v()
                                                        .newVirtualInvokeExpr(
                                                                parameterLocal,
                                                                PtolemyUtilities.portParameterGetPortMethod
                                                                        .makeRef())));
            } else if (objectNameToCreatorName.keySet().contains(
                    port.getFullName())) {
                //    System.out.println("already created!");
                // If the class for the object already creates the
                // port, then get a reference to the existing port.
                // First assign to temp
                body.getUnits().add(
                        Jimple.v().newAssignStmt(
                                tempPortLocal,
                                Jimple.v().newVirtualInvokeExpr(
                                        entityLocal,
                                        PtolemyUtilities.getPortMethod
                                                .makeRef(),
                                        StringConstant.v(port.getName()))));

                // and then cast to portLocal
                body.getUnits().add(
                        Jimple.v()
                                .newAssignStmt(
                                        portLocal,
                                        Jimple.v().newCastExpr(tempPortLocal,
                                                portType)));
            } else {
                //    System.out.println("Creating new!");
                // If the class does not create the port
                // then create a new port with the right name.
                Local local = PtolemyUtilities.createNamedObjAndLocal(body,
                        className, entityLocal, port.getName());

                //                 updateCreatedSet(entity.getFullName() + "."
                //                         + port.getName(),
                //                         port, port, objectNameToCreatorName);
                String name = entity.getFullName() + "." + port.getName();
                objectNameToCreatorName.put(name, name);

                // Then assign to portLocal.
                body.getUnits().add(Jimple.v().newAssignStmt(portLocal, local));

                if (port instanceof TypedIOPort) {
                    TypedIOPort ioport = (TypedIOPort) port;

                    if (ioport.isInput()) {
                        body.getUnits().add(
                                Jimple.v().newInvokeStmt(
                                        Jimple.v().newVirtualInvokeExpr(
                                                local,
                                                PtolemyUtilities.setInputMethod
                                                        .makeRef(),
                                                IntConstant.v(1))));
                    }

                    if (ioport.isOutput()) {
                        body
                                .getUnits()
                                .add(
                                        Jimple
                                                .v()
                                                .newInvokeStmt(
                                                        Jimple
                                                                .v()
                                                                .newVirtualInvokeExpr(
                                                                        local,
                                                                        PtolemyUtilities.setOutputMethod
                                                                                .makeRef(),
                                                                        IntConstant
                                                                                .v(1))));
                    }

                    if (ioport.isMultiport()) {
                        body
                                .getUnits()
                                .add(
                                        Jimple
                                                .v()
                                                .newInvokeStmt(
                                                        Jimple
                                                                .v()
                                                                .newVirtualInvokeExpr(
                                                                        local,
                                                                        PtolemyUtilities.setMultiportMethod
                                                                                .makeRef(),
                                                                        IntConstant
                                                                                .v(1))));
                    }

                    // Set the port's type.
                    Local ioportLocal = Jimple.v().newLocal(
                            "typed_" + port.getName(),
                            PtolemyUtilities.ioportType);
                    body.getLocals().add(ioportLocal);

                    Stmt castStmt = Jimple.v().newAssignStmt(
                            ioportLocal,
View Full Code Here

                ModalModel container = (ModalModel) getContainer();
                Iterator entities = container.entityList().iterator();

                while (entities.hasNext()) {
                    Entity entity = (Entity) entities.next();
                    Port mirrorPort = entity.getPort(getName());

                    if (mirrorPort instanceof RefinementPort) {
                        RefinementPort castPort = (RefinementPort) mirrorPort;
                        boolean disableStatus = castPort._mirrorDisable;
View Full Code Here

                ModalModel container = (ModalModel) getContainer();
                Iterator entities = container.entityList().iterator();

                while (entities.hasNext()) {
                    Entity entity = (Entity) entities.next();
                    Port mirrorPort = entity.getPort(getName());

                    if (mirrorPort instanceof RefinementPort) {
                        RefinementPort castPort = (RefinementPort) mirrorPort;
                        boolean disableStatus = castPort._mirrorDisable;
View Full Code Here

TOP

Related Classes of ptolemy.kernel.Port

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.