diff options
-rw-r--r-- | api/direct_bt/DBTEnv.hpp | 24 | ||||
-rw-r--r-- | scripts/run-dbt_scanner10.sh | 3 | ||||
-rw-r--r-- | src/direct_bt/DBTEnv.cpp | 23 |
3 files changed, 44 insertions, 6 deletions
diff --git a/api/direct_bt/DBTEnv.hpp b/api/direct_bt/DBTEnv.hpp index 7e63e917..99d5dc01 100644 --- a/api/direct_bt/DBTEnv.hpp +++ b/api/direct_bt/DBTEnv.hpp @@ -82,6 +82,15 @@ namespace direct_bt { * <p> * Note that only '[org.]tinyb.*' and 'direct_bt.*' Java JVM properties are passed via 'org.tinyb.BluetoothFactory' * </p> + * <p> + * Implementation attempts to also find a Unix conform environment name, + * e.g. 'direct_bt_debug' if ''direct_bt.debug' wasn't found.</br> + * + * 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.</br> + * This allows Unix shell user to set the property 'direct_bt_debug' instead of 'direct_bt.debug'. + * </p> */ static std::string getProperty(const std::string & name) noexcept; @@ -90,6 +99,8 @@ namespace direct_bt { * or the 'default_value' if the environment variable's value is null. * <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 std::string getProperty(const std::string & name, const std::string & default_value) noexcept; @@ -102,7 +113,9 @@ namespace direct_bt { * true is determined if the value equals 'true'. * </p> * <p> - * Implementation uses {@link #getProperty(const std::string & name)}. + * 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 bool getBooleanProperty(const std::string & name, const bool default_value) noexcept; @@ -113,6 +126,8 @@ namespace direct_bt { * or not within int32_t value range or within the given 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 int32_t getInt32Property(const std::string & name, const int32_t default_value, @@ -124,6 +139,8 @@ namespace direct_bt { * or not within uint32_t value range or within the given 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 uint32_t getUint32Property(const std::string & name, const uint32_t default_value, @@ -132,6 +149,11 @@ namespace direct_bt { /** * Fetches exploding variable-name (prefixDomain) values. * <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> + * <p> * If the value of a prefixDomain is neither 'true' or 'false', * it is treated as a list of sub-variable names including their optional value separated by comma ','. * <p> diff --git a/scripts/run-dbt_scanner10.sh b/scripts/run-dbt_scanner10.sh index af3b512b..899a54e2 100644 --- a/scripts/run-dbt_scanner10.sh +++ b/scripts/run-dbt_scanner10.sh @@ -1,5 +1,6 @@ #!/bin/sh +# export direct_bt_debug=hci.event,mgmt.event,gatt.data # # ../scripts/run-dbt_scanner10.sh -wait -mac C0:26:DA:01:DA:B1 2>&1 | tee ~/scanner-h01-dbt10.log # ../scripts/run-dbt_scanner10.sh -wait -wl C0:26:DA:01:DA:B1 2>&1 | tee ~/scanner-h01-dbt10.log @@ -16,5 +17,7 @@ fi export LANG=en_US.UTF-8 export LC_MEASUREMENT=en_US.UTF-8 +echo direct_bt_debug $direct_bt_debug + #LD_LIBRARY_PATH=`pwd`/lib strace bin/dbt_scanner10 $* LD_LIBRARY_PATH=`pwd`/lib bin/dbt_scanner10 $* diff --git a/src/direct_bt/DBTEnv.cpp b/src/direct_bt/DBTEnv.cpp index f9e8bf5a..14dcbebe 100644 --- a/src/direct_bt/DBTEnv.cpp +++ b/src/direct_bt/DBTEnv.cpp @@ -25,6 +25,7 @@ #include <cstring> #include <string> +#include <algorithm> #include <memory> #include <cstdint> #include <vector> @@ -39,13 +40,25 @@ const uint64_t DBTEnv::startupTimeMilliseconds = direct_bt::getCurrentMillisecon bool DBTEnv::debug = false; +static const std::string s_true("true"); +static const std::string s_false("false"); + std::string DBTEnv::getProperty(const std::string & name) noexcept { const char * value = getenv(name.c_str()); if( nullptr != value ) { return std::string( value ); - } else { - return std::string(); } + if( std::string::npos != name.find('.', 0) ) { + // Retry with '.' -> '_' to please unix shell + std::string alt_name(name); + std::replace( alt_name.begin(), alt_name.end(), '.', '_'); + value = getenv(alt_name.c_str()); + if( nullptr != value ) { + return std::string( value ); + } + } + // not found: empty string + return std::string(); } std::string DBTEnv::getProperty(const std::string & name, const std::string & default_value) noexcept { @@ -196,11 +209,11 @@ void DBTEnv::envExplodeProperties(std::string prefixDomain, std::string list) no } bool DBTEnv::getExplodingProperties(const std::string & prefixDomain) noexcept { - std::string value = DBTEnv::getProperty(prefixDomain, "false"); - if( "false" == value ) { + std::string value = DBTEnv::getProperty(prefixDomain, s_false); + if( s_false == value ) { return false; } - if( "true" == value ) { + if( s_true == value ) { return true; } if( "direct_bt.debug" == prefixDomain ) { |