EventBuffer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include <cstring>
  25. #include "Types.h"
  26. #define MAX_OS_EVENT_BUFFER_SIZE 1024
  27. namespace crown
  28. {
  29. /// __EventBuffer__ is a global buffer used for storing events.
  30. /// Each subsystem can read its relative events and modifies its behaviour consequently.
  31. ///
  32. /// [type #0][size #0][data #0] ... [type #n][size #n][data #n]
  33. class EventBuffer
  34. {
  35. public:
  36. /// Constructor
  37. EventBuffer();
  38. /// Pushes an @a event_data of size @a event_size with type @a event_type
  39. void push_event(uint32_t event_type, void* event_data, size_t event_size);
  40. /// Pushes an entire @a event_buffer of size @a buffer_size
  41. void push_event_buffer(char* event_buffer, size_t buffer_size);
  42. /// Retrieves the @a event_type and @a event_size of next os event
  43. void* get_next_event(uint32_t& event_type, size_t& event_size);
  44. /// Clears entire os buffer
  45. void clear();
  46. /// Flushes entire os buffer
  47. void flush();
  48. /// Returns buffer's size
  49. size_t size() const;
  50. /// Return buffer
  51. char* buffer();
  52. public:
  53. size_t m_size;
  54. char m_buffer[MAX_OS_EVENT_BUFFER_SIZE];
  55. uint32_t m_read;
  56. };
  57. } // namespace crown