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.
 
 
 

97 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. enum Value
  23. {
  24. AppIn = 0,
  25. AppOut,
  26. Bckt0,
  27. Bckt1,
  28. Bckt2,
  29. Bckt3,
  30. Bckt4,
  31. Bckt5,
  32. Bckt6,
  33. Bckt7,
  34. Bckt8,
  35. Bckt9,
  36. Max
  37. }
  38. m_value;
  39. inline MessageBucket(Value v) : m_value(v) {}
  40. inline MessageBucket() : m_value(AppIn) {}
  41. inline operator Value() { return m_value; }
  42. };
  43. //Message list container with time in it
  44. struct MessageList
  45. {
  46. MessageList(time_t timestamp, const String& message)
  47. {
  48. m_timestamp = timestamp;
  49. m_message = message;
  50. }
  51. time_t m_timestamp;
  52. String m_message;
  53. };
  54. /*
  55. A template class perhaps ?
  56. */
  57. class MessageService
  58. {
  59. public:
  60. //CTor/DTor
  61. MessageService();
  62. ~MessageService();
  63. static char const *GetName() { return "<messageservice>"; }
  64. //Setup/Destroy
  65. static void Setup();
  66. static void Destroy();
  67. //Common interactions
  68. static bool Send(MessageBucket id, const String& message);
  69. static bool Send(MessageBucket id, const char* message);
  70. static bool FetchFirst(MessageBucket id, String& message);
  71. static bool FetchFirst(MessageBucket id, String& message, time_t &timestamp);
  72. static bool FetchAll(MessageBucket id, String& message);
  73. static bool FetchAll(MessageBucket id, String& message, time_t &first_timestamp);
  74. private:
  75. Array<Array<MessageList> > m_bucket;
  76. };
  77. extern MessageService *g_messageservice;
  78. } /* namespace lol */
  79. #endif /* __MESSAGESERVICE_H__ */