Homepage Demos Overview Downloads Tutorials Reference
Credits

StateNode.cc

Go to the documentation of this file.
00001 #include "StateNode.h"
00002 #include "Events/EventRouter.h"
00003 #include "Wireless/Wireless.h"
00004 
00005 StateNode::~StateNode() {
00006   ASSERT(!isActive(), "Destructing while active?")
00007   for(std::vector<Transition*>::iterator it=transitions.begin(); it!=transitions.end(); it++)
00008     (*it)->RemoveReference();
00009   if(issetup) {
00010     for(std::vector<StateNode*>::iterator it=nodes.begin(); it!=nodes.end(); it++)
00011       (*it)->RemoveReference();
00012   }
00013 }
00014 
00015 void StateNode::addTransition(Transition* trans) {
00016   transitions.push_back(trans);
00017   trans->AddReference();
00018   trans->addSource(this);
00019 }
00020 
00021 void StateNode::DoStart() {
00022   BehaviorBase::DoStart();
00023   if(!issetup) {
00024     setup();
00025     issetup=true;
00026   }
00027   for(std::vector<Transition*>::iterator it=transitions.begin(); it!=transitions.end(); it++)
00028     (*it)->DoStart();
00029   erouter->postEvent(EventBase::stateMachineEGID,reinterpret_cast<unsigned int>(this),EventBase::activateETID,0,getName(),1);
00030   if(parent!=NULL)
00031     parent->transitionTo(this);
00032 }
00033 
00034 void StateNode::DoStop() {
00035   for(std::vector<Transition*>::iterator it=transitions.begin(); it!=transitions.end(); it++) {
00036     ASSERT((*it)->isActive(),"Inactive transition");
00037     if((*it)->isActive())
00038       (*it)->DoStop();
00039   }
00040   for(std::vector<StateNode*>::iterator it=nodes.begin(); it!=nodes.end(); it++)
00041     if((*it)->isActive())
00042       (*it)->DoStop();
00043   if(!retain) {
00044     teardown();
00045     issetup=false;
00046     for(std::vector<StateNode*>::iterator it=nodes.begin(); it!=nodes.end(); it++)
00047       (*it)->RemoveReference();
00048     nodes.clear();
00049   }
00050   erouter->postEvent(EventBase::stateMachineEGID,reinterpret_cast<unsigned int>(this),EventBase::deactivateETID,0,getName(),0);
00051   BehaviorBase::DoStop();
00052 }
00053 
00054 void StateNode::setName(const std::string& n) {
00055   name=n;
00056 }
00057 
00058 void StateNode::transitionTo(StateNode*) {
00059   // may want to throw a status event here
00060 }
00061 
00062 void StateNode::transitionFrom(StateNode*) {
00063   // may want to throw a status event here
00064 }
00065 
00066 /*! @file 
00067  * @brief Describes StateNode, which is both a state machine controller as well as a node within a state machine itself
00068  * @author ejt (Creator)
00069  *
00070  * $Author: ejt $
00071  * $Name: tekkotsu-2_1 $
00072  * $Revision: 1.13 $
00073  * $State: Exp $
00074  * $Date: 2003/11/11 00:08:09 $
00075  */
00076 

Tekkotsu v2.1
Generated Tue Mar 16 23:19:15 2004 by Doxygen 1.3.5