otsdaq_utilities  v2_05_02_indev
ChatSupervisor.h
1 #ifndef _ots_ChatSupervisor_h
2 #define _ots_ChatSupervisor_h
3 
4 #include "otsdaq/CoreSupervisors/CoreSupervisorBase.h"
5 
6 namespace ots
7 {
8 // ChatSupervisor
9 // This class handles the otsdaq user chat functionality available in the web desktop
10 // environment.
11 class ChatSupervisor : public CoreSupervisorBase
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  virtual void request(const std::string& requestType,
23  cgicc::Cgicc& cgiIn,
24  HttpXmlDocument& xmlOut,
25  const WebUsers::RequestUserInfo& userInfo) override;
26 
27  virtual void forceSupervisorPropertyValues(void) override; // override to force
28  // supervisor property
29  // values (and ignore user
30  // settings)
31 
32  private:
33  //"Chat History" database associations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34  // Maintain list of most recent chats and active display names
35  // keep for set period (e.g. 10 sec)
36  // each new chat is a string/displayName pair and is given a running index (0 is
37  // skipped)
38  std::vector<std::string> ChatHistoryEntry_, ChatHistoryAuthor_;
39  std::vector<time_t> ChatHistoryTime_;
40  std::vector<uint64_t> ChatHistoryIndex_;
41 
42  uint64_t ChatLastUpdateIndex;
43 
44  std::vector<std::string> ChatUsers_;
45  std::vector<time_t> ChatUsersTime_;
46 
47  enum
48  {
49  CHAT_HISTORY_EXPIRATION_TIME = 10, // 10 seconds
50  CHAT_HISTORY_MAX_ENTRIES = 100, // 100 entries is vector max size
51  };
52 
53  uint64_t incrementAndGetLastUpdate();
54  bool isLastUpdateIndexStale(uint64_t last);
55  bool isChatOld(uint64_t chatIndex, uint64_t last);
56 
57  void newUser(const std::string& user);
58  void newChat(const std::string& chat, const std::string& user);
59  void removeChatHistoryEntry(uint64_t i);
60  void removeChatUserEntry(uint64_t i);
61  void cleanupExpiredChats(void);
62 
63  void insertActiveUsers(HttpXmlDocument* xmldoc);
64  void insertChatRefresh(HttpXmlDocument* xmldoc,
65  uint64_t lastUpdateIndex,
66  const std::string& user);
67 
68  void escapeChat(std::string& chat);
69 };
70 }
71 
72 #endif
virtual void request(const std::string &requestType, cgicc::Cgicc &cgiIn, HttpXmlDocument &xmlOut, const WebUsers::RequestUserInfo &userInfo) override
end forceSupervisorPropertyValues()