OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
worker.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_WORKER_HPP
2 #define OPENPOSE_THREAD_WORKER_HPP
3 
5 
6 namespace op
7 {
8  template<typename TDatums>
9  class Worker
10  {
11  public:
12  Worker();
13 
14  virtual ~Worker();
15 
17 
18  bool checkAndWork(TDatums& tDatums);
19 
20  inline bool isRunning() const
21  {
22  return mIsRunning;
23  }
24 
25  inline void stop()
26  {
27  mIsRunning = false;
28  }
29 
30  // Virtual in case some function needs special stopping (e.g., buffers might not stop immediately and need a
31  // few iterations)
32  inline virtual void tryStop()
33  {
34  stop();
35  }
36 
37  protected:
38  virtual void initializationOnThread() = 0;
39 
40  virtual void work(TDatums& tDatums) = 0;
41 
42  private:
43  bool mIsRunning;
44 
45  DELETE_COPY(Worker);
46  };
47 }
48 
49 
50 
51 
52 
53 // Implementation
54 namespace op
55 {
56  template<typename TDatums>
58  mIsRunning{true}
59  {
60  }
61 
62  template<typename TDatums>
64  {
65  }
66 
67  template<typename TDatums>
69  {
70  try
71  {
72  this->initializationOnThread();
73  }
74  catch (const std::exception& e)
75  {
76  this->stop();
77  errorWorker(e.what(), __LINE__, __FUNCTION__, __FILE__);
78  }
79  }
80 
81  template<typename TDatums>
82  bool Worker<TDatums>::checkAndWork(TDatums& tDatums)
83  {
84  try
85  {
86  if (mIsRunning)
87  work(tDatums);
88  return mIsRunning;
89  }
90  catch (const std::exception& e)
91  {
92  this->stop();
93  errorWorker(e.what(), __LINE__, __FUNCTION__, __FILE__);
94  return false;
95  }
96  }
97 
99 }
100 
101 #endif // OPENPOSE_THREAD_WORKER_HPP
bool isRunning() const
Definition: worker.hpp:20
void initializationOnThreadNoException()
Definition: worker.hpp:68
bool checkAndWork(TDatums &tDatums)
Definition: worker.hpp:82
virtual ~Worker()
Definition: worker.hpp:63
virtual void work(TDatums &tDatums)=0
virtual void initializationOnThread()=0
virtual void tryStop()
Definition: worker.hpp:32
void stop()
Definition: worker.hpp:25
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
OP_API void errorWorker(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")