Critical Link MityCam SoC Firmware  1.0
Critical Link MityCam SoC Firmware
PeriodicJobThread.h
Go to the documentation of this file.
1 #ifndef PERIODICJOBTHREAD_H
2 #define PERIODICJOBTHREAD_H
3 
4 #include <limits.h>
5 #include <time.h>
6 #include <mqueue.h>
7 #include <iostream>
8 
9 #include <list>
10 #include "Utility/Types.h"
11 #include "Utility/Thread.h"
12 #include "Utility/Mutex.h"
13 
14 class tcJob;
15 
16 class tcJobSchedule;
17 
19 {
20 public:
28  void* run();
29 
31  int addJob(tcJob* apJob);
32 
34  int removeJob(tcJob* apJob);
35 
37  void stop();
38 
40  void printScheduledJobs();
41 
42  typedef std::list<tcJob*> tlJobList;
43 private:
45  void recomputeTimes();
47  void computeNextWakeup();
48  uint64 timespecToMs(const struct timespec arT) const { return (uint64)(arT.tv_sec) * 1000
49  + (arT.tv_nsec) / 1000000 ; }
50  bool msToTimespec(uint64 anMs, struct timespec& arT);
51  void sendSimpleMsg(uint32 anVal);
52  std::ostream& printTime(const struct timespec& arT, std::ostream& strm=std::cout) const;
53  std::ostream& printTime(uint64 anMs, std::ostream& strm=std::cout) const;
54  static const uint32 cnMsgQuit=0xDEADBEEF;
55  static const uint32 cnMsgRecompute=0xFACE0001;
56  tcMutex mcLock;
57  tlJobList mlJobs;
58  volatile bool mbDone;
59  struct timespec msLastTime;
60  struct timespec msNextTime;
62  char maMqName[NAME_MAX];
63  mqd_t mhMsgQ;
64 };
65 
66 
67 std::ostream& operator <<(std::ostream& arS, const struct tcJobSchedule& arJS);
68 
69 #endif // PERIODICJOBTHREAD_H
uint64
uint64_t uint64
Definition: Types.h:13
Types.h
tcPeriodicJobThread::addJob
int addJob(tcJob *apJob)
Add a job.
Definition: PeriodicJobThread.cpp:46
tcPeriodicJobThread::run
void * run()
Definition: PeriodicJobThread.cpp:92
tcPeriodicJobThread::printScheduledJobs
void printScheduledJobs()
print list of jobs
Definition: PeriodicJobThread.cpp:268
tcPeriodicJobThread
Definition: PeriodicJobThread.h:18
tcPeriodicJobThread::removeJob
int removeJob(tcJob *apJob)
Remove a job.
Definition: PeriodicJobThread.cpp:70
tcPeriodicJobThread::~tcPeriodicJobThread
~tcPeriodicJobThread()
Definition: PeriodicJobThread.cpp:34
tcThread
Definition: Thread.h:6
Thread.h
operator<<
std::ostream & operator<<(std::ostream &arS, const struct tcJobSchedule &arJS)
Mutex.h
tcPeriodicJobThread::tlJobList
std::list< tcJob * > tlJobList
Definition: PeriodicJobThread.h:42
uint32
uint32_t uint32
Definition: Types.h:11
tcPeriodicJobThread::tcPeriodicJobThread
tcPeriodicJobThread()
Definition: PeriodicJobThread.cpp:27
tcMutex
Definition: Mutex.h:11
tcPeriodicJobThread::stop
void stop()
terminate job thread processing
Definition: PeriodicJobThread.cpp:247
tcJob
The tcJob class is the base class for jobs that get added to the tcPeriodicJobThread.
Definition: Job.h:14