18 #ifndef _GAZEBO_EVENT_HH_
19 #define _GAZEBO_EVENT_HH_
29 #include <boost/function.hpp>
30 #include <boost/bind.hpp>
32 #include <gazebo/gazebo_config.h>
67 public:
virtual ~
Event();
75 public:
virtual void Disconnect(
int _id) = 0;
79 public:
bool GetSignaled()
const;
127 public:
int GetId()
const;
133 public:
template<
typename T>
friend class EventT;
142 boost::function<T> *_cb)
151 public: std::atomic_bool
on;
154 public: std::shared_ptr<boost::function<T> >
callback;
159 template<
typename T>
164 typedef std::map<int, std::shared_ptr<EventConnection<T> > >
174 public: std::list<typename EvtConnectionMap::const_iterator>
180 template<
typename T>
213 public:
template<
typename P >
222 public:
template<
typename P1,
typename P2 >
232 public:
template<
typename P1,
typename P2,
typename P3 >
235 this->
Signal(_p1, _p2, _p3);
243 public:
template<
typename P1,
typename P2,
typename P3,
typename P4 >
247 this->
Signal(_p1, _p2, _p3, _p4);
256 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
259 const P4 &_p4,
const P5 &_p5)
261 this->
Signal(_p1, _p2, _p3, _p4, _p5);
271 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
272 typename P5,
typename P6 >
274 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
276 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6);
287 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
288 typename P5,
typename P6,
typename P7 >
290 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
293 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
305 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
306 typename P5,
typename P6,
typename P7,
typename P8 >
308 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
309 const P7 &_p7,
const P8 &_p8)
311 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
324 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
325 typename P5,
typename P6,
typename P7,
typename P8,
328 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
329 const P7 &_p7,
const P8 &_p8,
const P9 &_p9)
331 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
345 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
346 typename P5,
typename P6,
typename P7,
typename P8,
347 typename P9,
typename P10 >
349 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
350 const P7 &_p7,
const P8 &_p8,
const P9 &_p9,
353 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
361 this->myDataPtr->signaled =
true;
362 for (
auto iter: this->myDataPtr->connections)
365 (*iter.second->callback)();
371 public:
template<
typename P >
376 this->myDataPtr->signaled =
true;
377 for (
auto iter: this->myDataPtr->connections)
380 (*iter.second->callback)(_p);
387 public:
template<
typename P1,
typename P2 >
388 void Signal(
const P1 &_p1,
const P2 &_p2)
392 this->myDataPtr->signaled =
true;
393 for (
auto iter: this->myDataPtr->connections)
396 (*iter.second->callback)(_p1, _p2);
404 public:
template<
typename P1,
typename P2,
typename P3 >
405 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3)
409 this->myDataPtr->signaled =
true;
410 for (
auto iter: this->myDataPtr->connections)
413 (*iter.second->callback)(_p1, _p2, _p3);
422 public:
template<
typename P1,
typename P2,
typename P3,
typename P4>
423 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
428 this->myDataPtr->signaled =
true;
429 for (
auto iter: this->myDataPtr->connections)
432 (*iter.second->callback)(_p1, _p2, _p3, _p4);
442 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
444 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
445 const P4 &_p4,
const P5 &_p5)
449 this->myDataPtr->signaled =
true;
450 for (
auto iter: this->myDataPtr->connections)
453 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5);
464 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
465 typename P5,
typename P6>
466 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
467 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
471 this->myDataPtr->signaled =
true;
472 for (
auto iter: this->myDataPtr->connections)
475 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5, _p6);
487 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
488 typename P5,
typename P6,
typename P7>
489 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
490 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7)
494 this->myDataPtr->signaled =
true;
495 for (
auto iter: this->myDataPtr->connections.begin())
498 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
511 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
512 typename P5,
typename P6,
typename P7,
typename P8>
513 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
514 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
519 this->myDataPtr->signaled =
true;
520 for (
auto iter: this->myDataPtr->connections)
524 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
539 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
540 typename P5,
typename P6,
typename P7,
typename P8,
542 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
543 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
544 const P8 &_p8,
const P9 &_p9)
548 this->myDataPtr->signaled =
true;
549 for (
auto iter: this->myDataPtr->connections)
553 (*iter.second->callback)(
554 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
570 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
571 typename P5,
typename P6,
typename P7,
typename P8,
572 typename P9,
typename P10 >
573 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
574 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
575 const P8 &_p8,
const P9 &_p9,
const P10 &_p10)
579 this->myDataPtr->signaled =
true;
580 for (
auto iter: this->myDataPtr->connections)
584 (*iter.second->callback)(
585 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
593 private:
void Cleanup();
611 this->myDataPtr->connections.clear();
620 if (!this->myDataPtr->connections.empty())
622 auto const &iter = this->myDataPtr->connections.rbegin();
623 index = iter->first + 1;
626 new boost::function<T>(_subscriber)));
638 this->Disconnect(_c->GetId());
639 _c->dataPtr->event =
NULL;
640 _c->dataPtr->id = -1;
648 return this->myDataPtr->connections.size();
657 auto const &it = this->myDataPtr->connections.find(_id);
659 if (it != this->myDataPtr->connections.end())
661 it->second->on =
false;
662 this->myDataPtr->connectionsToRemove.push_back(it);
670 std::lock_guard<std::mutex> lock(this->myDataPtr->mutex);
672 for (
auto &conn : this->myDataPtr->connectionsToRemove)
673 this->myDataPtr->connections.erase(conn);
674 this->myDataPtr->connectionsToRemove.clear();
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:542
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:153
Base class for all events.
Definition: Event.hh:61
std::list< typename EvtConnectionMap::const_iterator > connectionsToRemove
List of connections to remove.
Definition: Event.hh:175
A class that encapsulates a connection.
Definition: Event.hh:112
EventPrivate * dataPtr
Data pointer.
Definition: Event.hh:86
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:489
std::shared_ptr< boost::function< T > > callback
Callback function.
Definition: Event.hh:154
virtual void Disconnect(ConnectionPtr _c)
Disconnect a callback to this event.
Definition: Event.hh:633
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four parameter.
Definition: Event.hh:423
void Signal()
Signal the event for all subscribers.
Definition: Event.hh:357
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:444
void operator()(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:214
int id
the id set in the constructor
Definition: Event.hh:105
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameters.
Definition: Event.hh:233
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:289
EventConnection(const bool _on, boost::function< T > *_cb)
Constructor.
Definition: Event.hh:141
Event * event
the event for this connection
Definition: Event.hh:102
std::mutex mutex
A thread lock.
Definition: Event.hh:171
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:258
void operator()(const P1 &_p1, const P2 &_p2)
Signal the event with two parameters.
Definition: Event.hh:223
virtual ~EventT()
Destructor.
Definition: Event.hh:609
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameter.
Definition: Event.hh:405
EvtConnectionMap connections
Array of connection callbacks.
Definition: Event.hh:168
void Signal(const P1 &_p1, const P2 &_p2)
Signal the event with two parameter.
Definition: Event.hh:388
#define GZ_COMMON_VISIBLE
Definition: system.hh:84
bool signaled
True if the event has been signaled.
Definition: Event.hh:56
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:307
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:513
void Signal(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:372
std::atomic_bool on
On/off value for the event callback.
Definition: Event.hh:151
ConnectionPtr Connect(const boost::function< T > &_subscriber)
Connect a callback to this event.
Definition: Event.hh:617
void operator()()
Access the signal.
Definition: Event.hh:208
common::Time creationTime
set during the constructor
Definition: Event.hh:108
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:327
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:573
#define NULL
Definition: CommonTypes.hh:31
A class for event processing.
Definition: Event.hh:181
unsigned int ConnectionCount() const
Get the number of connections.
Definition: Event.hh:646
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four parameters.
Definition: Event.hh:244
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:273
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:466
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:348
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44
EventT()
Constructor.
Definition: Event.hh:601