00001 #ifndef _ots_ChatSupervisor_h
00002 #define _ots_ChatSupervisor_h
00003
00004 #include "otsdaq-core/CoreSupervisors/CoreSupervisorBase.h"
00005
00006
00007 namespace ots
00008 {
00009
00010
00011
00012 class ChatSupervisor: public CoreSupervisorBase
00013 {
00014
00015 public:
00016
00017 XDAQ_INSTANTIATOR();
00018
00019 ChatSupervisor (xdaq::ApplicationStub * s);
00020 virtual ~ChatSupervisor (void);
00021
00022 void destroy (void);
00023
00024 virtual void defaultPage (xgi::Input* in, xgi::Output* out) override;
00025 virtual void request (const std::string& requestType, cgicc::Cgicc& cgiIn, HttpXmlDocument& xmlOut, const WebUsers::RequestUserInfo& userInfo) override;
00026
00027 virtual void forceSupervisorPropertyValues (void) override;
00028
00029 private:
00030
00031
00032
00033
00034
00035
00036 std::vector<std::string> ChatHistoryEntry_, ChatHistoryAuthor_;
00037 std::vector<time_t> ChatHistoryTime_;
00038 std::vector<uint64_t> ChatHistoryIndex_;
00039
00040 uint64_t ChatLastUpdateIndex;
00041
00042 std::vector<std::string> ChatUsers_;
00043 std::vector<time_t> ChatUsersTime_;
00044
00045 enum {
00046 CHAT_HISTORY_EXPIRATION_TIME = 10,
00047 CHAT_HISTORY_MAX_ENTRIES = 100,
00048 };
00049
00050
00051 uint64_t incrementAndGetLastUpdate();
00052 bool isLastUpdateIndexStale(uint64_t last);
00053 bool isChatOld(uint64_t chatIndex, uint64_t last);
00054
00055 void newUser(std::string user);
00056 void newChat(std::string chat, std::string user);
00057 void removeChatHistoryEntry(uint64_t i);
00058 void removeChatUserEntry(uint64_t i);
00059 void cleanupExpiredChats();
00060
00061 void insertActiveUsers(HttpXmlDocument *xmldoc);
00062 void insertChatRefresh(HttpXmlDocument *xmldoc, uint64_t lastUpdateIndex, std::string user);
00063
00064 void escapeChat(std::string &chat);
00065
00066 };
00067
00068 }
00069
00070 #endif