diff options
-rw-r--r-- | host/include/uhd/utils/paths.hpp | 3 | ||||
-rw-r--r-- | host/lib/utils/paths.cpp | 19 | ||||
-rw-r--r-- | host/tests/paths_test.cpp | 4 |
3 files changed, 25 insertions, 1 deletions
diff --git a/host/include/uhd/utils/paths.hpp b/host/include/uhd/utils/paths.hpp index e5b451542..f55f584a5 100644 --- a/host/include/uhd/utils/paths.hpp +++ b/host/include/uhd/utils/paths.hpp @@ -29,6 +29,9 @@ UHD_API std::string get_lib_path(void); //! Get a string representing the system's pkg directory UHD_API std::string get_pkg_path(void); +//! Get a string representing the location of the calibration database +UHD_API std::string get_cal_data_path(void); + //! Get UHD library paths UHD_API std::vector<fs::path> get_module_paths(void); diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 326551c8c..ccf52f257 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -214,6 +214,25 @@ std::string uhd::get_lib_path(void) } #endif +std::string uhd::get_cal_data_path(void) +{ + const std::string uhdcalib_path = get_env_var("UHD_CAL_DATA_PATH"); + if (not uhdcalib_path.empty()) { + return uhdcalib_path; + } + + std::string xdg_data_home_str = get_env_var("XDG_DATA_HOME", ""); + fs::path xdg_data_home(xdg_data_home_str); + if (xdg_data_home_str.empty()) { + const std::string home = get_env_var("HOME", ""); + xdg_data_home = fs::path(home) / ".local" / "share"; + } + + // FIXME: This needs to check if paths make sense, work on Windows, etc. + + fs::path cal_data_path = fs::path(xdg_data_home) / "uhd" / "cal_data"; + return cal_data_path.string(); +} std::vector<fs::path> uhd::get_module_paths(void) { diff --git a/host/tests/paths_test.cpp b/host/tests/paths_test.cpp index 6ff496eb6..5115891b0 100644 --- a/host/tests/paths_test.cpp +++ b/host/tests/paths_test.cpp @@ -44,11 +44,13 @@ BOOST_AUTO_TEST_CASE(test_get_paths) const std::string tmp_path = get_tmp_path(); const std::string app_path = get_app_path(); const std::string pkg_path = get_pkg_path(); + const std::string cal_path = get_cal_data_path(); const auto module_paths = get_module_paths(); std::cout << "tmp_path: " << tmp_path << std::endl; std::cout << "app_path: " << app_path << std::endl; std::cout << "pkg_path: " << pkg_path << std::endl; + std::cout << "cal_path: " << cal_path << std::endl; for (const auto& module_path : module_paths) { std::cout << "module path: " << module_path << std::endl; } @@ -63,5 +65,5 @@ BOOST_AUTO_TEST_CASE(test_get_paths) const std::string utility_error = print_utility_error("uhd_images_downloader", "--help"); - std::cout << "utility_error: " << tmp_path << std::endl; + std::cout << "utility_error: " << utility_error << std::endl; } |