event_processor.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef BOOST_STATECHART_EVENT_PROCESSOR_INCLUDED
  2. #define BOOST_STATECHART_EVENT_PROCESSOR_INCLUDED
  3. //////////////////////////////////////////////////////////////////////////////
  4. // Copyright 2002-2008 Andreas Huber Doenni
  5. // Distributed under the Boost Software License, Version 1.0. (See accompany-
  6. // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //////////////////////////////////////////////////////////////////////////////
  8. namespace boost
  9. {
  10. namespace statechart
  11. {
  12. class event_base;
  13. //////////////////////////////////////////////////////////////////////////////
  14. template< class Scheduler >
  15. class event_processor
  16. {
  17. public:
  18. //////////////////////////////////////////////////////////////////////////
  19. virtual ~event_processor() {}
  20. Scheduler & my_scheduler() const
  21. {
  22. return myScheduler_;
  23. }
  24. typedef typename Scheduler::processor_handle processor_handle;
  25. processor_handle my_handle() const
  26. {
  27. return myHandle_;
  28. }
  29. void initiate()
  30. {
  31. initiate_impl();
  32. }
  33. void process_event( const event_base & evt )
  34. {
  35. process_event_impl( evt );
  36. }
  37. void terminate()
  38. {
  39. terminate_impl();
  40. }
  41. protected:
  42. //////////////////////////////////////////////////////////////////////////
  43. typedef const typename Scheduler::processor_context & my_context;
  44. event_processor( my_context ctx ) :
  45. myScheduler_( ctx.my_scheduler() ),
  46. myHandle_( ctx.my_handle() )
  47. {
  48. }
  49. private:
  50. //////////////////////////////////////////////////////////////////////////
  51. virtual void initiate_impl() = 0;
  52. virtual void process_event_impl( const event_base & evt ) = 0;
  53. virtual void terminate_impl() = 0;
  54. // avoids C4512 (assignment operator could not be generated)
  55. event_processor & operator=( const event_processor & );
  56. Scheduler & myScheduler_;
  57. const processor_handle myHandle_;
  58. };
  59. } // namespace statechart
  60. } // namespace boost
  61. #endif