36 #ifndef RTT_DYNAMIC_RECONFIGURE_SERVER_H 37 #define RTT_DYNAMIC_RECONFIGURE_SERVER_H 51 #include <dynamic_reconfigure/Reconfigure.h> 52 #include <dynamic_reconfigure/Config.h> 53 #include <dynamic_reconfigure/ConfigDescription.h> 55 #include <rtt/rtt-config.h> 56 #if !defined(RTT_VERSION_GTE) 57 #define RTT_VERSION_GTE(major,minor,patch) \ 58 ((RTT_VERSION_MAJOR > major) || (RTT_VERSION_MAJOR == major && \ 59 (RTT_VERSION_MINOR > minor) || (RTT_VERSION_MINOR == minor && \ 60 (RTT_VERSION_PATCH >= patch)))) 65 template <
class ConfigType>
class Server;
75 template <
class ConfigType>
81 template <
class ConfigType>
91 static void getMin(ConfigType &min,
const ServerType *) { min = ConfigType::__getMin__(); }
99 static void getMax(ConfigType &max,
const ServerType *) { max = ConfigType::__getMax__(); }
107 static void getDefault(ConfigType &dflt,
const ServerType *) { dflt = ConfigType::__getDefault__(); }
115 static dynamic_reconfigure::ConfigDescriptionPtr
getDescriptionMessage(
const ServerType *) {
return dynamic_reconfigure::ConfigDescriptionPtr(
new dynamic_reconfigure::ConfigDescription(ConfigType::__getDescriptionMessage__())); }
120 static const bool canRefresh =
false;
136 static void toMessage(ConfigType &config, dynamic_reconfigure::Config &message,
const ServerType *) { config.__toMessage__(message); }
145 static void fromMessage(ConfigType &config, dynamic_reconfigure::Config &message,
const ServerType *) { config.__fromMessage__(message); }
153 static void clamp(ConfigType &config,
const ServerType *) { config.__clamp__(); }
170 struct null_deleter {
171 void operator()(
const void *)
const {}
176 class DynamicReconfigureTestComponent;
182 template <
class ConfigType>
217 :
RTT::Service(name, owner)
219 , update_callback_default_impl_(
"updateProperties", &
Server<ConfigType>::updatePropertiesDefaultImpl, this,
RTT::OwnThread, owner->engine())
230 :
RTT::Service(
"reconfigure", owner)
232 , update_callback_default_impl_(
"updateProperties", &
Server<ConfigType>::updatePropertiesDefaultImpl, this,
RTT::OwnThread, owner->engine())
259 updateConfigInternal(config);
342 PublishDescription();
353 PublishDescription();
364 PublishDescription();
373 dynamic_reconfigure::ConfigDescriptionPtr description_message = traits::getDescriptionMessage(
this);
376 traits::toMessage(max_, description_message->max,
this);
377 traits::toMessage(min_, description_message->min,
this);
378 traits::toMessage(default_, description_message->dflt,
this);
380 return description_message;
396 if (getOwner()->getName() ==
"Deployer")
399 ns =
"~" + getOwner()->getName();
407 descr_pub_ = node_handle_->
advertise<dynamic_reconfigure::ConfigDescription>(
"parameter_descriptions", 1,
true);
408 update_pub_ = node_handle_->
advertise<dynamic_reconfigure::Config>(
"parameter_updates", 1,
true);
411 PublishDescription();
412 updateConfigInternal(config_);
435 ConfigType new_config = config_;
437 updateConfig(new_config);
450 traits::refreshDescription(
this);
453 traits::getMin(min_,
this);
454 traits::getMax(max_,
this);
455 traits::getDefault(default_,
this);
458 PublishDescription();
461 this->properties()->remove(this->properties()->
getProperty(
"min"));
462 this->properties()->remove(this->properties()->
getProperty(
"max"));
463 this->properties()->remove(this->properties()->
getProperty(
"default"));
464 this->properties()->ownProperty(
new RTT::Property<RTT::PropertyBag>(
"min",
"Minimum values as published to dynamic_reconfigure clients", traits::getDataSource(min_,
this)));
465 this->properties()->ownProperty(
new RTT::Property<RTT::PropertyBag>(
"max",
"Maximum values as published to dynamic_reconfigure clients", traits::getDataSource(max_,
this)));
466 this->properties()->ownProperty(
new RTT::Property<RTT::PropertyBag>(
"default",
"Default values as published to dynamic_reconfigure clients", traits::getDataSource(default_,
this)));
469 config_ = ConfigType();
470 traits::getDefault(config_,
this);
471 updater()->configFromProperties(config_, *(getOwner()->properties()));
473 config_.__fromServer__(*node_handle_);
474 traits::clamp(config_,
this);
478 updater()->propertiesFromConfig(config_, ~0, init_config);
481 #if !RTT_VERSION_GTE(2,8,99) 493 if (update_callback_impl) {
498 update_callback_impl.reset(update_callback_impl->cloneI(engine));
499 update_callback_impl->call(init_config, ~0);
501 update_callback_(init_config, ~0);
505 if (update_callback_const_impl) {
510 update_callback_const_impl.reset(update_callback_const_impl->cloneI(engine));
511 update_callback_const_impl->call(init_config, ~0);
513 update_callback_const_(init_config, ~0);
517 if (notify_callback_impl) {
522 notify_callback_impl.reset(notify_callback_impl->cloneI(engine));
523 notify_callback_impl->call(~0);
525 notify_callback_(~0);
529 if (update_callback_.
ready()) {
530 update_callback_(init_config, ~0);
531 }
else if (update_callback_const_.
ready()) {
532 update_callback_const_(init_config, ~0);
534 if (notify_callback_.
ready()) {
535 notify_callback_(~0);
539 updateConfigInternal(config_);
549 if (!updater_) updater_.reset(
new UpdaterType());
550 return updater_.get();
560 updater_.reset(updater, null_deleter());
570 update_callback_ = impl;
580 notify_callback_ = impl;
587 .doc(
"Advertise this dynamic_reconfigure server at the master.")
588 .arg(
"namespace",
"The namespace this server should be advertised in. Defaults to ~component.");
590 .doc(
"Shutdown this dynamic_reconfigure server.");
592 .doc(
"Notify the dynamic_reconfigure server that properties have been updated. This will update the GUI.");
595 .doc(
"Rediscover the owner's properties or update advertised min/max/default values. Call this operation after having added properties.");
598 UpdaterType *updater =
dynamic_cast<UpdaterType *
>(getOwner());
599 if (updater) setUpdater(updater);
602 if (getOwner() && getOwner()->provides()->hasMember(
"updateProperties")) {
605 update_callback_ = op;
607 update_callback_const_ = op;
614 if (getOwner() && getOwner()->provides()->hasMember(
"notifyPropertiesUpdate")) {
615 notify_callback_ = getOwner()->provides()->getPart(
"notifyPropertiesUpdate");
628 if (!descr_pub_)
return;
629 descr_pub_.
publish(getDescriptionMessage());
632 friend class DynamicReconfigureTestComponent;
634 dynamic_reconfigure::Reconfigure::Response &rsp)
638 ConfigType new_config = config_;
639 traits::fromMessage(new_config, req.config,
this);
640 traits::clamp(new_config,
this);
641 uint32_t level = config_.__level__(new_config);
645 if (update_callback_.
ready()) {
646 if (!update_callback_(bag, level))
return false;
647 updater()->configFromProperties(new_config, bag);
648 }
else if (update_callback_const_.
ready()) {
649 if (!update_callback_const_(bag, level))
return false;
653 if (notify_callback_.
ready()) notify_callback_(level);
655 updateConfigInternal(new_config);
656 new_config.__toMessage__(rsp.config);
665 config_.__toServer__(*node_handle_);
666 dynamic_reconfigure::Config msg;
667 config_.__toMessage__(msg);
689 template <
typename T,
typename ValueType>
702 if (boost::is_same<T,ValueType>::value) {
722 template <
typename T,
typename ValueType>
737 #define RTT_DYNAMIC_RECONFIGURE_SERVICE_PLUGIN(CONFIG, NAME) \ 739 RTT_EXPORT bool loadRTTPlugin(RTT::TaskContext* tc); \ 740 bool loadRTTPlugin(RTT::TaskContext* tc) { \ 741 if (tc == 0) return true; \ 742 RTT::Service::shared_ptr sp( new rtt_dynamic_reconfigure::Server<CONFIG>(NAME, tc ) ); \ 743 return tc->provides()->addService( sp ); \ 745 RTT_EXPORT RTT::Service::shared_ptr createService(); \ 746 RTT::Service::shared_ptr createService() { \ 747 RTT::Service::shared_ptr sp( new rtt_dynamic_reconfigure::Server<CONFIG>( 0 ) ); \ 750 RTT_EXPORT std::string getRTTPluginName(); \ 751 std::string getRTTPluginName() { \ 754 RTT_EXPORT std::string getRTTTargetName(); \ 755 std::string getRTTTargetName() { \ 756 return OROCOS_TARGET_NAME; \ 760 #endif // RTT_DYNAMIC_RECONFIGURE_SERVER_H
virtual base::OperationCallerBase< Signature >::shared_ptr getOperationCaller()
Property< T > * getPropertyType(const std::string &name) const
void publish(const boost::shared_ptr< M > &message) const
bool updateProperties(PropertyBag &target, const PropertyBag &source)
const OperationCallerBasePtr getOperationCallerImpl() const
Variable opBinary s not applicable to op
virtual void set(param_t t)=0
std::string getName(void *handle)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
const_reference_t rvalue() const
void setCaller(ExecutionEngine *caller)
bool ownProperty(base::PropertyBase *p)
Property< T > & addProperty(const std::string &name, T &attr)
static RTT_API ExecutionEngine * Instance()
virtual os::ThreadInterface * getThread() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
virtual RTT_API boost::shared_ptr< base::DisposableInterface > getLocalOperation() const
base::PropertyBase * getProperty(const std::string &name) const
ROSCONSOLE_DECL void shutdown()
static Logger::LogFunction endlog()