Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
jau::environment Class Reference

Main jau environment class, supporting environment variable access and fetching elapsed time using its stored startup-time. More...

#include <environment.hpp>

Inheritance diagram for jau::environment:
Collaboration diagram for jau::environment:

Public Member Functions

const std::string & getRootPrefixDomain () const noexcept
 Returns the project's global singleton root prefix_domain, used at first call of environment::get(const std::string root_prefix_domain). More...
 

Static Public Member Functions

static uint64_t getElapsedMillisecond () noexcept
 Returns current elapsed monotonic time in milliseconds since module startup, see startupTimeMilliseconds. More...
 
static uint64_t getElapsedMillisecond (const uint64_t &current_ts) noexcept
 Returns elapsed monotonic time in milliseconds since module startup comparing against the given timestamp, see startupTimeMilliseconds. More...
 
static std::string getProperty (const std::string &name) noexcept
 Returns the value of the environment's variable 'name'. More...
 
static std::string getProperty (const std::string &name, const std::string &default_value) noexcept
 Returns the value of the environment's variable 'name', or the 'default_value' if the environment variable's value is null. More...
 
static bool getBooleanProperty (const std::string &name, const bool default_value) noexcept
 Returns the boolean value of the environment's variable 'name', or the 'default_value' if the environment variable's value is null. More...
 
static int32_t getInt32Property (const std::string &name, const int32_t default_value, const int32_t min_allowed=INT32_MIN, const int32_t max_allowed=INT32_MAX) noexcept
 Returns the int32_t value of the environment's variable 'name', or the 'default_value' if the environment variable's value is null or not within int32_t value range or within the given value range. More...
 
static uint32_t getUint32Property (const std::string &name, const uint32_t default_value, const uint32_t min_allowed=0, const uint32_t max_allowed=UINT32_MAX) noexcept
 Returns the uint32_t value of the environment's variable 'name', or the 'default_value' if the environment variable's value is null or not within uint32_t value range or within the given value range. More...
 
static bool getExplodingProperties (const std::string &prefix_domain) noexcept
 Fetches exploding variable-name (prefix_domain) values. More...
 
static environmentget (const std::string root_prefix_domain="jau") noexcept
 Static singleton initialization of this project's environment with the given global root prefix_domain. More...
 

Public Attributes

const bool debug
 Debug logging enabled or disabled. More...
 
const bool debug_jni
 JNI Debug logging enabled or disabled. More...
 
const bool verbose
 Verbose info logging enabled or disabled. More...
 

Static Public Attributes

static const uint64_t startupTimeMilliseconds = jau::getCurrentMilliseconds()
 Module startup time t0 in monotonic time in milliseconds. More...
 

Detailed Description

Main jau environment class, supporting environment variable access and fetching elapsed time using its stored startup-time.

Definition at line 58 of file environment.hpp.

Member Function Documentation

◆ get()

static environment& jau::environment::get ( const std::string  root_prefix_domain = "jau")
inlinestaticnoexcept

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.

Parameters
root_prefix_domainthe 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!
Returns
the static singleton instance.

Definition at line 234 of file environment.hpp.

Here is the caller graph for this function:

◆ getBooleanProperty()

bool environment::getBooleanProperty ( const std::string &  name,
const bool  default_value 
)
staticnoexcept

Returns the boolean value of the environment's variable 'name', or the 'default_value' if the environment variable's value is null.

If the environment variable is set (value != null), true is determined if the value equals 'true'.

Implementation uses 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.

Definition at line 80 of file environment.cpp.

◆ getElapsedMillisecond() [1/2]

static uint64_t jau::environment::getElapsedMillisecond ( )
inlinestaticnoexcept

Returns current elapsed monotonic time in milliseconds since module startup, see startupTimeMilliseconds.

Definition at line 80 of file environment.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getElapsedMillisecond() [2/2]

static uint64_t jau::environment::getElapsedMillisecond ( const uint64_t &  current_ts)
inlinestaticnoexcept

Returns elapsed monotonic time in milliseconds since module startup comparing against the given timestamp, see startupTimeMilliseconds.

Definition at line 87 of file environment.hpp.

◆ getExplodingProperties()

static bool jau::environment::getExplodingProperties ( const std::string &  prefix_domain)
inlinestaticnoexcept

Fetches exploding variable-name (prefix_domain) values.

Implementation uses 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

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'.

Parameters
prefix_domainthe queried prefix domain, e.g. "direct_bt.debug" or "direct_bt.verbose" etc.
Returns

Definition at line 216 of file environment.hpp.

◆ getInt32Property()

int32_t environment::getInt32Property ( const std::string &  name,
const int32_t  default_value,
const int32_t  min_allowed = INT32_MIN,
const int32_t  max_allowed = INT32_MAX 
)
staticnoexcept

Returns the int32_t value of the environment's variable 'name', or the 'default_value' if the environment variable's value is null or not within int32_t value range or within the given value range.

Implementation uses 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.

Definition at line 94 of file environment.cpp.

◆ getProperty() [1/2]

std::string environment::getProperty ( const std::string &  name)
staticnoexcept

Returns the value of the environment's variable 'name'.

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'.

Definition at line 46 of file environment.cpp.

◆ getProperty() [2/2]

std::string environment::getProperty ( const std::string &  name,
const std::string &  default_value 
)
staticnoexcept

Returns the value of the environment's variable 'name', or the 'default_value' if the environment variable's value is null.

Implementation uses 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.

Definition at line 69 of file environment.cpp.

◆ getRootPrefixDomain()

const std::string& jau::environment::getRootPrefixDomain ( ) const
inlinenoexcept

Returns the project's global singleton root prefix_domain, used at first call of environment::get(const std::string root_prefix_domain).

Definition at line 253 of file environment.hpp.

◆ getUint32Property()

uint32_t environment::getUint32Property ( const std::string &  name,
const uint32_t  default_value,
const uint32_t  min_allowed = 0,
const uint32_t  max_allowed = UINT32_MAX 
)
staticnoexcept

Returns the uint32_t value of the environment's variable 'name', or the 'default_value' if the environment variable's value is null or not within uint32_t value range or within the given value range.

Implementation uses 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.

Definition at line 134 of file environment.cpp.

Member Data Documentation

◆ debug

const bool jau::environment::debug

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 getProperty(const std::string & name)

Exploding variable-name values are implemented here, see getExplodingProperties(const std::string & prefix_domain).

Definition at line 269 of file environment.hpp.

◆ debug_jni

const bool jau::environment::debug_jni

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().

Definition at line 281 of file environment.hpp.

◆ startupTimeMilliseconds

const uint64_t environment::startupTimeMilliseconds = jau::getCurrentMilliseconds()
static

Module startup time t0 in monotonic time in milliseconds.

Definition at line 75 of file environment.hpp.

◆ verbose

const bool jau::environment::verbose

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 getProperty(const std::string & name)

VERBOSE is also enabled if DEBUG is enabled!

Exploding variable-name values are implemented here, see getExplodingProperties(const std::string & prefix_domain).

Definition at line 300 of file environment.hpp.


The documentation for this class was generated from the following files: