Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArSyncTask Class Reference

Class used internally to manage the functions that are called every cycle. More...

#include <ArSyncTask.h>

List of all members.

Public Member Functions

void addNewBranch (const char *nameOfNew, int position, ArTaskState::State *state=NULL)
 Adds a new branch to this instance.
void addNewLeaf (const char *nameOfNew, int position, ArFunctor *functor, ArTaskState::State *state=NULL)
 Adds a new leaf to this instance.
 ArSyncTask (const char *name, ArFunctor *functor=NULL, ArTaskState::State *state=NULL, ArSyncTask *parent=NULL)
 Constructor, shouldn't ever do a new on anything besides the root node.
ArSyncTaskfind (ArFunctor *functor)
 Finds the task recursively down the tree by functor.
ArSyncTaskfind (const char *name)
 Finds the task recursively down the tree by name.
ArSyncTaskfindNonRecursive (ArFunctor *functor)
 Finds the task in the instances list of children, by functor.
ArSyncTaskfindNonRecursive (const char *name)
 Finds the task in the instances list of children, by name.
ArFunctorgetFunctor (void)
 Gets the functor this instance runs, if there is one.
std::string getName (void)
 Gets the name of this task.
ArRetFunctor< bool > * getNoTimeWarningCB (void)
 Gets the functor called to check if there should be a time warning this cycle (should only be used from the robot).
ArTaskState::State getState (void)
 Gets the state of the task.
ArRetFunctor< unsigned int > * getWarningTimeCB (void)
 Gets the functor called to get the cycle warning time (should only be used from the robot).
bool isDeleting (void)
void log (int depth=0)
 Prints the node, which prints all the children of this node as well.
void remove (ArSyncTask *proc)
void run (void)
 Runs the node, which runs all children of this node as well.
void setNoTimeWarningCB (ArRetFunctor< bool > *functor)
 Sets the functor called to check if there should be a time warning this cycle (should only be used from the robot).
void setState (ArTaskState::State state)
 Sets the state of the task.
void setWarningTimeCB (ArRetFunctor< unsigned int > *functor)
 Sets the functor called to get the cycle warning time (should only be used from the robot).
virtual ~ArSyncTask ()
 Destructor.

Protected Attributes

ArFunctormyFunctor
bool myIsDeleting
std::multimap< int, ArSyncTask * > myMultiMap
std::string myName
ArRetFunctor< bool > * myNoTimeWarningCB
ArSyncTaskmyParent
ArTaskState::State myState
ArTaskState::StatemyStatePointer
ArRetFunctor< unsigned int > * myWarningTimeCB


Detailed Description

Class used internally to manage the functions that are called every cycle.

This is used internally, no user should ever have to create one, but serious developers may want to use the members. Most users will be able to use the user tasks defined in the ArRobot class. This class should only be used by serious developers.

The way it works is that each instance is a node in a tree. The only node that should ever be created with a new is the top one. The run and print functions both call the run/print on themselves, then on all of their children, going from lowest numbered position to highest numbered, lower going first. There are no hard limits to the position, it can be any integer. ARIA uses the convention of 0 to 100, when you add things of your own you should leave room to add in between. Also you can add things with the same position, the only effect this has is that the first addition will show up first in the run or print.

After the top one is created, every other task should be created with either addNewBranch or addNewLeaf. Each node can either be a branch node or a list node. The list (multimap actually) of branches/nodes is ordered by the position passed in to the add function. addNewBranch adds a new branch node to the instance it is called on, with the given name and position. addNewLeaf adds a new leaf node to the instance it is called on, with the given name and position, and also with the ArFunctor given, this functor will be called when the leaf is run. Either add creates the new instance and puts it in the list of branches/nodes in the approriate spot.

The tree takes care of all of its own memory management and list management, the add functions put into the list and creates the memory, conversely if you delete an ArSyncTask (which is the correct way to get rid of one) it will remove itself from its parents list.

If you want to add something to the tree the proper way to do it is to get the pointer to the root of the tree (ie with ArRobot::getSyncProcRoot) and then to use find on the root to find the branch you want to travel down, then continue this until you find the node you want to add to. Once there just call addNewBranch or addNewLeaf and you're done.

There is now a pointer to an integer that is the state of the task, if this pointer is given whenever something changes the state of the task it will modify the value pointed to. If the pointer is NULL then the syncTask will use an integer of its own to keep track of the state of the process.

Definition at line 81 of file ArSyncTask.h.


Constructor & Destructor Documentation

ArSyncTask::ArSyncTask const char *  name,
ArFunctor functor = NULL,
ArTaskState::State state = NULL,
ArSyncTask parent = NULL
 

Constructor, shouldn't ever do a new on anything besides the root node.

New should never be called to create an ArSyncTask except to create the root node. Read the detailed documentation of the class for details.

Definition at line 37 of file ArSyncTask.cpp.

References setNoTimeWarningCB(), setState(), and setWarningTimeCB().

Referenced by addNewBranch(), and addNewLeaf().

ArSyncTask::~ArSyncTask  )  [virtual]
 

Destructor.

If you delete the task it deletes everything in its list, so to delete the whole tree just delete the top one... also note that if you delete a node, it will remove itself from its parents list.

Definition at line 63 of file ArSyncTask.cpp.

References ArUtil::deleteSetPairs(), isDeleting(), and remove().


Member Function Documentation

void ArSyncTask::addNewBranch const char *  nameOfNew,
int  position,
ArTaskState::State state = NULL
 

