Class Ports


  • public class Ports
    extends java.lang.Object
    A adapter class that allows generating code for ports.
    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Gang Zhou, Contributor: Bert Rodiers, Christopher Brooks
    Pt.AcceptedRating:
    Red (eal)
    Pt.ProposedRating:
    Yellow (zgang)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<IOPort,​PortInfo> _portInfo
      A map from IOPort to PortInfo.
    • Constructor Summary

      Constructors 
      Constructor Description
      Ports​(NamedObj component, PortDirector director)
      Create a Ports instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String generateOffset​(IOPort port, java.lang.String offset, int channel, boolean isWrite)
      Generate the expression that represents the offset in the generated code.
      int getBufferSize​(IOPort port)
      Return the buffer size of a given port, which is the maximum of the bufferSizes of all channels of the given port.
      int getBufferSize​(IOPort port, int channelNumber)
      Get the buffer size of channel of the port.
      GenericCodeGenerator getCodeGenerator()
      Return the code generator associated with the director.
      NamedObj getComponent()
      Return the component associated with the ports.
      java.lang.Object getReadOffset​(IOPort inputPort, int channelNumber)
      Get the read offset in the buffer of a given channel from which a token should be read.
      java.lang.Object getWriteOffset​(IOPort port, int channelNumber)
      Get the write offset in the buffer of a given channel to which a token should be put.
      java.lang.String initializeOffsets​(IOPort port)
      Initialize the offsets.
      void setBufferSize​(IOPort port, int channelNumber, int bufferSize)
      Set the buffer size of channel of the port.
      void setReadOffset​(IOPort port, int channelNumber, java.lang.Object readOffset)
      Set the read offset in a buffer of a given channel from which a token should be read.
      void setWriteOffset​(IOPort port, int channelNumber, java.lang.Object writeOffset)
      Set the write offset in a buffer of a given channel to which a token should be put.
      java.lang.String updateConnectedPortsOffset​(IOPort port, int rate)
      Update the offsets of the buffers associated with the ports connected with the given port in its downstream.
      java.lang.String updateOffset​(IOPort port, int rate)
      Update the read offset.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _portInfo

        protected java.util.Map<IOPort,​PortInfo> _portInfo
        A map from IOPort to PortInfo.
    • Constructor Detail

      • Ports

        public Ports​(NamedObj component,
                     PortDirector director)
        Create a Ports instance.
        Parameters:
        component - The component for which we are doing extra bookkeeping to generate code.
        director - The director associated with the ports.
    • Method Detail

      • getCodeGenerator

        public GenericCodeGenerator getCodeGenerator()
        Return the code generator associated with the director.
        Returns:
        the director.
      • getComponent

        public NamedObj getComponent()
        Return the component associated with the ports.
        Returns:
        the component.
      • generateOffset

        public java.lang.String generateOffset​(IOPort port,
                                               java.lang.String offset,
                                               int channel,
                                               boolean isWrite)
                                        throws IllegalActionException
        Generate the expression that represents the offset in the generated code.
        Parameters:
        port - The given port.
        offset - The specified offset from the user.
        channel - The referenced port channel.
        isWrite - Whether to generate the write or read offset.
        Returns:
        The expression that represents the offset in the generated code.
        Throws:
        IllegalActionException - If there is problems getting the port buffer size or the offset in the channel and offset map.
      • getBufferSize

        public int getBufferSize​(IOPort port,
                                 int channelNumber)
                          throws IllegalActionException
        Get the buffer size of channel of the port.
        Parameters:
        channelNumber - The number of the channel that is being set.
        port - The given port.
        Returns:
        return The size of the buffer.
        Throws:
        IllegalActionException - If thrown while getting the port information or getting the buffer size.
        See Also:
        setBufferSize(IOPort, int, int)
      • getReadOffset

        public java.lang.Object getReadOffset​(IOPort inputPort,
                                              int channelNumber)
                                       throws IllegalActionException
        Get the read offset in the buffer of a given channel from which a token should be read. The channel is given by its containing port and the channel number in that port.
        Parameters:
        inputPort - The given port.
        channelNumber - The given channel number.
        Returns:
        The offset in the buffer of a given channel from which a token should be read.
        Throws:
        IllegalActionException - Thrown if the adapter class cannot be found.
        See Also:
        setReadOffset(IOPort, int, Object)
      • getWriteOffset

        public java.lang.Object getWriteOffset​(IOPort port,
                                               int channelNumber)
                                        throws IllegalActionException
        Get the write offset in the buffer of a given channel to which a token should be put. The channel is given by its containing port and the channel number in that port.
        Parameters:
        port - The given port.
        channelNumber - The given channel number.
        Returns:
        The offset in the buffer of a given channel to which a token should be put.
        Throws:
        IllegalActionException - Thrown if the adapter class cannot be found.
        See Also:
        setWriteOffset(IOPort, int, Object)
      • initializeOffsets

        public java.lang.String initializeOffsets​(IOPort port)
                                           throws IllegalActionException
        Initialize the offsets.
        Parameters:
        port - The given port.
        Returns:
        The code to initialize the offsets.
        Throws:
        IllegalActionException - Thrown if offsets can't be initialized.
      • setBufferSize

        public void setBufferSize​(IOPort port,
                                  int channelNumber,
                                  int bufferSize)
                           throws IllegalActionException
        Set the buffer size of channel of the port.
        Parameters:
        port - The given port.
        channelNumber - The number of the channel that is being set.
        bufferSize - The size of the buffer.
        Throws:
        IllegalActionException - If thrown while getting the port information or while setting the buffer size.
        See Also:
        getBufferSize(IOPort, int)
      • setReadOffset

        public void setReadOffset​(IOPort port,
                                  int channelNumber,
                                  java.lang.Object readOffset)
                           throws IllegalActionException
        Set the read offset in a buffer of a given channel from which a token should be read.
        Parameters:
        port - The given port.
        channelNumber - The given channel.
        readOffset - The offset to be set to the buffer of that channel.
        Throws:
        IllegalActionException - Thrown if the adapter class cannot be found.
        See Also:
        getReadOffset(IOPort, int)
      • updateConnectedPortsOffset

        public java.lang.String updateConnectedPortsOffset​(IOPort port,
                                                           int rate)
                                                    throws IllegalActionException
        Update the offsets of the buffers associated with the ports connected with the given port in its downstream.
        Parameters:
        port - The port whose directly connected downstream actors update their write offsets.
        rate - The rate, which must be greater than or equal to 0.
        Returns:
        The generated code.
        Throws:
        IllegalActionException - If thrown while reading or writing offsets, or getting the buffer size, or if the rate is less than 0.
      • updateOffset

        public java.lang.String updateOffset​(IOPort port,
                                             int rate)
                                      throws IllegalActionException
        Update the read offset.
        Parameters:
        port - The given port.
        rate - The rate of the channels.
        Returns:
        The offset.
        Throws:
        IllegalActionException - If thrown while getting a token, adapter, read offset or buffer size.