Drake
DrakeLcmInterface Class Referenceabstract

A pure virtual interface that enables LCM to be mocked. More...

#include <drake/lcm/drake_lcm_interface.h>

Public Types

using HandlerFunction = std::function< void(const void *, int)>
 A callback used by DrakeLcmInterface::Subscribe(), with arguments: More...
 

Public Member Functions

virtual ~DrakeLcmInterface ()
 
virtual void Publish (const std::string &channel, const void *data, int data_size, optional< double > time_sec)=0
 Most users should use the drake::lcm::Publish() free function, instead of this interface method. More...
 
virtual std::shared_ptr< DrakeSubscriptionInterfaceSubscribe (const std::string &channel, HandlerFunction)=0
 Most users should use the drake::lcm::Subscribe() free function or the drake::lcm::Subscriber wrapper class, instead of this interface method. More...
 
virtual int HandleSubscriptions (int timeout_millis)=0
 Invokes the HandlerFunction callbacks for all subscriptions' pending messages. More...
 
Does not allow copy, move, or assignment
 DrakeLcmInterface (const DrakeLcmInterface &)=delete
 
DrakeLcmInterfaceoperator= (const DrakeLcmInterface &)=delete
 
 DrakeLcmInterface (DrakeLcmInterface &&)=delete
 
DrakeLcmInterfaceoperator= (DrakeLcmInterface &&)=delete
 

Protected Member Functions

 DrakeLcmInterface ()
 

Detailed Description

A pure virtual interface that enables LCM to be mocked.

Because it must be pure, in general it will receive breaking API changes without notice. Users should not subclass this interface directly, but rather use one of the existing subclasses instead.

Similarly, method arguments will receive breaking API changes without notice. Users should not call this interface directly, but rather use drake::lcm::Publish() or drake::lcm::Subscribe() instead.

Member Typedef Documentation

◆ HandlerFunction

using HandlerFunction = std::function<void(const void*, int)>

A callback used by DrakeLcmInterface::Subscribe(), with arguments:

  • message_buffer A pointer to the byte vector that is the serial representation of the LCM message.
  • message_size The size of message_buffer.

Constructor & Destructor Documentation

◆ DrakeLcmInterface() [1/3]

DrakeLcmInterface ( const DrakeLcmInterface )
delete

◆ DrakeLcmInterface() [2/3]

◆ ~DrakeLcmInterface()

~DrakeLcmInterface ( )
virtualdefault

◆ DrakeLcmInterface() [3/3]

DrakeLcmInterface ( )
protecteddefault

Member Function Documentation

◆ HandleSubscriptions()

virtual int HandleSubscriptions ( int  timeout_millis)
pure virtual

Invokes the HandlerFunction callbacks for all subscriptions' pending messages.

If timeout_millis is >0, blocks for up to that long until at least one message is handled.

Returns
the number of messages handled, or 0 on timeout.
Exceptions
std::exceptionwhen a subscribed handler throws.

Implemented in DrakeMockLcm, DrakeLcm, DrakeLcmLog, and LcmInterfaceSystem.

◆ operator=() [1/2]

DrakeLcmInterface& operator= ( DrakeLcmInterface &&  )
delete

◆ operator=() [2/2]

DrakeLcmInterface& operator= ( const DrakeLcmInterface )
delete

◆ Publish()

virtual void Publish ( const std::string &  channel,
const void *  data,
int  data_size,
optional< double time_sec 
)
pure virtual

Most users should use the drake::lcm::Publish() free function, instead of this interface method.

Publishes an LCM message on channel channel.

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

Implemented in DrakeMockLcm, DrakeLcm, DrakeLcmLog, and LcmInterfaceSystem.

◆ Subscribe()

virtual std::shared_ptr<DrakeSubscriptionInterface> Subscribe ( const std::string &  channel,
HandlerFunction   
)
pure virtual

Most users should use the drake::lcm::Subscribe() free function or the drake::lcm::Subscriber wrapper class, instead of this interface method.

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.
Returns
the object used to manage the subscription if that is supported, or else nullptr if not supported. The unsubscribe-on-delete default is false. Refer to the DrakeSubscriptionInterface class overview for details.

Implemented in DrakeMockLcm, DrakeLcm, DrakeLcmLog, and LcmInterfaceSystem.


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