17 #ifndef IGNITION_GAZEBO_EVENTMANAGER_HH_ 18 #define IGNITION_GAZEBO_EVENTMANAGER_HH_ 23 #include <unordered_map> 29 #include <ignition/gazebo/config.hh> 30 #include <ignition/gazebo/Export.hh> 38 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
67 public:
template <
typename E>
69 Connect(
const typename E::CallbackT &_subscriber)
71 if (this->events.find(
typeid(E)) == this->events.end()) {
72 this->events[
typeid(E)] = std::make_unique<E>();
75 E *eventPtr =
dynamic_cast<E *
>(this->events[
typeid(E)].
get());
78 if (eventPtr !=
nullptr)
80 return eventPtr->Connect(_subscriber);
84 ignerr <<
"Failed to connect event: " 93 public:
template <
typename E,
typename ... Args>
94 void Emit(Args && ... _args)
96 if (this->events.find(
typeid(E)) == this->events.end())
103 this->events[
typeid(E)] = std::make_unique<E>();
107 E *eventPtr =
dynamic_cast<E *
>(this->events[
typeid(E)].
get());
110 if (eventPtr !=
nullptr)
112 eventPtr->Signal(std::forward<Args>(_args) ...);
116 ignerr <<
"Failed to signal event: " 126 private:
struct Hasher
130 return _code.
get().hash_code();
135 private:
struct EqualTo
139 return _lhs.
get() == _rhs.
get();
146 Hasher, EqualTo> events;
152 #endif // IGNITION_GAZEBO_EVENTMANAGER_HH_
void Emit(Args &&... _args)
Emit an event signal to connected subscribers.
Definition: EventManager.hh:94
ignition::common::ConnectionPtr Connect(const typename E::CallbackT &_subscriber)
Add a connection to an event.
Definition: EventManager.hh:69
The EventManager is used to send/receive notifications of simulator events.
Definition: EventManager.hh:54
This library is part of the Ignition Robotics project.
class IGNITION_GAZEBO_HIDDEN EventManagerPrivate
Definition: EventManager.hh:40