Gazebo Transport

API Reference

13.4.0
Clock.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 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_CLOCK_HH_
18 #define GZ_TRANSPORT_CLOCK_HH_
19 
20 #include <chrono>
21 #include <memory>
22 #include <string>
23 
24 #include <gz/utils/SuppressWarning.hh>
25 
26 #include "gz/transport/config.hh"
27 #include "gz/transport/Export.hh"
28 
29 namespace gz
30 {
31  namespace transport
32  {
33  // Inline bracket to help doxygen filtering.
34  inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
35  //
38  class GZ_TRANSPORT_VISIBLE Clock
39  {
42  public: virtual std::chrono::nanoseconds Time() const = 0;
43 
46  public: virtual bool IsReady() const = 0;
47 
49  public: virtual ~Clock() = default;
50  };
51 
56  class GZ_TRANSPORT_VISIBLE NetworkClock : public Clock
57  {
59  public: enum class TimeBase : int64_t
60  {
61  REAL,
62  SIM,
63  SYS
64  };
65 
71  public: explicit NetworkClock(const std::string &_topicName,
72  const TimeBase _timeBase = TimeBase::SIM);
73 
75  public: ~NetworkClock() override;
76 
77  // Documentation inherited
78  public: std::chrono::nanoseconds Time() const override;
79 
83  public: void SetTime(const std::chrono::nanoseconds _time);
84 
85  // Documentation inherited
86  public: bool IsReady() const override;
87 
89  private: class Implementation;
90 
92  GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
93  private: std::unique_ptr<Implementation> dataPtr;
94  GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
95  };
96 
99  class GZ_TRANSPORT_VISIBLE WallClock : public Clock
100  {
103  public: static WallClock* Instance();
104 
105  // Documentation inherited
106  public: std::chrono::nanoseconds Time() const override;
107 
108  // Documentation inherited
109  public: bool IsReady() const override;
110 
112  private: WallClock();
113 
115  private: ~WallClock() override;
116 
118  private: class Implementation;
119 
121  GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
122  private: std::unique_ptr<Implementation> dataPtr;
123  GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
124  };
125  }
126  }
127 }
128 
129 #endif