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.
 
 
 

91 lines
2.0 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. //
  12. // The Message Service class
  13. // ----------------
  14. //
  15. #if !defined __MESSAGESERVICE_H__
  16. #define __MESSAGESERVICE_H__
  17. namespace lol
  18. {
  19. // Utility enum for message service
  20. struct MessageBucket
  21. {
  22. DEF_VALUE
  23. ADD_VALUE(AppIn)
  24. ADD_VALUE(AppOut)
  25. ADD_VALUE(Bckt0)
  26. ADD_VALUE(Bckt1)
  27. ADD_VALUE(Bckt2)
  28. ADD_VALUE(Bckt3)
  29. ADD_VALUE(Bckt4)
  30. ADD_VALUE(Bckt5)
  31. ADD_VALUE(Bckt6)
  32. ADD_VALUE(Bckt7)
  33. ADD_VALUE(Bckt8)
  34. ADD_VALUE(Bckt9)
  35. END_E_VALUE
  36. LOL_DECLARE_ENUM_METHODS(MessageBucket)
  37. };
  38. //Message list container with time in it
  39. struct MessageList
  40. {
  41. MessageList(time_t timestamp, const String& message)
  42. {
  43. m_timestamp = timestamp;
  44. m_message = message;
  45. }
  46. time_t m_timestamp;
  47. String m_message;
  48. };
  49. /*
  50. A template class perhaps ?
  51. */
  52. class MessageService
  53. {
  54. public:
  55. //CTor/DTor
  56. MessageService();
  57. ~MessageService();
  58. static char const *GetName() { return "<messageservice>"; }
  59. //Setup/Destroy
  60. static void Setup();
  61. static void Destroy();
  62. //Common interactions
  63. static bool Send(MessageBucket id, const String& message);
  64. static bool Send(MessageBucket id, const char* message);
  65. static bool FetchFirst(MessageBucket id, String& message);
  66. static bool FetchFirst(MessageBucket id, String& message, time_t &timestamp);
  67. static bool FetchAll(MessageBucket id, String& message);
  68. static bool FetchAll(MessageBucket id, String& message, time_t &first_timestamp);
  69. private:
  70. array<array<MessageList> > m_bucket;
  71. };
  72. extern MessageService *g_messageservice;
  73. } /* namespace lol */
  74. #endif /* __MESSAGESERVICE_H__ */