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
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;
268 template<
typename T,
typename N>
273 for (
auto &conn : this->connectionsToRemove)
274 this->connections.
erase(conn);
275 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:204
ConnectionPtr Connect(const CallbackT &_subscriber)
Connect a callback to this event.
Definition: Event.hh:222
Base class for all events.
Definition: Event.hh:38
EventT()
Constructor.
Definition: Event.hh:197
unsigned int ConnectionCount() const
Get the number of connections.
Definition: Event.hh:239
virtual void Disconnect(int _id)
Disconnect a callback to this event.
Definition: Event.hh:247
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.