001/* A triggered clock source. 002 003 Copyright (c) 1998-2016 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.actor.lib; 029 030import ptolemy.actor.TypedIOPort; 031import ptolemy.data.BooleanToken; 032import ptolemy.data.StringToken; 033import ptolemy.data.expr.Parameter; 034import ptolemy.data.expr.SingletonParameter; 035import ptolemy.kernel.CompositeEntity; 036import ptolemy.kernel.util.IllegalActionException; 037import ptolemy.kernel.util.NameDuplicationException; 038 039/////////////////////////////////////////////////////////////////// 040//// TriggeredClock 041 042/** 043 This actor is an extension of Clock with a <i>start</i> and <i>stop</i> 044 input. A token at the <i>start</i> input will start the clock. A token 045 at the <i>stop</i> input will stop the clock, if it is still running. 046 If both <i>start</i> and <i>stop</i> are received simultaneously, then 047 the clock will be stopped. 048 <p> 049 So that this <i>start</i> and <i>stop</i> ports can 050 be used meaningfully in the CT domain, they are declared DISCRETE, and they 051 should be connected to an event generator. Other domains ignore this 052 declaration. 053 054 @author Edward A. Lee 055 @version $Id$ 056 @since Ptolemy II 0.3 057 @deprecated Use DiscreteClock. 058 @Pt.ProposedRating Yellow (eal) 059 @Pt.AcceptedRating Yellow (yuhong) 060 */ 061@Deprecated 062public class TriggeredClock extends Clock { 063 /** Construct an actor with the specified container and name. 064 * @param container The container. 065 * @param name The name of this actor. 066 * @exception IllegalActionException If the entity 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 TriggeredClock(CompositeEntity container, String name) 072 throws NameDuplicationException, IllegalActionException { 073 super(container, name); 074 075 // start port. 076 start = new TypedIOPort(this, "start"); 077 start.setInput(true); 078 new SingletonParameter(start, "_showName").setToken(BooleanToken.TRUE); 079 080 // type is undeclared. 081 // Annotate DISCRETE, for the benefit of CT. 082 new Parameter(start, "signalType", new StringToken("DISCRETE")); 083 084 // stop port. 085 stop = new TypedIOPort(this, "stop"); 086 stop.setInput(true); 087 new SingletonParameter(stop, "_showName").setToken(BooleanToken.TRUE); 088 089 // type is undeclared. 090 // Annotate DISCRETE, for the benefit of CT. 091 new Parameter(stop, "signalType", new StringToken("DISCRETE")); 092 } 093 094 /////////////////////////////////////////////////////////////////// 095 //// ports and parameters //// 096 097 /** A port that, if connected, is used to specify when the clock 098 * starts. This port has undeclared type. 099 */ 100 public TypedIOPort start; 101 102 /** A port that, if connected, is used to specify when the clock 103 * stops. This port has undeclared type. 104 */ 105 public TypedIOPort stop; 106 107 /////////////////////////////////////////////////////////////////// 108 //// public methods //// 109 110 /** Override the base class to start not being enabled. 111 * @exception IllegalActionException If the parent class throws it, 112 * or if the <i>values</i> parameter is not a row vector, or if the 113 * fireAt() method of the director throws it, or if the director does not 114 * agree to fire the actor at the specified time. 115 */ 116 @Override 117 public void initialize() throws IllegalActionException { 118 super.initialize(); 119 _enabled = false; 120 } 121 122 /////////////////////////////////////////////////////////////////// 123 //// protected methods //// 124 125 /** Copy values committed in initialize() or in the last postfire() 126 * into the corresponding tentative variables. In effect, this loads 127 * the last known good value for these variables, which is particularly 128 * important if time has gone backwards. This overrides the base class 129 * to check whether the <i>start</i> or <i>stop</i> inputs have values. 130 * @exception IllegalActionException If thrown accessing start or stop 131 * input data. 132 */ 133 @Override 134 protected void _updateTentativeValues() throws IllegalActionException { 135 // Check the start input, to see whether everything needs to 136 // be reset. 137 if (start.isOutsideConnected()) { 138 if (start.hasToken(0)) { 139 if (_debugging) { 140 _debug("Received a start input."); 141 } 142 start.get(0); 143 // Restart everything. 144 initialize(); 145 _enabled = true; 146 } 147 } 148 // Check stop 149 if (stop.isOutsideConnected()) { 150 if (stop.hasToken(0)) { 151 if (_debugging) { 152 _debug("Received a stop input."); 153 } 154 stop.get(0); 155 _enabled = false; 156 } 157 } 158 super._updateTentativeValues(); 159 } 160}