Gazebo Transport

API Reference

11.4.2
gz/transport/log/Playback.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GZ_TRANSPORT_LOG_PLAYBACK_HH_
18 #define GZ_TRANSPORT_LOG_PLAYBACK_HH_
19 
20 #include <chrono>
21 #include <memory>
22 #include <regex>
23 #include <string>
24 
25 #include <gz/transport/config.hh>
26 #include <gz/transport/log/Export.hh>
28 
30 {
31  // Inline bracket to help doxygen filtering.
32  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
33  //
34  // Forward declarations
35  class PlaybackHandle;
37 
43  class IGNITION_TRANSPORT_LOG_VISIBLE Playback
44  {
48  public: explicit Playback(const std::string &_file,
49  const NodeOptions &_nodeOptions = NodeOptions());
50 
53  public: Playback(Playback &&_old); // NOLINT
54 
56  public: ~Playback();
57 
87  public: [[nodiscard]] PlaybackHandlePtr Start(
88  const std::chrono::nanoseconds &_waitAfterAdvertising =
90  bool _msgWaiting = true) const;
91 
94  public: bool Valid() const;
95 
102  public: bool AddTopic(const std::string &_topic);
103 
110  public: int64_t AddTopic(const std::regex &_topic);
111 
121  public: bool RemoveTopic(const std::string &_topic);
122 
133  public: int64_t RemoveTopic(const std::regex &_topic);
134 
136  private: class Implementation;
137 
138 #ifdef _WIN32
139 // Disable warning C4251 which is triggered by
140 // std::*
141 #pragma warning(push)
142 #pragma warning(disable: 4251)
143 #endif
145  private: std::unique_ptr<Implementation> dataPtr;
146 #ifdef _WIN32
147 #pragma warning(pop)
148 #endif
149  };
150 
159  class IGNITION_TRANSPORT_LOG_VISIBLE PlaybackHandle
160  {
162  public: void Stop();
163 
166  public: void Seek(const std::chrono::nanoseconds &_newElapsedTime);
167 
171  public: void Step(const std::chrono::nanoseconds &_stepDuration);
172 
174  public: void Pause();
175 
177  public: void Resume();
178 
180  public: bool IsPaused() const;
181 
183  public: void WaitUntilFinished();
184 
187  public: bool Finished() const;
188 
192 
196 
200 
202  public: ~PlaybackHandle();
203 
204  // Friendship
205  friend class Playback;
206 
207  // Forward declaration of implementation class
208  private: class Implementation;
209 
211  private: PlaybackHandle(
212  std::unique_ptr<Implementation> &&_internal); // NOLINT
213 
214 #ifdef _WIN32
215 // Disable warning C4251 which is triggered by
216 // std::*
217 #pragma warning(push)
218 #pragma warning(disable: 4251)
219 #endif
221  private: std::unique_ptr<Implementation> dataPtr;
222 #ifdef _WIN32
223 #pragma warning(pop)
224 #endif
225  };
226  }
227 }
228 #endif
A class for customizing the behavior of the Node. E.g.: Set a custom namespace or a partition name.
Definition: gz/transport/NodeOptions.hh:39
Handles the playback of ignition transport topics. This class allows you to manage a log playback onc...
Definition: gz/transport/log/Playback.hh:160
void Stop()
Stop playing messages.
void Seek(const std::chrono::nanoseconds &_newElapsedTime)
Jump current playback time to a specific elapsed time.
std::chrono::nanoseconds EndTime() const
Gets end time of the log being played.
std::chrono::nanoseconds StartTime() const
Gets start time of the log being played.
bool Finished() const
Check if this playback is finished.
void Step(const std::chrono::nanoseconds &_stepDuration)
Step the playback by a given amount of nanoseconds.
void Pause()
Pauses the playback.
std::chrono::nanoseconds CurrentTime() const
Gets current time of the log being played.
void Resume()
Unpauses the playback.
bool IsPaused() const
Check pause status.
void WaitUntilFinished()
Block until playback runs out of messages to publish.
Initiates playback of ignition transport topics This class makes it easy to play topics from a log fi...
Definition: gz/transport/log/Playback.hh:44
Playback(const std::string &_file, const NodeOptions &_nodeOptions=NodeOptions())
Constructor.
Playback(Playback &&_old)
move constructor
int64_t AddTopic(const std::regex &_topic)
Add a topic to be played back (regex match)
bool Valid() const
Check if this Playback object has a valid log to play back.
bool AddTopic(const std::string &_topic)
Add a topic to be played back (exact match only)
int64_t RemoveTopic(const std::regex &_topic)
Remove all topics matching the specified pattern from being played back.
PlaybackHandlePtr Start(const std::chrono::nanoseconds &_waitAfterAdvertising=std::chrono::seconds(1), bool _msgWaiting=true) const
Begin playing messages.
bool RemoveTopic(const std::string &_topic)
Remove a topic from being played back.
Definition: gz/transport/log/Batch.hh:28