ptolemy.domains.wireless.lib
Class TransmitPropertyTransformer

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.kernel.CompositeEntity
                      extended by ptolemy.actor.CompositeActor
                          extended by ptolemy.actor.TypedCompositeActor
                              extended by ptolemy.actor.lib.hoc.LifeCycleManager
                                  extended by ptolemy.domains.wireless.lib.TransmitPropertyTransformer
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, PropertyTransformer, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class TransmitPropertyTransformer
extends LifeCycleManager
implements PropertyTransformer

This actor reads input tokens and sends them unmodified to the output; its role is not to operate on input tokens, but rather to modify the properties of a transmission.

This actor implements the PropertyTransformer interface, which provides a callback that can be use to modify the transmit properties of a transmission. It register itself and its connected wireless output port with the channel that the wireless output port uses. The channel will call its transformProperties() method for each transmission from the registed output port.

When transformProperties() is called, this actor sets the value of three variables and then performs a complete execution of the contained model. The three variables are senderLocation (an array of doubles), receiverLocation (also an array of doubles), and properties (a record token containing the transmit properties to be modified). After execution of the contained model, the (possibly modified) value of the record properties is taken to be the modified properties. Thus, a contained model would normally read the variable properties, change it, and use a SetVariable actor to set the new value of properties.

This actor expects its output port to be connected directly to the inside of a WirelessIOPort belonging to this actor's container. It looks for this port in the preinitialize() method, and registers with the channel specified by that port. If there is no such port, or no such channel, then preinitialize() throws an exception. Note that since this connectivity is checked only during preinitialize(), this actor does not support dynamically reconnecting its output port during execution of the model.

Since:
Ptolemy II 4.0
Version:
$Id: TransmitPropertyTransformer.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Yang Zhao, Edward Lee
See Also:
Serialized Form
Accepted Rating:
Red (pjb2e)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
 
Field Summary
private  WirelessChannel _inputWirelessChannel
          The wireless channel for the connected input port found in preinitialize().
private  WirelessChannel _outputWirelessChannel
          The wireless channel for the connected output port found in preinitialize().
private  WirelessIOPort _wirelessInputPort
          The connected wireless input port found in preinitialize().
private  WirelessIOPort _wirelessOutputPort
          The connected wireless output port found in preinitialize().
 TypedIOPort input
          Port that receives the data to be transmitted on the output port.
private static java.lang.String LOCATION_ATTRIBUTE_NAME
          Name of the location attribute.
 TypedIOPort output
          Port that sends data to a wireless output.
 Parameter properties
          The properties to be transformed.
 Parameter receiverLocation
          The location of the receiver.
 Parameter senderLocation
          The location of the sender.
 
Fields inherited from class ptolemy.actor.CompositeActor
_actorFiringListeners, _causalityInterface, _initializables, _notifyingActorFiring, _publishedPorts, _publisherRelations, _stopRequested
 
Fields inherited from class ptolemy.kernel.CompositeEntity
_levelCrossingLinks
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
TransmitPropertyTransformer(CompositeEntity container, java.lang.String name)
          Construct an actor with the specified container and name.
 
Method Summary
private  double[] _locationOf(WirelessIOPort port)
          Return the location of the given WirelessIOPort.
protected  void _readInputs()
          Override the base class to not read any inputs.
protected  void _writeOutputs()
          Override the base class to not write any outputs.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Read at most one token from the input port and simply transmit the data to the output port.
 boolean postfire()
          Return true, indicating that execution can continue.
 boolean prefire()
          Return true, indicating that this actor is always ready to fire.
 void preinitialize()
          Register with the channel as a PropertyTransformer for its connected wireless output port.
 RecordToken transformProperties(RecordToken initialProperties, WirelessIOPort sender, WirelessIOPort destination)
          Set the senderLocation, receiverLocation, and properties variables and execute the contained model.
 void wrapup()
          Override the base class to unregister this actor with the channel.
 
Methods inherited from class ptolemy.actor.lib.hoc.LifeCycleManager
_executeInsideModel, _fireInsideModel, executeChangeRequests, isOpaque, requestChange
 
Methods inherited from class ptolemy.actor.TypedCompositeActor
_addEntity, _addPort, _addRelation, _checkTypesFromTo, _typeConstraintsFromTo, newPort, newRelation, resolveTypes, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _finishedAddEntity, _getPublishedPort, _setDirector, addActorFiringListener, addInitializable, addPiggyback, connectionsChanged, createReceivers, createSchedule, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inferringWidths, inferWidths, initialize, inputPortList, isFireFunctional, isStrict, iterate, linkToPublishedPort, linkToPublishedPort, needsWidthInference, newInsideReceiver, newReceiver, notifyConnectivityChange, outputPortList, recordFiring, registerPublisherPort, removeActorFiringListener, removeInitializable, removePiggyback, setContainer, setDirector, setManager, stop, stopFire, terminate, unlinkToPublishedPort, unlinkToPublishedPort, unregisterPublisherPort
 
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _deepOpaqueEntityList, _description, _exportMoMLContents, _recordDecoratedAttributes, _removeEntity, _removeRelation, _validateSettables, allAtomicEntityList, allCompositeEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepEntityList, deepGetEntities, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, exportMoML, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyClassDefinitionList, lazyDeepEntityList, lazyEntityList, lazyRelationList, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, statistics, uniqueName
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_removePort, connectedPortList, connectedPorts, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, deepContains, depthInHierarchy, description, description, event, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

