#ifndef __ShortHistory_h_ #define __ShortHistory_h_ #include "../shared/MiscSupport.h" #include "../shared/Messages.h" #include "../shared/DatabaseWithRetry.h" #include "AlertConfig.h" #include "../shared/ThreadClass.h" #include "../shared/XmlSupport.h" #include "Types.h" class ShortHistoryRequest : public Request { private: const AlertId _lastId; const AlertConfig::CustomSql _sql; public: ShortHistoryRequest(SocketInfo *socket, AlertId lastId, AlertConfig::CustomSql const &sql); AlertConfig::CustomSql const &getSql() const { return _sql; } AlertId getLastId() const { return _lastId; } XmlNode result; }; class ShortHistoryHandler : private ThreadClass { private: enum { mtNewRequest, mtAbortRequest, mtDeleteSocket, mtQuit }; int _callbackId; DatabaseWithRetry _database; RequestQueue *_fulfilledRequests; RequestQueue _incomingRequests; FairRequestQueue _inProgress; AlertId getFirstPossibleId(); protected: void threadFunction(); public: ShortHistoryHandler(RequestQueue *fulfilledRequests, int callbackId); ~ShortHistoryHandler(); // Adds the request to the queue in the appropriate thread. The caller // should keep a pointer to the request, in case he needs to abort the // request. Otherwise, the caller should not mess with the request until // it is returned. The caller might not get the request back if he attempts // to abort the request. The caller is only responsible for deleting the // request if he gets it back. void request(ShortHistoryRequest *request); // Aborts the request. Note: There is no gaurentee that this will succeed, // because the request could already be in progress, or complete and on it's // way back to the caller at this time. // Note: This only makes sense if the thread that calls abort is the same // thread the receives the completed requests. Otherwise an odd race // condition could appear. We want to avoid the case of creating a new // object with this identity, after the old one has been deleted, then // accidentally deleting the new object, not the old one. void abort(SocketInfo *socket, ShortHistoryRequest *request); // This aborts any and all outstanding requests for the socket. We already // listen to the socket shutdown mechanism. This could happen if a user // looses his privliges, and only the caller knows about that. void abort(SocketInfo *socket); }; #endif