BehaviorBase Class Reference#include <BehaviorBase.h>
List of all members.
Detailed Description
The basis from which all other Behaviors should inherit.
For complex behaviors, it may be helpful to break aspects of the behaviors into independent 'states', and use a state machine formalism to control them. See StateNode and Transition for more information.
Quick-start boilerplate is included in the distribution: project/templates/behavior.h :
Tutorials:
REMEMBER: If/when you override DoStart() / DoStop(), make sure that your own implementation calls BehaviorBase's implementation to allow proper reference counting... otherwise you'll get memory leaks and other odd issues. (see boilerplate link above for example usage)
Also, if you instantiate a behavior on the stack instead of the heap (this is very rarely done), remember to call SetAutoDelete(false) (provided from the ReferenceCounter base class) -- don't want it to try to free memory on the stack when the behavior is stopped! (The stack limits the allocation of the behavior to the current scope, which overrides the reference counting.)
Definition at line 30 of file BehaviorBase.h.
|
Public Member Functions |
virtual | ~BehaviorBase () |
| destructor - if is active when deleted, will display a warning (don't delete directly - use RemoveReference())
|
virtual void | DoStart () |
| By default, merely adds to the reference counter (through AddReference()); Note you should still call this from your overriding methods.
|
virtual void | DoStop () |
| By default, subtracts from the reference counter (RemoveReference()), and thus may deletex if zero; Don't forget to still call this when you override this; Warning: call this at the end of your DoStop(), not beginning (it might delete this ).
|
virtual void | processEvent (const EventBase &) |
| By defining here, allows you to get away with not supplying a processEvent() function for the EventListener interface. By default, does nothing.
|
virtual std::string | getName () const |
| Identifies the behavior in menus and such.
|
virtual void | setName (const std::string &name) |
| Allows dynamic renaming of behaviors.
|
virtual std::string | getDescription () const |
| Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).
|
virtual std::string | getClassName () const |
| Returns the name of the class of this behavior (aka its type).
|
virtual bool | isActive () const |
| Returns true if the behavior is currently running.
|
Static Public Member Functions |
static std::string | getClassDescription () |
| Gives a short description of what this class of behaviors does... you should override this (but don't have to).
|
static const std::set
< BehaviorBase * > & | getRegistry () |
| This read-only set allows us list all the currently instantiated behaviors.
|
Protected Member Functions |
| BehaviorBase (const std::string &name) |
| constructor, name is used as both instance name and class name
|
| BehaviorBase (const std::string &classname, const std::string &instancename) |
| constructor, allows different initial values for class name and instance name
|
| BehaviorBase (const BehaviorBase &b) |
| copy constructor; assumes subclass handles copying approriately - i.e. if b is active, the copy will be as well, even though DoStart was never called..
|
BehaviorBase & | operator= (const BehaviorBase &b) |
| assignment operator; assumes subclass handles assignment appropriately - i.e. if b is active, the copy will be as well, even though DoStart was never called..
|
Static Protected Member Functions |
static std::set< BehaviorBase * > & | getRegistryInstance () |
| static function to provide well-defined initialization order
|
Protected Attributes |
bool | started |
| true when the behavior is active
|
std::string | instanceName |
| holds the name of this instance of behavior
|
const std::string | className |
| holds the type of the subclass of this behavior as a string
|
Constructor & Destructor Documentation
BehaviorBase::~BehaviorBase |
( |
|
) |
[virtual] |
BehaviorBase::BehaviorBase |
( |
const std::string & |
name |
) |
[explicit, protected] |
constructor, name is used as both instance name and class name
Definition at line 4 of file BehaviorBase.cc.
BehaviorBase::BehaviorBase |
( |
const std::string & |
classname, |
|
|
const std::string & |
instancename | |
|
) |
| | [protected] |
constructor, allows different initial values for class name and instance name
Definition at line 11 of file BehaviorBase.cc.
BehaviorBase::BehaviorBase |
( |
const BehaviorBase & |
b |
) |
[protected] |
copy constructor; assumes subclass handles copying approriately - i.e. if b is active, the copy will be as well, even though DoStart was never called..
Definition at line 19 of file BehaviorBase.cc.
Member Function Documentation
void BehaviorBase::DoStart |
( |
|
) |
[virtual] |
By default, merely adds to the reference counter (through AddReference()); Note you should still call this from your overriding methods.
Reimplemented in Controller, FreeMemReportControl, Aibo3DControllerBehavior, EchoBehavior, EStopControllerBehavior, HeadPointControllerBehavior, MicrophoneServer, RawCamBehavior, RegionCamBehavior, RoverControllerBehavior, SegCamBehavior, SpeakerServer, StewartPlatformBehavior, UPennWalkControllerBehavior, ViewWMVarsBehavior, WalkControllerBehavior, WMMonitorBehavior, WorldStateSerializerBehavior, GroupNode, MCNodeBase, MotionSequenceNode< SIZE >, OutputNode, PostureNode, SoundNode, WalkEngineNode< W, mcName, mcDesc >, WalkToTargetNode, WaypointEngineNode< W, mcName, mcDesc >, AutoGetupBehavior, BatteryMonitorBehavior, DeadReckoningBehavior< ParticleT >, FlashIPAddrBehavior, WorldStateVelDaemon, StateNode, CompareTrans< T >, CompletionTrans, ConnectionMadeTrans, EventTrans, LostTargetTrans, NullTrans, SignalTrans< T >, SmoothCompareTrans< T >, TextMsgTrans, TimeOutTrans, VisualTargetCloseTrans, VisualTargetTrans, EventGeneratorBase, PitchDetector, BufferedImageGenerator, CDTGenerator, and RawCameraGenerator.
Definition at line 45 of file BehaviorBase.cc.
Referenced by BehaviorActivatorControl::activate(), WorldStateVelDaemon::DoStart(), WorldStateSerializerBehavior::DoStart(), WMMonitorBehavior::DoStart(), WalkControllerBehavior::DoStart(), VisualTargetTrans::DoStart(), VisualTargetCloseTrans::DoStart(), ViewWMVarsBehavior::DoStart(), UPennWalkControllerBehavior::DoStart(), TimeOutTrans::DoStart(), TextMsgTrans::DoStart(), StewartPlatformBehavior::DoStart(), StateNode::DoStart(), SpeakerServer::DoStart(), SignalTrans< T >::DoStart(), SegCamBehavior::DoStart(), RegionCamBehavior::DoStart(), RawCamBehavior::DoStart(), NullTrans::DoStart(), MicrophoneServer::DoStart(), HeadPointControllerBehavior::DoStart(), FreeMemReportControl::DoStart(), EventTrans::DoStart(), EventGeneratorBase::DoStart(), EStopControllerBehavior::DoStart(), EchoBehavior::DoStart(), DeadReckoningBehavior< ParticleT >::DoStart(), Controller::DoStart(), ConnectionMadeTrans::DoStart(), CompletionTrans::DoStart(), CompareTrans< T >::DoStart(), BatteryMonitorBehavior::DoStart(), AutoGetupBehavior::DoStart(), Aibo3DControllerBehavior::DoStart(), Transition::fire(), BehaviorSwitchControl< B, Al >::startmine(), and BehaviorSwitchControlBase::startmine().
void BehaviorBase::DoStop |
( |
|
) |
[virtual] |
By default, subtracts from the reference counter (RemoveReference()), and thus may deletex if zero; Don't forget to still call this when you override this; Warning: call this at the end of your DoStop(), not beginning (it might delete this ).
Reimplemented in Controller, FreeMemReportControl, Aibo3DControllerBehavior, EchoBehavior, EStopControllerBehavior, HeadPointControllerBehavior, MicrophoneServer, RawCamBehavior, RegionCamBehavior, RoverControllerBehavior, SegCamBehavior, SpeakerServer, StewartPlatformBehavior, UPennWalkControllerBehavior, ViewWMVarsBehavior, WalkControllerBehavior, WMMonitorBehavior, WorldStateSerializerBehavior, MCNodeBase, MotionSequenceNode< SIZE >, SoundNode, WalkToTargetNode, AutoGetupBehavior, BatteryMonitorBehavior, FlashIPAddrBehavior, WorldStateVelDaemon, StateNode, CompareTrans< T >, CompletionTrans, ConnectionMadeTrans, EventTrans, NullTrans, TextMsgTrans, TimeOutTrans, VisualTargetCloseTrans, VisualTargetTrans, EventGeneratorBase, and PitchDetector.
Definition at line 54 of file BehaviorBase.cc.
Referenced by BehaviorActivatorControl::activate(), BehaviorSwitchControlBase::BehaviorSwitchControlBase(), WorldStateVelDaemon::DoStop(), WorldStateSerializerBehavior::DoStop(), WMMonitorBehavior::DoStop(), WalkControllerBehavior::DoStop(), VisualTargetTrans::DoStop(), VisualTargetCloseTrans::DoStop(), ViewWMVarsBehavior::DoStop(), UPennWalkControllerBehavior::DoStop(), TimeOutTrans::DoStop(), TextMsgTrans::DoStop(), StewartPlatformBehavior::DoStop(), StateNode::DoStop(), SpeakerServer::DoStop(), SegCamBehavior::DoStop(), RegionCamBehavior::DoStop(), RawCamBehavior::DoStop(), NullTrans::DoStop(), MicrophoneServer::DoStop(), HeadPointControllerBehavior::DoStop(), FreeMemReportControl::DoStop(), EventTrans::DoStop(), EventGeneratorBase::DoStop(), EStopControllerBehavior::DoStop(), EchoBehavior::DoStop(), Controller::DoStop(), ConnectionMadeTrans::DoStop(), CompletionTrans::DoStop(), CompareTrans< T >::DoStop(), BatteryMonitorBehavior::DoStop(), AutoGetupBehavior::DoStop(), Aibo3DControllerBehavior::DoStop(), Transition::fire(), BehaviorSwitchControlBase::stopother(), and BehaviorSwitchControlBase::BehaviorGroup::~BehaviorGroup().
virtual void BehaviorBase::processEvent |
( |
const EventBase & |
|
) |
[inline, virtual] |
By defining here, allows you to get away with not supplying a processEvent() function for the EventListener interface. By default, does nothing.
Implements EventListener.
Reimplemented in Controller, FreeMemReportControl, CameraStreamBehavior, EchoBehavior, EStopControllerBehavior, MicrophoneServer, RawCamBehavior, RegionCamBehavior, SegCamBehavior, StewartPlatformBehavior, UPennWalkControllerBehavior, WalkControllerBehavior, WMMonitorBehavior, WorldStateSerializerBehavior, MCNodeBase, MotionSequenceNode< SIZE >, SoundNode, WalkToTargetNode, WaypointEngineNode< W, mcName, mcDesc >, AutoGetupBehavior, BatteryMonitorBehavior, DeadReckoningBehavior< ParticleT >, FlashIPAddrBehavior, WorldStateVelDaemon, CompareTrans< T >, CompletionTrans, ConnectionMadeTrans, EventTrans, LostTargetTrans, NullTrans, SignalTrans< T >, SmoothCompareTrans< T >, TextMsgTrans, TimeOutTrans, VisualTargetCloseTrans, VisualTargetTrans, EventGeneratorBase, PitchDetector, BallDetectionGenerator, BufferedImageGenerator, CDTGenerator, FilterBankGenerator, InterleavedYUVGenerator, JPEGGenerator, PNGGenerator, RawCameraGenerator, RegionGenerator, RLEGenerator, and SegmentedColorGenerator.
Definition at line 42 of file BehaviorBase.h.
Referenced by BehaviorSwitchControlBase::takeInput().
virtual std::string BehaviorBase::getName |
( |
|
) |
const [inline, virtual] |
Identifies the behavior in menus and such.
Reimplemented in FreeMemReportControl, and Transition.
Definition at line 45 of file BehaviorBase.h.
Referenced by PNGGenerator::calcImage(), JPEGGenerator::calcImage(), BallDetectionGenerator::createEvent(), StateNode::DoStart(), EventLogger::find(), getDescription(), BehaviorSwitchControlBase::getName(), EventLogger::isListening(), EventLogger::logImage(), EventLogger::logMessage(), EventLogger::logWebcam(), StateNode::postCompletionEvent(), StateNode::postStartEvent(), StateNode::postStopEvent(), SegCamBehavior::processEvent(), RawCamBehavior::processEvent(), FilterBankGenerator::processEvent(), BufferedImageGenerator::processEvent(), EventLogger::processStateMachineEvent(), CameraStreamBehavior::receiveData(), FilterBankGenerator::refresh(), EventLogger::runCommand(), Controller::select(), EventLogger::spider(), and ~BehaviorBase().
virtual void BehaviorBase::setName |
( |
const std::string & |
name |
) |
[inline, virtual] |
virtual std::string BehaviorBase::getDescription |
( |
|
) |
const [inline, virtual] |
Gives a short description of what this particular instantiation does (in case a more specific description is needed on an individual basis).
By default simply returns getName(), because any calls from a BehaviorBase function to getClassDescription() are going to call BehaviorBase::getClassDescription(), not ~YourSubClass~getClassDescription(), because static functions can't be virtual in C++ (doh!)
This means that getDescription called on a pointer to a BehaviorBase of unknown subtype would always return an empty string, which is pretty useless. So instead we return the name in this situation. If you want getDescription to return getClassDescription, you'll have to override it in your subclass to do so.
Reimplemented in Controller, Aibo3DControllerBehavior, CameraStreamBehavior, EchoBehavior, EStopControllerBehavior, HeadPointControllerBehavior, RawCamBehavior, RegionCamBehavior, RoverControllerBehavior, SegCamBehavior, StewartPlatformBehavior, UPennWalkControllerBehavior, ViewWMVarsBehavior, WalkControllerBehavior, WMMonitorBehavior, WorldStateSerializerBehavior, LedNode, MCNodeBase, MCNode< T, mcName, mcDesc, completes >, WalkToTargetNode, AutoGetupBehavior, BatteryMonitorBehavior, DeadReckoningBehavior< ParticleT >, FlashIPAddrBehavior, WorldStateVelDaemon, TextMsgTrans, PitchDetector, MCNode< LedMC >, MCNode< PostureMC, defPostureNodeName, defPostureNodeDesc, true >, MCNode< TailWagMC, defTailWagNodeName, defTailWagNodeDesc, false >, MCNode< W, mcName, mcDesc >, and MCNode< HeadPointerMC, defHeadPointerNodeName, defHeadPointerNodeDesc, true >.
Definition at line 63 of file BehaviorBase.h.
Referenced by BehaviorSwitchControl< B, Al >::getDescription(), and BehaviorSwitchControlBase::getDescription().
virtual std::string BehaviorBase::getClassName |
( |
|
) |
const [inline, virtual] |
static std::string BehaviorBase::getClassDescription |
( |
|
) |
[inline, static] |
Gives a short description of what this class of behaviors does... you should override this (but don't have to).
If you do override this, also consider overriding getDescription() to return it
Reimplemented in Controller, Aibo3DControllerBehavior, CameraStreamBehavior, EchoBehavior, EStopControllerBehavior, HeadPointControllerBehavior, RawCamBehavior, RegionCamBehavior, RoverControllerBehavior, SegCamBehavior, StewartPlatformBehavior, UPennWalkControllerBehavior, ViewWMVarsBehavior, WalkControllerBehavior, WMMonitorBehavior, WorldStateSerializerBehavior, LedNode, MCNodeBase, MCNode< T, mcName, mcDesc, completes >, WalkToTargetNode, AutoGetupBehavior, BatteryMonitorBehavior, DeadReckoningBehavior< ParticleT >, FlashIPAddrBehavior, WorldStateVelDaemon, TextMsgTrans, PitchDetector, BallDetectionGenerator, CDTGenerator, InterleavedYUVGenerator, JPEGGenerator, PNGGenerator, RawCameraGenerator, RegionGenerator, RLEGenerator, SegmentedColorGenerator, MCNode< LedMC >, MCNode< PostureMC, defPostureNodeName, defPostureNodeDesc, true >, MCNode< TailWagMC, defTailWagNodeName, defTailWagNodeDesc, false >, MCNode< W, mcName, mcDesc >, and MCNode< HeadPointerMC, defHeadPointerNodeName, defHeadPointerNodeDesc, true >.
Definition at line 77 of file BehaviorBase.h.
Referenced by getDescription().
virtual bool BehaviorBase::isActive |
( |
|
) |
const [inline, virtual] |
Returns true if the behavior is currently running.
Definition at line 80 of file BehaviorBase.h.
Referenced by BehaviorActivatorControl::activate(), BehaviorSwitchControl< B, Al >::BehaviorSwitchControl(), BehaviorSwitchControlBase::BehaviorSwitchControlBase(), StateNode::DoStart(), Transition::fire(), RandomTrans::fire(), FreeMemReportControl::getName(), BehaviorSwitchControlBase::getName(), BehaviorSwitchControlBase::isRunning(), EventGeneratorBase::setAutoListen(), MotionSequenceNode< SIZE >::setFile(), BehaviorSwitchControlBase::stopother(), RoverControllerBehavior::~RoverControllerBehavior(), and StateNode::~StateNode().
static const std::set<BehaviorBase*>& BehaviorBase::getRegistry |
( |
|
) |
[inline, static] |
std::set< BehaviorBase * > & BehaviorBase::getRegistryInstance |
( |
|
) |
[static, protected] |
assignment operator; assumes subclass handles assignment appropriately - i.e. if b is active, the copy will be as well, even though DoStart was never called..
Definition at line 27 of file BehaviorBase.cc.
Referenced by Transition::operator=().
Member Data Documentation
The documentation for this class was generated from the following files:
|