001/* 002 @Copyright (c) 1998-2014 The Regents of the University of California. 003 All rights reserved. 004 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 008 above copyright notice and the following two paragraphs appear in all 009 copies 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 */ 027package ptolemy.domains.sdf.kernel.test; 028 029import ptolemy.actor.TypedAtomicActor; 030import ptolemy.actor.TypedIOPort; 031import ptolemy.data.IntToken; 032import ptolemy.data.Token; 033import ptolemy.data.expr.Parameter; 034import ptolemy.data.type.BaseType; 035import ptolemy.kernel.CompositeEntity; 036import ptolemy.kernel.util.IllegalActionException; 037import ptolemy.kernel.util.NameDuplicationException; 038import ptolemy.kernel.util.Workspace; 039 040/** Create an increasing sequence of integer tokens, 041 starting with value zero, and incrementing by one. 042 This actor is aware of the rate that is set on its port and 043 will create the proper number of tokens with every firing. 044 045 @version $Id$ 046 @since Ptolemy II 0.4 047 @Pt.ProposedRating Red (neuendor) 048 @Pt.AcceptedRating Red (cxh) 049 @author Steve Neuendorffer 050 */ 051public class SDFTestRamp extends TypedAtomicActor { 052 public SDFTestRamp(CompositeEntity container, String name) 053 throws IllegalActionException, NameDuplicationException { 054 super(container, name); 055 output = new TypedIOPort(this, "output", false, true); 056 output_tokenProductionRate = new Parameter(output, 057 "tokenProductionRate", new IntToken(1)); 058 output.setTypeEquals(BaseType.INT); 059 _value = 0; 060 } 061 062 /////////////////////////////////////////////////////////////////// 063 //// public methods //// 064 public TypedIOPort output; 065 066 public Parameter output_tokenProductionRate; 067 068 /** Clone the actor into the specified workspace. This calls the 069 * base class and then creates new ports and parameters. The new 070 * actor will have the same parameter values as the old. 071 * @param workspace The workspace for the new object. 072 * @return A new actor. 073 * @exception CloneNotSupportedException If one of the attributes 074 * cannot be cloned. 075 */ 076 @Override 077 public Object clone(Workspace workspace) throws CloneNotSupportedException { 078 SDFTestRamp newObject = (SDFTestRamp) super.clone(workspace); 079 newObject.output = (TypedIOPort) newObject.getPort("output"); 080 return newObject; 081 } 082 083 /** 084 * Produce several integer tokens with values with incremental values. 085 * The number of tokens produced during each firing is determined by 086 * the rates on the ports, and the sequence of values continues across 087 * firings. 088 * @exception IllegalActionException If a contained method throws it. 089 */ 090 @Override 091 public void fire() throws IllegalActionException { 092 int i; 093 094 int tokens = ((IntToken) output_tokenProductionRate.getToken()) 095 .intValue(); 096 097 for (i = 0; i < tokens; i++) { 098 Token message = new IntToken(_value); 099 _value = _value + 1; 100 output.send(0, message); 101 } 102 } 103 104 /** 105 * Initialize the sequence so the first token created has value zero. 106 * @exception IllegalActionException If the parent class throws it. 107 */ 108 @Override 109 public void initialize() throws IllegalActionException { 110 super.initialize(); 111 _value = 0; 112 } 113 114 private int _value; 115}