#ifndef __RemoteHistory_h_ #define __RemoteHistory_h_ #include "../../shared/CommandDispatcher.h" #include "../../shared/TalkWithServer.h" #include "../DataFormat.h" /* These are the messages between the server requesting history and the server * providing it. */ class RemoteHistoryRequest { // True means that as we iterate over the alerts we start at older ones and // move toward newer ones. Typically the oddsmaker will set forward to true, // to help it simulate normal live trading. The history feature will set // forward to false, so the user sees older and older stuff as he scrolls // down or asks for more. bool forward; // This is specifically aimed at the OddsMaker. In previous versions of the // server, we'd send a request to the database with a limit of 1. Then we'd // grab the symbol from the result, and update the query, so future requests // would never repeat a symbol. By adding this flag to the query, we can // have a streaming query. That means less setup time. bool dontRepeatSymbols; // Do not allow these symbols to appear in a result. This goes with the // dontRepeatSymbols. Typically symbolsToSkip would be empty. But if you // requested dontRepeatSymbols, and you have to restart a query in the // middle, use symbolsToSkip to tell the server where you left off. std::set< std::string > symbolsToSkip; // Like the limit clause in MYSQL. Do not return more than this many // results. int maxCount; // This describes the first alert we want to see. The empty string (the // default) means to show all data, i.e. to start from the oldest or newest // depending on the direction we are going. Copy this from // RemoteHistoryResult::restartFrom to pick up where a previous query left // off. std::string startFrom; // Set startFrom to a specific time. Examine all alerts from this time // before regardless of the direction flag. This sets the startFrom field. // The exact format of that field is an implemention detail; no one outside // of this unit should read it. void setStartTime(time_t startTime); // Normal alert collaboration strings. Typically starts with "O=". Should // never start with "http://"; that should be stripped off by the GUI. std::string collaborate; // Stop if we go past this time. 0 means go to the end of the data, // regardless of which direction we are going. time_t stopTime; // Some reasonable defaults. RemoteHistoryRequest() : forward(false), dontRepeatSymbols(false), maxCount(1000), stopTime(0) { } void encode(TalkWithServer::Message &destination) const; // On success, returns true and completely loads this object. On failure, // returns false and this object is left in an undefined state. bool decode(ExternalRequest const *request); }; class RemoteHistoryResult { enum Disposition { Working, /* Data is still streaming. The consumer does not have * to do anything. Expect at least one more message. */ OutOfData, /* We got to the stopTime specified in the original * request. Or we got to the end of the database. No more * results will be streaming, and it doesn't make sense to * ask again. */ HitMaxCount, /* We returned as many results as were requested, i.e. * maxCount. There might be more. It might make sense * to send a new request that starts from restartFrom. * Typically the client (i.e. TI Pro) will display 1000 * records at a time. The user will get feedback to know * if we ran OutOfData or we hit that limit. If we hit * that limit, the user can ask for more. */ TryAgain /* The server wishes to stop processing this request. The * client (i.e. ax_alert_server) should repeat the request. * The client should start by making sure it is talking * with the correct server. We typically give this * response at the end of a file. Different servers are * responsible for different files, to maximize the chance * of a cache hit. Hopefully a library in the client will * hide this detail. The bulk of the code shouldn't know * or care about this case. */ }; Disposition disposition; // This is sent by the database manager in case we have to restart. The // client can send this back in a future request, so that request will // pick up where the last one left off. // // Often this is not used. Each time we send data, we update this field // in case we get disconnected and have to reconnect. The end user shouldn't // notice anything. No data sent to the user should be duplicated. And, if // we spend a significant amount of time looking through data without sending // anything to the user, we want to avoid repeating a lot of that work. // // This field will go the the ax_alert_server and to TI Pro. There are // two different places where we could be disconnected. Either of these // programs might have to request a restart. // // This field should be treated as a magic cookie. No one outside of this // unit should know or care how to interpret this. The old server put the // alert id into this field. Old clients (i.e. TI Pro) should not need to // change to make use of the new values. std::string restartFrom; std::vector< Record > rows; std::string encode() const; // On success, returns true and completely loads this object. On failure, // returns false and this object is left in an undefined state. bool decode(std::string const &encoded); std::string debugDump() const; }; #endif