Gazebo Transport

API Reference

12.2.1
Playback Class Reference

Initiates playback of Gazebo Transport topics This class makes it easy to play topics from a log file. More...

#include <Playback.hh>

Public Member Functions

 Playback (const std::string &_file, const NodeOptions &_nodeOptions=NodeOptions())
 Constructor. More...
 
 Playback (Playback &&_old)
 move constructor More...
 
 ~Playback ()
 destructor More...
 
int64_t AddTopic (const std::regex &_topic)
 Add a topic to be played back (regex match) More...
 
bool AddTopic (const std::string &_topic)
 Add a topic to be played back (exact match only) More...
 
int64_t RemoveTopic (const std::regex &_topic)
 Remove all topics matching the specified pattern from being played back. More...
 
bool RemoveTopic (const std::string &_topic)
 Remove a topic from being played back. More...
 
PlaybackHandlePtr Start (const std::chrono::nanoseconds &_waitAfterAdvertising=std::chrono::seconds(1), bool _msgWaiting=true) const
 Begin playing messages. More...
 
bool Valid () const
 Check if this Playback object has a valid log to play back. More...
 

Detailed Description

Initiates playback of Gazebo Transport topics This class makes it easy to play topics from a log file.

Responsibilities: topic name matching and initiating the playback

Constructor & Destructor Documentation

◆ Playback() [1/2]

Playback ( const std::string _file,
const NodeOptions _nodeOptions = NodeOptions() 
)
explicit

Constructor.

Parameters
[in]_filepath to log file
[in]_nodeOptionsOptions for creating a node.

◆ Playback() [2/2]

Playback ( Playback &&  _old)

move constructor

Parameters
[in]_oldthe instance being moved into this one

◆ ~Playback()

~Playback ( )

destructor

Member Function Documentation

◆ AddTopic() [1/2]

int64_t AddTopic ( const std::regex _topic)

Add a topic to be played back (regex match)

Parameters
[in]_topicPattern to match against topic names
Note
This method attempts to advertise topics immediately. These publishers will be kept until this is destructed.
Returns
number of topics that will be published or -1 if this Playback object is not valid.

◆ AddTopic() [2/2]

bool AddTopic ( const std::string _topic)

Add a topic to be played back (exact match only)

Parameters
[in]_topicThe exact topic name
Note
This method attempts to advertise the topic immediately. The publisher will be kept until this is destructed.
Returns
True if the topic exists in the log, false if it does not exist or if the log is not valid.

◆ RemoveTopic() [1/2]

int64_t RemoveTopic ( const std::regex _topic)

Remove all topics matching the specified pattern from being played back.

Note
If neither AddTopic() nor RemoveTopic() were called prior to this function, we will assume you want all of the topics and then remove the one passed in here.
Parameters
[in]_topicThe pattern of topics to be removed
Returns
The number of topics that have been removed from playback due to this function call.

◆ RemoveTopic() [2/2]

bool RemoveTopic ( const std::string _topic)

Remove a topic from being played back.

Note
If neither AddTopic() nor RemoveTopic() were called prior to this function, we will assume you want all of the topics and then remove the one passed in here.
Parameters
[in]_topicThe exact topic name to remove
Returns
True if the topic was in the list and has been removed, false otherwise.

◆ Start()

PlaybackHandlePtr Start ( const std::chrono::nanoseconds _waitAfterAdvertising = std::chrono::seconds(1),
bool  _msgWaiting = true 
) const

Begin playing messages.

Parameters
[in]_waitAfterAdvertisingHow long to wait before the publications begin after advertising the topics that will be played back.
[in]_msgWaitingTrue to wait between publication of messages based on the message timestamps. False to playback messages as fast as possible. Default value is true.
Note
The topic discovery process will need some time before publishing begins, or else subscribers in other processes will miss the outgoing messages. The default value is recommended unless you are confident in the timing of your system.
Remarks
If your application uses another library that uses sqlite3, it may be unsafe to start multiple simultaneous PlaybackHandles from the same Playback instance, because they will interact with the same sqlite3 database in multiple threads (see https://www.sqlite.org/threadsafe.html). In most cases there should be no issue, but if you or a library you are using calls sqlite3_config(~) to change the threading mode to Single-thread or Multi-thread (instead of the default setting of Seralized), then starting multiple simultaneous playbacks from the same log file could be dangerous.
Returns
A handle for managing the playback of the log. You must hold onto this object in order for the playback to continue, or else it will be cut short.

If an error prevents the playback from starting, this will return a nullptr.

◆ Valid()

bool Valid ( ) const

Check if this Playback object has a valid log to play back.

Returns
true if this has a valid log to play back, otherwise false.

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