001/* A dummy source actor for testing purposes 002 003Copyright (c) 2010-2014 The Regents of the University of California. 004All rights reserved. 005Permission is hereby granted, without written agreement and without 006license or royalty fees, to use, copy, modify, and distribute this 007software and its documentation for any purpose, provided that the above 008copyright notice and the following two paragraphs appear in all copies 009of this software. 010 011IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015SUCH DAMAGE. 016 017THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022ENHANCEMENTS, OR MODIFICATIONS. 023 024PT_COPYRIGHT_VERSION_2 025COPYRIGHTENDKEY 026 */ 027 028package ptolemy.domains.sdf.optimize.lib; 029 030import ptolemy.actor.lib.Source; 031import ptolemy.data.type.BaseType; 032import ptolemy.domains.sdf.optimize.BufferingProfile; 033import ptolemy.kernel.CompositeEntity; 034import ptolemy.kernel.util.IllegalActionException; 035import ptolemy.kernel.util.NameDuplicationException; 036 037/////////////////////////////////////////////////////////////////// 038//// DummySource 039 040/** 041<h1>Class comments</h1> 042A simple actor acting as a dummy source used for testing the OptimizingSDFDirector. 043<p> 044See {@link ptolemy.domains.sdf.optimize.OptimizingSDFDirector}, 045{@link ptolemy.domains.sdf.optimize.OptimizingSDFScheduler} and 046{@link ptolemy.domains.sdf.optimize.BufferingProfile} for more information. 047</p> 048@see ptolemy.domains.sdf.optimize.OptimizingSDFDirector 049@see ptolemy.domains.sdf.optimize.OptimizingSDFScheduler 050@see ptolemy.domains.sdf.optimize.BufferingProfile 051 052@author Marc Geilen 053@version $Id$ 054@since Ptolemy II 10.0 055@Pt.ProposedRating Red (mgeilen) 056@Pt.AcceptedRating Red () 057 */ 058 059public class DummySource extends Source implements BufferingProfile { 060 private int _counter; 061 062 /** 063 * Construct an actor with the given container and name. 064 * @param container The container. 065 * @param name The name of this actor. 066 * @exception IllegalActionException If the actor cannot be contained 067 * by the proposed container. 068 * @exception NameDuplicationException If the container already has an 069 * actor with this name. 070 */ 071 public DummySource(CompositeEntity container, String name) 072 throws IllegalActionException, NameDuplicationException { 073 super(container, name); 074 output.setTypeEquals(BaseType.GENERAL); 075 } 076 077 /////////////////////////////////////////////////////////////////// 078 //// public methods //// 079 080 /** 081 * Fire the source actor and output a frame. 082 * @exception IllegalActionException If thrown while writing to the port. 083 */ 084 @Override 085 public void fire() throws IllegalActionException { 086 DummyFrame f = new DummyFrame(); 087 f.value = _counter; 088 output.send(0, new DummyReferenceToken(f)); 089 } 090 091 /** 092 * Post-fire the source actor and update the counter to give 093 * next token a unique sequence number. 094 * @return True if execution can continue into the next iteration. 095 * @exception IllegalActionException Not thrown in this class or it base class. 096 */ 097 @Override 098 public boolean postfire() throws IllegalActionException { 099 _counter++; 100 return super.postfire(); 101 } 102 103 /** Initialize the actor. Initializes its counter. 104 * @exception IllegalActionException If thrown by the super class. 105 */ 106 @Override 107 public void initialize() throws IllegalActionException { 108 super.initialize(); 109 _counter = 0; 110 } 111 112 /** 113 * Iterate the actor. 114 * @param iterationCount The number of iterations to perform. 115 * @param fireExclusive Determines whether the firing is exclusive. 116 * @return NOT_READY, STOP_ITERATING, or COMPLETED. 117 * @exception IllegalActionException If iterating is not 118 * permitted, or if prefire(), fire(), or postfire() throw it. 119 */ 120 @Override 121 public int iterate(int iterationCount, boolean fireExclusive) 122 throws IllegalActionException { 123 return super.iterate(iterationCount); 124 } 125 126 /** 127 * Provides the buffering profile, number of buffers required for an exclusive firing. 128 * @return number of buffers for exclusive firing 129 */ 130 @Override 131 public int exclusiveBuffers() { 132 return 0; 133 } 134 135 /** 136 * Provides the buffering profile, execution time estimate required for an exclusive 137 * firing. 138 * @return execution time for exclusive firing 139 */ 140 @Override 141 public int exclusiveExecutionTime() { 142 return 0; 143 } 144 145 /** 146 * Provides the buffering profile, number of buffers required for a shared firing. 147 * @return number of buffers for shared firing 148 */ 149 @Override 150 public int sharedBuffers() { 151 return 0; 152 } 153 154 /** 155 * Provides the buffering profile, execution time estimate required for a shared firing. 156 * @return execution time for shared firing 157 */ 158 @Override 159 public int sharedExecutionTime() { 160 return 0; 161 } 162 163}