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>
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
35GZ_SINGLETON_DECLARE(GZ_UTIL_VISIBLE, gazebo, util, IntrospectionManager)
36
37namespace gazebo
38{
39 namespace util
40 {
41 // Forward declare private data classes.
42 class IntrospectionManagerPrivate;
43
46
49 class GZ_UTIL_VISIBLE IntrospectionManager
50 : public SingletonT<IntrospectionManager>
51 {
54 public: std::string Id() const;
55
61 public: template<typename T>
62 bool Register(const std::string &_item,
63 const std::function<T()> &_cb)
64 {
65 auto func = [=]()
66 {
67 return msgs::ConvertAny(_cb());
68 };
69
70 return this->Register(_item, func);
71 }
72
77 public: bool Unregister(const std::string &_item);
78
80 public: void Clear();
81
84 public: std::set<std::string> Items() const;
85
93 public: void Update();
94
98 public: void NotifyUpdates();
99
101 private: IntrospectionManager();
102
104 private: virtual ~IntrospectionManager();
105
111 private: bool Register(const std::string &_item,
112 const std::function <gazebo::msgs::Any()> &_cb);
113
123 private: bool NewFilterImpl(const std::set<std::string> &_newItems,
124 std::string &_filterId);
125
130 private: bool UpdateFilterImpl(const std::string &_filterId,
131 const std::set<std::string> &_newItems);
132
136 private: bool RemoveFilterImpl(const std::string &_filterId);
137
146 private: bool NewFilter(const gazebo::msgs::Param_V &_req,
147 gazebo::msgs::GzString &_rep);
148
158 private: bool UpdateFilter(const gazebo::msgs::Param_V &_req,
159 gazebo::msgs::Empty &_rep);
160
168 private: bool RemoveFilter(const gazebo::msgs::Param_V &_req,
169 gazebo::msgs::Empty &_rep);
170
178 private: bool Items(const gazebo::msgs::Empty &_req,
179 gazebo::msgs::Param_V &_rep);
180
185 private: std::string CreateRandomId(const unsigned int &_size) const;
186
193 private: bool ValidateParameter(const gazebo::msgs::Param &_msg,
194 const std::set<std::string> &_allowedValues) const;
195
197 private: friend class SingletonT<IntrospectionManager>;
198
201 private: std::unique_ptr<IntrospectionManagerPrivate> dataPtr;
202 };
204 }
205}
206#endif
util
Definition Diagnostics.hh:33
gazebo
Definition IntrospectionManager.hh:35
util
Definition IntrospectionManager.hh:35
Singleton template class.
Definition SingletonT.hh:34
addtogroup gazebo_util
Definition IntrospectionManager.hh:51
void NotifyUpdates()
If there are changes in the items list since the last update, a new message is published under the to...
bool Register(const std::string &_item, const std::function< T()> &_cb)
Register a new item in the introspection manager.
Definition IntrospectionManager.hh:62
std::set< std::string > Items() const
Get a copy of the items already registered in this manager.
void Clear()
Unregister all items.
bool Unregister(const std::string &_item)
Unregister an existing item from the introspection manager.
void Update()
Update all the items under observation and publish updates through all the topics.
std::string Id() const
Get the unique ID of this manager.
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition SingletonT.hh:58
Forward declarations for the common classes.
Definition Animation.hh:27