001/* An actor supporting regression tests for DEDirector.
002
003 Copyright (c) 1998-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026
027 */
028package ptolemy.domains.de.lib;
029
030import ptolemy.actor.Director;
031import ptolemy.actor.TypedAtomicActor;
032import ptolemy.actor.TypedIOPort;
033import ptolemy.data.StringToken;
034import ptolemy.data.type.BaseType;
035import ptolemy.domains.de.kernel.DEDirector;
036import ptolemy.kernel.CompositeEntity;
037import ptolemy.kernel.util.IllegalActionException;
038import ptolemy.kernel.util.NameDuplicationException;
039
040///////////////////////////////////////////////////////////////////
041//// TestActorPortDepth
042
043/**
044 An actor supporting regression tests for DEDirector.
045 On each firing, this actor outputs a string describing the
046 actor depths and port depths of all actors under the control
047 of the same director.
048
049 @author Edward A. Lee
050 @version $Id$
051 @since Ptolemy II 8.0
052 @Pt.ProposedRating Yellow (eal)
053 @Pt.AcceptedRating Red (eal)
054 */
055public class TestActorPortDepth extends TypedAtomicActor {
056
057    /** Construct an actor with the specified container and name.
058     *  @param container The composite entity to contain this one.
059     *  @param name The name of this actor.
060     *  @exception IllegalActionException If the entity cannot be contained
061     *   by the proposed container.
062     *  @exception NameDuplicationException If the container already has an
063     *   actor with this name.
064     */
065    public TestActorPortDepth(CompositeEntity container, String name)
066            throws NameDuplicationException, IllegalActionException {
067        super(container, name);
068
069        trigger = new TypedIOPort(this, "trigger", true, false);
070
071        output = new TypedIOPort(this, "output", false, true);
072        output.setTypeEquals(BaseType.STRING);
073    }
074
075    ///////////////////////////////////////////////////////////////////
076    ////                       ports and parameters                ////
077
078    /** The output, which has type string. */
079    public TypedIOPort output;
080
081    /** The trigger. */
082    public TypedIOPort trigger;
083
084    ///////////////////////////////////////////////////////////////////
085    ////                         public methods                    ////
086
087    /** Query the director for a description of the depths of its
088     *  actors and their ports, and produce that description on the
089     *  output.
090     *  @exception IllegalActionException If the superclass throws it,
091     *   or if the director is not a DEDirector.
092     */
093    @Override
094    public void fire() throws IllegalActionException {
095        super.fire();
096        if (trigger.hasToken(0)) {
097            // Consume the trigger token.
098            trigger.get(0);
099        }
100        Director director = getDirector();
101        if (!(director instanceof DEDirector)) {
102            throw new IllegalActionException(this,
103                    "TestActorPortDepth can only be used with DEDirector.");
104        }
105        String result = ((DEDirector) director).describePriorities();
106        output.send(0, new StringToken(result));
107    }
108}