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.

87 lines
2.5 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __BASICEVENTHEAP_H_INCL__
  2. #define __BASICEVENTHEAP_H_INCL__
  3. #include "basicLogCollection.h"
  4. #include "basicMutex.h"
  5. #include "basicThread.h"
  6. #include "basicEvent.h"
  7. #include "basicEventHandler.h"
  8. /**
  9. * @Description Singleton class to manage Events in the System
  10. *
  11. * @author Gagua
  12. */
  13. class basicEventHeap: public basicThread{
  14. private:
  15. basicLogCollection *m_pLog;
  16. basicMutex *m_pDispatchingMutex;
  17. basicMutex *m_pHandlerMutex;
  18. EventHandlerRing *m_pRing;
  19. pEventQueue m_vEventQueue;
  20. public:
  21. // Method to fetch singleton instance.
  22. static basicEventHeap* getInstance();
  23. // Destructor
  24. virtual ~basicEventHeap();
  25. void addHandler( basicEventHandler *handler, bool atBottom = false );
  26. void removeHandler( basicEventHandler *handler );
  27. void broadcast( basicEvent *Evt );
  28. protected:
  29. // Constructor - protected so users cannot call it.
  30. basicEventHeap();
  31. void m_fThreadProc( void );
  32. private:
  33. // private static member referencing the single instance of the object
  34. // TODO: Replace basicEventHeap with the type of object you want to
  35. // return the single instance of
  36. static basicEventHeap* _instance;
  37. // Copy constructor
  38. // Declared but not defined to prevent auto-generated
  39. // copy constructor. Refer to "Effective C++" by Meyers
  40. //basicEventHeap(const basicEventHeap& src);
  41. // Assignment operator
  42. // Declared but not defined to prevent auto-generated
  43. // assignment operator. Refer to "Effective C++" by Meyers
  44. //basicEventHeap& operator=(const basicEventHeap& src);
  45. };
  46. // Constructor implementation
  47. inline basicEventHeap::basicEventHeap(){
  48. m_pLog = basicLogCollection::getInstance();
  49. m_pRing = new EventHandlerRing();
  50. m_pDispatchingMutex = new basicMutex();
  51. m_pHandlerMutex = new basicMutex();
  52. basicThread::init();
  53. };
  54. // Destructor implementation
  55. inline basicEventHeap::~basicEventHeap(){
  56. while (m_pRing->count) m_pRing->pop();
  57. delete( m_pRing );
  58. delete( m_pDispatchingMutex );
  59. delete( m_pHandlerMutex );
  60. };
  61. // TODO: Uncomment the copy constructor when you need it.
  62. //inline basicEventHeap::basicEventHeap(const basicEventHeap& src)
  63. //{
  64. // // TODO: copy
  65. //}
  66. // TODO: Uncomment the assignment operator when you need it.
  67. //inline basicEventHeap& basicEventHeap::operator=(const basicEventHeap& rhs)
  68. //{
  69. // if (this == &rhs) {
  70. // return *this;
  71. // }
  72. //
  73. // // TODO: assignment
  74. //
  75. // return *this;
  76. //}
  77. #endif // __BASICEVENTHEAP_H_INCL__