001/* 002 * Copyright (c) 1998-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.geon; 031 032import ptolemy.actor.lib.Transformer; 033import ptolemy.data.Token; 034import ptolemy.kernel.CompositeEntity; 035import ptolemy.kernel.util.IllegalActionException; 036import ptolemy.kernel.util.NameDuplicationException; 037 038////////////////////////////////////////////////////////////////////////// 039//// TokenToSeparateChannels 040/** 041 * Transmit each received token to a different consecutive output channel. 042 * 043 * @author Efrat Jaeger 044 * @version $Id: TokenToSeparateChannels.java 12324 2006-04-04 17:23:50Z 045 * altintas $ 046 * @since Ptolemy II 3.0.2 047 */ 048 049public class TokenToSeparateChannels extends Transformer { 050 051 /** 052 * Construct an actor with the given container and name. 053 * 054 * @param container 055 * The container. 056 * @param name 057 * The name of this actor. 058 * @exception IllegalActionException 059 * If the actor cannot be contained by the proposed 060 * container. 061 * @exception NameDuplicationException 062 * If the container already has an actor with this name. 063 */ 064 public TokenToSeparateChannels(CompositeEntity container, String name) 065 throws NameDuplicationException, IllegalActionException { 066 super(container, name); 067 068 output.setMultiport(true); 069 output.setTypeAtLeast(input); 070 } 071 072 // ///////////////////////////////////////////////////////////////// 073 // // public methods //// 074 075 /** 076 * Read the input token, and transmits it each time to a different 077 * consecutive channel. May be used to parallel inputs to different 078 * processors. 079 * 080 * @exception IllegalActionException 081 * Not thrown in this base class 082 */ 083 public void fire() throws IllegalActionException { 084 085 if (channelInd == outputWidth) 086 channelInd = 0; 087 088 Token inputToken = input.get(0); 089 output.send(channelInd, inputToken); 090 channelInd++; 091 } 092 093 /** 094 * Gets the output port width. Sets the current channel index. 095 * 096 * @exception IllegalActionException 097 * If the parent class throws it. 098 * @return Whatever the superclass returns (probably true). 099 */ 100 public void initialize() throws IllegalActionException { 101 channelInd = 0; 102 outputWidth = output.getWidth(); 103 104 super.initialize(); 105 } 106 107 /** 108 * Specifies the width of the output port 109 */ 110 private int outputWidth; 111 112 /** 113 * The index of the channel used in the current iteration 114 */ 115 private int channelInd; 116}