Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BehaviorBase Class Reference

#include <BehaviorBase.h>

Inheritance diagram for BehaviorBase:

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..
BehaviorBaseoperator= (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]

destructor - if is active when deleted, will display a warning (don't delete directly - use RemoveReference())

Definition at line 35 of file BehaviorBase.cc.

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::setName ( const std::string &  name  )  [inline, virtual]

Allows dynamic renaming of behaviors.

Definition at line 48 of file BehaviorBase.h.

Referenced by BehaviorSwitchControlBase::BehaviorSwitchControlBase(), and BehaviorSwitchControl< B, Al >::startmine().

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]

Returns the name of the class of this behavior (aka its type).

Note that this isn't static to avoid the problems we found with getDescription/getClassDescription. So instead we wind up wasting some memory in each instance of the class to store the className, but at least it will work the way you expect.

Definition at line 73 of file BehaviorBase.h.

Referenced by PNGGenerator::calcImage(), JPEGGenerator::calcImage(), StateNode::DoStop(), BehaviorSwitchControlBase::getDescription(), FilterBankGenerator::processEvent(), BufferedImageGenerator::processEvent(), EventLogger::spider(), and StateNode::~StateNode().

static const std::set<BehaviorBase*>& BehaviorBase::getRegistry (  )  [inline, static]

This read-only set allows us list all the currently instantiated behaviors.

Not all of these behaviors are necessarily active, this is everything that has been allocated and not yet deallocated

Definition at line 84 of file BehaviorBase.h.

Referenced by BehaviorReportControl::activate(), EventLogger::find(), and EventLogger::runCommand().

std::set< BehaviorBase * > & BehaviorBase::getRegistryInstance (  )  [static, protected]

static function to provide well-defined initialization order

Definition at line 63 of file BehaviorBase.cc.

Referenced by BehaviorBase(), getRegistry(), and ~BehaviorBase().

BehaviorBase & BehaviorBase::operator= ( const BehaviorBase b  )  [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

bool BehaviorBase::started [protected]

true when the behavior is active

Definition at line 111 of file BehaviorBase.h.

Referenced by DoStart(), DoStop(), isActive(), operator=(), and ~BehaviorBase().

std::string BehaviorBase::instanceName [protected]

holds the name of this instance of behavior

Definition at line 112 of file BehaviorBase.h.

Referenced by Transition::getName(), getName(), operator=(), and setName().

const std::string BehaviorBase::className [protected]

holds the type of the subclass of this behavior as a string

Definition at line 113 of file BehaviorBase.h.

Referenced by getClassName(), and Transition::getName().


The documentation for this class was generated from the following files:

Tekkotsu v4.0
Generated Thu Nov 22 00:58:11 2007 by Doxygen 1.5.4