aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/device.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-03-02 15:25:13 -0800
committeratrnati <54334261+atrnati@users.noreply.github.com>2020-03-03 08:51:32 -0600
commit876d4150aa3da531ddd687b48afada6e43f79146 (patch)
treefd72a71419f4cd800d4e500cfcaded4dfc8dc367 /host/lib/device.cpp
parent1393553d623bdf4ba40d5435c9719b6ce990d9ac (diff)
downloaduhd-876d4150aa3da531ddd687b48afada6e43f79146.tar.gz
uhd-876d4150aa3da531ddd687b48afada6e43f79146.tar.bz2
uhd-876d4150aa3da531ddd687b48afada6e43f79146.zip
uhd: Apply clang-format against all .cpp and .hpp files in host/
Note: template_lvbitx.{cpp,hpp} need to be excluded from the list of files that clang-format gets applied against.
Diffstat (limited to 'host/lib/device.cpp')
-rw-r--r--host/lib/device.cpp140
1 files changed, 62 insertions, 78 deletions
diff --git a/host/lib/device.cpp b/host/lib/device.cpp
index 752e70288..9fdbc03ed 100644
--- a/host/lib/device.cpp
+++ b/host/lib/device.cpp
@@ -6,18 +6,15 @@
//
#include <uhd/device.hpp>
-#include <uhd/types/dict.hpp>
#include <uhd/exception.hpp>
+#include <uhd/types/dict.hpp>
+#include <uhd/utils/algorithm.hpp>
#include <uhd/utils/log.hpp>
-
#include <uhd/utils/static.hpp>
-#include <uhd/utils/algorithm.hpp>
#include <uhdlib/utils/prefs.hpp>
-
#include <boost/format.hpp>
#include <boost/functional/hash.hpp>
#include <boost/thread/mutex.hpp>
-
#include <future>
#include <memory>
#include <tuple>
@@ -35,30 +32,23 @@ static boost::mutex _device_mutex;
* \param dev_addr the device address
* \return the hash number
*/
-static size_t hash_device_addr(
- const device_addr_t &dev_addr
-){
- //combine the hashes of sorted keys/value pairs
+static size_t hash_device_addr(const device_addr_t& dev_addr)
+{
+ // combine the hashes of sorted keys/value pairs
size_t hash = 0;
// The device addr can contain all sorts of stuff, which sometimes gets in
// the way of hashing reliably. TODO: Make this a whitelist
const std::vector<std::string> hash_key_blacklist = {
- "claimed",
- "skip_dram",
- "skip_ddc",
- "skip_duc"
- };
+ "claimed", "skip_dram", "skip_ddc", "skip_duc"};
- if(dev_addr.has_key("resource")) {
+ if (dev_addr.has_key("resource")) {
boost::hash_combine(hash, "resource");
boost::hash_combine(hash, dev_addr["resource"]);
- }
- else {
- for (const std::string &key: uhd::sorted(dev_addr.keys())) {
- if (std::find(hash_key_blacklist.begin(),
- hash_key_blacklist.end(),
- key) == hash_key_blacklist.end()) {
+ } else {
+ for (const std::string& key : uhd::sorted(dev_addr.keys())) {
+ if (std::find(hash_key_blacklist.begin(), hash_key_blacklist.end(), key)
+ == hash_key_blacklist.end()) {
boost::hash_combine(hash, key);
boost::hash_combine(hash, dev_addr[key]);
}
@@ -76,45 +66,38 @@ typedef std::tuple<device::find_t, device::make_t, device::device_filter_t> dev_
UHD_SINGLETON_FCN(std::vector<dev_fcn_reg_t>, get_dev_fcn_regs)
void device::register_device(
- const find_t &find,
- const make_t &make,
- const device_filter_t filter
-){
+ const find_t& find, const make_t& make, const device_filter_t filter)
+{
// UHD_LOGGER_TRACE("UHD") << "registering device";
get_dev_fcn_regs().push_back(dev_fcn_reg_t(find, make, filter));
}
-device::~device(void){
+device::~device(void)
+{
/* NOP */
}
/***********************************************************************
* Discover
**********************************************************************/
-device_addrs_t device::find(const device_addr_t &hint, device_filter_t filter){
+device_addrs_t device::find(const device_addr_t& hint, device_filter_t filter)
+{
boost::mutex::scoped_lock lock(_device_mutex);
device_addrs_t device_addrs;
std::vector<std::future<device_addrs_t>> find_tasks;
for (const auto& fcn : get_dev_fcn_regs()) {
if (filter == ANY or std::get<2>(fcn) == filter) {
- find_tasks.emplace_back(std::async(std::launch::async,
- [fcn, hint](){
- return std::get<0>(fcn)(hint);
- }
- ));
+ find_tasks.emplace_back(std::async(
+ std::launch::async, [fcn, hint]() { return std::get<0>(fcn)(hint); }));
}
}
- for(auto &find_task : find_tasks) {
+ for (auto& find_task : find_tasks) {
try {
device_addrs_t discovered_addrs = find_task.get();
device_addrs.insert(
- device_addrs.begin(),
- discovered_addrs.begin(),
- discovered_addrs.end()
- );
- }
- catch (const std::exception &e) {
+ device_addrs.begin(), discovered_addrs.begin(), discovered_addrs.end());
+ } catch (const std::exception& e) {
UHD_LOGGER_ERROR("UHD") << "Device discovery error: " << e.what();
}
}
@@ -125,77 +108,78 @@ device_addrs_t device::find(const device_addr_t &hint, device_filter_t filter){
/***********************************************************************
* Make
**********************************************************************/
-device::sptr device::make(const device_addr_t &hint, device_filter_t filter, size_t which){
+device::sptr device::make(const device_addr_t& hint, device_filter_t filter, size_t which)
+{
boost::mutex::scoped_lock lock(_device_mutex);
typedef std::tuple<device_addr_t, make_t> dev_addr_make_t;
std::vector<dev_addr_make_t> dev_addr_makers;
device_addr_t hint_with_prefs = prefs::get_usrp_args(hint);
- UHD_LOGGER_DEBUG("UHD") << "Looking for device with hint: " << hint_with_prefs.to_string();
+ UHD_LOGGER_DEBUG("UHD") << "Looking for device with hint: "
+ << hint_with_prefs.to_string();
- for(const dev_fcn_reg_t &fcn: get_dev_fcn_regs()){
- try{
- if(filter == ANY or std::get<2>(fcn) == filter){
+ for (const dev_fcn_reg_t& fcn : get_dev_fcn_regs()) {
+ try {
+ if (filter == ANY or std::get<2>(fcn) == filter) {
for (device_addr_t dev_addr : std::get<0>(fcn)(hint_with_prefs)) {
- //append the discovered address and its factory function
- dev_addr_makers.push_back(dev_addr_make_t(dev_addr, std::get<1>(fcn)));
+ // append the discovered address and its factory function
+ dev_addr_makers.push_back(
+ dev_addr_make_t(dev_addr, std::get<1>(fcn)));
}
}
- }
- catch(const std::exception &e){
- UHD_LOGGER_ERROR("UHD") << "Device discovery error: " << e.what() ;
+ } catch (const std::exception& e) {
+ UHD_LOGGER_ERROR("UHD") << "Device discovery error: " << e.what();
}
}
- //check that we found any devices
- if (dev_addr_makers.size() == 0){
- throw uhd::key_error(str(
- boost::format("No devices found for ----->\n%s") % hint.to_pp_string()
- ));
+ // check that we found any devices
+ if (dev_addr_makers.size() == 0) {
+ throw uhd::key_error(
+ str(boost::format("No devices found for ----->\n%s") % hint.to_pp_string()));
}
- //check that the which index is valid
- if (dev_addr_makers.size() <= which){
- throw uhd::index_error(str(
- boost::format("No device at index %d for ----->\n%s") % which % hint.to_pp_string()
- ));
+ // check that the which index is valid
+ if (dev_addr_makers.size() <= which) {
+ throw uhd::index_error(str(boost::format("No device at index %d for ----->\n%s")
+ % which % hint.to_pp_string()));
}
- //create a unique hash for the device address
- device_addr_t dev_addr; make_t maker;
+ // create a unique hash for the device address
+ device_addr_t dev_addr;
+ make_t maker;
std::tie(dev_addr, maker) = dev_addr_makers.at(which);
- size_t dev_hash = hash_device_addr(dev_addr);
- UHD_LOGGER_TRACE("UHD") << boost::format("Device hash: %u") % dev_hash ;
-
- //copy keys that were in hint but not in dev_addr
- //this way, we can pass additional transport arguments
- for(const std::string &key: hint.keys()){
- if (not dev_addr.has_key(key)) dev_addr[key] = hint[key];
+ size_t dev_hash = hash_device_addr(dev_addr);
+ UHD_LOGGER_TRACE("UHD") << boost::format("Device hash: %u") % dev_hash;
+
+ // copy keys that were in hint but not in dev_addr
+ // this way, we can pass additional transport arguments
+ for (const std::string& key : hint.keys()) {
+ if (not dev_addr.has_key(key))
+ dev_addr[key] = hint[key];
}
- //map device address hash to created devices
- static uhd::dict<size_t, std::weak_ptr<device> > hash_to_device;
+ // map device address hash to created devices
+ static uhd::dict<size_t, std::weak_ptr<device>> hash_to_device;
- //try to find an existing device
- if (hash_to_device.has_key(dev_hash) and not hash_to_device[dev_hash].expired()){
+ // try to find an existing device
+ if (hash_to_device.has_key(dev_hash) and not hash_to_device[dev_hash].expired()) {
return hash_to_device[dev_hash].lock();
- }
- else {
+ } else {
// Add keys from the config files (note: the user-defined keys will
// always be applied, see also get_usrp_args()
// Then, create and register a new device.
- device::sptr dev = maker(prefs::get_usrp_args(dev_addr));
+ device::sptr dev = maker(prefs::get_usrp_args(dev_addr));
hash_to_device[dev_hash] = dev;
return dev;
}
}
-uhd::property_tree::sptr
-device::get_tree(void) const
+uhd::property_tree::sptr device::get_tree(void) const
{
return _tree;
}
-device::device_filter_t device::get_device_type() const {
+device::device_filter_t device::get_device_type() const
+{
return _type;
}