aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-05-04 20:40:36 -0700
committerJosh Blum <josh@joshknows.com>2011-05-04 20:40:36 -0700
commit9734a74366dd095256c2e2c58c5c9bcd7547f72d (patch)
tree34b169cd39dab8809937b6fc98eb57364521e61a
parent09be0518cee887878f3b070adea25eccc4c06e60 (diff)
downloaduhd-9734a74366dd095256c2e2c58c5c9bcd7547f72d.tar.gz
uhd-9734a74366dd095256c2e2c58c5c9bcd7547f72d.tar.bz2
uhd-9734a74366dd095256c2e2c58c5c9bcd7547f72d.zip
uhd: various tweaks to log and msg, replaced a few remaining stdio
-rw-r--r--host/include/uhd/utils/log.hpp9
-rw-r--r--host/include/uhd/utils/msg.hpp9
-rw-r--r--host/include/uhd/utils/safe_call.hpp4
-rw-r--r--host/lib/device.cpp5
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.cpp1
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp2
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp1
-rw-r--r--host/lib/usrp/usrp_e100/usrp_e100_impl.cpp1
-rw-r--r--host/lib/utils/log.cpp2
-rw-r--r--host/lib/utils/msg.cpp18
10 files changed, 27 insertions, 25 deletions
diff --git a/host/include/uhd/utils/log.hpp b/host/include/uhd/utils/log.hpp
index 666dfa982..8d8f42fd0 100644
--- a/host/include/uhd/utils/log.hpp
+++ b/host/include/uhd/utils/log.hpp
@@ -54,7 +54,7 @@
* Usage: UHD_LOGV(very_rarely) << "the log message" << std::endl;
*/
#define UHD_LOGV(verbosity) \
- uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
+ uhd::_log::log(uhd::_log::verbosity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)()
/*!
* A UHD logger macro with default verbosity.
@@ -85,12 +85,7 @@ namespace uhd{ namespace _log{
const std::string &function
);
~log(void);
-
- std::ostream &get(void);
-
- template <typename T> std::ostream &operator<<(const T &x){
- return get() << x;
- }
+ std::ostream &operator()(void);
};
}} //namespace uhd::_log
diff --git a/host/include/uhd/utils/msg.hpp b/host/include/uhd/utils/msg.hpp
index 2313215bf..17179f551 100644
--- a/host/include/uhd/utils/msg.hpp
+++ b/host/include/uhd/utils/msg.hpp
@@ -27,7 +27,7 @@
* Usage: UHD_MSG(warning) << "some warning message" << std::endl;
*/
#define UHD_MSG(type) \
- uhd::msg::_msg(uhd::msg::type)
+ uhd::msg::_msg(uhd::msg::type)()
namespace uhd{ namespace msg{
@@ -55,12 +55,7 @@ namespace uhd{ namespace msg{
struct UHD_API_FUTURE _msg{
_msg(const type_t type);
~_msg(void);
-
- std::ostream &get(void);
-
- template <typename T> std::ostream &operator<<(const T &x){
- return get() << x;
- }
+ std::ostream &operator()(void);
};
}} //namespace uhd::msg
diff --git a/host/include/uhd/utils/safe_call.hpp b/host/include/uhd/utils/safe_call.hpp
index b9f545b23..ab287cc66 100644
--- a/host/include/uhd/utils/safe_call.hpp
+++ b/host/include/uhd/utils/safe_call.hpp
@@ -20,10 +20,10 @@
#include <uhd/config.hpp>
#include <uhd/exception.hpp>
-#include <uhd/utils/msg.hpp>
+#include <uhd/utils/log.hpp>
//! helper macro for safe call to produce warnings
-#define _UHD_SAFE_CALL_WARNING(code, what) UHD_MSG(warning) << \
+#define _UHD_SAFE_CALL_WARNING(code, what) UHD_LOGV(rarely) << \
UHD_THROW_SITE_INFO("Exception caught in safe-call.") + #code + " -> " + what \
;
diff --git a/host/lib/device.cpp b/host/lib/device.cpp
index 84b4d5452..c5bc047da 100644
--- a/host/lib/device.cpp
+++ b/host/lib/device.cpp
@@ -18,6 +18,7 @@
#include <uhd/device.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/exception.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/utils/msg.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/algorithm.hpp>
@@ -65,7 +66,7 @@ void device::register_device(
const find_t &find,
const make_t &make
){
- //std::cout << "registering device" << std::endl;
+ UHD_LOGV(always) << "registering device" << std::endl;
get_dev_fcn_regs().push_back(dev_fcn_reg_t(find, make));
}
@@ -128,7 +129,7 @@ device::sptr device::make(const device_addr_t &hint, size_t which){
device_addr_t dev_addr; make_t maker;
boost::tie(dev_addr, maker) = dev_addr_makers.at(which);
size_t dev_hash = hash_device_addr(dev_addr);
- //std::cout << boost::format("Hash: %u") % dev_hash << std::endl;
+ UHD_LOG << boost::format("Device hash: %u") % dev_hash << std::endl;
//copy keys that were in hint but not in dev_addr
//this way, we can pass additional transport arguments
diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp
index 182705034..57aae1b58 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.cpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.cpp
@@ -123,6 +123,7 @@ static device_addrs_t usrp1_find(const device_addr_t &hint)
* Make
**********************************************************************/
static device::sptr usrp1_make(const device_addr_t &device_addr){
+ UHD_MSG(status) << "Opening a USRP1 device..." << std::endl;
//extract the FPGA path for the USRP1
std::string usrp1_fpga_image = find_image_path(
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index daccc0865..c9931be45 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -142,7 +142,7 @@ usrp2_mboard_impl::usrp2_mboard_impl(
else {
_mimo_clocking_mode_is_master = (_iface->peek32(_iface->regs.status) & (1 << 8)) != 0;
}
- UHD_MSG(status) << boost::format("mboard%d MIMO %s") % _index %
+ UHD_MSG(status) << boost::format("mboard%d is MIMO %s") % _index %
(_mimo_clocking_mode_is_master?"master":"slave") << std::endl;
//init the clock config
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 4eb5508e2..2bc259657 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -228,6 +228,7 @@ static mtu_result_t determine_mtu(const std::string &addr, const mtu_result_t &u
* Structors
**********************************************************************/
usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){
+ UHD_MSG(status) << "Opening a USRP2/N-Series device..." << std::endl;
device_addr_t device_addr = _device_addr;
//setup the dsp transport hints (default to a large recv buff)
diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp
index 4247746ab..00d7dd029 100644
--- a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp
+++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp
@@ -77,6 +77,7 @@ static device_addrs_t usrp_e100_find(const device_addr_t &hint){
* Make
**********************************************************************/
static device::sptr usrp_e100_make(const device_addr_t &device_addr){
+ UHD_MSG(status) << "Opening a USRP E-Series device..." << std::endl;
//setup the main interface into fpga
std::string node = device_addr["node"];
diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp
index f67a14411..8b270af6b 100644
--- a/host/lib/utils/log.cpp
+++ b/host/lib/utils/log.cpp
@@ -209,6 +209,6 @@ uhd::_log::log::~log(void){
uhd_logger_stream_resource().aquire(false);
}
-std::ostream & uhd::_log::log::get(void){
+std::ostream & uhd::_log::log::operator()(void){
return uhd_logger_stream_resource().get();
}
diff --git a/host/lib/utils/msg.cpp b/host/lib/utils/msg.cpp
index 0eaca05a5..e850b5a6d 100644
--- a/host/lib/utils/msg.cpp
+++ b/host/lib/utils/msg.cpp
@@ -34,11 +34,19 @@
static void msg_to_cout(const std::string &msg){
std::stringstream ss;
- BOOST_FOREACH(const std::string &line, tokenizer(msg, "\n")){
- ss << "-- " << line << std::endl;
+ static bool just_had_a_newline = true;
+ BOOST_FOREACH(char ch, msg){
+ if (just_had_a_newline){
+ just_had_a_newline = false;
+ ss << "-- ";
+ }
+ if (ch == '\n'){
+ just_had_a_newline = true;
+ }
+ ss << ch;
}
- std::cout << ss.str();
+ std::cout << ss.str() << std::flush;
}
static void msg_to_cerr(const std::string &title, const std::string &msg){
@@ -49,7 +57,7 @@ static void msg_to_cerr(const std::string &title, const std::string &msg){
ss << " " << line << std::endl;
}
- std::cerr << ss.str();
+ std::cerr << ss.str() << std::flush;
}
/***********************************************************************
@@ -110,6 +118,6 @@ uhd::msg::_msg::~_msg(void){
msg_mutex.unlock();
}
-std::ostream & uhd::msg::_msg::get(void){
+std::ostream & uhd::msg::_msg::operator()(void){
return msg_ss;
}