17 #ifndef GAZEBO_COMMON_EVENT_HH_ 18 #define GAZEBO_COMMON_EVENT_HH_ 27 #include <gazebo/gazebo_config.h> 49 public:
virtual ~
Event();
53 public:
virtual void Disconnect(
int _id) = 0;
57 public:
bool Signaled()
const;
61 public:
void SetSignaled(
const bool _sig);
64 private:
bool signaled;
80 public:
int Id()
const;
83 private:
Event *
event =
nullptr;
92 public:
template<
typename T>
friend class EventT;
103 public:
virtual ~
EventT();
109 public:
ConnectionPtr Connect(
const std::function<T> &_subscriber);
113 public:
virtual void Disconnect(
int _id);
117 public:
unsigned int ConnectionCount()
const;
125 public:
template<
typename P >
134 public:
template<
typename P1,
typename P2 >
137 this->Signal(_p1, _p2);
144 public:
template<
typename P1,
typename P2,
typename P3 >
147 this->Signal(_p1, _p2, _p3);
155 public:
template<
typename P1,
typename P2,
typename P3,
typename P4 >
159 this->Signal(_p1, _p2, _p3, _p4);
168 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
171 const P4 &_p4,
const P5 &_p5)
173 this->Signal(_p1, _p2, _p3, _p4, _p5);
183 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
184 typename P5,
typename P6 >
186 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
188 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6);
199 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
200 typename P5,
typename P6,
typename P7 >
202 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
205 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
217 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
218 typename P5,
typename P6,
typename P7,
typename P8 >
220 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
221 const P7 &_p7,
const P8 &_p8)
223 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
236 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
237 typename P5,
typename P6,
typename P7,
typename P8,
240 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
241 const P7 &_p7,
const P8 &_p8,
const P9 &_p9)
243 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
257 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
258 typename P5,
typename P6,
typename P7,
typename P8,
259 typename P9,
typename P10 >
261 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
262 const P7 &_p7,
const P8 &_p8,
const P9 &_p9,
265 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
273 this->SetSignaled(
true);
274 for (
const auto &iter: this->connections)
277 iter.second->callback();
283 public:
template<
typename P >
288 this->SetSignaled(
true);
289 for (
const auto &iter: this->connections)
292 iter.second->callback(_p);
299 public:
template<
typename P1,
typename P2 >
300 void Signal(
const P1 &_p1,
const P2 &_p2)
304 this->SetSignaled(
true);
305 for (
const auto &iter: this->connections)
308 iter.second->callback(_p1, _p2);
316 public:
template<
typename P1,
typename P2,
typename P3 >
317 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3)
321 this->SetSignaled(
true);
322 for (
const auto &iter: this->connections)
325 iter.second->callback(_p1, _p2, _p3);
334 public:
template<
typename P1,
typename P2,
typename P3,
typename P4>
335 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
340 this->SetSignaled(
true);
341 for (
const auto &iter: this->connections)
344 iter.second->callback(_p1, _p2, _p3, _p4);
354 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
356 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
357 const P4 &_p4,
const P5 &_p5)
361 this->SetSignaled(
true);
362 for (
const auto &iter: this->connections)
365 iter.second->callback(_p1, _p2, _p3, _p4, _p5);
376 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
377 typename P5,
typename P6>
378 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
379 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
383 this->SetSignaled(
true);
384 for (
const auto &iter: this->connections)
387 iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6);
399 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
400 typename P5,
typename P6,
typename P7>
401 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
402 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7)
406 this->SetSignaled(
true);
407 for (
const auto &iter: this->connections)
410 iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
423 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
424 typename P5,
typename P6,
typename P7,
typename P8>
425 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
426 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
431 this->SetSignaled(
true);
432 for (
const auto &iter: this->connections)
436 iter.second->callback(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
451 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
452 typename P5,
typename P6,
typename P7,
typename P8,
454 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
455 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
456 const P8 &_p8,
const P9 &_p9)
460 this->SetSignaled(
true);
461 for (
const auto &iter: this->connections)
465 iter.second->callback(
466 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
482 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
483 typename P5,
typename P6,
typename P7,
typename P8,
484 typename P9,
typename P10 >
485 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
486 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
487 const P8 &_p8,
const P9 &_p9,
const P10 &_p10)
491 this->SetSignaled(
true);
492 for (
const auto &iter: this->connections)
496 iter.second->callback(
497 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
505 private:
void Cleanup();
508 private:
class EventConnection
511 public: EventConnection(
const bool _on,
const std::function<T> &_cb)
520 public: std::atomic_bool on;
523 public: std::function<T> callback;
528 typedef std::map<int, std::unique_ptr<EventConnection>> EvtConnectionMap;
531 private: EvtConnectionMap connections;
534 private: std::mutex mutex;
537 private: std::list<typename EvtConnectionMap::const_iterator>
552 this->connections.clear();
561 if (!this->connections.empty())
563 auto const &iter = this->connections.rbegin();
564 index = iter->first + 1;
566 this->connections[index].reset(
new EventConnection(
true, _subscriber));
575 return this->connections.size();
584 auto const &it = this->connections.find(_id);
586 if (it != this->connections.end())
588 it->second->on =
false;
589 this->connectionsToRemove.push_back(it);
597 std::lock_guard<std::mutex> lock(this->mutex);
599 for (
auto &conn : this->connectionsToRemove)
600 this->connections.erase(conn);
601 this->connectionsToRemove.clear();
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four parameters.
Definition: Event.hh:156
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:170
void Signal(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:284
Base class for all events.
Definition: Event.hh:43
A class that encapsulates a connection.
Definition: Event.hh:68
Forward declarations for the common classes.
Definition: Animation.hh:26
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:378
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:454
void operator()()
Access the signal.
Definition: Event.hh:120
void Signal(const P1 &_p1, const P2 &_p2)
Signal the event with two parameter.
Definition: Event.hh:300
EventT()
Constructor.
Definition: Event.hh:543
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:201
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:219
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:185
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:260
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameters.
Definition: Event.hh:145
void operator()(const P1 &_p1, const P2 &_p2)
Signal the event with two parameters.
Definition: Event.hh:135
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:356
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameter.
Definition: Event.hh:317
A class for event processing.
Definition: Event.hh:97
void Signal()
Signal the event for all subscribers.
Definition: Event.hh:269
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four parameter.
Definition: Event.hh:335
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:401
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:485
void operator()(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:126
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:239
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:425