tdaq-develop-2025-02-12
ChatSupervisor.h
1 #ifndef _ots_ChatSupervisor_h
2 #define _ots_ChatSupervisor_h
3 
4 #include "otsdaq/CoreSupervisors/CoreSupervisorBase.h"
5 
6 // clang-format off
7 namespace ots
8 {
12 class ChatSupervisor : public CoreSupervisorBase
13 {
14  public:
15  XDAQ_INSTANTIATOR();
16 
17  ChatSupervisor (xdaq::ApplicationStub* s);
18  virtual ~ChatSupervisor (void);
19 
20  void destroy (void);
21 
22  virtual void defaultPage (xgi::Input* in, xgi::Output* out) override;
23  void Default (xgi::Input* in, xgi::Output* out);
24 
25  virtual void request (const std::string& requestType,
26  cgicc::Cgicc& cgiIn,
27  HttpXmlDocument& xmlOut,
28  const WebUsers::RequestUserInfo& userInfo) override;
29 
30  virtual void forceSupervisorPropertyValues (void) override;
34 
35  private:
41  std::vector<std::string> ChatHistoryEntry_, ChatHistoryAuthor_;
42  std::vector<time_t> ChatHistoryTime_;
43  std::vector<uint64_t> ChatHistoryIndex_;
44 
45  uint64_t ChatLastUpdateIndex;
46 
47  std::vector<std::string> ChatUsers_;
48  std::vector<time_t> ChatUsersTime_;
49 
50  enum
51  {
52  CHAT_HISTORY_EXPIRATION_TIME = 30*60,
53  CHAT_HISTORY_MAX_ENTRIES = 100,
54  };
55 
56  uint64_t incrementAndGetLastUpdate();
57  bool isLastUpdateIndexStale(uint64_t last);
58  bool isChatOld(uint64_t chatIndex, uint64_t last);
59 
60  void newUser(const std::string& user);
61  void newChat(const std::string& chat, const std::string& user);
62  void removeChatHistoryEntry(uint64_t i);
63  void removeChatUserEntry(uint64_t i);
64  void cleanupExpiredChats(void);
65 
66  void insertActiveUsers(HttpXmlDocument* xmldoc);
67  void insertChatRefresh(HttpXmlDocument* xmldoc,
68  uint64_t lastUpdateIndex,
69  const std::string& user);
70 
71  void escapeChat(std::string& chat);
72 };
73 } // namespace ots
74 // clang-format on
75 
76 #endif
virtual void request(const std::string &requestType, cgicc::Cgicc &cgiIn, HttpXmlDocument &xmlOut, const WebUsers::RequestUserInfo &userInfo) override
end forceSupervisorPropertyValues()
virtual void forceSupervisorPropertyValues(void) override