Gazebo Transport

API Reference

11.4.1
gz/transport/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/utilities/SuppressWarning.hh>
25 
26 #include "gz/transport/config.hh"
27 #include "gz/transport/Export.hh"
28 
29 namespace ignition
30 {
31  namespace transport
32  {
33  // Inline bracket to help doxygen filtering.
34  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
35  //
38  class IGNITION_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 IGNITION_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  IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
93  private: std::unique_ptr<Implementation> dataPtr;
94  IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
95  };
96 
99  class IGNITION_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  IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
122  private: std::unique_ptr<Implementation> dataPtr;
123  IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
124  };
125  }
126  }
127 }
128 
129 #endif
bool IsReady() const override
Checks whether the clock is ready to be used or not.
Definition: gz/transport/AdvertiseOptions.hh:28
STL class.
@ REAL
Use Clock message real time field as time base.
@ SYS
Use Clock message sys time field as time base.
A Clock interface implementation that uses gz::msgs::Clock messages distributed across the network.
Definition: gz/transport/Clock.hh:56
void SetTime(const std::chrono::nanoseconds _time)
Sets and distributes the given clock time.
static WallClock * Instance()
Returns system wall clock interface.
NetworkClock(const std::string &_topicName, const TimeBase _timeBase=TimeBase::SIM)
Constructor that sets the initial time range option.
std::chrono::nanoseconds Time() const override
Gets clock time.
virtual std::chrono::nanoseconds Time() const =0
Gets clock time.
virtual bool IsReady() const =0
Checks whether the clock is ready to be used or not.
A Clock interface for time tracking.
Definition: gz/transport/Clock.hh:38
~NetworkClock() override
Destructor.
@ SIM
Use Clock message sim time field as time base.
virtual ~Clock()=default
Virtual destructor.
TimeBase
Network clock time bases.
Definition: gz/transport/Clock.hh:59
bool IsReady() const override
Checks whether the clock is ready to be used or not.
std::chrono::nanoseconds Time() const override
Gets clock time.
A Clock implementation that leverages host OS time APIs.
Definition: gz/transport/Clock.hh:99