17 #ifndef GAZEBO_COMMON_EVENT_HH_
18 #define GAZEBO_COMMON_EVENT_HH_
27 #include <gazebo/gazebo_config.h>
49 public:
virtual ~
Event();
59 public:
virtual void Disconnect(
int _id) = 0;
68 public:
bool Signaled()
const;
72 public:
void SetSignaled(
const bool _sig);
75 private:
bool signaled;
96 public:
int Id()
const;
99 private:
Event *
event =
nullptr;
102 private:
int id = -1;
108 public:
template<
typename T>
friend class EventT;
147 public:
template<
typename P >
156 public:
template<
typename P1,
typename P2 >
166 public:
template<
typename P1,
typename P2,
typename P3 >
169 this->
Signal(_p1, _p2, _p3);
177 public:
template<
typename P1,
typename P2,
typename P3,
typename P4 >
181 this->
Signal(_p1, _p2, _p3, _p4);
190 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
193 const P4 &_p4,
const P5 &_p5)
195 this->
Signal(_p1, _p2, _p3, _p4, _p5);
205 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
206 typename P5,
typename P6 >
208 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
210 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6);
221 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
222 typename P5,
typename P6,
typename P7 >
224 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
227 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
239 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
240 typename P5,
typename P6,
typename P7,
typename P8 >
242 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
243 const P7 &_p7,
const P8 &_p8)
245 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
258 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
259 typename P5,
typename P6,
typename P7,
typename P8,
262 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
263 const P7 &_p7,
const P8 &_p8,
const P9 &_p9)
265 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
279 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
280 typename P5,
typename P6,
typename P7,
typename P8,
281 typename P9,
typename P10 >
283 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
284 const P7 &_p7,
const P8 &_p8,
const P9 &_p9,
287 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
296 for (
const auto &iter: this->connections)
299 iter.second->callback();
305 public:
template<
typename P >
311 for (
const auto &iter: this->connections)
314 iter.second->callback(_p);
321 public:
template<
typename P1,
typename P2 >
322 void Signal(
const P1 &_p1,
const P2 &_p2)
327 for (
const auto &iter: this->connections)
330 iter.second->callback(_p1, _p2);
338 public:
template<
typename P1,
typename P2,
typename P3 >
339 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3)
344 for (
const auto &iter: this->connections)
347 iter.second->callback(_p1, _p2, _p3);
356 public:
template<
typename P1,
typename P2,
typename P3,
typename P4>
357 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
363 for (
const auto &iter: this->connections)
366 iter.second->callback(_p1, _p2, _p3, _p4);
376 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
378 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
379 const P4 &_p4,
const P5 &_p5)
384 for (
const auto &iter: this->connections)
387 iter.second->callback(_p1, _p2, _p3, _p4, _p5);
398 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
399 typename P5,
typename P6>
400 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
401 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
406 for (
const auto &iter: this->connections)
409 iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6);
421 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
422 typename P5,
typename P6,
typename P7>
423 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
424 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7)
429 for (
const auto &iter: this->connections)
432 iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
445 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
446 typename P5,
typename P6,
typename P7,
typename P8>
447 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
448 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
454 for (
const auto &iter: this->connections)
458 iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
473 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
474 typename P5,
typename P6,
typename P7,
typename P8,
476 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
477 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
478 const P8 &_p8,
const P9 &_p9)
483 for (
const auto &iter: this->connections)
487 iter.second->callback(
488 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
504 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
505 typename P5,
typename P6,
typename P7,
typename P8,
506 typename P9,
typename P10 >
507 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
508 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
509 const P8 &_p8,
const P9 &_p9,
const P10 &_p10)
514 for (
const auto &iter: this->connections)
518 iter.second->callback(
519 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
527 private:
void Cleanup();
530 private:
class EventConnection
533 public: EventConnection(
const bool _on,
const std::function<T> &_cb)
542 public: std::atomic_bool on;
545 public: std::function<T> callback;
550 typedef std::map<int, std::unique_ptr<EventConnection>> EvtConnectionMap;
553 private: EvtConnectionMap connections;
556 private: std::mutex mutex;
559 private: std::list<typename EvtConnectionMap::const_iterator>
574 this->connections.clear();
583 if (!this->connections.empty())
585 auto const &iter = this->connections.rbegin();
586 index = iter->first + 1;
588 this->connections[index].reset(
new EventConnection(
true, _subscriber));
600 this->Disconnect(_c->Id());
610 return this->connections.size();
619 auto const &it = this->connections.find(_id);
621 if (it != this->connections.end())
623 it->second->on =
false;
624 this->connectionsToRemove.push_back(it);
632 std::lock_guard<std::mutex> lock(this->mutex);
634 for (
auto &conn : this->connectionsToRemove)
635 this->connections.erase(conn);
636 this->connectionsToRemove.clear();
unsigned int ConnectionCount() const
Get the number of connections.
Definition: Event.hh:608
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four parameters.
Definition: Event.hh:178
virtual ~EventT()
Destructor.
Definition: Event.hh:572
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5)
Signal the event with five parameters.
Definition: Event.hh:192
void Signal(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:306
Base class for all events.
Definition: Event.hh:43
A class that encapsulates a connection.
Definition: Event.hh:79
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6)
Signal the event with six parameter.
Definition: Event.hh:400
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7, const P8 &_p8, const P9 &_p9)
Signal the event with nine parameter.
Definition: Event.hh:476
void operator()()
Access the signal.
Definition: Event.hh:142
void Signal(const P1 &_p1, const P2 &_p2)
Signal the event with two parameter.
Definition: Event.hh:322
virtual void Disconnect(ConnectionPtr _c) GAZEBO_DEPRECATED(8.0)
Disconnect a callback to this event.
Definition: Event.hh:595
EventT()
Constructor.
Definition: Event.hh:565
void SetSignaled(const bool _sig)
Set whether this event has been signaled.
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7)
Signal the event with seven parameters.
Definition: Event.hh:223
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7, const P8 &_p8)
Signal the event with eight parameters.
Definition: Event.hh:241
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6)
Signal the event with six parameters.
Definition: Event.hh:207
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7, const P8 &_p8, const P9 &_p9, const P10 &_p10)
Signal the event with ten parameters.
Definition: Event.hh:282
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameters.
Definition: Event.hh:167
void operator()(const P1 &_p1, const P2 &_p2)
Signal the event with two parameters.
Definition: Event.hh:157
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5)
Signal the event with five parameter.
Definition: Event.hh:378
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameter.
Definition: Event.hh:339
A class for event processing.
Definition: Event.hh:113
void Signal()
Signal the event for all subscribers.
Definition: Event.hh:291
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four parameter.
Definition: Event.hh:357
ConnectionPtr Connect(const std::function< T > &_subscriber)
Connect a callback to this event.
Definition: Event.hh:580
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7)
Signal the event with seven parameter.
Definition: Event.hh:423
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7, const P8 &_p8, const P9 &_p9, const P10 &_p10)
Signal the event with ten parameter.
Definition: Event.hh:507
void operator()(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:148
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7, const P8 &_p8, const P9 &_p9)
Signal the event with nine parameters.
Definition: Event.hh:261
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4, const P5 &_p5, const P6 &_p6, const P7 &_p7, const P8 &_p8)
Signal the event with eight parameter.
Definition: Event.hh:447