root / include / usrp_uhd / gain_handler.hpp @ cc8caeb1
History | View | Annotate | Download (3.13 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include <boost/shared_ptr.hpp> |
| 19 |
#include <usrp_uhd/wax.hpp> |
| 20 |
#include <usrp_uhd/props.hpp> |
| 21 |
#include <boost/function.hpp> |
| 22 |
#include <boost/bind.hpp> |
| 23 |
|
| 24 |
#ifndef INCLUDED_USRP_UHD_GAIN_HANDLER_HPP
|
| 25 |
#define INCLUDED_USRP_UHD_GAIN_HANDLER_HPP
|
| 26 |
|
| 27 |
namespace usrp_uhd{
|
| 28 |
|
| 29 |
class gain_handler{ |
| 30 |
public:
|
| 31 |
typedef boost::shared_ptr<gain_handler> sptr;
|
| 32 |
|
| 33 |
template <class T> gain_handler( |
| 34 |
wax::obj::ptr wax_obj_ptr, const T &gain_prop,
|
| 35 |
const T &gain_min_prop, const T &gain_max_prop, |
| 36 |
const T &gain_step_prop, const T &gain_names_prop |
| 37 |
){
|
| 38 |
_wax_obj_ptr = wax_obj_ptr; |
| 39 |
_gain_prop = gain_prop; |
| 40 |
_gain_min_prop = gain_min_prop; |
| 41 |
_gain_max_prop = gain_max_prop; |
| 42 |
_gain_step_prop = gain_step_prop; |
| 43 |
_gain_names_prop = gain_names_prop; |
| 44 |
_is_equal = boost::bind(&gain_handler::is_equal<T>, _1, _2); |
| 45 |
} |
| 46 |
|
| 47 |
~gain_handler(void);
|
| 48 |
|
| 49 |
/*!
|
| 50 |
* Intercept gets for overall gain, min, max, step.
|
| 51 |
* Ensures that the gain name is valid.
|
| 52 |
* \return true for handled, false to pass on
|
| 53 |
*/
|
| 54 |
bool intercept_get(const wax::obj &key, wax::obj &val); |
| 55 |
|
| 56 |
/*!
|
| 57 |
* Intercept sets for overall gain.
|
| 58 |
* Ensures that the gain name is valid.
|
| 59 |
* Ensures that the new gain is within range.
|
| 60 |
* \return true for handled, false to pass on
|
| 61 |
*/
|
| 62 |
bool intercept_set(const wax::obj &key, const wax::obj &val); |
| 63 |
|
| 64 |
private:
|
| 65 |
|
| 66 |
wax::obj::ptr _wax_obj_ptr; |
| 67 |
wax::obj _gain_prop; |
| 68 |
wax::obj _gain_min_prop; |
| 69 |
wax::obj _gain_max_prop; |
| 70 |
wax::obj _gain_step_prop; |
| 71 |
wax::obj _gain_names_prop; |
| 72 |
|
| 73 |
/*!
|
| 74 |
* Verify that the key is valid:
|
| 75 |
* If its a named prop for gain, ensure that name is valid.
|
| 76 |
* If the name if not valid, throw a std::invalid_argument.
|
| 77 |
* The name can only be valid if its in the list of gain names.
|
| 78 |
*/
|
| 79 |
void _check_key(const wax::obj &key); |
| 80 |
|
| 81 |
/*
|
| 82 |
* Private interface to test if two wax types are equal:
|
| 83 |
* The constructor will bind an instance of this for a specific type.
|
| 84 |
* This bound equals functions allows the intercept methods to be non-templated.
|
| 85 |
*/
|
| 86 |
template <class T> static bool is_equal(const wax::obj &a, const wax::obj &b){ |
| 87 |
try{
|
| 88 |
return wax::cast<T>(a) == wax::cast<T>(b);
|
| 89 |
} |
| 90 |
catch(const wax::bad_cast &){ |
| 91 |
return false; |
| 92 |
} |
| 93 |
} |
| 94 |
boost::function<bool(const wax::obj &, const wax::obj &)> _is_equal; |
| 95 |
|
| 96 |
}; |
| 97 |
|
| 98 |
} //namespace usrp_uhd
|
| 99 |
|
| 100 |
#endif /* INCLUDED_USRP_UHD_GAIN_HANDLER_HPP */ |
| 101 |
|