Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laelaps::LaeAsyncJob Class Reference

Asynchronous job base class. More...

#include <laeThreadAsync.h>

Public Types

enum  JobState {
  JobStateNoJob,
  JobStateCreated,
  JobStateReady,
  JobStateRunning,
  JobStateTerminated
}
 Job states. More...
 

Public Member Functions

 LaeAsyncJob (const std::string strJobName="Job")
 Default constructor.
 
virtual ~LaeAsyncJob ()
 Destructor.
 
virtual void getReady ()
 Get ready to run. More...
 
virtual void start ()
 Start. More...
 
virtual int run ()
 Run the job. More...
 
virtual void terminate ()
 Terminate the job normally.
 
virtual void abort (int rc=-LAE_ECODE_INTR)
 Abort the job. More...
 
JobState getState ()
 Get the current job state. More...
 
std::string getJobName ()
 Get the name of the job. More...
 
bool isDone ()
 Test if job has completed or should be aborted. More...
 
int getRc ()
 Get job's return code. More...
 

Protected Attributes

JobState m_eJobState
 job state
 
std::string m_strJobName
 job name
 
bool m_bIsDone
 job is [not] done
 
int m_nJobRc
 job return code
 

Detailed Description

Asynchronous job base class.

Definition at line 81 of file laeThreadAsync.h.

Member Enumeration Documentation

enum laelaps::LaeAsyncJob::JobState

Job states.

Enumerator
JobStateNoJob 

no job

JobStateCreated 

job created, but not attached to thread

JobStateReady 

job attached to thread and ready to run

JobStateRunning 

job running

JobStateTerminated 

job terminated

Definition at line 87 of file laeThreadAsync.h.

88  {
89  JobStateNoJob, ///< no job
90  JobStateCreated, ///< job created, but not attached to thread
91  JobStateReady, ///< job attached to thread and ready to run
92  JobStateRunning, ///< job running
93  JobStateTerminated ///< job terminated
94  };
job attached to thread and ready to run
job created, but not attached to thread

Member Function Documentation

void LaeAsyncJob::abort ( int  rc = -LAE_ECODE_INTR)
virtual

Abort the job.

The abort is called when an error occurs or the thread is asynchronously terminated.

Parameters
rcJob error exit return code.

Definition at line 104 of file laeThreadAsync.cxx.

References JobStateTerminated, m_bIsDone, m_eJobState, m_nJobRc, laelaps::LaeThreadAsync::ThreadAsyncHzDft, laelaps::LaeThreadAsync::ThreadAsyncNameDft, and laelaps::LaeThreadAsync::ThreadAsyncPrioDft.

Referenced by laelaps::LaeThreadAsync::createThread(), laelaps::LaeThreadAsync::exec(), laelaps::LaeThreadAsync::terminateThread(), laelaps::LaeThreadAsync::transToExit(), and laelaps::LaeThreadAsync::~LaeThreadAsync().

105 {
107  m_bIsDone = true;
108  m_nJobRc = rc;
109 }
JobState m_eJobState
job state
int m_nJobRc
job return code
bool m_bIsDone
job is [not] done
std::string laelaps::LaeAsyncJob::getJobName ( )
inline

Get the name of the job.

Returns
String.

Definition at line 161 of file laeThreadAsync.h.

References m_strJobName.

Referenced by laelaps::LaeThreadAsync::createThread().

162  {
163  return m_strJobName;
164  }
std::string m_strJobName
job name
int laelaps::LaeAsyncJob::getRc ( )
inline

Get job's return code.

Returns
Returns return code.

Definition at line 181 of file laeThreadAsync.h.

References m_nJobRc.

Referenced by laelaps::LaeRobot::getAsyncJobRc().

182  {
183  return m_nJobRc;
184  }
int m_nJobRc
job return code
void LaeAsyncJob::getReady ( )
virtual

Get ready to run.

Called after job is attached to the thread and is ready to run.

Definition at line 81 of file laeThreadAsync.cxx.

References JobStateReady, and m_eJobState.

Referenced by laelaps::LaeThreadAsync::transToReady().

82 {
84 }
JobState m_eJobState
job state
job attached to thread and ready to run
JobState laelaps::LaeAsyncJob::getState ( )
inline

Get the current job state.

Returns
State.

Definition at line 151 of file laeThreadAsync.h.

References m_eJobState.

Referenced by laelaps::LaeRobot::getAsyncJobState().

152  {
153  return m_eJobState;
154  }
JobState m_eJobState
job state
bool laelaps::LaeAsyncJob::isDone ( )
inline

Test if job has completed or should be aborted.

Returns
Returns true or false.

Definition at line 171 of file laeThreadAsync.h.

References m_bIsDone.

Referenced by laelaps::LaeThreadAsync::exec(), laelaps::LaeThreadAsync::terminateThread(), laelaps::LaeThreadAsync::transToExit(), and laelaps::LaeThreadAsync::~LaeThreadAsync().

172  {
173  return m_bIsDone;
174  }
bool m_bIsDone
job is [not] done
int LaeAsyncJob::run ( )
virtual

Run the job.

The job can be time sliced, given that it is attached to a thread with a built-in scheduler, or it can run to completion in a single execution block.

Returns
On success, OK(0) is returned.
On error, RC_ERROR(-1) is returned.

Definition at line 91 of file laeThreadAsync.cxx.

References laelaps::LAE_ECODE_NO_EXEC, and m_nJobRc.

Referenced by laelaps::LaeThreadAsync::exec().

92 {
94 
95  return m_nJobRc;
96 }
static const int LAE_ECODE_NO_EXEC
cannot execute error
Definition: laelaps.h:85
int m_nJobRc
job return code
void LaeAsyncJob::start ( )
virtual

Start.

Called just prior to the attached thread starts execution.

Definition at line 86 of file laeThreadAsync.cxx.

References JobStateRunning, and m_eJobState.

Referenced by laelaps::LaeThreadAsync::transToRunning().

87 {
89 }
JobState m_eJobState
job state

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