$darkmode
sync.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
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  * SPDX-License-Identifier: Apache-2.0
17  */
22 #pragma once
23 #ifndef CLOE_SYNC_HPP_
24 #define CLOE_SYNC_HPP_
25 
26 #include <cstdint> // for uint64_t
27 
28 #include <cloe/core.hpp> // for Json, Duration
29 
30 namespace cloe {
31 
35 class Sync {
36  public:
42  virtual uint64_t step() const = 0;
43 
49  virtual Duration step_width() const = 0;
50 
54  virtual Duration time() const = 0;
55 
63  virtual Duration eta() const = 0;
64 
74  virtual double realtime_factor() const = 0;
75 
80  virtual bool is_realtime_factor_unlimited() const { return realtime_factor() < 0.0; }
81 
86  virtual double achievable_realtime_factor() const = 0;
87 
91  friend void to_json(Json& j, const Sync& s);
92 };
93 
97 inline void to_json(Json& j, const Sync& s) {
98  j = Json{
99  {"step", s.step()},
100  {"step_width", s.step_width()},
101  {"time", to_convenient_json(s.time())},
102  {"realtime_factor", s.realtime_factor()},
103  {"achievable_realtime_factor", s.achievable_realtime_factor()},
104  };
105  if (s.eta().count() == 0) {
106  j["eta"] = nullptr;
107  } else {
108  j["eta"] = to_convenient_json(s.eta());
109  }
110 }
111 
112 } // namespace cloe
113 
114 #endif // CLOE_SYNC_HPP_
virtual Duration eta() const =0
virtual double achievable_realtime_factor() const =0
virtual Duration time() const =0
friend void to_json(Json &j, const Sync &s)
Definition: sync.hpp:97
virtual Duration step_width() const =0
virtual double realtime_factor() const =0
virtual uint64_t step() const =0
Definition: sync.hpp:35
Definition: coordinator.hpp:36
std::chrono::nanoseconds Duration
Definition: duration.hpp:45
virtual bool is_realtime_factor_unlimited() const
Definition: sync.hpp:80