summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gain_handler.cpp20
-rw-r--r--lib/usrp/dboard/base.cpp9
-rw-r--r--lib/usrp/dboard/basic.cpp8
-rw-r--r--lib/usrp/dboard/dboards.hpp8
-rw-r--r--lib/usrp/dboard/manager.cpp4
-rw-r--r--lib/usrp/mboard/test.cpp16
-rw-r--r--lib/usrp/usrp.cpp10
-rw-r--r--lib/wax.cpp97
8 files changed, 99 insertions, 73 deletions
diff --git a/lib/gain_handler.cpp b/lib/gain_handler.cpp
index 0c54a0b8b..3d0c38aa1 100644
--- a/lib/gain_handler.cpp
+++ b/lib/gain_handler.cpp
@@ -33,7 +33,7 @@ using namespace usrp_uhd;
/*!
* Helper function to simplify getting a named gain (also min, max, step).
*/
-static gain_t get_named_gain(wax::obj::ptr wax_obj_ptr, wax::type prop, std::string name){
+static gain_t get_named_gain(wax::obj::ptr wax_obj_ptr, wax::obj prop, std::string name){
return wax::cast<gain_t>((*wax_obj_ptr)[named_prop_t(prop, name)]);
}
@@ -44,9 +44,9 @@ gain_handler::~gain_handler(void){
/* NOP */
}
-void gain_handler::_check_key(const wax::type &key_){
- wax::type key; std::string name;
- tie(key, name) = extract_named_prop(key_);
+void gain_handler::_check_key(const wax::obj &key_){
+ wax::obj key; std::string name;
+ boost::tie(key, name) = extract_named_prop(key_);
try{
//only handle non wildcard names
@@ -72,13 +72,13 @@ void gain_handler::_check_key(const wax::type &key_){
catch(const std::assert_error &){}
}
-bool gain_handler::intercept_get(const wax::type &key, wax::type &val){
+bool gain_handler::intercept_get(const wax::obj &key, wax::obj &val){
_check_key(key); //verify the key
// use a vector of tuples to map properties to a reducer function
- // we cant use a map because the wax::type cant be sorted
+ // we cant use a map because the wax::obj cant be sorted
typedef boost::function<gain_t(gain_t, gain_t)> reducer_t;
- typedef boost::tuple<wax::type, reducer_t> tuple_t;
+ typedef boost::tuple<wax::obj, reducer_t> tuple_t;
reducer_t reducer_sum = boost::bind(std::sum<gain_t>, _1, _2);
reducer_t reducer_max = boost::bind(std::max<gain_t>, _1, _2);
std::vector<tuple_t> prop_to_reducer = boost::assign::tuple_list_of
@@ -108,11 +108,11 @@ bool gain_handler::intercept_get(const wax::type &key, wax::type &val){
return false;
}
-bool gain_handler::intercept_set(const wax::type &key_, const wax::type &val){
+bool gain_handler::intercept_set(const wax::obj &key_, const wax::obj &val){
_check_key(key_); //verify the key
- wax::type key; std::string name;
- tie(key, name) = extract_named_prop(key_);
+ wax::obj key; std::string name;
+ boost::tie(key, name) = extract_named_prop(key_);
/*!
* Verify that a named gain component is in range.
diff --git a/lib/usrp/dboard/base.cpp b/lib/usrp/dboard/base.cpp
index 1dd722ed1..18489f3b2 100644
--- a/lib/usrp/dboard/base.cpp
+++ b/lib/usrp/dboard/base.cpp
@@ -16,6 +16,7 @@
//
#include <usrp_uhd/usrp/dboard/base.hpp>
+#include <stdexcept>
using namespace usrp_uhd::usrp::dboard;
@@ -60,11 +61,11 @@ rx_base::~rx_base(void){
/* NOP */
}
-void rx_base::tx_get(const wax::type &, wax::type &){
+void rx_base::tx_get(const wax::obj &, wax::obj &){
throw std::runtime_error("cannot call tx_get on a rx dboard");
}
-void rx_base::tx_set(const wax::type &, const wax::type &){
+void rx_base::tx_set(const wax::obj &, const wax::obj &){
throw std::runtime_error("cannot call tx_set on a rx dboard");
}
@@ -79,10 +80,10 @@ tx_base::~tx_base(void){
/* NOP */
}
-void tx_base::rx_get(const wax::type &, wax::type &){
+void tx_base::rx_get(const wax::obj &, wax::obj &){
throw std::runtime_error("cannot call rx_get on a tx dboard");
}
-void tx_base::rx_set(const wax::type &, const wax::type &){
+void tx_base::rx_set(const wax::obj &, const wax::obj &){
throw std::runtime_error("cannot call rx_set on a tx dboard");
}
diff --git a/lib/usrp/dboard/basic.cpp b/lib/usrp/dboard/basic.cpp
index d92d02eec..35512aa5f 100644
--- a/lib/usrp/dboard/basic.cpp
+++ b/lib/usrp/dboard/basic.cpp
@@ -28,11 +28,11 @@ basic_rx::~basic_rx(void){
/* NOP */
}
-void basic_rx::rx_get(const wax::type &, wax::type &){
+void basic_rx::rx_get(const wax::obj &, wax::obj &){
/* TODO */
}
-void basic_rx::rx_set(const wax::type &, const wax::type &){
+void basic_rx::rx_set(const wax::obj &, const wax::obj &){
/* TODO */
}
@@ -47,10 +47,10 @@ basic_tx::~basic_tx(void){
/* NOP */
}
-void basic_tx::tx_get(const wax::type &, wax::type &){
+void basic_tx::tx_get(const wax::obj &, wax::obj &){
/* TODO */
}
-void basic_tx::tx_set(const wax::type &, const wax::type &){
+void basic_tx::tx_set(const wax::obj &, const wax::obj &){
/* TODO */
}
diff --git a/lib/usrp/dboard/dboards.hpp b/lib/usrp/dboard/dboards.hpp
index 35433bb3a..218849eb6 100644
--- a/lib/usrp/dboard/dboards.hpp
+++ b/lib/usrp/dboard/dboards.hpp
@@ -33,8 +33,8 @@ public:
basic_rx(ctor_args_t const& args);
~basic_rx(void);
- void rx_get(const wax::type &key, wax::type &val);
- void rx_set(const wax::type &key, const wax::type &val);
+ void rx_get(const wax::obj &key, wax::obj &val);
+ void rx_set(const wax::obj &key, const wax::obj &val);
};
class basic_tx : public tx_base{
@@ -45,8 +45,8 @@ public:
basic_tx(ctor_args_t const& args);
~basic_tx(void);
- void tx_get(const wax::type &key, wax::type &val);
- void tx_set(const wax::type &key, const wax::type &val);
+ void tx_get(const wax::obj &key, wax::obj &val);
+ void tx_set(const wax::obj &key, const wax::obj &val);
};
diff --git a/lib/usrp/dboard/manager.cpp b/lib/usrp/dboard/manager.cpp
index fcdde84db..12cfdd156 100644
--- a/lib/usrp/dboard/manager.cpp
+++ b/lib/usrp/dboard/manager.cpp
@@ -93,7 +93,7 @@ private:
type_t _type;
//forward the get calls to the rx or tx
- void get(const wax::type &key, wax::type &val){
+ void get(const wax::obj &key, wax::obj &val){
switch(_type){
case RX_TYPE: return _subdev->rx_get(key, val);
case TX_TYPE: return _subdev->tx_get(key, val);
@@ -101,7 +101,7 @@ private:
}
//forward the set calls to the rx or tx
- void set(const wax::type &key, const wax::type &val){
+ void set(const wax::obj &key, const wax::obj &val){
switch(_type){
case RX_TYPE: return _subdev->rx_set(key, val);
case TX_TYPE: return _subdev->tx_set(key, val);
diff --git a/lib/usrp/mboard/test.cpp b/lib/usrp/mboard/test.cpp
index 071a10c2b..57482448c 100644
--- a/lib/usrp/mboard/test.cpp
+++ b/lib/usrp/mboard/test.cpp
@@ -59,9 +59,9 @@ public:
}
~shell_dboard(void){}
private:
- void get(const wax::type &key_, wax::type &val){
- wax::type key; std::string name;
- tie(key, name) = extract_named_prop(key_);
+ void get(const wax::obj &key_, wax::obj &val){
+ wax::obj key; std::string name;
+ boost::tie(key, name) = extract_named_prop(key_);
//handle the get request conditioned on the key
switch(wax::cast<dboard_prop_t>(key)){
@@ -97,7 +97,7 @@ private:
}
}
- void set(const wax::type &, const wax::type &){
+ void set(const wax::obj &, const wax::obj &){
throw std::runtime_error("Cannot set on usrp test dboard");
}
@@ -122,9 +122,9 @@ test::~test(void){
/* NOP */
}
-void test::get(const wax::type &key_, wax::type &val){
- wax::type key; std::string name;
- tie(key, name) = extract_named_prop(key_);
+void test::get(const wax::obj &key_, wax::obj &val){
+ wax::obj key; std::string name;
+ boost::tie(key, name) = extract_named_prop(key_);
//handle the get request conditioned on the key
switch(wax::cast<mboard_prop_t>(key)){
@@ -179,6 +179,6 @@ void test::get(const wax::type &key_, wax::type &val){
}
}
-void test::set(const wax::type &, const wax::type &){
+void test::set(const wax::obj &, const wax::obj &){
throw std::runtime_error("Cannot set on usrp test mboard");
}
diff --git a/lib/usrp/usrp.cpp b/lib/usrp/usrp.cpp
index 56bfd37fc..e3016be5f 100644
--- a/lib/usrp/usrp.cpp
+++ b/lib/usrp/usrp.cpp
@@ -54,9 +54,9 @@ usrp::~usrp(void){
/* NOP */
}
-void usrp::get(const wax::type &key_, wax::type &val){
- wax::type key; std::string name;
- tie(key, name) = extract_named_prop(key_);
+void usrp::get(const wax::obj &key_, wax::obj &val){
+ wax::obj key; std::string name;
+ boost::tie(key, name) = extract_named_prop(key_);
//handle the get request conditioned on the key
switch(wax::cast<device_prop_t>(key)){
@@ -70,7 +70,7 @@ void usrp::get(const wax::type &key_, wax::type &val){
);
//turn the mboard sptr object into a wax::obj::sptr
//this allows the properties access through the wax::proxy
- val = wax::obj::cast(_mboards[name]);
+ val = _mboards[name]->get_link();
return;
case DEVICE_PROP_MBOARD_NAMES:
@@ -79,7 +79,7 @@ void usrp::get(const wax::type &key_, wax::type &val){
}
}
-void usrp::set(const wax::type &, const wax::type &){
+void usrp::set(const wax::obj &, const wax::obj &){
throw std::runtime_error("Cannot set in usrp device");
}
diff --git a/lib/wax.cpp b/lib/wax.cpp
index 025aa1766..2a6fdc3bb 100644
--- a/lib/wax.cpp
+++ b/lib/wax.cpp
@@ -19,6 +19,15 @@
#include <stdexcept>
#include <boost/bind.hpp>
#include <boost/format.hpp>
+#include <boost/function.hpp>
+
+/***********************************************************************
+ * Proxy Contents
+ **********************************************************************/
+struct proxy_args_t{
+ boost::function<void(wax::obj &)> get;
+ boost::function<void(const wax::obj &)> set;
+};
/***********************************************************************
* WAX Object
@@ -27,58 +36,74 @@ wax::obj::obj(void){
/* NOP */
}
+wax::obj::obj(const obj &o){
+ _contents = o._contents;
+}
+
wax::obj::~obj(void){
/* NOP */
}
-wax::proxy wax::obj::operator[](const type &key){
- return proxy(
- boost::bind(&obj::get, this, key, _1),
- boost::bind(&obj::set, this, key, _1)
- );
+wax::obj wax::obj::operator[](const obj &key){
+ if (_contents.type() == typeid(proxy_args_t)){
+ obj val = resolve();
+ //check if its a regular pointer and call
+ if (val.type() == typeid(obj::ptr)){
+ return (*cast<obj::ptr>(val))[key];
+ }
+ //check if its a smart pointer and call
+ if (val.type() == typeid(obj::sptr)){
+ return (*cast<obj::sptr>(val))[key];
+ }
+ //unknown obj
+ throw std::runtime_error("cannot use [] on non wax::obj pointer");
+ }
+ else{
+ proxy_args_t proxy_args;
+ proxy_args.get = boost::bind(&obj::get, this, key, _1);
+ proxy_args.set = boost::bind(&obj::set, this, key, _1);
+ return wax::obj(proxy_args);
+ }
}
-/***********************************************************************
- * WAX Proxy
- **********************************************************************/
-wax::proxy::proxy(wax::proxy::getter_t getter, wax::proxy::setter_t setter)
-: d_getter(getter), d_setter(setter){
- /* NOP */
+wax::obj & wax::obj::operator=(const obj &val){
+ if (_contents.type() == typeid(proxy_args_t)){
+ boost::any_cast<proxy_args_t>(_contents).set(val);
+ }
+ else{
+ _contents = val._contents;
+ }
+ return *this;
}
-wax::proxy::~proxy(void){
- /* NOP */
+wax::obj wax::obj::get_link(void) const{
+ return ptr(this);
+}
+
+const std::type_info & wax::obj::type(void) const{
+ return _contents.type();
}
-wax::proxy wax::proxy::operator[](const type &key){
- type val((*this)());
- //check if its a regular pointer and call
- if (val.type() == typeid(obj::ptr)){
- return (*cast<obj::ptr>(val))[key];
+boost::any wax::obj::resolve(void) const{
+ if (_contents.type() == typeid(proxy_args_t)){
+ obj val;
+ boost::any_cast<proxy_args_t>(_contents).get(val);
+ return val.resolve();
}
- //check if its a smart pointer and call
- if (val.type() == typeid(obj::sptr)){
- return (*cast<obj::sptr>(val))[key];
+ else{
+ return _contents;
}
- //unknown type
- throw std::runtime_error("cannot use [] on non wax::obj pointer");
}
-wax::proxy wax::proxy::operator=(const type &val){
- d_setter(val);
- return *this;
+std::ostream& operator<<(std::ostream &os, const wax::obj &x){
+ os << boost::format("WAX obj (%s)") % x.type().name();
+ return os;
}
-wax::type wax::proxy::operator()(void){
- type val;
- d_getter(val);
- return val;
+void wax::obj::get(const obj &, obj &){
+ throw std::runtime_error("Cannot call get on wax obj base class");
}
-/***********************************************************************
- * WAX Type
- **********************************************************************/
-std::ostream& operator<<(std::ostream &os, const wax::type &x){
- os << boost::format("WAX type (%s)") % x.type().name();
- return os;
+void wax::obj::set(const obj &, const obj &){
+ throw std::runtime_error("Cannot call set on wax obj base class");
}