44 #include <boost/thread/locks.hpp> 46 #include <dynamic_reconfigure/config_tools.h> 66 typedef boost::intrusive_ptr<AutoConfigDataSource>
shared_ptr;
84 if ( replace[
this] != 0 ) {
85 assert ( dynamic_cast<AutoConfigDataSource*>( replace[
this] ) == static_cast<AutoConfigDataSource*>( replace[
this] ) );
105 : parent(), id(), state()
122 static std::string
getType() {
return "str"; }
124 static T
getMin() {
return std::numeric_limits<T>::lowest(); }
125 static T
getMax() {
return std::numeric_limits<T>::max(); }
131 static std::string
getType() {
return "bool"; }
140 static std::string
getType() {
return "int"; }
149 static std::string
getType() {
return "int"; }
158 static std::string
getType() {
return "str"; }
160 static std::string
getMin() {
return ""; }
161 static std::string
getMax() {
return ""; }
167 static std::string
getType() {
return "double"; }
169 static double getMin() {
return -DBL_MAX; }
170 static double getMax() {
return DBL_MAX; }
176 static std::string
getType() {
return "double"; }
178 static double getMin() {
return -FLT_MAX; }
179 static double getMax() {
return FLT_MAX; }
191 template <
typename T>
195 if (!sample_prop)
return false;
198 if (!ConfigTools::getParameter(msg, param_name, value))
return false;
202 prop = sample_prop->
create();
219 config.
id = sample.
id;
221 dynamic_reconfigure::ConfigTools::getGroupState(msg, config.
name, config);
226 std::string param_name = config.
prefix_ + (*i)->getName();
235 assert(ds->rvalue().getType() == sample_sub->
getType());
238 ds->set().setType(sample_sub->
getType());
244 if (!ds->rvalue().empty()) {
256 bool param_found =
false;
257 for(Config::_bools_type::const_iterator n = msg.bools.begin(); n != msg.bools.end(); ++n) {
258 if (n->name == param_name) param_found =
true;
260 for(Config::_ints_type::const_iterator n = msg.ints.begin(); n != msg.ints.end(); ++n) {
261 if (n->name == param_name) param_found =
true;
263 for(Config::_strs_type::const_iterator n = msg.strs.begin(); n != msg.strs.end(); ++n) {
264 if (n->name == param_name) param_found =
true;
266 for(Config::_doubles_type::const_iterator n = msg.doubles.begin(); n != msg.doubles.end(); ++n) {
267 if (n->name == param_name) param_found =
true;
269 if (!param_found)
continue;
273 propertyFromMessage<bool>(config, msg, *i, param_name) ||
274 propertyFromMessage<int>(config, msg, *i, param_name) ||
275 propertyFromMessage<unsigned int>(config, msg, *i, param_name) ||
276 propertyFromMessage<std::string>(config, msg, *i, param_name) ||
277 propertyFromMessage<double>(config, msg, *i, param_name) ||
278 propertyFromMessage<float>(config, msg, *i, param_name)
287 template <
typename T>
291 if (!prop)
return false;
294 ConfigTools::appendParameter(msg, _prefix + pb->
getName(), value);
306 dynamic_reconfigure::ConfigTools::appendGroup(msg, config.
name, config.
id, config.
parent, config);
311 if (propertyToMessage<bool>(msg, *i, config.
prefix_) ||
312 propertyToMessage<int>(msg, *i, config.
prefix_) ||
313 propertyToMessage<unsigned int>(msg, *i, config.
prefix_) ||
314 propertyToMessage<std::string>(msg, *i, config.
prefix_) ||
315 propertyToMessage<double>(msg, *i, config.
prefix_) ||
316 propertyToMessage<float>(msg, *i, config.
prefix_)
375 ds->
set().setType(sub->
rvalue().getType());
386 template <
typename T>
390 if (!prop)
return false;
392 ParamDescription
param;
393 param.name = prefix + pb->
getName();
396 params.push_back(param);
401 dflt_prop->
set(prop->
get());
420 static void buildGroupDescription(
RTT::TaskContext *owner,
const RTT::PropertyBag &bag, ConfigDescription& config_description,
AutoConfig& dflt,
AutoConfig& min,
AutoConfig& max,
const std::string &prefix,
const std::string &
name,
const std::string &
type, int32_t
parent, int32_t &
id)
422 std::size_t group_index = config_description.groups.size();
423 config_description.groups.push_back(Group());
425 Group &group = config_description.groups[group_index];
426 group.name = name.empty() ?
"Default" :
name;
432 dflt.
name = group.name;
433 dflt.
type = group.type;
434 dflt.
parent = group.parent;
439 min.
name = group.name;
440 min.
type = group.type;
441 min.
parent = group.parent;
446 max.
name = group.name;
447 max.
type = group.type;
448 max.
parent = group.parent;
454 if (buildParamDescription<bool>(*i, prefix, config_description.groups[group_index].parameters, dflt, min, max) ||
455 buildParamDescription<int>(*i, prefix, config_description.groups[group_index].parameters, dflt, min, max) ||
456 buildParamDescription<unsigned int>(*i, prefix, config_description.groups[group_index].parameters, dflt, min, max) ||
457 buildParamDescription<std::string>(*i, prefix, config_description.groups[group_index].parameters, dflt, min, max) ||
458 buildParamDescription<double>(*i, prefix, config_description.groups[group_index].parameters, dflt, min, max) ||
459 buildParamDescription<float>(*i, prefix, config_description.groups[group_index].parameters, dflt, min, max)
467 sub_dflt = &(ds->
set());
475 sub_min = &(ds->
set());
483 sub_max = &(ds->
set());
488 buildGroupDescription(owner, sub->
rvalue(), config_description, *sub_dflt, *sub_min, *sub_max, prefix + sub->
getName() +
"__", prefix + sub->
getName(),
"", config_description.groups[group_index].id, ++
id);
500 RTT::log(
RTT::Error) <<
"Failed to decompose properties of '" << owner->
getName() <<
"' for dynamic_reconfigure. Properties with custom types will not be available for reconfiguration." <<
RTT::endlog();
504 boost::upgrade_lock<boost::shared_mutex> upgrade_lock(
cache_mutex_);
505 if (upgrade_lock.owns_lock())
507 boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock(upgrade_lock);
509 if (!cache) cache.reset(
new Cache());
510 cache->description_message_.reset(
new ConfigDescription);
512 buildGroupDescription(owner, decomposed, *(cache->description_message_), cache->default_, cache->min_, cache->max_,
"",
"",
"", 0,
id);
518 boost::shared_lock<boost::shared_mutex> lock(
cache_mutex_);
520 return cache_.at(server)->description_message_;
525 boost::shared_lock<boost::shared_mutex> lock(
cache_mutex_);
527 return cache_.at(server)->default_;
532 boost::shared_lock<boost::shared_mutex> lock(
cache_mutex_);
534 return cache_.at(server)->max_;
539 boost::shared_lock<boost::shared_mutex> lock(
cache_mutex_);
541 return cache_.at(server)->min_;
virtual base::DataSourceBase::shared_ptr getDataSource() const
TaskContext * getOwner() const
DataSourceType get() const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
Property< T > * getPropertyType(const std::string &name) const
bool updateProperties(PropertyBag &target, const PropertyBag &source)
const T & min(const T &a, const T &b)
const std::string & getType() const
void setType(const std::string &newtype)
bool RTT_API composePropertyBag(PropertyBag const &sourcebag, PropertyBag &target)
const_reference_t rvalue() const
const T & max(const T &a, const T &b)
bool ownProperty(base::PropertyBase *p)
bool RTT_API decomposePropertyBag(PropertyBag const &sourcebag, PropertyBag &target)
const std::string & getDescription() const
Properties::const_iterator const_iterator
base::PropertyBase * getProperty(const std::string &name) const
PropertyBag * properties()
const std::string & getName() const
virtual Property< T > * create() const
virtual bool update(const PropertyBase *other)=0
static Logger::LogFunction endlog()
virtual const std::string & getName() const
boost::call_traits< value_t >::param_type param_t