diff options
author | Josh Blum <josh@joshknows.com> | 2010-04-29 06:29:54 +0000 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-04-29 06:29:54 +0000 |
commit | ef678a479cc4d4d60e16300e8654d19ebb6e43f0 (patch) | |
tree | da968df0580f1043b353d76ed550a56b35864974 /host/lib/load_modules.cpp | |
parent | 4e97e9c4845814994e1e9d3deabb5abd4d177738 (diff) | |
parent | c7df3878779cf461cef01d910e6c52c7ac3e1105 (diff) | |
download | uhd-ef678a479cc4d4d60e16300e8654d19ebb6e43f0.tar.gz uhd-ef678a479cc4d4d60e16300e8654d19ebb6e43f0.tar.bz2 uhd-ef678a479cc4d4d60e16300e8654d19ebb6e43f0.zip |
Merge branch 'master' of git@ettus.sourcerepo.com:ettus/uhdpriv into usrp_e
Diffstat (limited to 'host/lib/load_modules.cpp')
-rw-r--r-- | host/lib/load_modules.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/host/lib/load_modules.cpp b/host/lib/load_modules.cpp index ef633325d..d6bfe1369 100644 --- a/host/lib/load_modules.cpp +++ b/host/lib/load_modules.cpp @@ -20,10 +20,11 @@ #include <boost/foreach.hpp> #include <boost/algorithm/string.hpp> #include <boost/filesystem.hpp> +#include <boost/program_options.hpp> #include <iostream> #include <stdexcept> -#include <cstdlib> +namespace po = boost::program_options; namespace fs = boost::filesystem; /*********************************************************************** @@ -100,14 +101,39 @@ static void load_path(const fs::path &path){ } } +//! The string constant for the module path environment variable +static const std::string MODULE_PATH_KEY = "UHD_MODULE_PATH"; + +/*! + * Name mapper function for the environment variable parser. + * Map environment variable names (that we use) to option names. + * \param the variable name + * \return the option name or blank string + */ +static std::string name_mapper(const std::string &var_name){ + if (var_name == MODULE_PATH_KEY) return var_name; + return ""; +} + /*! * Load all the modules given by the module path enviroment variable. * The path variable may be several paths split by path separators. */ UHD_STATIC_BLOCK(load_modules){ - //get the environment variable module path - char *env_module_path = std::getenv("UHD_MODULE_PATH"); - if (env_module_path == NULL) return; + //register the options + std::string env_module_path; + po::options_description desc("UHD Module Options"); + desc.add_options() + (MODULE_PATH_KEY.c_str(), po::value<std::string>(&env_module_path)->default_value("")) + ; + + //parse environment variables + po::variables_map vm; + po::store(po::parse_environment(desc, &name_mapper), vm); + po::notify(vm); + + if (env_module_path == "") return; + //std::cout << "env_module_path: " << env_module_path << std::endl; //split the path at the path separators std::vector<std::string> module_paths; |