diff options
-rw-r--r-- | host/include/uhd/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/utils/warning.hpp | 34 | ||||
-rw-r--r-- | host/lib/transport/udp_zero_copy_asio.cpp | 12 | ||||
-rw-r--r-- | host/lib/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/utils/warning.cpp | 36 | ||||
-rw-r--r-- | host/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/test/warning_test.cpp | 29 |
7 files changed, 108 insertions, 6 deletions
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index d484788b2..aa7842094 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -28,5 +28,6 @@ INSTALL(FILES safe_main.hpp static.hpp thread_priority.hpp + warning.hpp DESTINATION ${INCLUDE_DIR}/uhd/utils ) diff --git a/host/include/uhd/utils/warning.hpp b/host/include/uhd/utils/warning.hpp new file mode 100644 index 000000000..91d8400ab --- /dev/null +++ b/host/include/uhd/utils/warning.hpp @@ -0,0 +1,34 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef INCLUDED_UHD_UTILS_WARNING_HPP +#define INCLUDED_UHD_UTILS_WARNING_HPP + +#include <uhd/config.hpp> +#include <string> + +namespace uhd{ + + /*! + * Print a formatted warning string to stderr. + * \param msg the multiline warning message + */ + UHD_API void print_warning(const std::string &msg); + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_WARNING_HPP */ diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index bbbabf6d0..ee989ee2b 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -18,6 +18,7 @@ #include <uhd/transport/udp_zero_copy.hpp> #include <uhd/transport/udp_simple.hpp> //mtu #include <uhd/utils/assert.hpp> +#include <uhd/utils/warning.hpp> #include <boost/cstdint.hpp> #include <boost/asio.hpp> #include <boost/format.hpp> @@ -161,12 +162,11 @@ template<typename Opt> static void resize_buff_helper( else std::cout << boost::format( "Current %s sock buff size: %d bytes" ) % name % actual_size << std::endl; - if (actual_size < target_size) std::cerr << boost::format( - "Warning:\n" - " The %s buffer is smaller than the requested size.\n" - " The minimum recommended buffer size is %d bytes.\n" - " See the USRP2 application notes on buffer resizing.\n" - ) % name % min_sock_buff_size << std::endl; + if (actual_size < target_size) uhd::print_warning(str(boost::format( + "The %s buffer is smaller than the requested size.\n" + "The minimum recommended buffer size is %d bytes.\n" + "See the USRP2 application notes on buffer resizing.\n" + ) % name % min_sock_buff_size)); } //only enable on platforms that are happy with the large buffer resize diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 450112462..07e3b71b3 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -23,4 +23,5 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_SOURCE_DIR}/lib/utils/load_modules.cpp ${CMAKE_SOURCE_DIR}/lib/utils/props.cpp ${CMAKE_SOURCE_DIR}/lib/utils/thread_priority.cpp + ${CMAKE_SOURCE_DIR}/lib/utils/warning.cpp ) diff --git a/host/lib/utils/warning.cpp b/host/lib/utils/warning.cpp new file mode 100644 index 000000000..ae4d4c7aa --- /dev/null +++ b/host/lib/utils/warning.cpp @@ -0,0 +1,36 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd/utils/warning.hpp> +#include <boost/algorithm/string.hpp> +#include <boost/foreach.hpp> +#include <iostream> +#include <vector> + +using namespace uhd; + +void uhd::print_warning(const std::string &msg){ + //extract the message lines + std::vector<std::string> lines; + boost::split(lines, msg, boost::is_any_of("\n")); + + //print the warning message + std::cerr << std::endl << "Warning:" << std::endl; + BOOST_FOREACH(const std::string &line, lines){ + std::cerr << " " << line << std::endl; + } +} diff --git a/host/test/CMakeLists.txt b/host/test/CMakeLists.txt index b7dcb741a..ad2f33a3b 100644 --- a/host/test/CMakeLists.txt +++ b/host/test/CMakeLists.txt @@ -29,6 +29,7 @@ ADD_EXECUTABLE(main_test gain_handler_test.cpp tune_helper_test.cpp vrt_test.cpp + warning_test.cpp wax_test.cpp ) TARGET_LINK_LIBRARIES(main_test uhd) diff --git a/host/test/warning_test.cpp b/host/test/warning_test.cpp new file mode 100644 index 000000000..6202c4270 --- /dev/null +++ b/host/test/warning_test.cpp @@ -0,0 +1,29 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <boost/test/unit_test.hpp> +#include <uhd/utils/warning.hpp> +#include <iostream> + +BOOST_AUTO_TEST_CASE(test_print_warning){ + std::cerr << "---begin print test ---" << std::endl; + uhd::print_warning( + "This is a test print for a warning message.\n" + "And this is the second line of the test print.\n" + ); + std::cerr << "---end print test ---" << std::endl; +} |