MADARA  3.1.8
SimTime.h
Go to the documentation of this file.
1 #ifndef MADARA_UTILITY_SIMTIME_H_
2 #define MADARA_UTILITY_SIMTIME_H_
3 
4 #ifdef __cplusplus
5 #include <mutex>
6 #include <madara/MADARA_export.h>
7 
8 #define MADARA_EXTERN_C extern "C" MADARA_Export
9 
10 namespace madara { namespace utility {
11 #else
12 #define MADARA_EXTERN_C
13 #endif
14 
15 #if defined(MADARA_FEATURE_SIMTIME) && MADARA_FEATURE_SIMTIME==1
16 
17 typedef void (*sim_time_callback_fn)(uint64_t*, double*);
18 
22 MADARA_EXTERN_C sim_time_callback_fn set_sim_time_callback(
23  sim_time_callback_fn fn);
24 
28 MADARA_EXTERN_C void sim_time_notify(uint64_t, double);
29 
31 MADARA_EXTERN_C const double minrate;
32 
33 #ifdef __cplusplus
34 constexpr bool simtime = true;
35 
36 class SimTime {
37 private:
38  static std::mutex mutex_;
39  static sim_time_callback_fn callback_;
40 
41  static uint64_t last_realtime_;
42  static uint64_t last_simtime_;
43  static double last_rate_;
44 
45 public:
46  SimTime() = delete;
47 
48  static uint64_t last_realtime() {
49  std::lock_guard<std::mutex> guard(mutex_);
50  return last_realtime_;
51  }
52 
53  static uint64_t last_simtime() {
54  std::lock_guard<std::mutex> guard(mutex_);
55  return last_simtime_;
56  }
57 
58  static double last_rate() {
59  std::lock_guard<std::mutex> guard(mutex_);
60  return last_rate_;
61  }
62 
63  static uint64_t realtime();
64  static uint64_t time();
65  static double rate();
66  static uint64_t duration(uint64_t sim_duration);
67  static uint64_t future(uint64_t sim_offset);
68 
69  friend sim_time_callback_fn set_sim_time_callback(
70  sim_time_callback_fn fn);
71 
72  friend void sim_time_notify(uint64_t, double);
73 };
74 
75 #endif // ifdef __cplusplus
76 #else
77 #ifdef __cplusplus
78 constexpr bool simtime = false;
79 #endif
80 #endif
81 
82 #ifdef __cplusplus
83 } } // namespace madara::utility
84 #endif
85 
86 #endif
#define MADARA_EXTERN_C
Definition: SimTime.h:12
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:14
Copyright (c) 2015 Carnegie Mellon University.