Adds a new branch to this instance.

Creates a new task with the given name and puts the task into its own iternal list at the given position.

Parameters:
nameOfNew Name to give to the new task.
position place in list to put the branch, things are run/printed in the order of highest number to lowest number, no limit on numbers (other than that it is an int). ARIA uses 0 to 100 just as a convention.

Definition at line 187 of file ArSyncTask.cpp.

References ArSyncTask().

Referenced by ArRobot::setUpSyncList().

void ArSyncTask::addNewLeaf const char *  nameOfNew,
int  position,
ArFunctor functor,
ArTaskState::State state = NULL
 

Adds a new leaf to this instance.

Creates a new task with the given name and puts the task into its own iternal list at the given position. Sets the nodes functor so that it will call the functor when run is called.

Parameters:
nameOfNew Name to give to the new task.
position place in list to put the branch, things are run/printed in the order of highest number to lowest number, no limit on numbers (other than that it is an int). ARIA uses 0 to 100 just as a convention.
functor ArFunctor which contains the functor to invoke when run is called.

Definition at line 205 of file ArSyncTask.cpp.

References ArSyncTask().

Referenced by ArRobot::addSensorInterpTask(), ArRobot::addUserTask(), ArNetServer::open(), and ArRobot::setUpSyncList().

ArSyncTask * ArSyncTask::find ArFunctor functor  ) 
 

Finds the task recursively down the tree by functor.

Finds a node below (or at) this level in the tree with the given name

Parameters:
name The name of the child we are interested in finding
Returns:
The task, if found. If not found, NULL.

Definition at line 100 of file ArSyncTask.cpp.

References find().

ArSyncTask * ArSyncTask::find const char *  name  ) 
 

Finds the task recursively down the tree by name.

Finds a node below (or at) this level in the tree with the given name

Parameters:
name The name of the child we are interested in finding
Returns:
The task, if found. If not found, NULL.

Definition at line 123 of file ArSyncTask.cpp.

Referenced by find(), ArRobot::findTask(), and ArRobot::findUserTask().

ArSyncTask * ArSyncTask::findNonRecursive ArFunctor functor  ) 
 

Finds the task in the instances list of children, by functor.

Finds a child of this node with the given functor

Parameters:
functor the functor we are interested in finding
Returns:
The task, if found. If not found, NULL.

Definition at line 165 of file ArSyncTask.cpp.

References getFunctor().

ArSyncTask * ArSyncTask::findNonRecursive const char *  name  ) 
 

Finds the task in the instances list of children, by name.

Finds a child of this node with the given name

Parameters:
name The name of the child we are interested in finding
Returns:
The task, if found. If not found, NULL.

Definition at line 146 of file ArSyncTask.cpp.

References getName().

Referenced by ArRobot::addSensorInterpTask(), ArRobot::addUserTask(), ArRobot::findUserTask(), ArRobot::logUserTasks(), ArNetServer::open(), ArRobot::remSensorInterpTask(), ArRobot::remUserTask(), and ArNetServer::~ArNetServer().

ArRetFunctor< bool > * ArSyncTask::getNoTimeWarningCB void   ) 
 

Gets the functor called to check if there should be a time warning this cycle (should only be used from the robot).

This sets a functor which will be called to see if we should warn this time through or not.

Definition at line 319 of file ArSyncTask.cpp.

ArRetFunctor< unsigned int > * ArSyncTask::getWarningTimeCB void   ) 
 

Gets the functor called to get the cycle warning time (should only be used from the robot).

This gets a functor which will be called to find the time on the task such that if it takes longer than this number of ms to run a warning message will be issued, sets this on the children too.

Definition at line 298 of file ArSyncTask.cpp.

void ArSyncTask::log int  depth = 0  ) 
 

Prints the node, which prints all the children of this node as well.

Prints the node... the defaulted depth parameter controls how far over to print the data (how many tabs)... it recurses down all its children.

Definition at line 329 of file ArSyncTask.cpp.

References getState(), and ArLog::log().

Referenced by ArRobot::logAllTasks(), and ArRobot::logUserTasks().

void ArSyncTask::run void   ) 
 

Runs the node, which runs all children of this node as well.

If this node is a leaf it calls the functor for the node, if it is a branch it goes through all of the children in the order of highest position to lowest position and calls run on them.

Definition at line 242 of file ArSyncTask.cpp.

References getState(), ArFunctor::invoke(), ArRetFunctor< Ret >::invokeR(), ArLog::log(), ArTime::mSecSince(), and ArTime::setToNow().

Referenced by ArRobot::loopOnce().

void ArSyncTask::setNoTimeWarningCB ArRetFunctor< bool > *  functor  ) 
 

Sets the functor called to check if there should be a time warning this cycle (should only be used from the robot).

This sets a functor which will be called to see if we should warn this time through or not.

Definition at line 307 of file ArSyncTask.cpp.

Referenced by ArSyncTask(), and ArRobot::setUpSyncList().

void ArSyncTask::setWarningTimeCB ArRetFunctor< unsigned int > *  functor  ) 
 

Sets the functor called to get the cycle warning time (should only be used from the robot).

This sets a functor which will be called to find the time on the task such that if it takes longer than this number of ms to run a warning message will be issued, sets this on the children too.

Definition at line 285 of file ArSyncTask.cpp.

Referenced by ArSyncTask(), and ArRobot::setUpSyncList().


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:55 2005 for Aria by  doxygen 1.4.0