org.commonreality.sensors.speech
Class VocalizationCommandHandler

java.lang.Object
  extended by org.commonreality.sensors.handlers.AbstractCommandHandlerDelegate
      extended by org.commonreality.sensors.speech.VocalizationCommandHandler
All Implemented Interfaces:
ICommandHandlerDelegate

public class VocalizationCommandHandler
extends AbstractCommandHandlerDelegate

this generalized vocalization command handler can be used by any sensor that wants to avoid vocal abilities. A few things to note: any agent that can speak must have an IEfferentObject associated with it (by the sensor) that has VocalConstants.CAN_VOCALIZE set to true. This IEfferentObject must also have a VocalizationCommandTemplate as a member of the collection IEfferentObject.COMMAND_TEMPLATES. The sensor must also be able to track the vocalizations (recommend extending #start(DeltaTracker)) and then set the command as completed upon termination #completed(IEfferentCommand, Object) or #aborted(IEfferentCommand, Object)
This class will then handle the commands on the provided executor. And when a vocalization is actually executed it will be delegated to ISpeaker

Author:
harrison

Constructor Summary
VocalizationCommandHandler(ICommandTimingEquation duration, ISpeaker speaker)
           
 
Method Summary
 void abort(IEfferentCommand command, IAgentObject agent, EfferentCommandHandler parent)
           
 ISpeaker getSpeaker()
           
 ICommandTimingEquation getTimingEquation(IEfferentCommand command, IAgentObject agent, EfferentCommandHandler handler)
          return the timing equation used
 void setSpeaker(ISpeaker speaker)
           
 java.lang.Object shouldAccept(IEfferentCommand command, IAgentObject agent, EfferentCommandHandler handler)
          only accept vocalization commands where the source matched the provided efferent
 java.lang.Object shouldStart(IEfferentCommand command, IAgentObject agent, EfferentCommandHandler handler)
          return Boolean.TRUE if the command should be started.
 void start(IEfferentCommand command, IAgentObject agent, EfferentCommandHandler parent)
          actually start the processing of the command.
 
Methods inherited from class org.commonreality.sensors.handlers.AbstractCommandHandlerDelegate
shouldAbort
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VocalizationCommandHandler

public VocalizationCommandHandler(ICommandTimingEquation duration,
                                  ISpeaker speaker)
Method Detail

setSpeaker

public void setSpeaker(ISpeaker speaker)

getSpeaker

public ISpeaker getSpeaker()

shouldAccept

public java.lang.Object shouldAccept(IEfferentCommand command,
                                     IAgentObject agent,
                                     EfferentCommandHandler handler)
only accept vocalization commands where the source matched the provided efferent

Specified by:
shouldAccept in interface ICommandHandlerDelegate
Overrides:
shouldAccept in class AbstractCommandHandlerDelegate
Returns:

shouldStart

public java.lang.Object shouldStart(IEfferentCommand command,
                                    IAgentObject agent,
                                    EfferentCommandHandler handler)
Description copied from interface: ICommandHandlerDelegate
return Boolean.TRUE if the command should be started. Any other value will be returned as the explanation for the rejection of the command start. If this returns Boolean.TRUE, the EfferentCommandHandler will next call ICommandHandlerDelegate.start(IEfferentCommand, IAgentObject, EfferentCommandHandler) and then send a state update for the command noting that the actual state is running.

Specified by:
shouldStart in interface ICommandHandlerDelegate
Overrides:
shouldStart in class AbstractCommandHandlerDelegate
Returns:

abort

public void abort(IEfferentCommand command,
                  IAgentObject agent,
                  EfferentCommandHandler parent)

getTimingEquation

public ICommandTimingEquation getTimingEquation(IEfferentCommand command,
                                                IAgentObject agent,
                                                EfferentCommandHandler handler)
Description copied from interface: ICommandHandlerDelegate
return the timing equation used

Returns:

start

public void start(IEfferentCommand command,
                  IAgentObject agent,
                  EfferentCommandHandler parent)
Description copied from interface: ICommandHandlerDelegate
actually start the processing of the command. The EfferentCommandHandler is passed along as well so that later EfferentCommandHandler.completed(IEfferentCommand, Object) may be called. However, it should not be called from within here. The reason is simple, after returning from start, EfferentCommandHandler will set the state of the command as RUNNING. If you call EfferentCommandHandler.completed(IEfferentCommand, Object) from within start, the states will be inconsistent