18 #ifndef _GAZEBO_EVENT_HH_ 19 #define _GAZEBO_EVENT_HH_ 30 #include <boost/function.hpp> 31 #include <boost/bind.hpp> 34 #include <gazebo/gazebo_config.h> 54 class GZ_COMMON_VISIBLE EventPrivate
57 public: EventPrivate();
60 public:
bool signaled;
72 public:
virtual ~
Event();
80 public:
virtual void Disconnect(
int _id) = 0;
84 public:
bool GetSignaled()
const;
88 protected:
Event(EventPrivate &_d);
96 class GZ_COMMON_VISIBLE ConnectionPrivate
99 public: ConnectionPrivate();
104 public: ConnectionPrivate(
Event *_e,
int _i);
107 public:
Event *event;
133 public:
int GetId()
const;
136 private: ConnectionPrivate *dataPtr;
139 public:
template<
typename T>
friend class EventT;
148 boost::function<T> *_cb)
157 public: std::atomic_bool
on;
160 public: std::shared_ptr<boost::function<T> >
callback;
165 template<
typename T>
166 class EventTPrivate :
public EventPrivate
170 typedef std::map<int, std::shared_ptr<EventConnection<T> > >
174 public: EvtConnectionMap connections;
177 public: std::mutex mutex;
180 public: std::list<typename EvtConnectionMap::const_iterator>
187 template<
typename T>
194 public:
virtual ~
EventT();
200 public:
ConnectionPtr Connect(
const boost::function<T> &_subscriber);
208 public:
virtual void Disconnect(
int _id);
212 public:
unsigned int ConnectionCount()
const;
220 public:
template<
typename P >
229 public:
template<
typename P1,
typename P2 >
232 this->Signal(_p1, _p2);
239 public:
template<
typename P1,
typename P2,
typename P3 >
242 this->Signal(_p1, _p2, _p3);
250 public:
template<
typename P1,
typename P2,
typename P3,
typename P4 >
254 this->Signal(_p1, _p2, _p3, _p4);
263 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
266 const P4 &_p4,
const P5 &_p5)
268 this->Signal(_p1, _p2, _p3, _p4, _p5);
278 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
279 typename P5,
typename P6 >
281 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
283 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6);
294 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
295 typename P5,
typename P6,
typename P7 >
297 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
300 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
312 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
313 typename P5,
typename P6,
typename P7,
typename P8 >
315 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
316 const P7 &_p7,
const P8 &_p8)
318 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
331 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
332 typename P5,
typename P6,
typename P7,
typename P8,
335 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
336 const P7 &_p7,
const P8 &_p8,
const P9 &_p9)
338 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
352 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
353 typename P5,
typename P6,
typename P7,
typename P8,
354 typename P9,
typename P10 >
356 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
357 const P7 &_p7,
const P8 &_p8,
const P9 &_p9,
360 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
368 this->myDataPtr->signaled =
true;
369 for (
auto iter: this->myDataPtr->connections)
372 (*iter.second->callback)();
378 public:
template<
typename P >
383 this->myDataPtr->signaled =
true;
384 for (
auto iter: this->myDataPtr->connections)
387 (*iter.second->callback)(_p);
394 public:
template<
typename P1,
typename P2 >
395 void Signal(
const P1 &_p1,
const P2 &_p2)
399 this->myDataPtr->signaled =
true;
400 for (
auto iter: this->myDataPtr->connections)
403 (*iter.second->callback)(_p1, _p2);
411 public:
template<
typename P1,
typename P2,
typename P3 >
412 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3)
416 this->myDataPtr->signaled =
true;
417 for (
auto iter: this->myDataPtr->connections)
420 (*iter.second->callback)(_p1, _p2, _p3);
429 public:
template<
typename P1,
typename P2,
typename P3,
typename P4>
430 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
435 this->myDataPtr->signaled =
true;
436 for (
auto iter: this->myDataPtr->connections)
439 (*iter.second->callback)(_p1, _p2, _p3, _p4);
449 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
451 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
452 const P4 &_p4,
const P5 &_p5)
456 this->myDataPtr->signaled =
true;
457 for (
auto iter: this->myDataPtr->connections)
460 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5);
471 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
472 typename P5,
typename P6>
473 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
474 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
478 this->myDataPtr->signaled =
true;
479 for (
auto iter: this->myDataPtr->connections)
482 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5, _p6);
494 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
495 typename P5,
typename P6,
typename P7>
496 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
497 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7)
501 this->myDataPtr->signaled =
true;
502 for (
auto iter: this->myDataPtr->connections.begin())
505 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
518 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
519 typename P5,
typename P6,
typename P7,
typename P8>
520 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
521 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
526 this->myDataPtr->signaled =
true;
527 for (
auto iter: this->myDataPtr->connections)
531 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
546 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
547 typename P5,
typename P6,
typename P7,
typename P8,
549 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
550 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
551 const P8 &_p8,
const P9 &_p9)
555 this->myDataPtr->signaled =
true;
556 for (
auto iter: this->myDataPtr->connections)
560 (*iter.second->callback)(
561 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
577 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
578 typename P5,
typename P6,
typename P7,
typename P8,
579 typename P9,
typename P10 >
580 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
581 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
582 const P8 &_p8,
const P9 &_p9,
const P10 &_p10)
586 this->myDataPtr->signaled =
true;
587 for (
auto iter: this->myDataPtr->connections)
591 (*iter.second->callback)(
592 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
600 private:
void Cleanup();
603 private: EventTPrivate<T> *myDataPtr;
609 :
Event(*(new EventTPrivate<T>()))
611 this->myDataPtr =
static_cast<EventTPrivate<T>*
>(this->dataPtr);
618 this->myDataPtr->connections.clear();
627 if (!this->myDataPtr->connections.empty())
629 auto const &iter = this->myDataPtr->connections.rbegin();
630 index = iter->first + 1;
633 new boost::function<T>(_subscriber)));
645 this->Disconnect(_c->GetId());
647 _c->dataPtr->id = -1;
655 return this->myDataPtr->connections.size();
664 auto const &it = this->myDataPtr->connections.find(_id);
666 if (it != this->myDataPtr->connections.end())
668 it->second->on =
false;
669 this->myDataPtr->connectionsToRemove.push_back(it);
677 std::lock_guard<std::mutex> lock(this->myDataPtr->mutex);
679 for (
auto &conn : this->myDataPtr->connectionsToRemove)
680 this->myDataPtr->connections.erase(conn);
681 this->myDataPtr->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:251
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:265
void Signal(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:379
Base class for all events.
Definition: Event.hh:66
A class that encapsulates a connection.
Definition: Event.hh:118
Forward declarations for the common classes.
Definition: Animation.hh:33
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:473
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:549
EventPrivate * dataPtr
Data pointer.
Definition: Event.hh:91
void operator()()
Access the signal.
Definition: Event.hh:215
void Signal(const P1 &_p1, const P2 &_p2)
Signal the event with two parameter.
Definition: Event.hh:395
EventT()
Constructor.
Definition: Event.hh:608
std::shared_ptr< boost::function< T > > callback
Callback function.
Definition: Event.hh:160
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:296
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:314
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:280
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:355
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameters.
Definition: Event.hh:240
void operator()(const P1 &_p1, const P2 &_p2)
Signal the event with two parameters.
Definition: Event.hh:230
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:155
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:451
#define NULL
Definition: CommonTypes.hh:33
std::atomic_bool on
On/off value for the event callback.
Definition: Event.hh:157
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameter.
Definition: Event.hh:412
A class for event processing.
Definition: Event.hh:188
void Signal()
Signal the event for all subscribers.
Definition: Event.hh:364
EventConnection(const bool _on, boost::function< T > *_cb)
Constructor.
Definition: Event.hh:147
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four parameter.
Definition: Event.hh:430
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:496
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:580
void operator()(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:221
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:334
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:520