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