#ifndef __HistoryHandler_h_ #define __HistoryHandler_h_ #include #include "../shared/SocketInfo.h" #include "../shared/ThreadClass.h" #include "../shared/Messages.h" #include "../shared/MiscSupport.h" #include "AlertConfig.h" #include "WorkerThread.h" ///////////////////////////////////////////////////////////////////// // An alert window can exist in two modes, realtime or historical. // in the realtime mode we constantly check for new alerts as they // happen. However, we don't like to start with an empty window, so // when the user requests realtime data we try to fill in the last // alert that he would have seen. This is sometimes left off if it // would take too long to find. That one entry is usually called // the short history in the code. The user documentation makes // little if any reference to that type of history. // // The user can also set an alert window to display only historical // data. In this case we take more time and we are less likely to // give up until the request is satisfied. This request will // typically contain a lot more than one line. The code will // typically call this the "long history" and the user docuemtnation // will refer to this only as "history." If the code talks about // "history" without being specific, you (unfortunately) can't be be // sure which that means. This file is dedicated strictly to the // long history. // ///////////////////////////////////////////////////////////////////// // These are used internally. class CombinedHistoryRequest; class HistoryRequest; class HistoryHandler : private ThreadClass { private: enum { mtOpenChannel, mtCancelRequest, mtAddRequest, mtWorkFinished, mtQuit }; class ListenerInfo { // This helps us delete things. std::map< std::string, CombinedHistoryRequest * > _all; public: ExternalRequest::MessageId messageId; // For returning data to the client. CombinedHistoryRequest *find(std::string windowId); /* Returns a pointer * to the request or null. */ void add(std::string windowId, CombinedHistoryRequest *request); /* Request should not exist for this windowId yet. Call remove() first if necessary. */ void remove(std::string windowId); }; std::map< SocketInfo *, ListenerInfo > _listenerInfo; RequestQueue _incoming; WorkerCluster _workerCluster; void cancelRequestImpl(SocketInfo *socket, std::string windowId); void addWork(CombinedHistoryRequest *request); protected: void threadFunction(); private: HistoryHandler(); ~HistoryHandler(); static HistoryHandler *_instance; void addRequest(CombinedHistoryRequest *request); public: static void initInstance(); static HistoryHandler &getInstance(); void cancelRequest(SocketInfo *socket, std::string windowId); // If the incoming request is something that this unit needs to handle, this // function will return true and store whatever it needs for further work. // Otherwise this function will return false and do nothing. Either way, // the caller still owns the original request object. bool createHistoryRequest(ExternalRequest *request); }; #endif