ptolemy.codegen.kernel
Interface PortCodeGenerator

All Superinterfaces:
ComponentCodeGenerator
All Known Implementing Classes:
IOPort, IOPort, IOPort, ModalPort, ModalPort, MultiCompositePort, MultiCompositePort, ParameterPort, ParameterPort, ParameterPort, RefinementPort, RefinementPort, RefinementPort, RefinementPort, TransitionRefinementPort, TransitionRefinementPort, TypedIOPort, TypedIOPort

public interface PortCodeGenerator
extends ComponentCodeGenerator

Language independent code generator for Ptolemy ports.

Since:
Ptolemy II 8.0
Version:
$Id: PortCodeGenerator.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Man-kit Leung
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Method Summary
 java.lang.String generateCodeForGet(java.lang.String channel)
          Generate code for replacing the get() macro.
 java.lang.String generateCodeForSend(java.lang.String channel, java.lang.String dataToken)
          Generate code for replacing the send() macro.
 java.lang.String generateOffset(java.lang.String offset, int channel, boolean isWrite, Director directorHelper)
          Generate the expression that represents the offset in the generated code.
 int getBufferSize(int channelNumber)
          Get the buffer size of channel of the port.
 java.lang.Object getReadOffset(int channelNumber)
          Get the read offset of a channel of the port.
 java.lang.Object getWriteOffset(int channelNumber)
          Get the write offset of a channel of the port.
 java.lang.String initializeOffsets()
          Initialize the offsets.
 void setBufferSize(int channelNumber, int bufferSize)
          Set the buffer size of channel of the port.
 void setReadOffset(int channelNumber, java.lang.Object readOffset)
          Set the read offset of a channel of the port.
 void setWriteOffset(int channelNumber, java.lang.Object writeOffset)
          Set the write offset of a channel of the port.
 java.lang.String updateConnectedPortsOffset(int rate, Director director)
          Update the write offset of the [multiple] connected ports.
 java.lang.String updateOffset(int rate, Director directorHelper)
          Update the read offset.
 
Methods inherited from interface ptolemy.codegen.kernel.ComponentCodeGenerator
generateInitializeCode, generateWrapupCode, getComponent, setCodeGenerator
 

Method Detail

generateOffset

java.lang.String generateOffset(java.lang.String offset,
                                int channel,
                                boolean isWrite,
                                Director directorHelper)
                                throws IllegalActionException
Generate the expression that represents the offset in the generated code.

Parameters:
offset - The specified offset from the user.
channel - The referenced port channel.
isWrite - Whether to generate the write or read offset.
directorHelper - The helper of the director associated with the port.
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.

generateCodeForGet

java.lang.String generateCodeForGet(java.lang.String channel)
                                    throws IllegalActionException
Generate code for replacing the get() macro. This delegates to the receiver adapter for the specified channel and asks it to generate the get code.

Parameters:
channel - The channel for which the get code is generated.
Returns:
The code that gets data from the channel.
Throws:
IllegalActionException - If the director adapter class cannot be found. FIXME: potentially, we could also pass in a boolean that indicates whether the port the channel resides is a multiport, if it is, then only a static variable is needed instead of an array of length 1.

generateCodeForSend

java.lang.String generateCodeForSend(java.lang.String channel,
                                     java.lang.String dataToken)
                                     throws IllegalActionException
Generate code for replacing the send() macro.

Parameters:
channel - The channel for which the send code is generated.
dataToken - The token to be sent
Returns:
The code that sends the dataToken on the channel.
Throws:
IllegalActionException - If the director adapter class cannot be found. FIXME: potentially, we could also pass in a boolean that indicates whether the port the channel resides is a multiport, if it is, then only a static variable is needed instead of an array of length 1.

getBufferSize

int getBufferSize(int channelNumber)
                  throws IllegalActionException
Get the buffer size of channel of the port.

Parameters:
channelNumber - The number of the channel that is being set.
Returns:
return The size of the buffer.
Throws:
IllegalActionException - If the buffer size cannot be set.
See Also:
setBufferSize(int, int)

getReadOffset

java.lang.Object getReadOffset(int channelNumber)
                               throws IllegalActionException
Get the read offset of a channel of the port.

Parameters:
channelNumber - The number of the channel.
Returns:
The read offset.
Throws:
IllegalActionException - If thrown while getting the channel.
See Also:
setReadOffset(int, Object)

getWriteOffset

java.lang.Object getWriteOffset(int channelNumber)
                                throws IllegalActionException
Get the write offset of a channel of the port.

Parameters:
channelNumber - The number of the channel.
Returns:
The write offset.
Throws:
IllegalActionException - If thrown while getting the channel.
See Also:
setWriteOffset(int, Object)

setBufferSize

void setBufferSize(int channelNumber,
                   int bufferSize)
Set the buffer size of channel of the port.

Parameters:
channelNumber - The number of the channel that is being set.
bufferSize - The size of the buffer.
See Also:
getBufferSize(int)

setReadOffset

void setReadOffset(int channelNumber,
                   java.lang.Object readOffset)
Set the read offset of a channel of the port.

Parameters:
channelNumber - The number of the channel that is being set.
readOffset - The offset.
See Also:
getReadOffset(int)

setWriteOffset

void setWriteOffset(int channelNumber,
                    java.lang.Object writeOffset)
Set the write offset of a channel of the port.

Parameters:
channelNumber - The number of the channel that is being set.
writeOffset - The offset.
See Also:
getWriteOffset(int)

updateOffset

java.lang.String updateOffset(int rate,
                              Director directorHelper)
                              throws IllegalActionException
Update the read offset.

Parameters:
rate - The rate of the channels.
directorHelper - The Director helper
Returns:
The offset.
Throws:
IllegalActionException - If thrown while getting the channel or updating the offset.

updateConnectedPortsOffset

java.lang.String updateConnectedPortsOffset(int rate,
                                            Director director)
                                            throws IllegalActionException
Update the write offset of the [multiple] connected ports.

Parameters:
rate - The rate of the channels.
director - The Director helper.
Returns:
The offset.
Throws:
IllegalActionException - If thrown while getting the channel or updating the offset.

initializeOffsets

java.lang.String initializeOffsets()
                                   throws IllegalActionException
Initialize the offsets.

Returns:
The code to initialize the offsets.
Throws:
IllegalActionException - If thrown while getting the channel or initializing the offset.