summaryrefslogtreecommitdiffstats
path: root/host/lib/utils
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-10-26 14:14:01 -0700
committerJosh Blum <josh@joshknows.com>2010-10-26 14:14:01 -0700
commitcea3d05095202413be12cd4792ab9f781cbccef7 (patch)
tree0b588edfcf3f1173abfcf9c656fac3e824e2d532 /host/lib/utils
parent0168bff835371140c0d75cc381e3228f8093fe70 (diff)
downloaduhd-cea3d05095202413be12cd4792ab9f781cbccef7.tar.gz
uhd-cea3d05095202413be12cd4792ab9f781cbccef7.tar.bz2
uhd-cea3d05095202413be12cd4792ab9f781cbccef7.zip
uhd: replaced print warning with a post warning call and registry
renamed print warning calls in the implementation fixed issue with dict::pop so it now works even if the value is not comparable
Diffstat (limited to 'host/lib/utils')
-rw-r--r--host/lib/utils/thread_priority.cpp2
-rw-r--r--host/lib/utils/warning.cpp59
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();
+}