2 #pragma clang diagnostic push 3 #pragma ide diagnostic ignored "OCDFAInspection" 4 #pragma clang diagnostic ignored "-Wunknown-pragmas" 5 #pragma ide diagnostic ignored "modernize-loop-convert" 6 #pragma ide diagnostic ignored "modernize-use-auto" 12 #include <boost/foreach.hpp> 14 using namespace boost;
21 void DDynamicReconfigure::add(
DDPtr param) {
22 params_[param->getName()] = param;
25 void DDynamicReconfigure::add(
DDParam *param) {
29 void DDynamicReconfigure::remove(
DDPtr param) {
30 remove(param->getName());
33 void DDynamicReconfigure::remove(
DDParam *param) {
37 void DDynamicReconfigure::remove(
string param_name) {
38 params_.erase(param_name);
41 void DDynamicReconfigure::start() {
42 ConfigDescription conf_desc = makeDescription();
43 Config conf = makeConfig();
45 function<bool(Reconfigure::Request& req, Reconfigure::Response& rsp)>
callback = bind(&internalCallback,
this,_1,_2);
47 set_service_ = nh_.advertiseService(
"set_parameters", callback);
50 desc_pub_ = nh_.advertise<ConfigDescription>(
"parameter_descriptions", 1,
true);
51 desc_pub_.publish(conf_desc);
54 update_pub_ = nh_.advertise<Config>(
"parameter_updates", 1,
true);
55 update_pub_.publish(conf);
58 Config DDynamicReconfigure::makeConfig() {
60 GroupState group_state;
63 group_state.name =
"Default";
64 group_state.state = (
unsigned char)
true;
67 conf.groups.push_back(group_state);
68 for(DDMap::const_iterator it = params_.begin(); it != params_.end(); it++) {it->second->prepConfig(conf);}
72 ConfigDescription DDynamicReconfigure::makeDescription() {
73 ConfigDescription conf_desc;
77 group.name =
"default";
78 for(DDMap::const_iterator it = params_.begin(); it != params_.end(); it++) {it->second->prepGroup(group);}
81 for(DDMap::const_iterator it = params_.begin(); it != params_.end(); it++) {it->second->prepConfigDescription(conf_desc);}
82 conf_desc.groups.push_back(group);
88 setCallback(callback);
103 callback_ = make_shared<function<void(const DDMap&,int)> >(
callback);
108 void DDynamicReconfigure::clearCallback() {
113 bool DDynamicReconfigure::internalCallback(
DDynamicReconfigure *obj, Reconfigure::Request& req, Reconfigure::Response& rsp) {
121 }
catch (std::exception &e) {
122 ROS_WARN(
"Reconfigure callback failed with exception %s: ", e.what());
124 ROS_WARN(
"Reconfigure callback failed with unprintable exception.");
133 int DDynamicReconfigure::getUpdates(
const Reconfigure::Request &req,
DDMap &config) {
136 BOOST_FOREACH(
const IntParameter i,req.config.ints) {
137 int new_level = reassign(config, i.name, i.value);
138 if(new_level == -1) {
144 BOOST_FOREACH(
const DoubleParameter i,req.config.doubles) {
145 int new_level = reassign(config, i.name, i.value);
146 if(new_level == -1) {
152 BOOST_FOREACH(
const BoolParameter i,req.config.bools) {
153 int new_level = reassign(config, i.name, (
bool)i.value);
154 if(new_level == -1) {
160 BOOST_FOREACH(
const StrParameter i,req.config.strs) {
161 int new_level = reassign(config, i.name, i.value);
162 if(new_level == -1) {
172 int DDynamicReconfigure::reassign(
DDMap& map,
const string &name, T value) {
174 if(map.find(name) != map.end() && map[name]->sameType(val)) {
175 DDPtr old = map[name];
176 if(old->sameValue(val)) {
return 0;}
else {
178 return old->getLevel();
194 os <<
"{" << *dd.
params_.begin()->second;
195 for(DDMap::const_iterator it = ++dd.
params_.begin(); it != dd.
params_.end(); it++) {
196 os <<
"," << *it->second;
203 DDMap::const_iterator it = map.find(name);
204 if(it == map.end()) {
206 }
else {
return it->second;}
210 DDMap::const_iterator it = map.find(name);
211 if(it == map.end()) {
212 return Value(
"\000");
213 }
else {
return it->second->getValue();}
217 #pragma clang diagnostic pop
void publish(const boost::shared_ptr< M > &message) const
void callback(const DDMap &map, int)
#define ROS_DEBUG_STREAM(args)
#define ROS_ERROR_STREAM(args)