forked from sammy-tri/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcm_receive_thread.h
57 lines (44 loc) · 1.3 KB
/
lcm_receive_thread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#include <atomic>
#include <thread>
#include <lcm/lcm-cpp.hpp>
#include "drake/common/drake_copyable.h"
namespace drake {
namespace lcm {
/**
* Maintains a thread that receives LCM messages and dispatches the messages to
* the appropriate message handlers.
*/
class LcmReceiveThread {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(LcmReceiveThread);
/**
* A constructor that instantiates the thread.
*
* @param[in] lcm A pointer to the LCM instance through which to access the
* LCM network. This parameter cannot be `nullptr` and must remain valid for
* the lifetime of this object.
*/
explicit LcmReceiveThread(::lcm::LCM* lcm);
/**
* The destructor that ensures the thread that receives LCM message is
* stopped.
*/
~LcmReceiveThread();
/**
* Stops the LCM receive thread. This stops the reception of LCM messages.
*/
void Stop();
private:
// Loops waiting for LCM messages and dispatching them to the appropriate
// subscriber message handlers when they arrive.
void LoopWithSelect();
// Whether to stop lcm_thread_.
std::atomic<bool> stop_{false};
// A pointer to the LCM instance.
::lcm::LCM* const lcm_{nullptr};
// The thread responsible for receiving LCM messages.
std::thread lcm_thread_;
};
} // namespace lcm
} // namespace drake