Go to the documentation of this file.
17 #ifndef GZ_COMMON_EVENT_HH_
18 #define GZ_COMMON_EVENT_HH_
28 #include <gz/common/config.hh>
29 #include <gz/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");
130 public:
template<
typename ... Args>
133 this->
Signal(std::forward<Args>(args)...);
137 public:
template <
typename ... Args>
143 for (
const auto &iter : this->connections)
146 iter.second->callback(std::forward<Args>(args)...);
153 private:
void Cleanup();
156 private:
class EventConnection
161 : callback(_cb), publicConnection(_publicConn)
169 public: std::atomic_bool on;
185 private: EvtConnectionMap connections;
196 template<
typename T,
typename N>
203 template<
typename T,
typename N>
208 for (
auto &conn : this->connections)
210 auto publicCon = conn.second->publicConnection.lock();
213 publicCon->event =
nullptr;
216 this->connections.clear();
221 template<
typename T,
typename N>
225 if (!this->connections.empty())
227 auto const &iter = this->connections.rbegin();
228 index = iter->first + 1;
231 this->connections[index].reset(
232 new EventConnection(
true, _subscriber, connection));
238 template<
typename T,
typename N>
241 return this->connections.size();
246 template<
typename T,
typename N>
250 auto const &it = this->connections.find(_id);
252 if (it != this->connections.end())
254 it->second->on =
false;
262 it->second->callback =
nullptr;
263 this->connectionsToRemove.push_back(it);
268 template<
typename T,
typename N>
273 for (
auto &conn : this->connectionsToRemove)
274 this->connections.erase(conn);
275 this->connectionsToRemove.clear();
virtual void Disconnect(int _id)
Disconnect a callback to this event.
Definition: gz/common/Event.hh:247
Forward declarations for the common classes.
void operator()(Args &&... args)
Access the signal.
Definition: gz/common/Event.hh:131
unsigned int ConnectionCount() const
Get the number of connections.
Definition: gz/common/Event.hh:239
A class that encapsulates a connection.
Definition: gz/common/Event.hh:63
std::shared_ptr< Connection > ConnectionPtr
Definition: events/include/gz/common/events/Types.hh:32
Base class for all events.
Definition: gz/common/Event.hh:38
ConnectionPtr Connect(const CallbackT &_subscriber)
Connect a callback to this event.
Definition: gz/common/Event.hh:222
void Signal(Args &&... args)
Signal the event for all subscribers.
Definition: gz/common/Event.hh:138
virtual ~EventT()
Destructor.
Definition: gz/common/Event.hh:204
void SetSignaled(const bool _sig)
Set whether this event has been signaled.
EventT()
Constructor.
Definition: gz/common/Event.hh:197
A class for event processing.
Definition: gz/common/Event.hh:103