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)
148 public: std::atomic_bool
on;
151 public: std::shared_ptr<boost::function<T> >
callback;
156 template<
typename T>
161 typedef std::map<int, std::shared_ptr<EventConnection<T> > >
171 public: std::list<typename EvtConnectionMap::const_iterator>
177 template<
typename T>
210 public:
template<
typename P >
219 public:
template<
typename P1,
typename P2 >
229 public:
template<
typename P1,
typename P2,
typename P3 >
232 this->
Signal(_p1, _p2, _p3);
240 public:
template<
typename P1,
typename P2,
typename P3,
typename P4 >
244 this->
Signal(_p1, _p2, _p3, _p4);
253 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
256 const P4 &_p4,
const P5 &_p5)
258 this->
Signal(_p1, _p2, _p3, _p4, _p5);
268 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
269 typename P5,
typename P6 >
271 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
273 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6);
284 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
285 typename P5,
typename P6,
typename P7 >
287 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
290 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
302 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
303 typename P5,
typename P6,
typename P7,
typename P8 >
305 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
306 const P7 &_p7,
const P8 &_p8)
308 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
321 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
322 typename P5,
typename P6,
typename P7,
typename P8,
325 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
326 const P7 &_p7,
const P8 &_p8,
const P9 &_p9)
328 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
342 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
343 typename P5,
typename P6,
typename P7,
typename P8,
344 typename P9,
typename P10 >
346 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
347 const P7 &_p7,
const P8 &_p8,
const P9 &_p9,
350 this->
Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
358 this->myDataPtr->signaled =
true;
359 for (
auto iter: this->myDataPtr->connections)
362 (*iter.second->callback)();
368 public:
template<
typename P >
373 this->myDataPtr->signaled =
true;
374 for (
auto iter: this->myDataPtr->connections)
377 (*iter.second->callback)(_p);
384 public:
template<
typename P1,
typename P2 >
385 void Signal(
const P1 &_p1,
const P2 &_p2)
389 this->myDataPtr->signaled =
true;
390 for (
auto iter: this->myDataPtr->connections)
393 (*iter.second->callback)(_p1, _p2);
401 public:
template<
typename P1,
typename P2,
typename P3 >
402 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3)
406 this->myDataPtr->signaled =
true;
407 for (
auto iter: this->myDataPtr->connections)
410 (*iter.second->callback)(_p1, _p2, _p3);
419 public:
template<
typename P1,
typename P2,
typename P3,
typename P4>
420 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
425 this->myDataPtr->signaled =
true;
426 for (
auto iter: this->myDataPtr->connections)
429 (*iter.second->callback)(_p1, _p2, _p3, _p4);
439 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
441 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
442 const P4 &_p4,
const P5 &_p5)
446 this->myDataPtr->signaled =
true;
447 for (
auto iter: this->myDataPtr->connections)
450 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5);
461 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
462 typename P5,
typename P6>
463 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
464 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
468 this->myDataPtr->signaled =
true;
469 for (
auto iter: this->myDataPtr->connections)
472 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5, _p6);
484 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
485 typename P5,
typename P6,
typename P7>
486 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
487 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7)
491 this->myDataPtr->signaled =
true;
492 for (
auto iter: this->myDataPtr->connections.begin())
495 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
508 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
509 typename P5,
typename P6,
typename P7,
typename P8>
510 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
511 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
516 this->myDataPtr->signaled =
true;
517 for (
auto iter: this->myDataPtr->connections)
521 (*iter.second->callback)(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
536 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
537 typename P5,
typename P6,
typename P7,
typename P8,
539 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
540 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
541 const P8 &_p8,
const P9 &_p9)
545 this->myDataPtr->signaled =
true;
546 for (
auto iter: this->myDataPtr->connections)
550 (*iter.second->callback)(
551 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
567 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
568 typename P5,
typename P6,
typename P7,
typename P8,
569 typename P9,
typename P10 >
570 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
571 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
572 const P8 &_p8,
const P9 &_p9,
const P10 &_p10)
576 this->myDataPtr->signaled =
true;
577 for (
auto iter: this->myDataPtr->connections)
581 (*iter.second->callback)(
582 _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
590 private:
void Cleanup();
608 this->myDataPtr->connections.clear();
617 if (!this->myDataPtr->connections.empty())
619 auto const &iter = this->myDataPtr->connections.rbegin();
620 index = iter->first + 1;
623 new boost::function<T>(_subscriber)));
635 this->Disconnect(_c->GetId());
636 _c->dataPtr->event =
NULL;
637 _c->dataPtr->id = -1;
645 return this->myDataPtr->connections.size();
654 auto const &it = this->myDataPtr->connections.find(_id);
656 if (it != this->myDataPtr->connections.end())
658 it->second->on =
false;
659 this->myDataPtr->connectionsToRemove.push_back(it);
667 std::lock_guard<std::mutex> lock(this->myDataPtr->mutex);
669 for (
auto &conn : this->myDataPtr->connectionsToRemove)
670 this->myDataPtr->connections.erase(conn);
671 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:539
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:147
Base class for all events.
Definition: Event.hh:61
std::list< typename EvtConnectionMap::const_iterator > connectionsToRemove
List of connections to remove.
Definition: Event.hh:172
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:486
std::shared_ptr< boost::function< T > > callback
Callback function.
Definition: Event.hh:151
virtual void Disconnect(ConnectionPtr _c)
Disconnect a callback to this event.
Definition: Event.hh:630
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four parameter.
Definition: Event.hh:420
void Signal()
Signal the event for all subscribers.
Definition: Event.hh:354
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:441
void operator()(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:211
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:230
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:286
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:168
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:255
void operator()(const P1 &_p1, const P2 &_p2)
Signal the event with two parameters.
Definition: Event.hh:220
virtual ~EventT()
Destructor.
Definition: Event.hh:606
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameter.
Definition: Event.hh:402
EvtConnectionMap connections
Array of connection callbacks.
Definition: Event.hh:165
void Signal(const P1 &_p1, const P2 &_p2)
Signal the event with two parameter.
Definition: Event.hh:385
#define GZ_COMMON_VISIBLE
Definition: system.hh:91
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:304
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:510
void Signal(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:369
std::atomic_bool on
On/off value for the event callback.
Definition: Event.hh:148
ConnectionPtr Connect(const boost::function< T > &_subscriber)
Connect a callback to this event.
Definition: Event.hh:614
void operator()()
Access the signal.
Definition: Event.hh:205
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:324
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:570
#define NULL
Definition: CommonTypes.hh:30
A class for event processing.
Definition: Event.hh:178
unsigned int ConnectionCount() const
Get the number of connections.
Definition: Event.hh:643
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four 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:270
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:463
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:345
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:39
EventT()
Constructor.
Definition: Event.hh:598