Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

messageservice.h 2.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. //MessageBucket -- Utility enum for message service ---------------------------
  19. struct MessageBucketBase : public StructSafeEnum
  20. {
  21. enum Type
  22. {
  23. AppIn,
  24. AppOut,
  25. Bckt0,
  26. Bckt1,
  27. Bckt2,
  28. Bckt3,
  29. Bckt4,
  30. Bckt5,
  31. Bckt6,
  32. Bckt7,
  33. Bckt8,
  34. Bckt9,
  35. MAX
  36. };
  37. protected:
  38. virtual bool BuildEnumMap(map<int64_t, String>& enum_map)
  39. {
  40. enum_map[AppIn] = "AppIn";
  41. enum_map[AppOut] = "AppOut";
  42. enum_map[Bckt0] = "Bckt0";
  43. enum_map[Bckt1] = "Bckt1";
  44. enum_map[Bckt2] = "Bckt2";
  45. enum_map[Bckt3] = "Bckt3";
  46. enum_map[Bckt4] = "Bckt4";
  47. enum_map[Bckt5] = "Bckt5";
  48. enum_map[Bckt6] = "Bckt6";
  49. enum_map[Bckt7] = "Bckt7";
  50. enum_map[Bckt8] = "Bckt8";
  51. enum_map[Bckt9] = "Bckt9";
  52. enum_map[MAX] = "MAX";
  53. return true;
  54. }
  55. };
  56. typedef SafeEnum<MessageBucketBase> MessageBucket;
  57. //Message list container with time in it
  58. struct MessageList
  59. {
  60. MessageList(time_t timestamp, const String& message)
  61. {
  62. m_timestamp = timestamp;
  63. m_message = message;
  64. }
  65. time_t m_timestamp;
  66. String m_message;
  67. };
  68. /*
  69. A template class perhaps ?
  70. */
  71. class MessageService
  72. {
  73. public:
  74. //CTor/DTor
  75. MessageService();
  76. ~MessageService();
  77. static char const *GetName() { return "<messageservice>"; }
  78. //Setup/Destroy
  79. static void Setup();
  80. static void Destroy();
  81. //Common interactions
  82. static bool Send(MessageBucket id, const String& message);
  83. static bool Send(MessageBucket id, const char* message);
  84. static bool FetchFirst(MessageBucket id, String& message);
  85. static bool FetchFirst(MessageBucket id, String& message, time_t &timestamp);
  86. static bool FetchAll(MessageBucket id, String& message);
  87. static bool FetchAll(MessageBucket id, String& message, time_t &first_timestamp);
  88. private:
  89. array<array<MessageList> > m_bucket;
  90. };
  91. extern MessageService *g_messageservice;
  92. } /* namespace lol */