otsdaq-utilities  3.10.00
ChatSupervisor.h
1 #ifndef _ots_ChatSupervisor_h
2 #define _ots_ChatSupervisor_h
3 
4 #include "otsdaq/CoreSupervisors/CoreSupervisorBase.h"
5 
6 namespace ots
7 {
12 {
13  public:
14  XDAQ_INSTANTIATOR();
15 
16  ChatSupervisor(xdaq::ApplicationStub* s);
17  virtual ~ChatSupervisor(void);
18 
19  void destroy(void);
20 
21  virtual void defaultPage(xgi::Input* in, xgi::Output* out) override;
22  void Default(xgi::Input* in, xgi::Output* out);
23 
24  virtual void request(const std::string& requestType,
25  cgicc::Cgicc& cgiIn,
26  HttpXmlDocument& xmlOut,
27  const WebUsers::RequestUserInfo& userInfo) override;
28 
29  virtual void forceSupervisorPropertyValues(void)
30  override;
31 
32  private:
38  std::vector<std::string> ChatHistoryEntry_, ChatHistoryAuthor_;
39  std::vector<std::string> ChatHistoryType_;
40  std::vector<time_t> ChatHistoryTime_;
41  std::vector<uint64_t> ChatHistoryIndex_;
42 
43  uint64_t ChatLastUpdateIndex;
44 
45  std::vector<std::string> ChatUsers_;
46  std::vector<time_t> ChatUsersTime_;
47 
48  std::string chatSupervisorToolsPath_;
49  bool enableSlackChat;
50  std::string slackInboxPath_;
51  int slackDaemonPid_;
52 
53  enum
54  {
55  CHAT_HISTORY_EXPIRATION_TIME = 30 * 60,
56  CHAT_HISTORY_MAX_ENTRIES = 100,
57  };
58 
59  uint64_t incrementAndGetLastUpdate();
60  bool isLastUpdateIndexStale(uint64_t last);
61  bool isChatOld(uint64_t chatIndex, uint64_t last);
62 
63  void newUser(const std::string& user);
64  void newChat(const std::string& chat, const std::string& user, const std::string& type = "", bool fromSlack = false);
65  void sendToSlack(const std::string& user, const std::string& message);
66  void receiveFromSlack();
67  void startSlackDaemon();
68  void stopSlackDaemon();
69  void removeChatHistoryEntry(uint64_t i);
70  void removeChatUserEntry(uint64_t i);
71  void cleanupExpiredChats(void);
72 
73  void insertActiveUsers(HttpXmlDocument* xmldoc);
74  void insertChatRefresh(HttpXmlDocument* xmldoc,
75  uint64_t lastUpdateIndex,
76  const std::string& user);
77 
78  void escapeChat(std::string& chat);
79 };
80 } // namespace ots
81 
82 #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
override to force supervisor property values (and ignore user settings)