IntrospectionManager.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GAZEBO_UTIL_INTROSPECTION_MANAGER_HH_
18 #define GAZEBO_UTIL_INTROSPECTION_MANAGER_HH_
19 
20 #include <functional>
21 #include <memory>
22 #include <set>
23 #include <string>
24 #include "gazebo/common/Console.hh"
26 #include "gazebo/msgs/any.pb.h"
27 #include "gazebo/msgs/empty.pb.h"
28 #include "gazebo/msgs/gz_string.pb.h"
29 #include "gazebo/msgs/msgs.hh"
30 #include "gazebo/msgs/param.pb.h"
31 #include "gazebo/msgs/param_v.pb.h"
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace util
37  {
38  // Forward declare private data classes.
39  class IntrospectionManagerPrivate;
40 
43 
46  class GZ_UTIL_VISIBLE IntrospectionManager
47  : public SingletonT<IntrospectionManager>
48  {
51  public: std::string Id() const;
52 
58  public: template<typename T>
59  bool Register(const std::string &_item,
60  const std::function<T()> &_cb)
61  {
62  auto func = [=]()
63  {
64  return msgs::ConvertAny(_cb());
65  };
66 
67  return this->Register(_item, func);
68  }
69 
74  public: bool Unregister(const std::string &_item);
75 
77  public: void Clear();
78 
81  public: std::set<std::string> Items() const;
82 
90  public: void Update();
91 
95  public: void NotifyUpdates();
96 
98  private: IntrospectionManager();
99 
101  private: virtual ~IntrospectionManager();
102 
108  private: bool Register(const std::string &_item,
109  const std::function <gazebo::msgs::Any()> &_cb);
110 
120  private: bool NewFilter(const std::set<std::string> &_newItems,
121  std::string &_filterId);
122 
127  private: bool UpdateFilter(const std::string &_filterId,
128  const std::set<std::string> &_newItems);
129 
133  private: bool RemoveFilter(const std::string &_filterId);
134 
143  private: void NewFilter(const gazebo::msgs::Param_V &_req,
144  gazebo::msgs::GzString &_rep,
145  bool &_result);
146 
156  private: void UpdateFilter(const gazebo::msgs::Param_V &_req,
157  gazebo::msgs::Empty &_rep,
158  bool &_result);
159 
167  private: void RemoveFilter(const gazebo::msgs::Param_V &_req,
168  gazebo::msgs::Empty &_rep,
169  bool &_result);
170 
178  private: void Items(const gazebo::msgs::Empty &_req,
179  gazebo::msgs::Param_V &_rep,
180  bool &_result);
181 
186  private: std::string CreateRandomId(const unsigned int &_size) const;
187 
194  private: bool ValidateParameter(const gazebo::msgs::Param &_msg,
195  const std::set<std::string> &_allowedValues) const;
196 
198  private: friend class SingletonT<IntrospectionManager>;
199 
202  private: std::unique_ptr<IntrospectionManagerPrivate> dataPtr;
203  };
205  }
206 }
207 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
std::vector< common::Param * > Param_V
Definition: CommonTypes.hh:97
addtogroup gazebo_util
Definition: IntrospectionManager.hh:46
bool Register(const std::string &_item, const std::function< T()> &_cb)
Register a new item in the introspection manager.
Definition: IntrospectionManager.hh:59
Singleton template class.
Definition: SingletonT.hh:33
GAZEBO_VISIBLE msgs::Any ConvertAny(const double _v)
Convert a double to a msgs::Any.