17 #ifndef IGNITION_COMMON_EVENT_HH_ 18 #define IGNITION_COMMON_EVENT_HH_ 28 #include <ignition/common/config.hh> 29 #include <ignition/common/events/Export.hh> 38 class IGNITION_COMMON_EVENTS_VISIBLE
Event 44 public:
virtual ~
Event();
48 public:
virtual void Disconnect(
int _id) = 0;
52 public:
bool Signaled()
const;
56 public:
void SetSignaled(
const bool _sig);
59 private:
bool signaled;
75 public:
int Id()
const;
78 private:
Event *
event =
nullptr;
86 #pragma warning(disable: 4251) 95 public:
template<
typename T,
typename N>
friend class EventT;
102 template<
typename T,
typename N =
void>
107 "Event callback must have void return type");
113 public:
virtual ~
EventT();
123 public:
virtual void Disconnect(
int _id);
127 public:
unsigned int ConnectionCount()
const;
130 public:
template<
typename ... Args>
133 this->Signal(std::forward<Args>(args)...);
137 public:
template <
typename ... Args>
142 this->SetSignaled(
true);
143 for (
const auto &iter : this->connections)
146 iter.second->callback(std::forward<Args>(args)...);
153 private:
void Cleanup();
156 private:
class EventConnection
168 public: std::atomic_bool on;
179 private: EvtConnectionMap connections;
190 template<
typename T,
typename N>
197 template<
typename T,
typename N>
200 this->connections.
clear();
205 template<
typename T,
typename N>
209 if (!this->connections.
empty())
211 auto const &iter = this->connections.
rbegin();
212 index = iter->first + 1;
214 this->connections[index].reset(
new EventConnection(
true, _subscriber));
220 template<
typename T,
typename N>
223 return this->connections.
size();
228 template<
typename T,
typename N>
232 auto const &it = this->connections.
find(_id);
234 if (it != this->connections.
end())
236 it->second->on =
false;
242 template<
typename T,
typename N>
247 for (
auto &conn : this->connectionsToRemove)
248 this->connections.
erase(conn);
249 this->connectionsToRemove.clear();
void Signal(Args &&... args)
Signal the event for all subscribers.
Definition: Event.hh:138
A class that encapsulates a connection.
Definition: Event.hh:63
virtual ~EventT()
Destructor.
Definition: Event.hh:198
ConnectionPtr Connect(const CallbackT &_subscriber)
Connect a callback to this event.
Definition: Event.hh:206
Base class for all events.
Definition: Event.hh:38
EventT()
Constructor.
Definition: Event.hh:191
unsigned int ConnectionCount() const
Get the number of connections.
Definition: Event.hh:221
virtual void Disconnect(int _id)
Disconnect a callback to this event.
Definition: Event.hh:229
void operator()(Args &&... args)
Access the signal.
Definition: Event.hh:131
std::shared_ptr< Connection > ConnectionPtr
Definition: events/include/ignition/common/events/Types.hh:32
A class for event processing.
Definition: Event.hh:103
Forward declarations for the common classes.