##

IntrospectionManager.hh
Go to the documentation of this file.
/*
* Copyright (C) 2016 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_UTIL_INTROSPECTION_MANAGER_HH_
#define GAZEBO_UTIL_INTROSPECTION_MANAGER_HH_
#include <functional>
#include <memory>
#include <set>
#include <string>
#include "gazebo/common/Console.hh"
#include "gazebo/common/SingletonT.hh"
#include "gazebo/msgs/any.pb.h"
#include "gazebo/msgs/empty.pb.h"
#include "gazebo/msgs/gz_string.pb.h"
#include "gazebo/msgs/msgs.hh"
#include "gazebo/msgs/param.pb.h"
#include "gazebo/msgs/param_v.pb.h"
#include "gazebo/util/system.hh"
GZ_SINGLETON_DECLARE(GZ_UTIL_VISIBLE, gazebo, util, IntrospectionManager)
namespace gazebo
{
namespace util
{
// Forward declare private data classes.
class IntrospectionManagerPrivate;
class GZ_UTIL_VISIBLE IntrospectionManager
: public SingletonT<IntrospectionManager>
{
public: std::string Id() const;
public: template<typename T>
bool Register(const std::string &_item,
const std::function<T()> &_cb)
{
auto func = [=]()
{
return msgs::ConvertAny(_cb());
};
return this->Register(_item, func);
}
public: bool Unregister(const std::string &_item);
public: void Clear();
public: std::set<std::string> Items() const;
public: void Update();
public: void NotifyUpdates();
private: IntrospectionManager();
private: virtual ~IntrospectionManager();
private: bool Register(const std::string &_item,
const std::function <gazebo::msgs::Any()> &_cb);
private: bool NewFilterImpl(const std::set<std::string> &_newItems,
std::string &_filterId);
private: bool UpdateFilterImpl(const std::string &_filterId,
const std::set<std::string> &_newItems);
private: bool RemoveFilterImpl(const std::string &_filterId);
private: bool NewFilter(const gazebo::msgs::Param_V &_req,
gazebo::msgs::GzString &_rep);
private: bool UpdateFilter(const gazebo::msgs::Param_V &_req,
gazebo::msgs::Empty &_rep);
private: bool RemoveFilter(const gazebo::msgs::Param_V &_req,
gazebo::msgs::Empty &_rep);
private: bool Items(const gazebo::msgs::Empty &_req,
gazebo::msgs::Param_V &_rep);
private: std::string CreateRandomId(const unsigned int &_size) const;
private: bool ValidateParameter(const gazebo::msgs::Param &_msg,
const std::set<std::string> &_allowedValues) const;
private: friend class SingletonT<IntrospectionManager>;
private: std::unique_ptr<IntrospectionManagerPrivate> dataPtr;
};
}
}
#endif
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
SingletonT
Singleton template class.
Definition: SingletonT.hh:33
gazebo
gazebo
Definition: IntrospectionManager.hh:35
Console.hh
system.hh
msgs.hh
gazebo::common::Param_V
std::vector< common::Param * > Param_V
Definition: CommonTypes.hh:97
util
util
Definition: IntrospectionManager.hh:35
gazebo::util::IntrospectionManager
addtogroup gazebo_util
Definition: IntrospectionManager.hh:49
gazebo::util::IntrospectionManager::Register
bool Register(const std::string &_item, const std::function< T()> &_cb)
Register a new item in the introspection manager.
Definition: IntrospectionManager.hh:62
gazebo::msgs::ConvertAny
GAZEBO_VISIBLE msgs::Any ConvertAny(const double _v)
Convert a double to a msgs::Any.
GZ_SINGLETON_DECLARE
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
SingletonT.hh