Critical Link MityCam SoC Firmware  1.0
Critical Link MityCam SoC Firmware
Job.h
Go to the documentation of this file.
1 #ifndef JOB_H
2 #define JOB_H
3 
4 #include <time.h>
5 #include <ostream>
6 #include "Utility/Types.h"
7 
9 
14 class tcJob
15 {
16 public:
17  tcJob(const char* apName);
18  virtual ~tcJob();
19 
20  enum teStatus
21  {
26  };
27 
28  class tcStats
29  {
30  public:
31  struct timespec msStartLast;
32  struct timespec msStopLast;
34  };
35 
37  const char* getName() const { return mpName; }
38 
40  void attachThread(tcPeriodicJobThread* apThread);
42  void detachThread();
44  virtual int getPeriodMs() const { return mnPeriodMs; }
45  virtual uint64 getNextRunTimeMs() const;
47  int doExecute();
49  virtual teStatus status() const { return mcStats.meStatus; }
50 
51 protected:
53  virtual int execute() = 0;
62  uint64 timespecToMs(const struct timespec arT) const { return (uint64)(arT.tv_sec) * 1000
63  + (arT.tv_nsec) / 1000000 ; }
65  void enterExecute();
66  void exitExecute();
67 
68 private:
69  const char* mpName;
70 };
71 
72 // should be in some common utility header...
73 std::ostream& operator <<(std::ostream& arS, const struct timespec& arT);
74 
75 #endif // JOB_H
tcJob::tcStats
Definition: Job.h:28
tcJob::eeScheduled
@ eeScheduled
Definition: Job.h:23
tcJob::doExecute
int doExecute()
run the job
Definition: Job.cpp:22
tcJob::getNextRunTimeMs
virtual uint64 getNextRunTimeMs() const
Definition: Job.cpp:70
uint64
uint64_t uint64
Definition: Types.h:13
tcJob::status
virtual teStatus status() const
get the job status
Definition: Job.h:49
Types.h
tcJob::mnPeriodMs
int mnPeriodMs
task period (ms)
Definition: Job.h:57
tcJob::mpThread
tcPeriodicJobThread * mpThread
thread job will run in
Definition: Job.h:55
tcJob::tcStats::meStatus
teStatus meStatus
Definition: Job.h:33
tcJob::detachThread
void detachThread()
remove this job from its thread (if attached)
Definition: Job.cpp:47
tcJob::mnLastRunMs
uint64 mnLastRunMs
last run time
Definition: Job.h:59
tcJob::teStatus
teStatus
Definition: Job.h:20
tcJob::~tcJob
virtual ~tcJob()
Definition: Job.cpp:12
tcJob::eeRunning
@ eeRunning
Definition: Job.h:24
tcPeriodicJobThread
Definition: PeriodicJobThread.h:18
tcJob::getPeriodMs
virtual int getPeriodMs() const
Get the period of this job (called by thread!)
Definition: Job.h:44
tcJob::getName
const char * getName() const
get the name of the job
Definition: Job.h:37
tcJob::attachThread
void attachThread(tcPeriodicJobThread *apThread)
attach this job to a thread
Definition: Job.cpp:35
tcJob::enterExecute
void enterExecute()
convenience function for stats
Definition: Job.cpp:57
tcJob::eeStopped
@ eeStopped
Definition: Job.h:22
operator<<
std::ostream & operator<<(std::ostream &arS, const struct timespec &arT)
Definition: Job.cpp:92
tcJob::tcJob
tcJob(const char *apName)
Definition: Job.cpp:5
tcJob::tcStats::msStopLast
struct timespec msStopLast
Definition: Job.h:32
tcJob::exitExecute
void exitExecute()
tcJob::exitExecute - called at the end of execute to update stats
Definition: Job.cpp:85
tcJob::eeFailed
@ eeFailed
Definition: Job.h:25
tcJob::tcStats::msStartLast
struct timespec msStartLast
Definition: Job.h:31
tcJob::execute
virtual int execute()=0
run the job
tcJob::timespecToMs
uint64 timespecToMs(const struct timespec arT) const
Definition: Job.h:62
tcJob::mcStats
tcStats mcStats
job status
Definition: Job.h:61
tcJob
The tcJob class is the base class for jobs that get added to the tcPeriodicJobThread.
Definition: Job.h:14