OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
16  virtual void initializationOnThread() = 0;
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 spetial stopping (e.g., buffers might not stop inmediately and need a
31  // few iterations)
32  inline virtual void tryStop()
33  {
34  stop();
35  }
36 
37  protected:
38  virtual void work(TDatums& tDatums) = 0;
39 
40  private:
41  bool mIsRunning;
42 
43  DELETE_COPY(Worker);
44  };
45 }
46 
47 
48 
49 
50 
51 // Implementation
52 namespace op
53 {
54  template<typename TDatums>
56  mIsRunning{true}
57  {
58  }
59 
60  template<typename TDatums>
62  {
63  }
64 
65  template<typename TDatums>
66  bool Worker<TDatums>::checkAndWork(TDatums& tDatums)
67  {
68  if (mIsRunning)
69  work(tDatums);
70  return mIsRunning;
71  }
72 
74 }
75 
76 #endif // OPENPOSE_THREAD_WORKER_HPP
Definition: worker.hpp:9
virtual ~Worker()
Definition: worker.hpp:61
Worker()
Definition: worker.hpp:55
virtual void tryStop()
Definition: worker.hpp:32
bool isRunning() const
Definition: worker.hpp:20
virtual void initializationOnThread()=0
virtual void work(TDatums &tDatums)=0
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
bool checkAndWork(TDatums &tDatums)
Definition: worker.hpp:66
void stop()
Definition: worker.hpp:25