summaryrefslogtreecommitdiffstats
path: root/include/jau/environment.hpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-05-01 06:57:55 +0200
committerSven Gothel <[email protected]>2022-05-01 06:57:55 +0200
commit043ab5ce128b4e6b6e08034f0d050fb1d8308c33 (patch)
treeef51a19266a9851827416291221ed42e90357f0e /include/jau/environment.hpp
parentea2a46c821d23b02095a7a78b0342a97c30ea728 (diff)
Introduce new types: fraction, fraction_timespec; its constants & literals as well adoption in latch, ringbuffer, service_runner and simple_timer.
Also adds string -> fraction conversion via to_fraction_i64(), supported by environment. fraction provides similar properties like C++11's `std::ratio`, but is evaluated at runtime time without `constexpr` constraints using a common integral template type. std::ratio is evaluated at compile time and must use `constexpr` literal values. fraction provides similar properties like C++11's `std::chrono::duration`, but is flexible with its denominator and always reduce() its fraction to the lowest terms. `std::chrono::duration` uses a fixed `std::ratio` denominator and hence is inflexible. Further, fraction can be converted to std::chrono::duration, matching the selected duration's period, see to_duration_count() and to_duration(). ... see fraction_type.hpp
Diffstat (limited to 'include/jau/environment.hpp')
-rw-r--r--include/jau/environment.hpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/include/jau/environment.hpp b/include/jau/environment.hpp
index c2f855f..261f103 100644
--- a/include/jau/environment.hpp
+++ b/include/jau/environment.hpp
@@ -70,11 +70,37 @@ namespace jau {
public:
/**
+ * Module startup time t0 in monotonic time using high precision and range of fraction_timespec.
+ */
+ static const fraction_timespec startupTimeMonotonic;
+
+ /**
* Module startup time t0 in monotonic time in milliseconds.
*/
static const uint64_t startupTimeMilliseconds;
/**
+ * Returns elapsed monotonic time using fraction_timespec since module startup,
+ * see {@link #startupTimeMonotonic} and getMonotonicTime().
+ * <pre>
+ * return getMonotonicTime() - startupTimeMonotonic;
+ * </pre>
+ */
+ static fraction_timespec getElapsedMonotonicTime() noexcept {
+ return getMonotonicTime() - startupTimeMonotonic;
+ }
+
+ /**
+ * Returns elapsed monotonic time using fraction_timespec since module startup up to the given current_ts, see {@link #startupTimeMonotonic}.
+ * <pre>
+ * return current_ts - startupTimeMonotonic;
+ * </pre>
+ */
+ static fraction_timespec getElapsedMonotonicTime(const fraction_timespec& current_ts) noexcept {
+ return current_ts - startupTimeMonotonic;
+ }
+
+ /**
* Returns current elapsed monotonic time in milliseconds since module startup, see {@link #startupTimeMilliseconds}.
*/
static uint64_t getElapsedMillisecond() noexcept {
@@ -158,6 +184,21 @@ namespace jau {
const uint32_t min_allowed=0, const uint32_t max_allowed=UINT32_MAX) noexcept;
/**
+ * Returns the fraction_i64 value of the environment's variable 'name' in format `<num>/<denom>`,
+ * with white space allowed, if within given fraction_i64 value range.
+ *
+ * Otherwise returns the 'default_value' if the environment variable's value is null
+ * or of invalid format or not within given fraction_i64 value range.
+ * <p>
+ * Implementation uses {@link #getProperty(const std::string & name)}
+ * and hence attempts to also find a Unix conform name,
+ * e.g. 'direct_bt_debug' if ''direct_bt.debug' wasn't found.
+ * </p>
+ */
+ static fraction_i64 getFractionProperty(const std::string & name, const fraction_i64& default_value,
+ const fraction_i64& min_allowed, const fraction_i64& max_allowed) noexcept;
+
+ /**
* Fetches exploding variable-name (prefix_domain) values.
* <p>
* Implementation uses {@link #getProperty(const std::string & name)}