MADARA  3.4.1
Threader.h
Go to the documentation of this file.
1 
2 
3 #ifndef _MADARA_THREADS_THREADER_H_
4 #define _MADARA_THREADS_THREADER_H_
5 
14 #include <string>
15 #include <vector>
16 #include <map>
17 #include <list>
19 #include "BaseThread.h"
20 #include "WorkerThread.h"
21 #include "madara/MadaraExport.h"
22 
23 #ifdef _MADARA_JAVA_
24 #include <jni.h>
25 #include "madara_jni.h"
26 #endif
27 
28 namespace madara
29 {
30 namespace threads
31 {
35 class MADARA_EXPORT Threader
36 {
37 public:
41  Threader();
42 
48 
52  ~Threader();
53 
54  Threader(const Threader&) = delete;
55  Threader(Threader&&) = default;
56  Threader& operator=(const Threader&) = delete;
57  Threader& operator=(Threader&&) = default;
58 
69  void change_hertz(const std::string& name, double hertz);
70 
75  knowledge::KnowledgeBase get_control_plane(void);
76 
81  knowledge::KnowledgeBase get_data_plane(void);
82 
87  void pause(const std::string& name);
88 
92  void pause(void);
93 
98  void resume(const std::string& name);
99 
103  void resume(void);
104 
120  void run(const std::string& name, BaseThread* thread, bool paused = false);
121 
142  void run(double hertz, const std::string& name, BaseThread* thread,
143  bool paused = false);
144 
145 #ifdef _MADARA_JAVA_
146 
161  void run(const std::string& name, jobject thread, bool paused = false);
162 
182  void run(double hertz, const std::string& name, jobject thread,
183  bool paused = false);
184 
185 #endif
186 
191  void set_data_plane(knowledge::KnowledgeBase& data_plane);
192 
197  void terminate(const std::string& name);
198 
206  void debug_to_kb(const std::string& prefix = ".threader");
207 
214  void disable_debug(const std::string& name);
215 
221  void disable_debug(void);
222 
229  void enable_debug(const std::string& name);
230 
236  void enable_debug(void);
237 
241  void terminate(void);
242 
249  bool wait(const std::string& name,
251 
257  bool wait(const knowledge::WaitSettings& ws = knowledge::WaitSettings());
258 
265  bool wait_for_paused(const std::string& name,
267 
273  bool wait_for_paused(const knowledge::WaitSettings& ws = knowledge::WaitSettings());
274 
275 private:
280 
287 
292 
296  bool debug_ = false;
297 
303 };
304 }
305 }
306 
307 #include "Threader.inl"
308 
309 #endif // _MADARA_THREADS_THREADER_H_
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
Abstract base class for implementing threads.
Definition: BaseThread.h:39
Starts threads with first class support of MADARA contexts.
Definition: Threader.h:36
Threader & operator=(const Threader &)=delete
Threader & operator=(Threader &&)=default
knowledge::KnowledgeBase control_
The control plane used by threads for termination and pause information.
Definition: Threader.h:286
Threader(Threader &&)=default
NamedWorkerThreads threads_
the threads that are still active
Definition: Threader.h:291
Threader(const Threader &)=delete
knowledge::KnowledgeBase data_
The data plane used by threads.
Definition: Threader.h:279
std::string debug_to_kb_prefix_
if not empty, user has specified debug information should go to the data plane at this prefix
Definition: Threader.h:302
constexpr string_t string
Provides a quality-of-service-enabled threading library.
Definition: BaseThread.h:28
std::map< std::string, std::unique_ptr< WorkerThread > > NamedWorkerThreads
Collection of named threads.
Definition: WorkerThread.h:205
Copyright(c) 2020 Galois.
Encapsulates settings for a wait statement.
Definition: WaitSettings.h:25