param.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, Willow Garage, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the names of Willow Garage, Inc. nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "ros/param.h"
29 #include "ros/master.h"
30 #include "ros/xmlrpc_manager.h"
31 #include "ros/this_node.h"
32 #include "ros/names.h"
33 
34 #include <ros/console.h>
35 
36 #include <boost/thread/mutex.hpp>
37 #include <boost/lexical_cast.hpp>
38 
39 #include <vector>
40 #include <map>
41 
42 namespace ros
43 {
44 
45 namespace param
46 {
47 
48 typedef std::map<std::string, XmlRpc::XmlRpcValue> M_Param;
49 M_Param g_params;
50 boost::mutex g_params_mutex;
52 
53 void invalidateParentParams(const std::string& key)
54 {
55  std::string ns_key = names::parentNamespace(key);
56  while (ns_key != "" && ns_key != "/")
57  {
58  if (g_subscribed_params.find(ns_key) != g_subscribed_params.end())
59  {
60  // by erasing the key the parameter will be re-queried
61  g_params.erase(ns_key);
62  }
63  ns_key = names::parentNamespace(ns_key);
64  }
65 }
66 
67 void set(const std::string& key, const XmlRpc::XmlRpcValue& v)
68 {
69  std::string mapped_key = ros::names::resolve(key);
70 
71  XmlRpc::XmlRpcValue params, result, payload;
72  params[0] = this_node::getName();
73  params[1] = mapped_key;
74  params[2] = v;
75 
76  {
77  // Lock around the execute to the master in case we get a parameter update on this value between
78  // executing on the master and setting the parameter in the g_params list.
79  boost::mutex::scoped_lock lock(g_params_mutex);
80 
81  if (master::execute("setParam", params, result, payload, true))
82  {
83  // Update our cached params list now so that if get() is called immediately after param::set()
84  // we already have the cached state and our value will be correct
85  if (g_subscribed_params.find(mapped_key) != g_subscribed_params.end())
86  {
87  g_params[mapped_key] = v;
88  }
89  invalidateParentParams(mapped_key);
90  }
91  }
92 }
93 
94 void set(const std::string& key, const std::string& s)
95 {
96  // construct xmlrpc_c::value object of the std::string and
97  // call param::set(key, xmlvalue);
99  ros::param::set(key, v);
100 }
101 
102 void set(const std::string& key, const char* s)
103 {
104  // construct xmlrpc_c::value object of the std::string and
105  // call param::set(key, xmlvalue);
106  std::string sxx = std::string(s);
107  XmlRpc::XmlRpcValue v(sxx);
108  ros::param::set(key, v);
109 }
110 
111 void set(const std::string& key, double d)
112 {
114  ros::param::set(key, v);
115 }
116 
117 void set(const std::string& key, int i)
118 {
119  XmlRpc::XmlRpcValue v(i);
120  ros::param::set(key, v);
121 }
122 
123 void set(const std::string& key, bool b)
124 {
125  XmlRpc::XmlRpcValue v(b);
126  ros::param::set(key, v);
127 }
128 
129 template <class T>
130  void setImpl(const std::string& key, const std::vector<T>& vec)
131 {
132  // Note: the XmlRpcValue starts off as "invalid" and assertArray turns it
133  // into an array type with the given size
134  XmlRpc::XmlRpcValue xml_vec;
135  xml_vec.setSize(vec.size());
136 
137  // Copy the contents into the XmlRpcValue
138  for(size_t i=0; i < vec.size(); i++) {
139  xml_vec[i] = vec.at(i);
140  }
141 
142  ros::param::set(key, xml_vec);
143 }
144 
145 void set(const std::string& key, const std::vector<std::string>& vec)
146 {
147  setImpl(key, vec);
148 }
149 
150 void set(const std::string& key, const std::vector<double>& vec)
151 {
152  setImpl(key, vec);
153 }
154 
155 void set(const std::string& key, const std::vector<float>& vec)
156 {
157  setImpl(key, vec);
158 }
159 
160 void set(const std::string& key, const std::vector<int>& vec)
161 {
162  setImpl(key, vec);
163 }
164 
165 void set(const std::string& key, const std::vector<bool>& vec)
166 {
167  setImpl(key, vec);
168 }
169 
170 template <class T>
171  void setImpl(const std::string& key, const std::map<std::string, T>& map)
172 {
173  // Note: the XmlRpcValue starts off as "invalid" and assertStruct turns it
174  // into a struct type
175  XmlRpc::XmlRpcValue xml_value;
176  xml_value.begin();
177 
178  // Copy the contents into the XmlRpcValue
179  for(typename std::map<std::string, T>::const_iterator it = map.begin(); it != map.end(); ++it) {
180  xml_value[it->first] = it->second;
181  }
182 
183  ros::param::set(key, xml_value);
184 }
185 
186 void set(const std::string& key, const std::map<std::string, std::string>& map)
187 {
188  setImpl(key, map);
189 }
190 
191 void set(const std::string& key, const std::map<std::string, double>& map)
192 {
193  setImpl(key, map);
194 }
195 
196 void set(const std::string& key, const std::map<std::string, float>& map)
197 {
198  setImpl(key, map);
199 }
200 
201 void set(const std::string& key, const std::map<std::string, int>& map)
202 {
203  setImpl(key, map);
204 }
205 
206 void set(const std::string& key, const std::map<std::string, bool>& map)
207 {
208  setImpl(key, map);
209 }
210 
211 bool has(const std::string& key)
212 {
213  XmlRpc::XmlRpcValue params, result, payload;
214  params[0] = this_node::getName();
215  params[1] = ros::names::resolve(key);
216  //params[1] = key;
217  // We don't loop here, because validateXmlrpcResponse() returns false
218  // both when we can't contact the master and when the master says, "I
219  // don't have that param."
220  if (!master::execute("hasParam", params, result, payload, false))
221  {
222  return false;
223  }
224 
225  return payload;
226 }
227 
228 bool del(const std::string& key)
229 {
230  std::string mapped_key = ros::names::resolve(key);
231 
232  {
233  boost::mutex::scoped_lock lock(g_params_mutex);
234 
235  if (g_subscribed_params.find(mapped_key) != g_subscribed_params.end())
236  {
237  g_subscribed_params.erase(mapped_key);
238  unsubscribeCachedParam(mapped_key);
239  }
240  g_params.erase(mapped_key);
241  }
242 
243  XmlRpc::XmlRpcValue params, result, payload;
244  params[0] = this_node::getName();
245  params[1] = mapped_key;
246  // We don't loop here, because validateXmlrpcResponse() returns false
247  // both when we can't contact the master and when the master says, "I
248  // don't have that param."
249  if (!master::execute("deleteParam", params, result, payload, false))
250  {
251  return false;
252  }
253 
254  return true;
255 }
256 
257 bool getImpl(const std::string& key, XmlRpc::XmlRpcValue& v, bool use_cache)
258 {
259  std::string mapped_key = ros::names::resolve(key);
260  if (mapped_key.empty()) mapped_key = "/";
261 
262  if (use_cache)
263  {
264  boost::mutex::scoped_lock lock(g_params_mutex);
265 
266  if (g_subscribed_params.find(mapped_key) != g_subscribed_params.end())
267  {
268  M_Param::iterator it = g_params.find(mapped_key);
269  if (it != g_params.end())
270  {
271  if (it->second.valid())
272  {
273  ROS_DEBUG_NAMED("cached_parameters", "Using cached parameter value for key [%s]", mapped_key.c_str());
274 
275  v = it->second;
276  return true;
277  }
278  else
279  {
280  ROS_DEBUG_NAMED("cached_parameters", "Cached parameter is invalid for key [%s]", mapped_key.c_str());
281  return false;
282  }
283  }
284  }
285  else
286  {
287  // parameter we've never seen before, register for update from the master
288  if (g_subscribed_params.insert(mapped_key).second)
289  {
290  XmlRpc::XmlRpcValue params, result, payload;
291  params[0] = this_node::getName();
292  params[1] = XMLRPCManager::instance()->getServerURI();
293  params[2] = mapped_key;
294 
295  if (!master::execute("subscribeParam", params, result, payload, false))
296  {
297  ROS_DEBUG_NAMED("cached_parameters", "Subscribe to parameter [%s]: call to the master failed", mapped_key.c_str());
298  g_subscribed_params.erase(mapped_key);
299  use_cache = false;
300  }
301  else
302  {
303  ROS_DEBUG_NAMED("cached_parameters", "Subscribed to parameter [%s]", mapped_key.c_str());
304  }
305  }
306  }
307  }
308 
309  XmlRpc::XmlRpcValue params, result;
310  params[0] = this_node::getName();
311  params[1] = mapped_key;
312 
313  // We don't loop here, because validateXmlrpcResponse() returns false
314  // both when we can't contact the master and when the master says, "I
315  // don't have that param."
316  bool ret = master::execute("getParam", params, result, v, false);
317 
318  if (use_cache)
319  {
320  boost::mutex::scoped_lock lock(g_params_mutex);
321 
322  ROS_DEBUG_NAMED("cached_parameters", "Caching parameter [%s] with value type [%d]", mapped_key.c_str(), v.getType());
323  g_params[mapped_key] = v;
324  }
325 
326  return ret;
327 }
328 
329 bool getImpl(const std::string& key, std::string& s, bool use_cache)
330 {
332  if (!getImpl(key, v, use_cache))
333  return false;
335  return false;
336  s = std::string(v);
337  return true;
338 }
339 
340 bool getImpl(const std::string& key, double& d, bool use_cache)
341 {
343  if (!getImpl(key, v, use_cache))
344  {
345  return false;
346  }
347 
349  {
350  d = (int)v;
351  }
353  {
354  return false;
355  }
356  else
357  {
358  d = v;
359  }
360 
361  return true;
362 }
363 
364 bool getImpl(const std::string& key, float& f, bool use_cache)
365 {
366  double d = static_cast<double>(f);
367  bool result = getImpl(key, d, use_cache);
368  if (result)
369  f = static_cast<float>(d);
370  return result;
371 }
372 
373 bool getImpl(const std::string& key, int& i, bool use_cache)
374 {
376  if (!getImpl(key, v, use_cache))
377  {
378  return false;
379  }
380 
382  {
383  double d = v;
384 
385  if (fmod(d, 1.0) < 0.5)
386  {
387  d = floor(d);
388  }
389  else
390  {
391  d = ceil(d);
392  }
393 
394  i = d;
395  }
396  else if (v.getType() != XmlRpc::XmlRpcValue::TypeInt)
397  {
398  return false;
399  }
400  else
401  {
402  i = v;
403  }
404 
405  return true;
406 }
407 
408 bool getImpl(const std::string& key, bool& b, bool use_cache)
409 {
411  if (!getImpl(key, v, use_cache))
412  return false;
414  return false;
415  b = v;
416  return true;
417 }
418 
419 bool get(const std::string& key, std::string& s)
420 {
421  return getImpl(key, s, false);
422 }
423 
424 bool get(const std::string& key, double& d)
425 {
426  return getImpl(key, d, false);
427 }
428 
429 bool get(const std::string& key, float& f)
430 {
431  return getImpl(key, f, false);
432 }
433 
434 bool get(const std::string& key, int& i)
435 {
436  return getImpl(key, i, false);
437 }
438 
439 bool get(const std::string& key, bool& b)
440 {
441  return getImpl(key, b, false);
442 }
443 
444 bool get(const std::string& key, XmlRpc::XmlRpcValue& v)
445 {
446  return getImpl(key, v, false);
447 }
448 
449 bool getCached(const std::string& key, std::string& s)
450 {
451  return getImpl(key, s, true);
452 }
453 
454 bool getCached(const std::string& key, double& d)
455 {
456  return getImpl(key, d, true);
457 }
458 
459 bool getCached(const std::string& key, float& f)
460 {
461  return getImpl(key, f, true);
462 }
463 
464 bool getCached(const std::string& key, int& i)
465 {
466  return getImpl(key, i, true);
467 }
468 
469 bool getCached(const std::string& key, bool& b)
470 {
471  return getImpl(key, b, true);
472 }
473 
474 bool getCached(const std::string& key, XmlRpc::XmlRpcValue& v)
475 {
476  return getImpl(key, v, true);
477 }
478 
479 template <class T> T xml_cast(XmlRpc::XmlRpcValue xml_value)
480 {
481  return static_cast<T>(xml_value);
482 }
483 
484 template <class T> bool xml_castable(int XmlType)
485 {
486  return false;
487 }
488 
489 template<> bool xml_castable<std::string>(int XmlType)
490 {
491  return XmlType == XmlRpc::XmlRpcValue::TypeString;
492 }
493 
494 template<> bool xml_castable<double>(int XmlType)
495 {
496  return (
497  XmlType == XmlRpc::XmlRpcValue::TypeDouble ||
498  XmlType == XmlRpc::XmlRpcValue::TypeInt ||
500 }
501 
502 template<> bool xml_castable<float>(int XmlType)
503 {
504  return (
505  XmlType == XmlRpc::XmlRpcValue::TypeDouble ||
506  XmlType == XmlRpc::XmlRpcValue::TypeInt ||
508 }
509 
510 template<> bool xml_castable<int>(int XmlType)
511 {
512  return (
513  XmlType == XmlRpc::XmlRpcValue::TypeDouble ||
514  XmlType == XmlRpc::XmlRpcValue::TypeInt ||
516 }
517 
518 template<> bool xml_castable<bool>(int XmlType)
519 {
520  return (
521  XmlType == XmlRpc::XmlRpcValue::TypeDouble ||
522  XmlType == XmlRpc::XmlRpcValue::TypeInt ||
524 }
525 
526 template<> double xml_cast(XmlRpc::XmlRpcValue xml_value)
527 {
528  using namespace XmlRpc;
529  switch(xml_value.getType()) {
530  case XmlRpcValue::TypeDouble:
531  return static_cast<double>(xml_value);
532  case XmlRpcValue::TypeInt:
533  return static_cast<double>(static_cast<int>(xml_value));
534  case XmlRpcValue::TypeBoolean:
535  return static_cast<double>(static_cast<bool>(xml_value));
536  default:
537  return 0.0;
538  };
539 }
540 
541 template<> float xml_cast(XmlRpc::XmlRpcValue xml_value)
542 {
543  using namespace XmlRpc;
544  switch(xml_value.getType()) {
545  case XmlRpcValue::TypeDouble:
546  return static_cast<float>(static_cast<double>(xml_value));
547  case XmlRpcValue::TypeInt:
548  return static_cast<float>(static_cast<int>(xml_value));
549  case XmlRpcValue::TypeBoolean:
550  return static_cast<float>(static_cast<bool>(xml_value));
551  default:
552  return 0.0f;
553  };
554 }
555 
556 template<> int xml_cast(XmlRpc::XmlRpcValue xml_value)
557 {
558  using namespace XmlRpc;
559  switch(xml_value.getType()) {
560  case XmlRpcValue::TypeDouble:
561  return static_cast<int>(static_cast<double>(xml_value));
562  case XmlRpcValue::TypeInt:
563  return static_cast<int>(xml_value);
564  case XmlRpcValue::TypeBoolean:
565  return static_cast<int>(static_cast<bool>(xml_value));
566  default:
567  return 0;
568  };
569 }
570 
571 template<> bool xml_cast(XmlRpc::XmlRpcValue xml_value)
572 {
573  using namespace XmlRpc;
574  switch(xml_value.getType()) {
575  case XmlRpcValue::TypeDouble:
576  return static_cast<bool>(static_cast<double>(xml_value));
577  case XmlRpcValue::TypeInt:
578  return static_cast<bool>(static_cast<int>(xml_value));
579  case XmlRpcValue::TypeBoolean:
580  return static_cast<bool>(xml_value);
581  default:
582  return false;
583  };
584 }
585 
586 template <class T>
587  bool getImpl(const std::string& key, std::vector<T>& vec, bool cached)
588 {
589  XmlRpc::XmlRpcValue xml_array;
590  if(!getImpl(key, xml_array, cached)) {
591  return false;
592  }
593 
594  // Make sure it's an array type
595  if(xml_array.getType() != XmlRpc::XmlRpcValue::TypeArray) {
596  return false;
597  }
598 
599  // Resize the target vector (destructive)
600  vec.resize(xml_array.size());
601 
602  // Fill the vector with stuff
603  for (int i = 0; i < xml_array.size(); i++) {
604  if(!xml_castable<T>(xml_array[i].getType())) {
605  return false;
606  }
607 
608  vec[i] = xml_cast<T>(xml_array[i]);
609  }
610 
611  return true;
612 }
613 
614 bool get(const std::string& key, std::vector<std::string>& vec)
615 {
616  return getImpl(key, vec, false);
617 }
618 bool get(const std::string& key, std::vector<double>& vec)
619 {
620  return getImpl(key, vec, false);
621 }
622 bool get(const std::string& key, std::vector<float>& vec)
623 {
624  return getImpl(key, vec, false);
625 }
626 bool get(const std::string& key, std::vector<int>& vec)
627 {
628  return getImpl(key, vec, false);
629 }
630 bool get(const std::string& key, std::vector<bool>& vec)
631 {
632  return getImpl(key, vec, false);
633 }
634 
635 bool getCached(const std::string& key, std::vector<std::string>& vec)
636 {
637  return getImpl(key, vec, true);
638 }
639 bool getCached(const std::string& key, std::vector<double>& vec)
640 {
641  return getImpl(key, vec, true);
642 }
643 bool getCached(const std::string& key, std::vector<float>& vec)
644 {
645  return getImpl(key, vec, true);
646 }
647 bool getCached(const std::string& key, std::vector<int>& vec)
648 {
649  return getImpl(key, vec, true);
650 }
651 bool getCached(const std::string& key, std::vector<bool>& vec)
652 {
653  return getImpl(key, vec, true);
654 }
655 
656 template <class T>
657  bool getImpl(const std::string& key, std::map<std::string, T>& map, bool cached)
658 {
659  XmlRpc::XmlRpcValue xml_value;
660  if(!getImpl(key, xml_value, cached)) {
661  return false;
662  }
663 
664  // Make sure it's a struct type
665  if(xml_value.getType() != XmlRpc::XmlRpcValue::TypeStruct) {
666  return false;
667  }
668 
669  // Fill the map with stuff
670  for (XmlRpc::XmlRpcValue::ValueStruct::const_iterator it = xml_value.begin();
671  it != xml_value.end();
672  ++it)
673  {
674  // Make sure this element is the right type
675  if(!xml_castable<T>(it->second.getType())) {
676  return false;
677  }
678  // Store the element
679  map[it->first] = xml_cast<T>(it->second);
680  }
681 
682  return true;
683 }
684 
685 bool get(const std::string& key, std::map<std::string, std::string>& map)
686 {
687  return getImpl(key, map, false);
688 }
689 bool get(const std::string& key, std::map<std::string, double>& map)
690 {
691  return getImpl(key, map, false);
692 }
693 bool get(const std::string& key, std::map<std::string, float>& map)
694 {
695  return getImpl(key, map, false);
696 }
697 bool get(const std::string& key, std::map<std::string, int>& map)
698 {
699  return getImpl(key, map, false);
700 }
701 bool get(const std::string& key, std::map<std::string, bool>& map)
702 {
703  return getImpl(key, map, false);
704 }
705 
706 bool getCached(const std::string& key, std::map<std::string, std::string>& map)
707 {
708  return getImpl(key, map, true);
709 }
710 bool getCached(const std::string& key, std::map<std::string, double>& map)
711 {
712  return getImpl(key, map, true);
713 }
714 bool getCached(const std::string& key, std::map<std::string, float>& map)
715 {
716  return getImpl(key, map, true);
717 }
718 bool getCached(const std::string& key, std::map<std::string, int>& map)
719 {
720  return getImpl(key, map, true);
721 }
722 bool getCached(const std::string& key, std::map<std::string, bool>& map)
723 {
724  return getImpl(key, map, true);
725 }
726 
727 bool getParamNames(std::vector<std::string>& keys)
728 {
729  XmlRpc::XmlRpcValue params, result, payload;
730  params[0] = this_node::getName();
731  if (!master::execute("getParamNames", params, result, payload, false)) {
732  return false;
733  }
734  // Make sure it's an array type
735  if (result.getType() != XmlRpc::XmlRpcValue::TypeArray) {
736  return false;
737  }
738  // Make sure it returned 3 elements
739  if (result.size() != 3) {
740  return false;
741  }
742  // Get the actual parameter keys
743  XmlRpc::XmlRpcValue parameters = result[2];
744  // Resize the output
745  keys.resize(parameters.size());
746 
747  // Fill the output vector with the answer
748  for (int i = 0; i < parameters.size(); ++i) {
749  if (parameters[i].getType() != XmlRpc::XmlRpcValue::TypeString) {
750  return false;
751  }
752  keys[i] = std::string(parameters[i]);
753  }
754  return true;
755 }
756 
757 bool search(const std::string& key, std::string& result_out)
758 {
759  return search(this_node::getName(), key, result_out);
760 }
761 
762 bool search(const std::string& ns, const std::string& key, std::string& result_out)
763 {
764  XmlRpc::XmlRpcValue params, result, payload;
765  params[0] = ns;
766 
767  // searchParam needs a separate form of remapping -- remapping on the unresolved name, rather than the
768  // resolved one.
769 
770  std::string remapped = key;
771  M_string::const_iterator it = names::getUnresolvedRemappings().find(key);
772  if (it != names::getUnresolvedRemappings().end())
773  {
774  remapped = it->second;
775  }
776 
777  params[1] = remapped;
778  // We don't loop here, because validateXmlrpcResponse() returns false
779  // both when we can't contact the master and when the master says, "I
780  // don't have that param."
781  if (!master::execute("searchParam", params, result, payload, false))
782  {
783  return false;
784  }
785 
786  result_out = (std::string)payload;
787 
788  return true;
789 }
790 
791 void update(const std::string& key, const XmlRpc::XmlRpcValue& v)
792 {
793  std::string clean_key = names::clean(key);
794  ROS_DEBUG_NAMED("cached_parameters", "Received parameter update for key [%s]", clean_key.c_str());
795 
796  boost::mutex::scoped_lock lock(g_params_mutex);
797 
798  if (g_subscribed_params.find(clean_key) != g_subscribed_params.end())
799  {
800  g_params[clean_key] = v;
801  }
802  invalidateParentParams(clean_key);
803 }
804 
806 {
807  result[0] = 1;
808  result[1] = std::string("");
809  result[2] = 0;
810 
811  ros::param::update((std::string)params[1], params[2]);
812 }
813 
814 void unsubscribeCachedParam(const std::string& key)
815 {
816  XmlRpc::XmlRpcValue params, result, payload;
817  params[0] = this_node::getName();
818  params[1] = XMLRPCManager::instance()->getServerURI();
819  params[2] = key;
820  master::execute("unsubscribeParam", params, result, payload, false);
821 }
822 
824 {
825  // lock required, all of the cached parameter will be unsubscribed.
826  boost::mutex::scoped_lock lock(g_params_mutex);
827 
828  for(S_string::iterator itr = g_subscribed_params.begin();
829  itr != g_subscribed_params.end(); ++itr)
830  {
831  const std::string mapped_key(*itr);
832  unsubscribeCachedParam(mapped_key);
833  }
834 }
835 
836 void init(const M_string& remappings)
837 {
838  M_string::const_iterator it = remappings.begin();
839  M_string::const_iterator end = remappings.end();
840  for (; it != end; ++it)
841  {
842  const std::string& name = it->first;
843  const std::string& param = it->second;
844 
845  if (name.size() < 2)
846  {
847  continue;
848  }
849 
850  if (name[0] == '_' && name[1] != '_')
851  {
852  std::string local_name = "~" + name.substr(1);
853 
854  bool success = false;
855 
856  try
857  {
858  int32_t i = boost::lexical_cast<int32_t>(param);
859  ros::param::set(names::resolve(local_name), i);
860  success = true;
861  }
862  catch (boost::bad_lexical_cast&)
863  {
864 
865  }
866 
867  if (success)
868  {
869  continue;
870  }
871 
872  try
873  {
874  double d = boost::lexical_cast<double>(param);
875  ros::param::set(names::resolve(local_name), d);
876  success = true;
877  }
878  catch (boost::bad_lexical_cast&)
879  {
880 
881  }
882 
883  if (success)
884  {
885  continue;
886  }
887 
888  if (param == "true" || param == "True" || param == "TRUE")
889  {
890  ros::param::set(names::resolve(local_name), true);
891  }
892  else if (param == "false" || param == "False" || param == "FALSE")
893  {
894  ros::param::set(names::resolve(local_name), false);
895  }
896  else
897  {
898  ros::param::set(names::resolve(local_name), param);
899  }
900  }
901  }
902 
903  XMLRPCManager::instance()->bind("paramUpdate", paramUpdateCallback);
904 }
905 
906 } // namespace param
907 
908 } // namespace ros
d
ROSCPP_DECL bool getParamNames(std::vector< std::string > &keys)
Get the list of all the parameters in the server.
Definition: param.cpp:727
std::map< std::string, XmlRpc::XmlRpcValue > M_Param
Definition: param.cpp:48
bool xml_castable(int XmlType)
Definition: param.cpp:484
bool param(const std::string &param_name, T &param_val, const T &default_val)
Assign value from parameter server, with default.
Definition: param.h:619
std::set< std::string > S_string
boost::mutex g_params_mutex
Definition: param.cpp:50
bool xml_castable< int >(int XmlType)
Definition: param.cpp:510
f
ROSCPP_DECL std::string parentNamespace(const std::string &name)
Get the parent namespace of a name.
Definition: names.cpp:206
int size() const
S_string g_subscribed_params
Definition: param.cpp:51
T xml_cast(XmlRpc::XmlRpcValue xml_value)
Definition: param.cpp:479
XmlRpcServer s
ROSCPP_DECL const std::string & getName()
Returns the name of the current node.
Definition: this_node.cpp:81
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
Resolve a graph resource name into a fully qualified graph resource name.
Definition: names.cpp:136
ROSCPP_DECL std::string clean(const std::string &name)
Cleans a graph resource name: removes double slashes, trailing slash.
Definition: names.cpp:99
Type const & getType() const
void setImpl(const std::string &key, const std::vector< T > &vec)
Definition: param.cpp:130
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
Definition: param.cpp:791
std::map< std::string, std::string > M_string
#define ROS_DEBUG_NAMED(name,...)
bool getImpl(const std::string &key, XmlRpc::XmlRpcValue &v, bool use_cache)
Definition: param.cpp:257
ROSCPP_DECL void set(const std::string &key, const XmlRpc::XmlRpcValue &v)
Set an arbitrary XML/RPC value on the parameter server.
Definition: param.cpp:67
void init(const M_string &remappings)
Definition: param.cpp:836
void invalidateParentParams(const std::string &key)
Definition: param.cpp:53
M_Param g_params
Definition: param.cpp:49
void setSize(int size)
ROSCPP_DECL bool execute(const std::string &method, const XmlRpc::XmlRpcValue &request, XmlRpc::XmlRpcValue &response, XmlRpc::XmlRpcValue &payload, bool wait_for_master)
Execute an XMLRPC call on the master.
Definition: master.cpp:179
ROSCPP_DECL const M_string & getUnresolvedRemappings()
Definition: names.cpp:51
ROSCPP_DECL bool has(const std::string &key)
Check whether a parameter exists on the parameter server.
Definition: param.cpp:211
ROSCPP_DECL bool getCached(const std::string &key, std::string &s)
Get a string value from the parameter server, with local caching.
Definition: param.cpp:449
ROSCPP_DECL bool del(const std::string &key)
Delete a parameter from the parameter server.
Definition: param.cpp:228
bool xml_castable< double >(int XmlType)
Definition: param.cpp:494
ROSCPP_DECL void unsubscribeCachedParam(const std::string &key)
Unsubscribe cached parameter from the master.
Definition: param.cpp:814
static const XMLRPCManagerPtr & instance()
bool xml_castable< float >(int XmlType)
Definition: param.cpp:502
ROSCPP_DECL bool search(const std::string &ns, const std::string &key, std::string &result)
Search up the tree for a parameter with a given key.
Definition: param.cpp:762
void paramUpdateCallback(XmlRpc::XmlRpcValue &params, XmlRpc::XmlRpcValue &result)
Definition: param.cpp:805
bool xml_castable< bool >(int XmlType)
Definition: param.cpp:518


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:26