forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drake_lcm.h
93 lines (76 loc) · 2.47 KB
/
drake_lcm.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <list>
#include <memory>
#include <string>
#include "lcm/lcm-cpp.hpp"
#include "drake/common/drake_copyable.h"
#include "drake/lcm/drake_lcm_interface.h"
#include "drake/lcm/lcm_receive_thread.h"
namespace drake {
namespace lcm {
/**
* A wrapper around a *real* LCM instance.
*/
class DrakeLcm : public DrakeLcmInterface {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(DrakeLcm);
/**
* Constructs using LCM's default URL (either the default hard-coded URL, or
* else LCM_DEFAULT_URL environment variable if it is set).
*/
DrakeLcm();
/**
* Constructs using the given URL. If empty, it will use the default URL as
* per the no-argument constructor.
*/
explicit DrakeLcm(std::string lcm_url);
/**
* A destructor that forces the receive thread to be stopped.
*/
~DrakeLcm() override;
/**
* Starts the receive thread. This must be called for subscribers to receive
* any messages.
*
* @pre StartReceiveThread() was not called.
*/
void StartReceiveThread();
/**
* Stops the receive thread. This must be called prior to any subscribers
* being destroyed. Note that the receive thread will be automatically stopped
* by this class's destructor, so usage of this method will be extremely rare.
* It will only be needed if this class's instance and the subscribers to LCM
* channels are owned by different classes. In such a scenario, this method
* can be used to ensure the receive thread is destroyed before the
* subscribers are destroyed.
*
* @pre StartReceiveThread() was called.
*/
void StopReceiveThread();
/**
* Indicates that the receiving thread is running.
*/
bool IsReceiveThreadRunning() const {
return receive_thread_ != nullptr;
}
/**
* An accessor to the real LCM instance encapsulated by this object. The
* returned pointer is guaranteed to be valid for the duration of this
* object's lifetime.
*/
::lcm::LCM* get_lcm_instance();
/**
* Returns the LCM URL passed into the constructor; this can be empty.
*/
std::string get_requested_lcm_url() const;
void Publish(const std::string& channel, const void* data,
int data_size, optional<double> time_sec) override;
void Subscribe(const std::string&, HandlerFunction) override;
private:
std::string requested_lcm_url_;
::lcm::LCM lcm_;
std::unique_ptr<LcmReceiveThread> receive_thread_{nullptr};
std::list<HandlerFunction> handlers_;
};
} // namespace lcm
} // namespace drake