1 #ifndef GCPP_UTIL_HORIZONSCOMMUNICATOR_H
2 #define GCPP_UTIL_HORIZONSCOMMUNICATOR_H
17 #include "gcp/util/common/AntNum.h"
18 #include "gcp/util/common/Date.h"
19 #include "gcp/util/common/Communicator.h"
20 #include "gcp/util/common/GenericTask.h"
21 #include "gcp/util/common/GenericTaskMsg.h"
22 #include "gcp/util/common/SpawnableTask.h"
23 #include "gcp/util/common/String.h"
24 #include "gcp/util/common/TcpClient.h"
25 #include "gcp/util/common/TimeOut.h"
27 #include "gcp/control/code/unix/libunix_src/common/genericregs.h"
29 #define HORIZONS_FILENAME_MAX 100
30 #define HORIZONS_HANDLER(fn) void (fn)(void* args, std::string srcName, std::string fileName, bool error)
55 char fileName[HORIZONS_FILENAME_MAX];
56 char sourceId[SRC_LEN];
62 HORIZONS_HANDLER(*fn);
67 HORIZONS_HANDLER(*fn);
82 HORIZONS_HANDLER(*fn_);
109 bool useSshTunnel=
false,
110 std::string gateway=
"");
114 unsigned intervalInSeconds=300,
115 bool useSshTunnel=
false,
116 std::string getway=
"");
129 std::string fileName,
135 void addHandler(HORIZONS_HANDLER(*handler),
void* args=0);
139 void removeHandler(HORIZONS_HANDLER(*handler));
161 static const std::string horizonsHost_;
162 static const unsigned horizonsPort_;
164 std::string gateway_;
176 std::map<std::string, std::string> sourceMap_;
180 std::map<std::string, std::string> updateMap_;
184 std::map<std::string, std::string>::iterator updateMapIter_;
195 std::string fileName_;
196 std::string srcName_;
197 std::string horizonsSrcName_;
198 std::string interval_;
199 std::string startUtc_;
200 std::string stopUtc_;
206 std::map<std::string, std::string> horizonsSrcNames_;
207 std::map<std::string, std::string> intervals_;
212 double expiryThresholdInDays_;
217 double updateThresholdInDays_;
228 struct timeval* timeOutPtr_;
232 std::vector<Handler> handlers_;
241 void initialize(
bool useSshTunnel, std::string gateway);
245 void setupTimeOuts(
unsigned timeOutIntervalInSeconds);
249 void stepState(CommState state);
260 void registerTimeOut();
265 void registerCommTimeOut();
270 bool initiateSshConnection();
274 void terminateSshConnection();
278 void terminateCommSequence(
bool error);
284 void executeAddHandler(HORIZONS_HANDLER(*handler),
void* args=0);
285 void executeRemoveHandler(HORIZONS_HANDLER(*handler));
293 void initiateGetEphemerisCommSequence(std::string body,
294 std::string fileName,
295 std::string startUtc,
296 std::string stopUtc);
301 void compileGetEphemerisStateMachine(std::string& body,
302 std::string& startUtc,
303 std::string& stopUtc);
308 static COMM_PARSER_FN(readEphemeris);
314 static COMM_END_PARSER_FN(endEphemeris);
320 void printHeader(std::ofstream& fout);
321 void printEphem(std::ofstream& fout);
326 static COMM_PARSER_FN(quitFromServer);
327 void quitFromServer();
332 void checkNextSource();
337 void callHandlers(
bool error);
348 void setSource(std::string src);
350 void setEphemerisDates();
352 std::string getSource();
353 std::string getFilename();
354 std::string getHorizonsSource();
355 std::string getInterval();
363 bool ephemerisNeedsUpdating();
367 bool ephemExists(std::string ephemFileName);
372 bool ephemIsAboutToRunOut(std::string ephemFileName);
376 double getLastEphemMjd(std::string ephemFileName);
381 bool ephemFileIsOutOfDate(std::string ephemFileName);
390 #endif // End #ifndef GCP_UTIL_HORIZONSCOMMUNICATOR_H
void deregisterEphemeris(std::string sourceName)
Definition: HorizonsCommunicator.cc:161
Definition: GenericTaskMsg.h:31
Definition: HorizonsCommunicator.h:42
Definition: SshTunnel.h:40
void getEphem(std::string source, std::string fileName, Date start, Date stop)
Definition: HorizonsCommunicator.cc:667
void setFilename(std::string fileName)
Definition: HorizonsCommunicator.cc:903
Definition: SpawnableTask.h:31
Definition: HorizonsCommunicator.h:80
Definition: Communicator.h:26
void loadFile(std::string name)
Definition: HorizonsCommunicator.cc:1019
virtual ~HorizonsCommunicator()
Definition: HorizonsCommunicator.cc:132
void clearEphemeris()
Definition: HorizonsCommunicator.cc:171
void addHandler(HORIZONS_HANDLER(*handler), void *args=0)
Definition: HorizonsCommunicator.cc:645
HorizonsCommunicator(unsigned intervalInSeconds=300, bool useSshTunnel=false, std::string gateway="")
Definition: HorizonsCommunicator.cc:37
void registerEphemeris(std::string sourceName, std::string fileName)
Definition: HorizonsCommunicator.cc:150
Definition: HorizonsCommunicator.h:90