diff options
author | Josh Blum <josh@joshknows.com> | 2010-10-28 18:23:27 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-10-28 18:23:27 -0700 |
commit | a8d2c2944b329218af1c0b171b92f775b679b409 (patch) | |
tree | 02e558d525055cb82e8d00a7a2d75fe324015ae6 /host/lib/utils | |
parent | ef8ed898cbc6cb6cd1994d2a8b090112f4f3a664 (diff) | |
parent | 6a3e499f586513d48ef648aa910e252b7d8b046b (diff) | |
download | uhd-a8d2c2944b329218af1c0b171b92f775b679b409.tar.gz uhd-a8d2c2944b329218af1c0b171b92f775b679b409.tar.bz2 uhd-a8d2c2944b329218af1c0b171b92f775b679b409.zip |
Merge branch 'next'
Diffstat (limited to 'host/lib/utils')
-rw-r--r-- | host/lib/utils/thread_priority.cpp | 2 | ||||
-rw-r--r-- | host/lib/utils/warning.cpp | 59 |
2 files changed, 56 insertions, 5 deletions
diff --git a/host/lib/utils/thread_priority.cpp b/host/lib/utils/thread_priority.cpp index f09d1b1d6..40b74f655 100644 --- a/host/lib/utils/thread_priority.cpp +++ b/host/lib/utils/thread_priority.cpp @@ -26,7 +26,7 @@ bool uhd::set_thread_priority_safe(float priority, bool realtime){ set_thread_priority(priority, realtime); return true; }catch(const std::exception &e){ - uhd::print_warning(str(boost::format( + uhd::warning::post(str(boost::format( "%s\n" "Failed to set thread priority %d (%s):\n" "Performance may be negatively affected.\n" diff --git a/host/lib/utils/warning.cpp b/host/lib/utils/warning.cpp index 8a7d35a23..05be7ae4d 100644 --- a/host/lib/utils/warning.cpp +++ b/host/lib/utils/warning.cpp @@ -17,16 +17,67 @@ #include <uhd/utils/warning.hpp> #include <uhd/utils/algorithm.hpp> +#include <uhd/utils/static.hpp> +#include <uhd/types/dict.hpp> #include <boost/foreach.hpp> +#include <sstream> +#include <stdexcept> #include <iostream> #include <vector> using namespace uhd; -void uhd::print_warning(const std::string &msg){ - //print the warning message - std::cerr << std::endl << "Warning:" << std::endl; +/*********************************************************************** + * Registry implementation + **********************************************************************/ +//create the registry for the handlers +typedef uhd::dict<std::string, warning::handler_t> registry_t; +UHD_SINGLETON_FCN(registry_t, get_registry) + +//the default warning handler +static void stderr_warning(const std::string &msg){ + std::cerr << msg; +} + +//register a default handler +UHD_STATIC_BLOCK(warning_register_default){ + warning::register_handler("default", &stderr_warning); +} + +/*********************************************************************** + * Post + format + **********************************************************************/ +void warning::post(const std::string &msg){ + std::stringstream ss; + + //format the warning message + ss << std::endl << "Warning:" << std::endl; BOOST_FOREACH(const std::string &line, std::split_string(msg, "\n")){ - std::cerr << " " << line << std::endl; + ss << " " << line << std::endl; + } + + //post the formatted message + BOOST_FOREACH(const std::string &name, get_registry().keys()){ + get_registry()[name](ss.str()); } } + +/*********************************************************************** + * Registry accessor functions + **********************************************************************/ +void warning::register_handler( + const std::string &name, const handler_t &handler +){ + get_registry()[name] = handler; +} + +warning::handler_t warning::unregister_handler(const std::string &name){ + if (not get_registry().has_key(name)) throw std::runtime_error( + "The warning registry does not have a handler registered to " + name + ); + return get_registry().pop(name); +} + +const std::vector<std::string> warning::registry_names(void){ + return get_registry().keys(); +} |