17 #ifndef IGNITION_GAZEBO_EVENTMANAGER_HH_ 18 #define IGNITION_GAZEBO_EVENTMANAGER_HH_ 23 #include <unordered_map> 26 #include <ignition/common/Console.hh> 27 #include <ignition/common/Event.hh> 29 #include <ignition/gazebo/config.hh> 30 #include <ignition/gazebo/Export.hh> 38 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
63 public:
template <
typename E>
64 ignition::common::ConnectionPtr
65 Connect(
const typename E::CallbackT &_subscriber)
67 if (this->events.find(
typeid(E)) == this->events.end()) {
68 this->events[
typeid(E)] = std::make_unique<E>();
71 E *eventPtr =
dynamic_cast<E *
>(this->events[
typeid(E)].
get());
74 if (eventPtr !=
nullptr)
76 return eventPtr->Connect(_subscriber);
80 ignerr <<
"Failed to connect event: " 81 <<
typeid(E).name() << std::endl;
89 public:
template <
typename E,
typename ... Args>
90 void Emit(Args && ... _args)
92 if (this->events.find(
typeid(E)) == this->events.end())
99 this->events[
typeid(E)] = std::make_unique<E>();
103 E *eventPtr =
dynamic_cast<E *
>(this->events[
typeid(E)].
get());
106 if (eventPtr !=
nullptr)
108 eventPtr->Signal(std::forward<Args>(_args) ...);
112 ignerr <<
"Failed to signal event: " 113 <<
typeid(E).name() << std::endl;
119 private:
using TypeInfoRef = std::reference_wrapper<const std::type_info>;
122 private:
struct Hasher
124 std::size_t operator()(TypeInfoRef _code)
const 126 return _code.get().hash_code();
131 private:
struct EqualTo
133 bool operator()(TypeInfoRef _lhs, TypeInfoRef _rhs)
const 135 return _lhs.get() == _rhs.get();
140 private: std::unordered_map<TypeInfoRef,
141 std::unique_ptr<ignition::common::Event>,
142 Hasher, EqualTo> events;
148 #endif // IGNITION_GAZEBO_EVENTMANAGER_HH_ void Emit(Args &&... _args)
Emit an event signal to connected subscribers.
Definition: EventManager.hh:90
ignition::common::ConnectionPtr Connect(const typename E::CallbackT &_subscriber)
Add a connection to an event.
Definition: EventManager.hh:65
The EventManager is used to send/receive notifications of simulator events.
Definition: EventManager.hh:50
This library is part of the Ignition Robotics project.
Definition: Altimeter.hh:25
class IGNITION_GAZEBO_HIDDEN EventManagerPrivate
Definition: EventManager.hh:40