$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 
24 #include <cstdint> // for uint64_t
25 
26 #include <cloe/core/duration.hpp> // for Duration, to_convenient_json
27 #include <fable/json.hpp> // for Json
28 
29 namespace cloe {
30 
34 class Sync {
35  public:
41  virtual uint64_t step() const = 0;
42 
48  virtual Duration step_width() const = 0;
49 
53  virtual Duration time() const = 0;
54 
62  virtual Duration eta() const = 0;
63 
73  virtual double realtime_factor() const = 0;
74 
79  virtual bool is_realtime_factor_unlimited() const { return realtime_factor() < 0.0; }
80 
85  virtual double achievable_realtime_factor() const = 0;
86 
90  friend void to_json(fable::Json& j, const Sync& s);
91 };
92 
96 inline void to_json(fable::Json& j, const Sync& s) {
97  j = fable::Json{
98  {"step", s.step()},
99  {"step_width", s.step_width()},
100  {"time", to_convenient_json(s.time())},
101  {"realtime_factor", s.realtime_factor()},
102  {"achievable_realtime_factor", s.achievable_realtime_factor()},
103  };
104  if (s.eta().count() == 0) {
105  j["eta"] = nullptr;
106  } else {
107  j["eta"] = to_convenient_json(s.eta());
108  }
109 }
110 
111 } // namespace cloe
Definition: sync.hpp:34
virtual Duration eta() const =0
virtual double realtime_factor() const =0
virtual Duration time() const =0
virtual uint64_t step() const =0
friend void to_json(fable::Json &j, const Sync &s)
Definition: sync.hpp:96
virtual Duration step_width() const =0
virtual bool is_realtime_factor_unlimited() const
Definition: sync.hpp:79
virtual double achievable_realtime_factor() const =0
std::chrono::nanoseconds Duration
Definition: cloe_fwd.hpp:36
nlohmann::json Json
Definition: fable_fwd.hpp:35