From bc9dd05988454428de1b6efd235d980b8eaa9afe Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Wed, 12 Aug 2015 12:19:20 -0700 Subject: 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 handle --- host/lib/error_c.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'host/lib/error_c.cpp') 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 #include +#include + +#include + +#include #define MAP_TO_ERROR(exception_type, error_type) \ if (dynamic_cast(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; +} -- cgit v1.2.3