input

public TypedIOPort input
Port that receives the data to be transmitted on the output port. The type is unconstrained.


output

public TypedIOPort output
Port that sends data to a wireless output. The type is constrained to be the same as the input.


senderLocation

public Parameter senderLocation
The location of the sender. This is a double array with default value {0.0, 0.0}.


receiverLocation

public Parameter receiverLocation
The location of the receiver. This is a double array with default value {0.0, 0.0}.


properties

public Parameter properties
The properties to be transformed. This is a record token with value {power = 0.0, range = 0.0}.


_inputWirelessChannel

private WirelessChannel _inputWirelessChannel
The wireless channel for the connected input port found in preinitialize().


_wirelessInputPort

private WirelessIOPort _wirelessInputPort
The connected wireless input port found in preinitialize().


_outputWirelessChannel

private WirelessChannel _outputWirelessChannel
The wireless channel for the connected output port found in preinitialize().


_wirelessOutputPort

private WirelessIOPort _wirelessOutputPort
The connected wireless output port found in preinitialize().


LOCATION_ATTRIBUTE_NAME

private static final java.lang.String LOCATION_ATTRIBUTE_NAME
Name of the location attribute.

See Also:
Constant Field Values
Constructor Detail

TransmitPropertyTransformer

public TransmitPropertyTransformer(CompositeEntity container,
                                   java.lang.String name)
                            throws NameDuplicationException,
                                   IllegalActionException
Construct an actor with the specified container and name.

Parameters:
container - The container.
name - The name.
Throws:
IllegalActionException - If the entity cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace.

Overrides:
clone in class CompositeActor
Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

fire

public void fire()
          throws IllegalActionException
Read at most one token from the input port and simply transmit the data to the output port.

Specified by:
fire in interface Executable
Overrides:
fire in class CompositeActor
Throws:
IllegalActionException - If there is no director, or if the director's action methods throw it.

postfire

public boolean postfire()
                 throws IllegalActionException
Return true, indicating that execution can continue.

Specified by:
postfire in interface Executable
Overrides:
postfire in class CompositeActor
Returns:
True if the execution can continue into the next iteration.
Throws:
IllegalActionException - Not thrown in this class, but declared so the subclasses can throw it.

prefire

public boolean prefire()
                throws IllegalActionException
Return true, indicating that this actor is always ready to fire.

Specified by:
prefire in interface Executable
Overrides:
prefire in class CompositeActor
Returns:
True if the iteration can proceed.
Throws:
IllegalActionException - Not thrown in this class, but declared so the subclasses can throw it.

preinitialize

public void preinitialize()
                   throws IllegalActionException
Register with the channel as a PropertyTransformer for its connected wireless output port. If the output is not connected directly to a WirelessIOPort, then throw an exception.

Specified by:
preinitialize in interface Initializable
Overrides:
preinitialize in class CompositeActor
Throws:
IllegalActionException - If the output is not connected directly to a WirelessIOPort, or if the port's container does not have a container, or if no channel is found.

transformProperties

public RecordToken transformProperties(RecordToken initialProperties,
                                       WirelessIOPort sender,
                                       WirelessIOPort destination)
                                throws IllegalActionException
Set the senderLocation, receiverLocation, and properties variables and execute the contained model. Return the final value of the properties variable.

Specified by:
transformProperties in interface PropertyTransformer
Parameters:
initialProperties - The initial value of the properties.
sender - The sending port.
destination - The receiving port.
Returns:
The modified transform properties.
Throws:
IllegalActionException - If executing the model throws it.

wrapup

public void wrapup()
            throws IllegalActionException
Override the base class to unregister this actor with the channel.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class CompositeActor
Throws:
IllegalActionException - If the base class throws it.

_readInputs

protected void _readInputs()
Override the base class to not read any inputs.

Overrides:
_readInputs in class LifeCycleManager

_writeOutputs

protected void _writeOutputs()
Override the base class to not write any outputs.

Overrides:
_writeOutputs in class LifeCycleManager

_locationOf

private double[] _locationOf(WirelessIOPort port)
                      throws IllegalActionException
Return the location of the given WirelessIOPort.

Parameters:
port - A port with a location.
Returns:
The location of the port.
Throws:
IllegalActionException - If a valid location attribute cannot be found.