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.

89 lines
1.9 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  5. // (c) 2013 Sam Hocevar <sam@hocevar.net>
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the Do What The Fuck You Want To
  8. // Public License, Version 2, as published by Sam Hocevar. See
  9. // http://www.wtfpl.net/ for more details.
  10. //
  11. #pragma once
  12. //
  13. // The Message Service class
  14. // ----------------
  15. //
  16. namespace lol
  17. {
  18. // Utility enum for message service
  19. struct MessageBucket
  20. {
  21. DEF_VALUE
  22. ADD_VALUE(AppIn)
  23. ADD_VALUE(AppOut)
  24. ADD_VALUE(Bckt0)
  25. ADD_VALUE(Bckt1)
  26. ADD_VALUE(Bckt2)
  27. ADD_VALUE(Bckt3)
  28. ADD_VALUE(Bckt4)
  29. ADD_VALUE(Bckt5)
  30. ADD_VALUE(Bckt6)
  31. ADD_VALUE(Bckt7)
  32. ADD_VALUE(Bckt8)
  33. ADD_VALUE(Bckt9)
  34. END_E_VALUE
  35. LOL_DECLARE_ENUM_METHODS(MessageBucket)
  36. };
  37. //Message list container with time in it
  38. struct MessageList
  39. {
  40. MessageList(time_t timestamp, const String& message)
  41. {
  42. m_timestamp = timestamp;
  43. m_message = message;
  44. }
  45. time_t m_timestamp;
  46. String m_message;
  47. };
  48. /*
  49. A template class perhaps ?
  50. */
  51. class MessageService
  52. {
  53. public:
  54. //CTor/DTor
  55. MessageService();
  56. ~MessageService();
  57. static char const *GetName() { return "<messageservice>"; }
  58. //Setup/Destroy
  59. static void Setup();
  60. static void Destroy();
  61. //Common interactions
  62. static bool Send(MessageBucket id, const String& message);
  63. static bool Send(MessageBucket id, const char* message);
  64. static bool FetchFirst(MessageBucket id, String& message);
  65. static bool FetchFirst(MessageBucket id, String& message, time_t &timestamp);
  66. static bool FetchAll(MessageBucket id, String& message);
  67. static bool FetchAll(MessageBucket id, String& message, time_t &first_timestamp);
  68. private:
  69. array<array<MessageList> > m_bucket;
  70. };
  71. extern MessageService *g_messageservice;
  72. } /* namespace lol */