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 few iterations)
31  inline virtual void tryStop()
32  {
33  stop();
34  }
35 
36  protected:
37  virtual void work(TDatums& tDatums) = 0;
38 
39  private:
40  bool mIsRunning;
41 
42  DELETE_COPY(Worker);
43  };
44 }
45 
46 
47 
48 
49 
50 // Implementation
51 namespace op
52 {
53  template<typename TDatums>
55  mIsRunning{true}
56  {
57  }
58 
59  template<typename TDatums>
61  {
62  }
63 
64  template<typename TDatums>
65  bool Worker<TDatums>::checkAndWork(TDatums& tDatums)
66  {
67  if (mIsRunning)
68  work(tDatums);
69  return mIsRunning;
70  }
71 
73 }
74 
75 #endif // OPENPOSE_THREAD_WORKER_HPP
Definition: worker.hpp:9
virtual ~Worker()
Definition: worker.hpp:60
Worker()
Definition: worker.hpp:54
virtual void tryStop()
Definition: worker.hpp:31
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:65
void stop()
Definition: worker.hpp:25