Subscribes to and stores a copy of the most recent message on a given channel, for some Message
type.
All copies of a given Subscriber share the same underlying data. This class does NOT provide any mutex behavior for multi-threaded locking; it should only be used in cases where the governing DrakeLcmInterface::HandleSubscriptions is called from the same thread that owns all copies of this object.
#include <drake/lcm/drake_lcm_interface.h>
Public Member Functions | |
Subscriber (DrakeLcmInterface *lcm, const std::string &channel, std::function< void()> on_error={}) | |
Subscribes to the (non-empty) channel on the given (non-null) lcm instance. More... | |
const Message & | message () const |
Returns the most recently received message, or a value-initialized (zeros) message otherwise. More... | |
Message & | message () |
int64_t | count () const |
Returns the total number of received messages. More... | |
int64_t & | count () |
void | clear () |
Clears all data (sets the message and count to all zeros). More... | |
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable | |
Subscriber (const Subscriber &)=default | |
Subscriber & | operator= (const Subscriber &)=default |
Subscriber (Subscriber &&)=default | |
Subscriber & | operator= (Subscriber &&)=default |
|
default |
|
default |
Subscriber | ( | DrakeLcmInterface * | lcm, |
const std::string & | channel, | ||
std::function< void()> | on_error = {} |
||
) |
Subscribes to the (non-empty) channel
on the given (non-null) lcm
instance.
The lcm
pointer is only used during construction; it is not retained by this object. When a undecodable message is received, on_error
handler is invoked; when on_error
is not provided, an exception will be thrown instead.
void clear | ( | ) |
Clears all data (sets the message and count to all zeros).
int64_t count | ( | ) | const |
Returns the total number of received messages.
int64_t& count | ( | ) |
const Message& message | ( | ) | const |
Returns the most recently received message, or a value-initialized (zeros) message otherwise.
Message& message | ( | ) |
|
default |
|
default |