From 876d4150aa3da531ddd687b48afada6e43f79146 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 2 Mar 2020 15:25:13 -0800 Subject: uhd: Apply clang-format against all .cpp and .hpp files in host/ Note: template_lvbitx.{cpp,hpp} need to be excluded from the list of files that clang-format gets applied against. --- host/lib/utils/prefs.cpp | 126 +++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 71 deletions(-) (limited to 'host/lib/utils/prefs.cpp') diff --git a/host/lib/utils/prefs.cpp b/host/lib/utils/prefs.cpp index 63479c911..72a9c9eea 100644 --- a/host/lib/utils/prefs.cpp +++ b/host/lib/utils/prefs.cpp @@ -4,74 +4,69 @@ // SPDX-License-Identifier: GPL-3.0+ // -#include #include #include -#include #include +#include +#include #include #include using namespace uhd; namespace { - constexpr char UHD_CONF_FILE_VAR[] = "UHD_CONFIG_FILE"; +constexpr char UHD_CONF_FILE_VAR[] = "UHD_CONFIG_FILE"; - inline void _update_conf_file( - const std::string& path, - const std::string& config_type, - config_parser& conf_file - ) { - if (not path.empty()) { - UHD_LOG_TRACE("PREFS", "Trying to load " << path); - if (boost::filesystem::exists(path)) { - try { - conf_file.read_file(path); - UHD_LOG_DEBUG("PREFS", - "Loaded " << config_type << " config file " << path); - } catch (...) { - UHD_LOG_DEBUG("PREFS", - "Failed to load " << config_type << " config file " << path); - } - } else { - UHD_LOG_TRACE("PREFS", - "No " << config_type << " config file found at " << path); +inline void _update_conf_file( + const std::string& path, const std::string& config_type, config_parser& conf_file) +{ + if (not path.empty()) { + UHD_LOG_TRACE("PREFS", "Trying to load " << path); + if (boost::filesystem::exists(path)) { + try { + conf_file.read_file(path); + UHD_LOG_DEBUG( + "PREFS", "Loaded " << config_type << " config file " << path); + } catch (...) { + UHD_LOG_DEBUG( + "PREFS", "Failed to load " << config_type << " config file " << path); } + } else { + UHD_LOG_TRACE( + "PREFS", "No " << config_type << " config file found at " << path); } } +} - void update_from_key( - const std::string& key, const std::string &value, - uhd::device_addr_t& user_args - ) { - if (value.empty()) { - return; - } - - const std::string key_str = key + "=" + value; - for (const auto& key : uhd::prefs::get_uhd_config().options(key_str)) { - user_args[key] = - uhd::prefs::get_uhd_config().get(key_str, key); - } +void update_from_key( + const std::string& key, const std::string& value, uhd::device_addr_t& user_args) +{ + if (value.empty()) { + return; } - device_addr_t get_args( - const uhd::device_addr_t& user_args, - const std::vector& keys_to_update_from - ) { - device_addr_t args; - for (const auto& key : keys_to_update_from) { - update_from_key(key, user_args.get(key, ""), args); - } + const std::string key_str = key + "=" + value; + for (const auto& key : uhd::prefs::get_uhd_config().options(key_str)) { + user_args[key] = uhd::prefs::get_uhd_config().get(key_str, key); + } +} - // Finally, copy over the original user args: - for (const auto& user_key : user_args.keys()) { - args[user_key] = user_args[user_key]; - } +device_addr_t get_args(const uhd::device_addr_t& user_args, + const std::vector& keys_to_update_from) +{ + device_addr_t args; + for (const auto& key : keys_to_update_from) { + update_from_key(key, user_args.get(key, ""), args); + } - return args; + // Finally, copy over the original user args: + for (const auto& user_key : user_args.keys()) { + args[user_key] = user_args[user_key]; } + + return args; } +} // namespace config_parser& uhd::prefs::get_uhd_config() { @@ -82,8 +77,8 @@ config_parser& uhd::prefs::get_uhd_config() const std::string sys_conf_file = path_expandvars(UHD_SYS_CONF_FILE); _update_conf_file(sys_conf_file, "system", _conf_files); const std::string user_conf_file = - (boost::filesystem::path(get_app_path()) - / std::string(UHD_USER_CONF_FILE)).string(); + (boost::filesystem::path(get_app_path()) / std::string(UHD_USER_CONF_FILE)) + .string(); _update_conf_file(user_conf_file, "user", _conf_files); std::string env_conf_file; try { // getenv into std::string can fail @@ -91,7 +86,7 @@ config_parser& uhd::prefs::get_uhd_config() env_conf_file = std::string(std::getenv(UHD_CONF_FILE_VAR)); } _update_conf_file(env_conf_file, "ENV", _conf_files); - } catch (const std::exception &) { + } catch (const std::exception&) { // nop } init_done = true; @@ -102,31 +97,20 @@ config_parser& uhd::prefs::get_uhd_config() } -device_addr_t uhd::prefs::get_usrp_args( - const uhd::device_addr_t &user_args -) { - const std::vector keys_to_update_from = { - "type", - "product", - "serial" - }; +device_addr_t uhd::prefs::get_usrp_args(const uhd::device_addr_t& user_args) +{ + const std::vector keys_to_update_from = {"type", "product", "serial"}; return get_args(user_args, keys_to_update_from); } -device_addr_t uhd::prefs::get_dpdk_args( - const uhd::device_addr_t &user_args -) { - const std::vector keys_to_update_from = { - "use_dpdk" - }; +device_addr_t uhd::prefs::get_dpdk_args(const uhd::device_addr_t& user_args) +{ + const std::vector keys_to_update_from = {"use_dpdk"}; return get_args(user_args, keys_to_update_from); } -device_addr_t uhd::prefs::get_dpdk_nic_args( - const uhd::device_addr_t &user_args -) { - const std::vector keys_to_update_from = { - "dpdk_mac" - }; +device_addr_t uhd::prefs::get_dpdk_nic_args(const uhd::device_addr_t& user_args) +{ + const std::vector keys_to_update_from = {"dpdk_mac"}; return get_args(user_args, keys_to_update_from); } -- cgit v1.2.3