Gazebo Transport

API Reference

13.7.0
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 
29 namespace gz::transport::log
30 {
31  // Inline bracket to help doxygen filtering.
32  inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
33  //
34  // Forward declarations
35  class PlaybackHandle;
37 
43  class GZ_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 GZ_TRANSPORT_LOG_VISIBLE PlaybackHandle
160  {
162  public: void Stop();
163 
168  public: void Seek(const std::chrono::nanoseconds &_newElapsedTime);
169 
173  public: void Step(const std::chrono::nanoseconds &_stepDuration);
174 
176  public: void Pause();
177 
179  public: void Resume();
180 
182  public: bool IsPaused() const;
183 
185  public: void WaitUntilFinished();
186 
189  public: bool Finished() const;
190 
194 
198 
202 
204  public: ~PlaybackHandle();
205 
206  // Friendship
207  friend class Playback;
208 
209  // Forward declaration of implementation class
210  private: class Implementation;
211 
213  private: PlaybackHandle(
214  std::unique_ptr<Implementation> &&_internal); // NOLINT
215 
216 #ifdef _WIN32
217 // Disable warning C4251 which is triggered by
218 // std::*
219 #pragma warning(push)
220 #pragma warning(disable: 4251)
221 #endif
223  private: std::unique_ptr<Implementation> dataPtr;
224 #ifdef _WIN32
225 #pragma warning(pop)
226 #endif
227  };
228  }
229 }
230 #endif