aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/error_c.cpp
diff options
context:
space:
mode:
authorAshish Chaudhari <ashish@ettus.com>2015-08-12 16:33:26 -0700
committerAshish Chaudhari <ashish@ettus.com>2015-08-12 16:33:26 -0700
commitd745b5cf6d9a918be141339ceca5fbf9d6259eab (patch)
treee08c449fe7041b734cd537cdca06f68dac219387 /host/lib/error_c.cpp
parent094bf7607362b08663c1b94ca05432da519036c5 (diff)
parentbc9dd05988454428de1b6efd235d980b8eaa9afe (diff)
downloaduhd-d745b5cf6d9a918be141339ceca5fbf9d6259eab.tar.gz
uhd-d745b5cf6d9a918be141339ceca5fbf9d6259eab.tar.bz2
uhd-d745b5cf6d9a918be141339ceca5fbf9d6259eab.zip
Merge branch 'master' into ashish/register_api
Diffstat (limited to 'host/lib/error_c.cpp')
-rw-r--r--host/lib/error_c.cpp36
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;
+}