server.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*********************************************************************
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2009-2010, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of the Willow Garage nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *********************************************************************/
35 
36 
46 #ifndef __SERVER_H__
47 #define __SERVER_H__
48 
49 //#include <boost/function.hpp>
50 //#include <boost/thread/recursive_mutex.hpp>
51 #include <ros/node_handle.h>
54 
59 namespace dynamic_reconfigure
60 {
64 template <class ConfigType>
65 class Server
66 {
67 public:
69  node_handle_(nh),
71  own_mutex_warn_(true)
72  {
73  init();
74  }
75 
76  Server(boost::recursive_mutex &mutex, const ros::NodeHandle &nh = ros::NodeHandle("~")) :
77  node_handle_(nh),
78  mutex_(mutex),
79  own_mutex_warn_(false)
80  {
81  init();
82  }
83 
84  typedef std::function<void(ConfigType &, uint32_t level)> CallbackType;
85 
87  {
88  boost::recursive_mutex::scoped_lock lock(mutex_);
90  callCallback(config_, ~0); // At startup we need to load the configuration with all level bits set. (Everything has changed.)
92  }
93 
95  {
96  boost::recursive_mutex::scoped_lock lock(mutex_);
97  callback_.clear();
98  }
99 
100  void updateConfig(const ConfigType &config)
101  {
102  if (own_mutex_warn_)
103  {
104  ROS_WARN("updateConfig() called on a dynamic_reconfigure::Server that provides its own mutex. This can lead to deadlocks if updateConfig() is called during an update. Providing a mutex to the constructor is highly recommended in this case. Please forward this message to the node author.");
105  own_mutex_warn_ = false;
106  }
108  }
109 
110 
111  void getConfigMax(ConfigType &config)
112  {
113  config = max_;
114  }
115 
116  void getConfigMin(ConfigType &config)
117  {
118  config = min_;
119  }
120 
121  void getConfigDefault(ConfigType &config)
122  {
123  config = default_;
124  }
125 
126  void setConfigMax(const ConfigType &config)
127  {
128  max_ = config;
130  }
131 
132  void setConfigMin(const ConfigType &config)
133  {
134  min_ = config;
136  }
137 
138  void setConfigDefault(const ConfigType &config)
139  {
140  default_ = config;
142  }
143 
144 
145 private:
151  ConfigType config_;
152  ConfigType min_;
153  ConfigType max_;
154  ConfigType default_;
155  boost::recursive_mutex &mutex_;
156  boost::recursive_mutex own_mutex_; // Used only if an external one isn't specified.
158 
159 
160 
162  {
163  boost::recursive_mutex::scoped_lock lock(mutex_);
164  //Copy over min_ max_ default_
165  dynamic_reconfigure::ConfigDescription description_message = ConfigType::__getDescriptionMessage__();
166 
167  max_.__toMessage__(description_message.max, ConfigType::__getParamDescriptions__(),ConfigType::__getGroupDescriptions__());
168  min_.__toMessage__(description_message.min,ConfigType::__getParamDescriptions__(),ConfigType::__getGroupDescriptions__());
169  default_.__toMessage__(description_message.dflt,ConfigType::__getParamDescriptions__(),ConfigType::__getGroupDescriptions__());
170 
171  //Publish description
172  descr_pub_.publish(description_message);
173  }
174 
175  void init()
176  {
177  //Grab copys of the data from the config files. These are declared in the generated config file.
178  min_ = ConfigType::__getMin__();
179  max_ = ConfigType::__getMax__();
180  default_ = ConfigType::__getDefault__();
181 
182  boost::recursive_mutex::scoped_lock lock(mutex_);
183  set_service_ = node_handle_.advertiseService("set_parameters",
185 
186  descr_pub_ = node_handle_.advertise<dynamic_reconfigure::ConfigDescription>("parameter_descriptions", 1, true);
187  descr_pub_.publish(ConfigType::__getDescriptionMessage__());
188 
189  update_pub_ = node_handle_.advertise<dynamic_reconfigure::Config>("parameter_updates", 1, true);
190  ConfigType init_config = ConfigType::__getDefault__();
191  init_config.__fromServer__(node_handle_);
192  init_config.__clamp__();
193  updateConfigInternal(init_config);
194  }
195 
196  void callCallback(ConfigType &config, int level)
197  {
198  if (callback_) // At startup we need to load the configuration with all level bits set. (Everything has changed.)
199  try {
200  callback_(config, level);
201  }
202  catch (std::exception &e)
203  {
204  ROS_WARN("Reconfigure callback failed with exception %s: ", e.what());
205  }
206  catch (...)
207  {
208  ROS_WARN("Reconfigure callback failed with unprintable exception.");
209  }
210  else
211  ROS_DEBUG("setCallback did not call callback because it was zero.");
212  }
213 
216  {
217  boost::recursive_mutex::scoped_lock lock(mutex_);
218 
219  ConfigType new_config = config_;
220  new_config.__fromMessage__(req.config);
221  new_config.__clamp__();
222  uint32_t level = config_.__level__(new_config);
223 
224  callCallback(new_config, level);
225 
226  updateConfigInternal(new_config);
227  new_config.__toMessage__(rsp.config);
228  return true;
229  }
230 
231  void updateConfigInternal(const ConfigType &config)
232  {
233  boost::recursive_mutex::scoped_lock lock(mutex_);
234  config_ = config;
235  config_.__toServer__(node_handle_);
237  config_.__toMessage__(msg);
239  }
240 };
241 
242 }
243 #endif
dynamic_reconfigure::Server::callCallback
void callCallback(ConfigType &config, int level)
Definition: server.h:196
msg
msg
ros::Publisher
dynamic_reconfigure::Config_< std::allocator< void > >
dynamic_reconfigure::Server::clearCallback
void clearCallback()
Definition: server.h:94
dynamic_reconfigure::Server::setConfigDefault
void setConfigDefault(const ConfigType &config)
Definition: server.h:138
dynamic_reconfigure::Server::updateConfig
void updateConfig(const ConfigType &config)
Definition: server.h:100
dynamic_reconfigure::Server::PublishDescription
void PublishDescription()
Definition: server.h:161
dynamic_reconfigure::Server::getConfigDefault
void getConfigDefault(ConfigType &config)
Definition: server.h:121
Reconfigure.h
dynamic_reconfigure::Server::own_mutex_warn_
bool own_mutex_warn_
Definition: server.h:157
dynamic_reconfigure::ReconfigureRequest_::config
_config_type config
Definition: ReconfigureRequest.h:39
dynamic_reconfigure::Server::config_
ConfigType config_
Definition: server.h:151
dynamic_reconfigure::Server::setCallback
void setCallback(const CallbackType &callback)
Definition: server.h:86
ros::NodeHandle::advertiseService
ServiceServer advertiseService(AdvertiseServiceOptions &ops)
Definition: rossimu.cpp:386
dynamic_reconfigure::Server::default_
ConfigType default_
Definition: server.h:154
dynamic_reconfigure::ReconfigureResponse_
Definition: ReconfigureResponse.h:24
ROS_WARN
#define ROS_WARN(...)
Definition: sick_scan_logging.h:122
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
Definition: rossimu.cpp:350
dynamic_reconfigure::ConfigDescription_< std::allocator< void > >
ros::ServiceServer
dynamic_reconfigure::Server::min_
ConfigType min_
Definition: server.h:152
dynamic_reconfigure::Server::update_pub_
ros::Publisher update_pub_
Definition: server.h:148
dynamic_reconfigure::Server::callback_
CallbackType callback_
Definition: server.h:150
dynamic_reconfigure::ReconfigureRequest_
Definition: ReconfigureRequest.h:24
dynamic_reconfigure::Server::set_service_
ros::ServiceServer set_service_
Definition: server.h:147
dynamic_reconfigure::ReconfigureResponse_::config
_config_type config
Definition: ReconfigureResponse.h:39
dynamic_reconfigure::Server::own_mutex_
boost::recursive_mutex own_mutex_
Definition: server.h:156
dynamic_reconfigure::Server::mutex_
boost::recursive_mutex & mutex_
Definition: server.h:155
dynamic_reconfigure::Server::CallbackType
std::function< void(ConfigType &, uint32_t level)> CallbackType
Definition: server.h:84
dynamic_reconfigure::Server::setConfigMin
void setConfigMin(const ConfigType &config)
Definition: server.h:132
dynamic_reconfigure::Server::updateConfigInternal
void updateConfigInternal(const ConfigType &config)
Definition: server.h:231
dynamic_reconfigure::Server::Server
Server(boost::recursive_mutex &mutex, const ros::NodeHandle &nh=ros::NodeHandle("~"))
Definition: server.h:76
dynamic_reconfigure::ConfigDescription_::dflt
_dflt_type dflt
Definition: ConfigDescription.h:53
dynamic_reconfigure
Definition: BoolParameter.h:20
dynamic_reconfigure::ConfigDescription_::max
_max_type max
Definition: ConfigDescription.h:47
dynamic_reconfigure::Server::getConfigMax
void getConfigMax(ConfigType &config)
Definition: server.h:111
dynamic_reconfigure::Server::setConfigCallback
bool setConfigCallback(dynamic_reconfigure::Reconfigure::Request &req, dynamic_reconfigure::Reconfigure::Response &rsp)
Definition: server.h:214
dynamic_reconfigure::Server
Definition: server.h:65
sick_scan_base.h
dynamic_reconfigure::Server::max_
ConfigType max_
Definition: server.h:153
ROS_DEBUG
#define ROS_DEBUG(...)
Definition: sick_scan_logging.h:112
dynamic_reconfigure::Server::Server
Server(const ros::NodeHandle &nh=ros::NodeHandle("~"))
Definition: server.h:68
dynamic_reconfigure::ConfigDescription_::min
_min_type min
Definition: ConfigDescription.h:50
dynamic_reconfigure::Server::setConfigMax
void setConfigMax(const ConfigType &config)
Definition: server.h:126
config
config
dynamic_reconfigure::Server::init
void init()
Definition: server.h:175
dynamic_reconfigure::Server::node_handle_
ros::NodeHandle node_handle_
Definition: server.h:146
ConfigDescription.h
dynamic_reconfigure::Server::getConfigMin
void getConfigMin(ConfigType &config)
Definition: server.h:116
ros::NodeHandle
callback
void callback(const sick_scan_xd::RadarScan::ConstPtr &oa)
Definition: radar_object_marker.cpp:157
dynamic_reconfigure::Server::descr_pub_
ros::Publisher descr_pub_
Definition: server.h:149


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:10