Ignition Transport

API Reference

7.1.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 IGNITION_TRANSPORT_LOG_PLAYBACK_HH_
18 #define IGNITION_TRANSPORT_LOG_PLAYBACK_HH_
19 
20 #include <chrono>
21 #include <memory>
22 #include <regex>
23 #include <string>
24 
25 #include <ignition/transport/config.hh>
26 #include <ignition/transport/log/Export.hh>
28 
29 namespace ignition
30 {
31  namespace transport
32  {
33  namespace log
34  {
35  // Inline bracket to help doxygen filtering.
36  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
37  //
38  // Forward declarations
39  class PlaybackHandle;
41 
47  class IGNITION_TRANSPORT_LOG_VISIBLE Playback
48  {
51  public: explicit Playback(const std::string &_file,
52  const NodeOptions &_nodeOptions = NodeOptions());
53 
56  public: Playback(Playback &&_old); // NOLINT
57 
59  public: ~Playback();
60 
87  //
88  // TODO(MXG): When we can use C++17, add a [[nodiscard]] attribute here.
89  public: PlaybackHandlePtr Start(
90  const std::chrono::nanoseconds &_waitAfterAdvertising =
91  std::chrono::seconds(1)) const;
92 
95  public: bool Valid() const;
96 
103  public: bool AddTopic(const std::string &_topic);
104 
111  public: int64_t AddTopic(const std::regex &_topic);
112 
122  public: bool RemoveTopic(const std::string &_topic);
123 
134  public: int64_t RemoveTopic(const std::regex &_topic);
135 
137  private: class Implementation;
138 
139 #ifdef _WIN32
140 // Disable warning C4251 which is triggered by
141 // std::*
142 #pragma warning(push)
143 #pragma warning(disable: 4251)
144 #endif
145  private: std::unique_ptr<Implementation> dataPtr;
147 #ifdef _WIN32
148 #pragma warning(pop)
149 #endif
150  };
151 
160  class IGNITION_TRANSPORT_LOG_VISIBLE PlaybackHandle
161  {
163  public: void Stop();
164 
167  public: void Seek(const std::chrono::nanoseconds &_newElapsedTime);
168 
172  public: void Step(const std::chrono::nanoseconds &_stepDuration);
173 
175  public: void Pause();
176 
178  public: void Resume();
179 
181  public: bool IsPaused() const;
182 
184  public: void WaitUntilFinished();
185 
188  public: bool Finished() const;
189 
192  public: std::chrono::nanoseconds StartTime() const;
193 
196  public: std::chrono::nanoseconds CurrentTime() const;
197 
200  public: std::chrono::nanoseconds EndTime() const;
201 
203  public: ~PlaybackHandle();
204 
205  // Friendship
206  friend class Playback;
207 
208  // Forward declaration of implementation class
209  private: class Implementation;
210 
212  private: PlaybackHandle(
213  std::unique_ptr<Implementation> &&_internal); // NOLINT
214 
215 #ifdef _WIN32
216 // Disable warning C4251 which is triggered by
217 // std::*
218 #pragma warning(push)
219 #pragma warning(disable: 4251)
220 #endif
221  private: std::unique_ptr<Implementation> dataPtr;
223 #ifdef _WIN32
224 #pragma warning(pop)
225 #endif
226  };
227  }
228  }
229  }
230 }
231 #endif
A class for customizing the behavior of the Node. E.g.: Set a custom namespace or a partition name...
Definition: NodeOptions.hh:40
T log(T... args)
Initiates playback of ignition transport topics This class makes it easy to play topics from a log fi...
Definition: Playback.hh:47
Handles the playback of ignition transport topics. This class allows you to manage a log playback onc...
Definition: Playback.hh:160
STL class.
Definition: AdvertiseOptions.hh:28