You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __BASICEVENTHEAP_H_INCL__
  2. #define __BASICEVENTHEAP_H_INCL__
  3. #include "basicEvent.h"
  4. #include "basicEventHandler.h"
  5. #include "basicLogCollection.h"
  6. #include "basicMutex.h"
  7. #include "basicThread.h"
  8. typedef std::vector<basicEventHandler *> V_EVT_HANDLER;
  9. /**
  10. * @Description Singleton class to manage Events in the System
  11. *
  12. * @author Gagua
  13. */
  14. class basicEventHeap : public basicThread
  15. {
  16. private:
  17. basicLogCollection * m_pLog;
  18. basicMutex * m_pDispatchingMutex;
  19. basicMutex * m_pHandlerMutex;
  20. // EventHandlerRing *m_pRing;
  21. V_EVT_HANDLER m_vHandlers;
  22. pEventQueue m_vEventQueue;
  23. public:
  24. static basicEventHeap * getInstance();
  25. virtual ~basicEventHeap();
  26. void addHandler(basicEventHandler * handler, bool atBottom = false);
  27. void removeHandler(basicEventHandler * handler);
  28. void broadcast(EVENT_CONTAINER * Evt);
  29. void moveHandlerBottom( basicEventHandler * handler );
  30. void moveHandlerTop( basicEventHandler * handler );
  31. protected:
  32. basicEventHeap();
  33. void m_fThreadProc(void);
  34. private:
  35. static basicEventHeap * _instance;
  36. };
  37. // Constructor implementation
  38. inline basicEventHeap::basicEventHeap()
  39. {
  40. m_pLog = basicLogCollection::getInstance();
  41. // m_pRing = new EventHandlerRing();
  42. m_pDispatchingMutex = new basicMutex();
  43. m_pHandlerMutex = new basicMutex();
  44. basicThread::init();
  45. }
  46. // Destructor implementation
  47. inline basicEventHeap::~basicEventHeap()
  48. {
  49. waitThreadEnd(true);
  50. m_vHandlers.clear();
  51. // while (m_pRing->count) m_pRing->pop();
  52. // delete( m_pRing );
  53. delete(m_pDispatchingMutex);
  54. delete(m_pHandlerMutex);
  55. }
  56. #endif // __BASICEVENTHEAP_H_INCL__