diff options
author | Nicholas Corgan <nick.corgan@ettus.com> | 2015-08-12 12:19:20 -0700 |
---|---|---|
committer | Nicholas Corgan <nick.corgan@ettus.com> | 2015-08-12 12:19:20 -0700 |
commit | bc9dd05988454428de1b6efd235d980b8eaa9afe (patch) | |
tree | f61a72cfb1cfa81305e75e11a1646a12ed4b63cf /host/lib/error_c.cpp | |
parent | 95108f6f6ed6bf44fe38fc9e686fc9c5ae9c0e65 (diff) | |
download | uhd-bc9dd05988454428de1b6efd235d980b8eaa9afe.tar.gz uhd-bc9dd05988454428de1b6efd235d980b8eaa9afe.tar.bz2 uhd-bc9dd05988454428de1b6efd235d980b8eaa9afe.zip |
C API cleanup, feature additions
* Cleaned up usage of handles vs. handle pointers
* Store global string for last error thrown
* Removed uhd::device_addr_t handle, added std::vector<std::string> handle
Diffstat (limited to 'host/lib/error_c.cpp')
-rw-r--r-- | host/lib/error_c.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/host/lib/error_c.cpp b/host/lib/error_c.cpp index c3a83eec9..3ce63a81d 100644 --- a/host/lib/error_c.cpp +++ b/host/lib/error_c.cpp @@ -17,6 +17,11 @@ #include <uhd/error.h> #include <uhd/exception.hpp> +#include <uhd/utils/static.hpp> + +#include <boost/thread/mutex.hpp> + +#include <cstring> #define MAP_TO_ERROR(exception_type, error_type) \ if (dynamic_cast<const uhd::exception_type*>(e)) return error_type; @@ -38,3 +43,34 @@ uhd_error error_from_uhd_exception(const uhd::exception* e){ return UHD_ERROR_EXCEPT; } + +// Store the error string in a single place in library +UHD_SINGLETON_FCN(std::string, _c_global_error_string) + +static boost::mutex _error_c_mutex; + +const std::string& get_c_global_error_string(){ + boost::mutex::scoped_lock lock(_error_c_mutex); + return _c_global_error_string(); +} + +void set_c_global_error_string( + const std::string &msg +){ + boost::mutex::scoped_lock lock(_error_c_mutex); + _c_global_error_string() = msg; +} + +uhd_error uhd_get_last_error( + char* error_out, + size_t strbuffer_len +){ + try{ + memset(error_out, '\0', strbuffer_len); + strncpy(error_out, _c_global_error_string().c_str(), strbuffer_len); + } + catch(...){ + return UHD_ERROR_UNKNOWN; + } + return UHD_ERROR_NONE; +} |