33 #include <uhd/usrp/multi_usrp.hpp> 34 #include <uhd/property_tree.hpp> 35 #include <boost/format.hpp> 37 #include <boost/property_tree/exceptions.hpp> 54 PropTree(
const uhd::usrp::multi_usrp::sptr usrp,
const std::string & requester,
int mb_index = 0) {
57 mb0_name = usrp->get_device()->get_tree()->list(
"/mboards").at(mb_index);
59 catch (std::runtime_error e) {
60 complain((boost::format(
"Exception looking for motherboard %d") % mb_index).str(), e,
false);
66 tree = usrp->get_device()->get_tree()->subtree(
fqpn);
68 catch (std::runtime_error e) {
69 complain(
"Exception while creating initial motherboard property tree",
fqpn, e,
false);
103 std::vector<std::string> pslis =
tree->list(
"");
104 ret = std::find(pslis.begin(), pslis.end(), propname) != pslis.end();
106 catch (std::runtime_error e) {
107 complain(
"Exception while looking for property",
fqpn +
"/" + propname, e,
false);
112 std::vector<std::string>
getPropNames(
const std::string & path = std::string(
""))
114 return tree->list(path);
117 std::string
getStringProp(
const std::string & propname,
const std::string defval = std::string(
"None"))
119 return getProperty<std::string>(propname, defval);
122 int getIntProp(
const std::string & propname,
const int defval = 0)
124 return getProperty<int>(propname, defval);
129 return getProperty<double>(propname, defval);
132 bool getBoolProp(
const std::string & propname,
const bool defval =
false)
134 return getProperty<bool>(propname, defval);
137 void setStringProp(
const std::string & propname,
const std::string val = std::string(
"None"))
139 setProperty<std::string>(propname, val);
142 void setIntProp(
const std::string & propname,
const int val = 0)
144 setProperty<int>(propname, val);
149 setProperty<double>(propname, val);
152 void setBoolProp(
const std::string & propname,
const bool val =
false)
154 setProperty<bool>(propname, val);
157 template <
typename T> T
getProperty(
const std::string & propname,
const T defval) {
159 std::string path =
fqpn +
"/" + propname;
161 ret =
tree->access<T>(propname).
get();
163 catch (std::runtime_error e) {
164 complain(
"getProperty Unknown exception -- unknown property", path, e);
170 template <
typename T> T
getProperty(
const std::string & propname) {
172 std::string path =
fqpn +
"/" + propname;
174 ret =
tree->access<T>(propname).
get();
176 catch (std::runtime_error e) {
177 complain(
"getProperty Unknown exception -- unknown property", path, e,
false);
183 template <
typename T>
void setProperty(
const std::string & propname,
const T val) {
184 std::string path =
fqpn +
"/" + propname;
186 tree->access<T>(propname).
set(val);
188 catch (std::runtime_error e) {
189 complain(
"setProperty Unknown exception -- unknown property", path, e);
200 catch (std::runtime_error e) {
201 complain(
"Exception while creating a subtree", path, e,
false);
209 std::runtime_error & e,
210 bool continue_p =
true) {
211 std::cerr << boost::format(
"PropTree encountered %s\n\tRequester: %s\n\tException: [%s]\n\t%s\n")
212 % explain_string %
client_name % e.what() % (continue_p ?
"Thread will continue" :
"Thread will terminate");
213 if(!continue_p) exit(-1);
217 const std::string & path,
218 std::runtime_error & e,
219 bool continue_p =
true) {
220 std::cerr << boost::format(
"PropTree encountered %s\n\twhile looking for path [%s]\n\tRequester: %s\n\tException: [%s]\n\t%s\n")
221 % explain_string % path %
client_name % e.what() % (continue_p ?
"Thread will continue" :
"Thread will terminate");
223 if(!continue_p) exit(-1);
void setBoolProp(const std::string &propname, const bool val=false)
void init(PropTree *ptree, const std::string &path)
T getProperty(const std::string &propname, const T defval)
PropTree class encapsulates the USRP property tree functions to allow better trap and error recovery ...
T getProperty(const std::string &propname)
void setStringProp(const std::string &propname, const std::string val=std::string("None"))
PropTree(const uhd::usrp::multi_usrp::sptr usrp, const std::string &requester, int mb_index=0)
Constructor – build a property tree widget rooted at the first motherboard in this multi-usrp...
void complain(const std::string &explain_string, std::runtime_error &e, bool continue_p=true)
bool getBoolProp(const std::string &propname, const bool defval=false)
PropTree(PropTree &ptree, const std::string &path)
Constructor – build a property tree widget that is a subtree of the mboard property tree...
std::string getStringProp(const std::string &propname, const std::string defval=std::string("None"))
void complain(const std::string &explain_string, const std::string &path, std::runtime_error &e, bool continue_p=true)
uhd::property_tree::sptr tree
std::vector< std::string > getPropNames(const std::string &path=std::string(""))
void setProperty(const std::string &propname, const T val)
void setDoubleProp(const std::string &propname, const double val=0.0)
std::string client_name
the name of the runtime object/thread that created this tree.
void setIntProp(const std::string &propname, const int val=0)
int getIntProp(const std::string &propname, const int defval=0)
PropTree(PropTree *ptree, const std::string &path)
Constructor – build a property tree widget that is a subtree of the mboard property tree...
bool hasProperty(const std::string &propname)
does the property tree have this property name as a child?
int getDoubleProp(const std::string &propname, const double defval=0.0)