Aria  2.8.0
ArRecurrentTask Class Referenceabstract

Recurrent task (runs in its own thread) More...

#include <ArRecurrentTask.h>

Inherits ArASyncTask.

Public Member Functions

 ArRecurrentTask ()
 Constructor.
 
int done ()
 Check if the task is running or not. More...
 
void go ()
 Starts up on cycle of the recurrent task.
 
void kill ()
 
void reset ()
 Cancel the task and reset for the next cycle.
 
void * runThread (void *ptr)
 
virtual void task ()=0
 The main run loop. More...
 
 ~ArRecurrentTask ()
 Descructor.
 
- Public Member Functions inherited from ArASyncTask
 ArASyncTask ()
 Constructor.
 
virtual int create (bool joinable=true, bool lowerPriority=true)
 Create the task and start it going.
 
virtual const char * getThreadActivity (void)
 Gets a string that describes what the thread is doing, or NULL if it doesn't know. More...
 
virtual void run (void)
 Run without creating a new thread. More...
 
virtual void runAsync (void)
 Run in its own thread.
 
virtual void * runInThisThread (void *arg=0)
 Internal function used with system threading system to run the new thread. More...
 
virtual void stopRunning (void)
 Stop the thread.
 
virtual ~ArASyncTask ()
 Destructor.
 
- Public Member Functions inherited from ArThread
 ArThread (bool blockAllSignals=true)
 Constructor.
 
 ArThread (ThreadType thread, bool joinable, bool blockAllSignals=true)
 Constructor - starts the thread.
 
 ArThread (ArFunctor *func, bool joinable=true, bool blockAllSignals=true)
 Constructor - starts the thread.
 
virtual void cancel (void)
 Cancel the thread.
 
virtual int detach (void)
 Detatch the thread so it cant be joined.
 
bool getBlockAllSignals (void)
 Do we block all process signals at startup?
 
virtual ArFunctorgetFunc (void) const
 Get the functor that the thread runs.
 
virtual bool getJoinable (void) const
 Get the joinable status of the thread.
 
virtual ThreadType getOSThread (void) const
 Get the underlying os thread type.
 
pid_t getPID (void)
 
virtual bool getRunning (void) const
 Get the running status of the thread.
 
virtual bool getRunningWithLock (void)
 Get the running status of the thread, locking around the variable.
 
virtual const ThreadType * getThread (void) const
 Get the underlying thread type.
 
virtual const char * getThreadName (void)
 Gets the name of the thread.
 
pid_t getTID (void)
 
virtual bool isThreadFinished () const
 Returns whether the thread has been completed and can be deleted. More...
 
virtual bool isThreadStarted () const
 Returns whether the thread has been started. More...
 
virtual int join (void **ret=NULL)
 Join on the thread.
 
int lock (void)
 Lock the thread instance. More...
 
virtual void logThreadInfo (void)
 Logs the information about this thread.
 
virtual void setRunning (bool running)
 Set the running value on the thread.
 
virtual void setThreadName (const char *name)
 Sets the name of the thread.
 
virtual void threadFinished (void)
 Marks the thread as finished and logs useful debugging information. More...
 
virtual void threadStarted (void)
 Marks the thread as started and logs useful debugging information. More...
 
int tryLock (void)
 Try to lock the thread instance without blocking. More...
 
int unlock (void)
 Unlock the thread instance. More...
 
virtual ~ArThread ()
 Destructor.
 

Additional Inherited Members

- Public Types inherited from ArThread
typedef std::map< ThreadType, ArThread * > MapType
 
enum  Status {
  STATUS_FAILED =1, STATUS_NORESOURCE, STATUS_NO_SUCH_THREAD, STATUS_INVALID,
  STATUS_JOIN_SELF, STATUS_ALREADY_DETATCHED
}
 
typedef pthread_t ThreadType
 
- Static Public Member Functions inherited from ArThread
static void cancelAll (void)
 Cancel all threads.
 
static ArLog::LogLevel getLogLevel (void)
 Gets the logging level for thread information.
 
static ThreadType getThisOSThread (void)
 Get the underlying os thread type of this thread.
 
static const ThreadType * getThisThread (void)
 Get the underlying thread type of this thread.
 
static const char * getThisThreadName (void)
 Gets the name of the this thread.
 
static void init (void)
 Initialize the internal book keeping structures. More...
 
static void joinAll (void)
 Join on all threads.
 
static ThreadType osSelf (void)
 Returns the os self of the current thread. More...
 
static ArThreadself (void)
 Returns the instance of your own thread (the current one) More...
 
static void setLogLevel (ArLog::LogLevel level)
 Sets the logging level for thread information.
 
static void shutdown ()
 Shuts down and deletes the last remaining thread; call after joinAll.
 
static void stopAll ()
 Stop all threads.
 
static void yieldProcessor (void)
 Yield the processor to another thread.
 
- Protected Member Functions inherited from ArThread
virtual int doJoin (void **ret=NULL)
 
- Static Protected Member Functions inherited from ArThread
static void addThreadToMap (ThreadType pt, ArThread *at)
 
static ArThreadfindThreadInMap (ThreadType t)
 
static void removeThreadFromMap (ThreadType t)
 
- Protected Attributes inherited from ArThread
bool myBlockAllSignals
 
bool myFinished
 
ArFunctormyFunc
 
bool myJoinable
 
ArMutex myMutex
 
std::string myName
 
pid_t myPID
 
bool myRunning
 State variable to denote when the thread should continue or exit.
 
bool myStarted
 
ArStrMap myStrMap
 
ThreadType myThread
 
pid_t myTID
 
- Static Protected Attributes inherited from ArThread
static ArLog::LogLevel ourLogLevel = ArLog::Verbose
 
static MapType ourThreads
 
static ArMutex ourThreadsMutex
 
static std::string ourUnknownThreadName = "unknown"
 

Detailed Description

Recurrent task (runs in its own thread)

The ArRecurrentTask is a task that runs in its own thread. Recurrent tasks are asynchronous tasks that complete in a finite amount of time, and need to be reinvoked recurrently. A typical example is Saphira's localization task: it runs for a few hundred milliseconds, localizes the robot, and returns. Then the cycle starts over. The user simply needs to derive their own class from ArRecurrentTask and define the task() function. This is the user code that will be called to execute the task body. Then, create an object of the class, and call the go() function to start the task. The status of the task can be checked with the done() function, which returns 0 if running, 1 if completed, and 2 if killed. go() can be called whenever the task is done to restart it. To stop the task in midstream, call reset(). kill() kills off the thread, shouldn't be used unless exiting the async task permanently

Member Function Documentation

◆ done()

int ArRecurrentTask::done ( )

Check if the task is running or not.

0 = running, 1 = finished normally, 2 = canceled

◆ task()

virtual void ArRecurrentTask::task ( )
pure virtual

The main run loop.

Override this function and put your task here.


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