25 #include <boost/function.hpp>
26 #include <boost/bind.hpp>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/thread/mutex.hpp>
30 #include <gazebo/gazebo_config.h>
65 public:
virtual ~
Event();
73 public:
virtual void Disconnect(
int _id) = 0;
77 public:
bool GetSignaled()
const;
125 public:
int GetId()
const;
131 public:
template<
typename T>
friend class EventT;
136 template<
typename T>
141 typedef std::map<int, boost::function<T>*> EvtConnectionMap;
155 template<
typename T>
160 typedef std::map<int, boost::function<T>*> EvtConnectionMap;
166 public:
virtual ~
EventT();
172 public:
ConnectionPtr Connect(
const boost::function<T> &_subscriber);
180 public:
virtual void Disconnect(
int _id);
184 public:
unsigned int ConnectionCount()
const;
193 this->myDataPtr->signaled =
true;
195 for (
typename EvtConnectionMap::iterator iter =
196 this->myDataPtr->connections.begin();
197 iter != this->myDataPtr->connections.end(); ++iter)
205 public:
template<
typename P >
207 { this->Signal(_p); }
212 public:
template<
typename P1,
typename P2 >
214 { this->Signal(_p1, _p2); }
220 public:
template<
typename P1,
typename P2,
typename P3 >
222 { this->Signal(_p1, _p2, _p3); }
229 public:
template<
typename P1,
typename P2,
typename P3,
typename P4 >
232 { this->Signal(_p1, _p2, _p3, _p4); }
240 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
243 const P4 &_p4,
const P5 &_p5)
244 { this->Signal(_p1, _p2, _p3, _p4, _p5); }
253 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
254 typename P5,
typename P6 >
256 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
257 { this->Signal(_p1, _p2, _p3, _p4, _p5, _p6); }
267 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
268 typename P5,
typename P6,
typename P7 >
270 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
272 { this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7); }
283 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
284 typename P5,
typename P6,
typename P7,
typename P8 >
286 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
287 const P7 &_p7,
const P8 &_p8)
288 { this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8); }
300 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
301 typename P5,
typename P6,
typename P7,
typename P8,
304 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
305 const P7 &_p7,
const P8 &_p8,
const P9 &_p9)
306 { this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9); }
319 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
320 typename P5,
typename P6,
typename P7,
typename P8,
321 typename P9,
typename P10 >
323 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
324 const P7 &_p7,
const P8 &_p8,
const P9 &_p9,
327 this->Signal(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10);
332 public:
template<
typename P >
335 this->myDataPtr->signaled =
true;
337 for (
typename EvtConnectionMap::iterator iter =
338 this->myDataPtr->connections.begin();
339 iter != this->myDataPtr->connections.end(); ++iter)
348 public:
template<
typename P1,
typename P2 >
349 void Signal(
const P1 &_p1,
const P2 &_p2)
351 this->myDataPtr->signaled =
true;
353 for (
typename EvtConnectionMap::iterator iter =
354 this->myDataPtr->connections.begin();
355 iter != this->myDataPtr->connections.end(); ++iter)
357 (*iter->second)(_p1, _p2);
365 public:
template<
typename P1,
typename P2,
typename P3 >
366 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3)
368 this->myDataPtr->signaled =
true;
370 for (
typename EvtConnectionMap::iterator iter =
371 this->myDataPtr->connections.begin();
372 iter != this->myDataPtr->connections.end(); ++iter)
374 (*iter->second)(_p1, _p2, _p3);
383 public:
template<
typename P1,
typename P2,
typename P3,
typename P4>
384 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
387 this->myDataPtr->signaled =
true;
389 for (
typename EvtConnectionMap::iterator iter =
390 this->myDataPtr->connections.begin();
391 iter != this->myDataPtr->connections.end(); ++iter)
393 (*iter->second)(_p1, _p2, _p3, _p4);
403 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
405 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
406 const P4 &_p4,
const P5 &_p5)
408 this->myDataPtr->signaled =
true;
410 for (
typename EvtConnectionMap::iterator iter =
411 this->myDataPtr->connections.begin();
412 iter != this->myDataPtr->connections.end(); ++iter)
414 (*iter->second)(_p1, _p2, _p3, _p4, _p5);
426 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
427 typename P5,
typename P6>
428 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
429 const P4 &_p4,
const P5 &_p5,
const P6 &_p6)
431 this->myDataPtr->signaled =
true;
433 for (
typename EvtConnectionMap::iterator iter =
434 this->myDataPtr->connections.begin();
435 iter != this->myDataPtr->connections.end(); ++iter)
437 (*iter->second)(_p1, _p2, _p3, _p4, _p5, _p6);
449 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
450 typename P5,
typename P6,
typename P7>
451 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
452 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7)
454 this->myDataPtr->signaled =
true;
456 for (
typename EvtConnectionMap::iterator iter =
457 this->myDataPtr->connections.begin();
458 iter != this->myDataPtr->connections.end(); ++iter)
460 (*iter->second)(_p1, _p2, _p3, _p4, _p5, _p6, _p7);
473 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
474 typename P5,
typename P6,
typename P7,
typename P8>
475 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
476 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
479 this->myDataPtr->signaled =
true;
481 for (
typename EvtConnectionMap::iterator iter =
482 this->myDataPtr->connections.begin();
483 iter != this->myDataPtr->connections.end(); ++iter)
485 (*iter->second)(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8);
499 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
500 typename P5,
typename P6,
typename P7,
typename P8,
502 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
503 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
504 const P8 &_p8,
const P9 &_p9)
506 this->myDataPtr->signaled =
true;
508 for (
typename EvtConnectionMap::iterator iter =
509 this->myDataPtr->connections.begin();
510 iter != this->myDataPtr->connections.end(); ++iter)
512 (*iter->second)(_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9);
527 public:
template<
typename P1,
typename P2,
typename P3,
typename P4,
528 typename P5,
typename P6,
typename P7,
typename P8,
529 typename P9,
typename P10 >
530 void Signal(
const P1 &_p1,
const P2 &_p2,
const P3 &_p3,
531 const P4 &_p4,
const P5 &_p5,
const P6 &_p6,
const P7 &_p7,
532 const P8 &_p8,
const P9 &_p9,
const P10 &_p10)
534 this->myDataPtr->signaled =
true;
536 for (
typename EvtConnectionMap::iterator iter =
537 this->myDataPtr->connections.begin();
538 iter != this->myDataPtr->connections.end(); ++iter)
540 (*iter->second)(_p1, _p2, _p3, _p4, _p5,
541 _p6, _p7, _p8, _p9, _p10);
546 private:
void Cleanup();
564 for (
typename EvtConnectionMap::iterator iter =
565 this->myDataPtr->connections.begin();
566 iter != this->myDataPtr->connections.end(); ++iter)
571 this->myDataPtr->connections.clear();
580 if (!this->myDataPtr->connections.empty())
582 typename EvtConnectionMap::reverse_iterator iter =
583 this->myDataPtr->connections.rbegin();
584 index = iter->first + 1;
586 this->myDataPtr->connections[index] =
new boost::function<T>(_subscriber);
598 this->Disconnect(_c->GetId());
599 _c->dataPtr->event =
NULL;
600 _c->dataPtr->id = -1;
608 return this->myDataPtr->connections.size();
616 boost::mutex::scoped_lock lock(this->myDataPtr->connectionsEraseMutex);
617 this->myDataPtr->connectionsToErase.push_back(_id);
624 if (this->myDataPtr->connectionsToErase.empty())
626 boost::mutex::scoped_lock lock(this->myDataPtr->connectionsEraseMutex);
628 for (std::vector<int>::iterator iter =
629 this->myDataPtr->connectionsToErase.begin();
630 iter != this->myDataPtr->connectionsToErase.end(); ++iter)
632 typename EvtConnectionMap::iterator iter2 =
633 this->myDataPtr->connections.find(*iter);
634 if (iter2 != this->myDataPtr->connections.end())
636 delete iter2->second;
637 this->myDataPtr->connections.erase(iter2);
640 this->myDataPtr->connectionsToErase.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:502
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:144
Base class for all events.
Definition: Event.hh:59
A class that encapsulates a connection.
Definition: Event.hh:110
EventPrivate * dataPtr
Data pointer.
Definition: Event.hh:84
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:451
virtual void Disconnect(ConnectionPtr _c)
Disconnect a callback to this event.
Definition: Event.hh:593
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four parameter.
Definition: Event.hh:384
void Signal()
Signal the event for all subscribers.
Definition: Event.hh:191
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:405
boost::mutex connectionsEraseMutex
A thread lock.
Definition: Event.hh:150
std::vector< int > connectionsToErase
Set of connections to erased.
Definition: Event.hh:147
void operator()(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:206
int id
the id set in the constructor
Definition: Event.hh:103
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameters.
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)
Signal the event with seven parameters.
Definition: Event.hh:269
Event * event
the event for this connection
Definition: Event.hh:100
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:242
void operator()(const P1 &_p1, const P2 &_p2)
Signal the event with two parameters.
Definition: Event.hh:213
virtual ~EventT()
Destructor.
Definition: Event.hh:562
void Signal(const P1 &_p1, const P2 &_p2, const P3 &_p3)
Signal the event with three parameter.
Definition: Event.hh:366
EvtConnectionMap connections
Array of connection callbacks.
Definition: Event.hh:144
void Signal(const P1 &_p1, const P2 &_p2)
Signal the event with two parameter.
Definition: Event.hh:349
bool signaled
True if the event has been signaled.
Definition: Event.hh:54
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:285
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:475
void Signal(const P &_p)
Signal the event with one parameter.
Definition: Event.hh:333
ConnectionPtr Connect(const boost::function< T > &_subscriber)
Connect a callback to this event.
Definition: Event.hh:577
void operator()()
Access the signal.
Definition: Event.hh:187
common::Time creationTime
set during the constructor
Definition: Event.hh:106
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:303
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:530
#define NULL
Definition: CommonTypes.hh:30
A class for event processing.
Definition: Event.hh:156
unsigned int ConnectionCount() const
Get the number of connections.
Definition: Event.hh:606
void operator()(const P1 &_p1, const P2 &_p2, const P3 &_p3, const P4 &_p4)
Signal the event with four 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)
Signal the event with six parameters.
Definition: Event.hh:255
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:428
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
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:322
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43
EventT()
Constructor.
Definition: Event.hh:554