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();