/* An actor supporting regression tests for DEDirector. Copyright (c) 1998-2009 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ package ptolemy.domains.de.lib; import ptolemy.actor.Director; import ptolemy.actor.TypedAtomicActor; import ptolemy.actor.TypedIOPort; import ptolemy.data.StringToken; import ptolemy.data.type.BaseType; import ptolemy.domains.de.kernel.DEDirector; import ptolemy.kernel.CompositeEntity; import ptolemy.kernel.util.IllegalActionException; import ptolemy.kernel.util.NameDuplicationException; ////////////////////////////////////////////////////////////////////////// //// TestActorPortDepth /** An actor supporting regression tests for DEDirector. On each firing, this actor outputs a string describing the actor depths and port depths of all actors under the control of the same director. @author Edward A. Lee @version $Id$ @since Ptolemy II 7.1 @Pt.ProposedRating Yellow (eal) @Pt.AcceptedRating Red (eal) */ public class TestActorPortDepth extends TypedAtomicActor { /** Construct an actor with the specified container and name. * @param container The composite entity to contain this one. * @param name The name of this actor. * @exception IllegalActionException If the entity cannot be contained * by the proposed container. * @exception NameDuplicationException If the container already has an * actor with this name. */ public TestActorPortDepth(CompositeEntity container, String name) throws NameDuplicationException, IllegalActionException { super(container, name); trigger = new TypedIOPort(this, "trigger", true, false); output = new TypedIOPort(this, "output", false, true); output.setTypeEquals(BaseType.STRING); } /////////////////////////////////////////////////////////////////// //// ports and parameters //// /** The output, which has type string. */ public TypedIOPort output; /** The trigger. */ public TypedIOPort trigger; /////////////////////////////////////////////////////////////////// //// public methods //// /** Query the director for a description of the depths of its * actors and their ports, and produce that description on the * output. * @exception IllegalActionException If the superclass throws it, * or if the director is not a DEDirector. */ public void fire() throws IllegalActionException { super.fire(); if (trigger.hasToken(0)) { // Consume the trigger token. trigger.get(0); } Director director = getDirector(); if (!(director instanceof DEDirector)) { throw new IllegalActionException(this, "TestActorPortDepth can only be used with DEDirector."); } String result = ((DEDirector) director).describePriorities(); output.send(0, new StringToken(result)); } }