001/* An abstract ancestor for filter actors acting on shared buffers 002 003 Copyright (c) 1998-2015 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 */ 028 029package ptolemy.domains.sdf.optimize; 030 031import ptolemy.actor.lib.Transformer; 032import ptolemy.kernel.CompositeEntity; 033import ptolemy.kernel.util.IllegalActionException; 034import ptolemy.kernel.util.NameDuplicationException; 035 036/////////////////////////////////////////////////////////////////// 037////SharedBufferTransformer 038 039/** 040An abstract ancestor class to be used for filters 041using references to shared data frames. 042It implements a default version of the BufferingProfile interface. 043<p> 044See {@link ptolemy.domains.sdf.optimize.OptimizingSDFDirector} and 045{@link ptolemy.domains.sdf.optimize.BufferingProfile} for more information. 046</p> 047@see ptolemy.domains.sdf.optimize.OptimizingSDFDirector 048@see ptolemy.domains.sdf.optimize.BufferingProfile 049 050@author Marc Geilen 051@version $Id$ 052@since Ptolemy II 10.0 053@Pt.ProposedRating Red (mgeilen) 054@Pt.AcceptedRating Red () 055 */ 056 057public abstract class SharedBufferTransformer extends Transformer 058 implements BufferingProfile { 059 060 /** 061 * Construct an instance of a SharedBufferTransformer. Should not be used 062 * because this in an abstract class. 063 * TODO Is there a way to avoid defining a constructor for this abstract class? 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 SharedBufferTransformer(CompositeEntity container, String name) 072 throws NameDuplicationException, IllegalActionException { 073 super(container, name); 074 } 075 076 /** 077 * initialize. Set the default firing to non exclusive. 078 */ 079 @Override 080 public void initialize() throws IllegalActionException { 081 // default to copying firing 082 _nextIterationExclusive = false; 083 super.initialize(); 084 } 085 086 /** 087 * Fire according to the value _nextIterationExclusive in shared or exclusive 088 * firing mode. 089 */ 090 @Override 091 public void fire() throws IllegalActionException { 092 if (_nextIterationExclusive) { 093 _fireExclusive(); 094 } else { 095 _fireCopying(); 096 } 097 } 098 099 /** 100 * Default value for number of frame buffers required for shared firing. 101 * @return the number of buffers required for a shared buffer firing 102 */ 103 @Override 104 public int sharedBuffers() { 105 return 1; 106 } 107 108 /** 109 * Default value for number of frame buffers required for exclusive firing. 110 * @return the number of buffers required for an exclusive buffer firing 111 */ 112 @Override 113 public int exclusiveBuffers() { 114 return 0; 115 } 116 117 /** 118 * Default value for execution time for shared firing. 119 * @return execution time of a shared buffer firing 120 */ 121 @Override 122 public int sharedExecutionTime() { 123 return 1; 124 } 125 126 /** 127 * Default value for execution time for exclusive firing. 128 * @return execution time of an exclusive buffer firing 129 */ 130 @Override 131 public int exclusiveExecutionTime() { 132 return 2; 133 } 134 135 /** 136 * Invoke a specified number of iterations of the actor in either shared or 137 * exclusive mode as indicated by the fireExclusive argument. 138 * @param iterationCount The number of iterations to perform. 139 * @param fireExclusive whether to fire exclusive or not. 140 * @return NOT_READY, STOP_ITERATING, or COMPLETED. 141 * @exception IllegalActionException If iterating is not 142 * permitted, or if prefire(), fire(), or postfire() throw it. 143 **/ 144 @Override 145 public int iterate(int iterationCount, boolean fireExclusive) 146 throws IllegalActionException { 147 _nextIterationExclusive = fireExclusive; 148 int result = super.iterate(iterationCount); 149 // default to copying firing 150 _nextIterationExclusive = false; 151 return result; 152 } 153 154 /////////////////////////////////////////////////////////////////// 155 //// protected methods //// 156 157 /** 158 * Fire the actor in shared firing mode. 159 * Shared firing method to be implemented in subclasses. 160 * @exception IllegalActionException If thrown while writing to the port. 161 */ 162 protected abstract void _fireCopying() throws IllegalActionException; 163 164 /** 165 * Fire the actor in exclusive firing mode. 166 * Exclusive firing method to be implemented in subclasses. 167 * @exception IllegalActionException If thrown while writing to the port. 168 */ 169 protected abstract void _fireExclusive() throws IllegalActionException; 170 171 //// private fields 172 /** 173 * determines whether the next firing will be exclusive or shared 174 */ 175 private boolean _nextIterationExclusive; 176 177}