/*
* Author: Sven Gothel
* See main environment {@link environment} and
* {@link environment::getExplodingProperties(const std::string & prefix_domain)}.
*
* Note that only '[org.]tinyb.*' and 'direct_bt.*' Java JVM properties are passed via 'org.tinyb.BluetoothFactory'
*
* Implementation attempts to also find a Unix conform environment name,
* e.g. 'direct_bt_debug' if ''direct_bt.debug' wasn't found.
*
* Dots are not allowed as valid Unix envrionment variable identifier.
* If the property 'name' isn't found and if the 'name' contains a dot ('.'),
* all dots ('.') will be replaced y underscore ('_') and looked up again.
* This allows Unix shell user to set the property 'direct_bt_debug' instead of 'direct_bt.debug'.
*
* 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.
*
* If the environment variable is set (value != null),
* true is determined if the value equals 'true'.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
*
* If the value of a prefix_domain is neither 'true' or 'false',
* it is treated as a list of sub-variable names including their optional value separated by comma ','.
*
* If the value is not given for the sub-variable name, a boolean "true" will be used per default.
*
* Example 1
*
* return getMonotonicTime() - startupTimeMonotonic;
*
*/
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}.
*
* return current_ts - startupTimeMonotonic;
*
*/
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 {
return getCurrentMilliseconds() - startupTimeMilliseconds;
}
/**
* Returns elapsed monotonic time in milliseconds since module startup comparing against the given timestamp, see {@link #startupTimeMilliseconds}.
*/
static uint64_t getElapsedMillisecond(const uint64_t& current_ts) noexcept {
return current_ts - startupTimeMilliseconds;
}
/**
* Returns the value of the environment's variable 'name'.
*
* Input Environment:
* "direct_bt.debug" := "jni,adapter.event,gatt.data=false,hci.event,mgmt.event=true"
*
* Result Environment:
* "direct_bt.debug.jni" := "true"
* "direct_bt.debug.adapter.event" := "true"
* "direct_bt.debug.gatt.data" := "false"
* "direct_bt.debug.hci.event" := "true"
* "direct_bt.debug.mgmt.event" := "true"
* "direct_bt.debug" := "true" (will be overwritten)
*
* Example 2
*
* Input Environment:
* "direct_bt.gatt" := "cmd.read.timeout=20000,cmd.write.timeout=20001,ringsize=256"
*
* Result Environment:
* "direct_bt.gatt.cmd.read.timeout" := "20000"
* "direct_bt.gatt.cmd.write.timeout" := "20001"
* "direct_bt.gatt.ringsize" := "256"
* "direct_bt.gatt" := "true" (will be overwritten)
*
*
* Each sub-variable name/value pair will be trimmed and if not zero-length * appended to the prefix_domain with a dot '.'. * * Each new variable name will be set in the environment with value 'true'. * * The prefix_domain will also be set to the new value 'true', hence gets overwritten. *
** This is automatically performed for environment::debug root_prefix_domain+".debug", * and environment::verbose root_prefix_domain+'.verbose', * e.g: 'direct_bt.debug' and verbose 'direct_bt.verbose'. *
* * @param prefix_domain the queried prefix domain, e.g. "direct_bt.debug" or "direct_bt.verbose" etc. * @return */ static bool getExplodingProperties(const std::string & prefix_domain) noexcept { return getExplodingPropertiesImpl("", prefix_domain); } /** * Static singleton initialization of this project's environment * with the given global root prefix_domain. ** The root prefix_domain defines the value for environment::debug, environment::debug_jni and environment::verbose. *
** The resulting singleton instance will be constructed only once. *
* @param root_prefix_domain the project's global singleton root prefix_domain, e.g. "direct_bt". * Default value to "jau", only intended for subsequent queries. * Initial call shall utilize the actual project's root_prefix_domain! * @return the static singleton instance. */ static environment& get(const std::string root_prefix_domain="jau") noexcept { /** * Thread safe starting with C++11 6.7: * * If control enters the declaration concurrently while the variable is being initialized, * the concurrent execution shall wait for completion of the initialization. * * (Magic Statics) * * Avoiding non-working double checked locking. */ static environment e(root_prefix_domain); return e; } /** * Returns the project's global singleton root prefix_domain, used at first call of * environment::get(const std::string root_prefix_domain). */ const std::string & getRootPrefixDomain() const noexcept { return root_prefix_domain; } /** * Debug logging enabled or disabled. ** Environment variable depending on the root prefix_domain, e.g. for "direct_bt" this is 'direct_bt.debug', boolean, default 'false', * see get(const std::string & root_prefix_domain). *
** Implementation uses {@link #getProperty(const std::string & name)} *
** Exploding variable-name values are implemented here, * see {@link #getExplodingProperties(const std::string & prefix_domain)}. *
*/ const bool debug; /** * JNI Debug logging enabled or disabled. ** Environment variable depending on the root prefix_domain, e.g. for "direct_bt" this is 'direct_bt.debug.jni', boolean, default 'false', * see get(const std::string & root_prefix_domain). *
** Implementation uses getBooleanProperty(). *
*/ const bool debug_jni; /** * Verbose info logging enabled or disabled. ** Environment variable depending on the root prefix_domain, e.g. for "direct_bt" this is 'direct_bt.verbose', boolean, default 'false', * see get(const std::string & root_prefix_domain). *
** Implementation uses {@link #getProperty(const std::string & name)} *
** VERBOSE is also enabled if DEBUG is enabled! *
** Exploding variable-name values are implemented here, * see {@link #getExplodingProperties(const std::string & prefix_domain)}. *
*/ const bool verbose; }; /**@}*/ } // namespace jau #endif /* JAU_ENV_HPP_ */