#ifndef __RemoteHistoryRequests_h_ #define __RemoteHistoryRequests_h_ #include "../DataFormat.h" #include "RemoteHistoryConnection.h" class AlertHistoryRequest : public RemoteHistoryRequest { private: int _rowsRequested; int _rowsReturned; AlertHistoryRequest(SocketInfo *socket) : RemoteHistoryRequest(socket) { forward = false; command = "history_alerts"; } std::weak_ptr< AlertHistoryRequest > _me; std::string _restartKey; std::string _collaborate; time_t _endTime; virtual void onEventInternal(); void buildAndSendRequest(); public: // Presumably the callback will send a message to a different thread which // will do the real work. In that case wait until you are in the other // thread to call updateResults(). This will move as much work as possible // from the communications thread to the worker thread. This will also // reduce the number of messages you have to send between the threads. void updateResults(); // These are the results so far. Feel free to clear this list after you have // read these. std::vector< RecordRef > rows; bool done() const; // Please call updateResults() soon, possibly after switching threads. std::function< void(std::shared_ptr< AlertHistoryRequest > const &) > onEvent; void submit(); static std::shared_ptr< AlertHistoryRequest > create(SocketInfo *socket, time_t startTime, time_t endTime, int maxCount, std::string const &restartKey, std::string const &collaborate); }; class TopListHistoryRequest : public RemoteHistoryRequest { private: TopListHistoryRequest(SocketInfo *socket) : RemoteHistoryRequest(socket) { forward = true; command = "history_top_list"; } std::weak_ptr< TopListHistoryRequest > _me; virtual void onEventInternal(); public: // Presumably the callback will send a message to a different thread which // will do the real work. In that case wait until you are in the other // thread to call updateResults(). This will move as much work as possible // from the communications thread to the worker thread. This will also // reduce the number of messages you have to send between the threads. void updateResults(); // Please call updateResults() soon, possibly after switching threads. std::function< void(std::shared_ptr< TopListHistoryRequest > const &) > onEvent; // You cannot have more than one request out at a time. Call this after // calling create(). If you are stopped out because you hit your max count, // you can call this again and the maxCount will be reset. TODO how do you // know if it's a good idea to call submit() a second time? void submit(); static std::shared_ptr< TopListHistoryRequest > create(SocketInfo *socket); }; class OddsMakerHistoryRequest : public RemoteHistoryRequest { private: OddsMakerHistoryRequest(SocketInfo *socket) : RemoteHistoryRequest(socket) { forward = true; command = "history_oddsmaker"; } std::weak_ptr< OddsMakerHistoryRequest > _me; virtual void onEventInternal(); public: // Presumably the callback will send a message to a different thread which // will do the real work. In that case wait until you are in the other // thread to call updateResults(). This will move as much work as possible // from the communications thread to the worker thread. This will also // reduce the number of messages you have to send between the threads. void updateResults(); // Please call updateResults() soon, possibly after switching threads. std::function< void(std::shared_ptr< OddsMakerHistoryRequest > const &) > onEvent; void submit(); static std::shared_ptr< OddsMakerHistoryRequest > create(SocketInfo *socket); }; #endif