API
logMap.hpp
Go to the documentation of this file.
1 /** \file logMap.hpp
2  * \brief Declares and defines the logMap class and related classes.
3  * \author Jared R. Males (jaredmales@gmail.com)
4  *
5  * \ingroup logger_files
6  *
7  * History:
8  * - 2020-01-02 created by JRM
9  */
10 
11 #ifndef logger_logMap_hpp
12 #define logger_logMap_hpp
13 
14 #include <mx/sys/timeUtils.hpp>
15 using namespace mx::sys::tscomp;
16 
17 #include <mx/ioutils/fileUtils.hpp>
18 
19 #include <vector>
20 #include <map>
21 
22 #include <flatlogs/flatlogs.hpp>
23 #include "logFileName.hpp"
24 
25 namespace MagAOX
26 {
27 namespace logger
28 {
29 
30 /// Structure to hold a log file in memory, tracking when a new file needs to be opened.
32 {
33  std::vector<char> m_memory; ///< The buffer holding the log.
34 
35  flatlogs::timespecX m_startTime {0,0};
36  flatlogs::timespecX m_endTime{0,0};
37 
38  int loadFile( logFileName const& lfn);
39 
40 };
41 
42 /// Map of log entries by application name, mapping both to files and to loaded buffers.
43 struct logMap
44 {
45  /// The app-name to file-name map type, for sorting the input files by application
46  typedef std::map< std::string, std::set<logFileName, compLogFileName>> appToFileMapT;
47 
48  /// The app-name to buffer map type, for looking up the currently loaded logs for a given app.
49  typedef std::map< std::string, logInMemory> appToBufferMapT;
50 
52 
54 
55  ///Get log file names in a directory and distribute them into the map by app-name
56  int loadAppToFileMap( const std::string & dir, ///< [in] the directory to search for files
57  const std::string & ext ///< [in] the extension to search for
58  );
59 
60  ///Get the log for an event code which is the first prior to the supplied time
61  int getPriorLog( char * &logBefore, ///< [out] pointer to the first byte of the prior log entry
62  const std::string & appName, ///< [in] the name of the app specifying which log to search
63  const flatlogs::eventCodeT & ev, ///< [in] the event code to search for
64  const flatlogs::timespecX & ts, ///< [in] the timestamp to be prior to
65  char * hint = 0 ///< [in] [optional] a hint specifying where to start searching. If null search starts at beginning.
66  );
67 
68  ///Get the next log with the same event code which is after the supplied time
69  int getNextLog( char * &logAfter, ///< [out] pointer to the first byte of the prior log entry
70  char * logCurrent, ///< [in] The log to start from
71  const std::string & appName ///< [in] the name of the app specifying which log to search
72  );
73 
75  flatlogs::bufferPtrT & logAfter,
76  const std::string & appName
77  );
78 
79  int loadFiles( const std::string & appName, ///< MagAO-X app name for which to load files
80  const flatlogs::timespecX & startTime ///<
81  );
82 
83 
84 };
85 
86 } //namespace logger
87 } //namespace MagAOX
88 
89 #endif //logger_logMap_hpp
Organize and analyze the name of a log or telemetry file.
Definition: logFileName.hpp:29
Flatlogs single include file.
uint16_t eventCodeT
The type of an event code (16-bit unsigned int).
Definition: logDefs.hpp:40
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition: logHeader.hpp:58
Declares and defines the logFileName class.
Definition: dm.hpp:24
Structure to hold a log file in memory, tracking when a new file needs to be opened.
Definition: logMap.hpp:32
std::vector< char > m_memory
The buffer holding the log.
Definition: logMap.hpp:33
Map of log entries by application name, mapping both to files and to loaded buffers.
Definition: logMap.hpp:44
std::map< std::string, std::set< logFileName, compLogFileName > > appToFileMapT
The app-name to file-name map type, for sorting the input files by application.
Definition: logMap.hpp:46
appToBufferMapT m_appToBufferMap
Definition: logMap.hpp:53
int getNearestLogs(flatlogs::bufferPtrT &logBefore, flatlogs::bufferPtrT &logAfter, const std::string &appName)
std::map< std::string, logInMemory > appToBufferMapT
The app-name to buffer map type, for looking up the currently loaded logs for a given app.
Definition: logMap.hpp:49
appToFileMapT m_appToFileMap
Definition: logMap.hpp:51
A fixed-width timespec structure.
Definition: timespecX.hpp:35