Drake
DrakeMockLcm Class Reference

A mock LCM instance. More...

#include <drake/lcm/drake_mock_lcm.h>

Inheritance diagram for DrakeMockLcm:
[legend]
Collaboration diagram for DrakeMockLcm:
[legend]

Public Member Functions

 DrakeMockLcm ()
 A constructor that creates a DrakeMockLcm with loopback disabled, i.e., a call to Publish() will not result in subscriber callback functions being executed. More...
 
void EnableLoopBack ()
 Enables loopback behavior. More...
 
void Publish (const std::string &, const void *, int, optional< double >) override
 Publishes an LCM message on channel channel. More...
 
template<typename T >
T DecodeLastPublishedMessageAs (const std::string &channel) const
 Obtains the most recently "published" message on a particular channel. More...
 
const std::vector< uint8_t > & get_last_published_message (const std::string &channel) const
 Obtains the most recently "published" message on a particular channel. More...
 
optional< doubleget_last_publication_time (const std::string &channel) const
 Returns the time of the most recent publication on a particular channel. More...
 
void Subscribe (const std::string &, HandlerFunction) override
 Subscribes to an LCM channel without automatic message decoding. More...
 
void Subscribe (const std::string &, DrakeLcmMessageHandlerInterface *) override
 A deprecated overload of Subscribe. More...
 
void InduceSubscriberCallback (const std::string &channel, const void *data, int data_size)
 Fakes a callback. More...
 
Does not allow copy, move, or assignment
 DrakeMockLcm (const DrakeMockLcm &)=delete
 
DrakeMockLcmoperator= (const DrakeMockLcm &)=delete
 
 DrakeMockLcm (DrakeMockLcm &&)=delete
 
DrakeMockLcmoperator= (DrakeMockLcm &&)=delete
 
- Public Member Functions inherited from DrakeLcmInterface
virtual ~DrakeLcmInterface ()=default
 
 DrakeLcmInterface (const DrakeLcmInterface &)=delete
 
DrakeLcmInterfaceoperator= (const DrakeLcmInterface &)=delete
 
 DrakeLcmInterface (DrakeLcmInterface &&)=delete
 
DrakeLcmInterfaceoperator= (DrakeLcmInterface &&)=delete
 

Additional Inherited Members

- Public Types inherited from DrakeLcmInterface
using HandlerFunction = std::function< void(const void *, int)>
 A callback used by DrakeLcmInterface::Subscribe(), with arguments: More...
 
- Protected Member Functions inherited from DrakeLcmInterface
 DrakeLcmInterface ()=default
 

Detailed Description

A mock LCM instance.

This does not actually publish or subscribe to LCM messages. It contains additional methods for accessing the most recent message that was "published," and faking a callback.

Constructor & Destructor Documentation

DrakeMockLcm ( const DrakeMockLcm )
delete
DrakeMockLcm ( DrakeMockLcm &&  )
delete

A constructor that creates a DrakeMockLcm with loopback disabled, i.e., a call to Publish() will not result in subscriber callback functions being executed.

To enable loopback behavior, call EnableLoopBack().

Member Function Documentation

T DecodeLastPublishedMessageAs ( const std::string &  channel) const
inline

Obtains the most recently "published" message on a particular channel.

This method automatically decodes the message into an LCM message whose type is specified by the template type. Throws a std::runtime_error exception if no LCM message was published on the provided channel or if the message failed to be decoded by the provided LCM message type.

Template Parameters
TThe LCM message type.
Parameters
[in]channelthe LCM channel for which the last published message is returned.
Returns
the decoded most recently transmitted LCM message on the provided channel.

Here is the call graph for this function:

void EnableLoopBack ( )
inline

Enables loopback behavior.

With loopback enabled, a call to Publish() will result in subscriber callback functions being called. Without loopback enabled, the only way to induce a call to a subscriber's callback function is through InduceSubscriberCallback().

Here is the call graph for this function:

optional< double > get_last_publication_time ( const std::string &  channel) const

Returns the time of the most recent publication on a particular channel.

Returns nullopt iff a message has never been published on this channel or the most recent Publish call had no time_sec.

Here is the caller graph for this function:

const std::vector< uint8_t > & get_last_published_message ( const std::string &  channel) const

Obtains the most recently "published" message on a particular channel.

A std::runtime_error will be thrown if no message was published on the provide channel.

Parameters
[in]channelThe channel on which the LCM message was published.
Returns
A reference to a vector containing the serialized bytes of the LCM message that was previously published on channel channel.
Precondition
A message was previously published on channel channel.

Here is the caller graph for this function:

void InduceSubscriberCallback ( const std::string &  channel,
const void *  data,
int  data_size 
)

Fakes a callback.

The callback is executed by the same thread as the one calling this method.

Parameters
[in]channelThe channel on which to publish the message.
[in]dataA buffer containing the serialized bytes of the message to publish.
[in]data_sizeThe length of in bytes.

Here is the caller graph for this function:

DrakeMockLcm& operator= ( DrakeMockLcm &&  )
delete
DrakeMockLcm& operator= ( const DrakeMockLcm )
delete
void Publish ( const std::string &  channel,
const void *  data,
int  data_size,
optional< double time_sec 
)
overridevirtual

Publishes an LCM message on channel channel.

Parameters
[in]channelThe channel on which to publish the message. Must not be the empty string.
[in]dataA buffer containing the serialized bytes of the message to publish.
[in]data_sizeThe length of in bytes.
[in]time_secTime in seconds when the publish event occurred. If unknown, use drake::nullopt or a default-constructed optional.

Implements DrakeLcmInterface.

Here is the call graph for this function:

Here is the caller graph for this function:

void Subscribe ( const std::string &  channel,
HandlerFunction   
)
overridevirtual

Subscribes to an LCM channel without automatic message decoding.

The handler will be invoked when a message arrives on channel channel.

Parameters
channelThe channel to subscribe to. Must not be the empty string.

Implements DrakeLcmInterface.

Here is the caller graph for this function:

void Subscribe ( const std::string &  channel,
DrakeLcmMessageHandlerInterface *   
)
overridevirtual

A deprecated overload of Subscribe.

Implements DrakeLcmInterface.

Here is the call graph for this function:


The documentation for this class was generated from the following files: