API
git_state.hpp
Go to the documentation of this file.
1 /** \file git_state.hpp
2  * \brief The MagAO-X logger git_state log type.
3  * \author Jared R. Males (jaredmales@gmail.com)
4  *
5  * \ingroup logger_types_files
6  *
7  * History:
8  * - 2018-08-18 created by JRM
9  */
10 #ifndef logger_types_git_state_hpp
11 #define logger_types_git_state_hpp
12 
13 #include "generated/git_state_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 namespace logger
19 {
20 
21 
22 /// Log entry recording the build-time git state.
23 /** \ingroup logger_types
24  */
25 struct git_state : public flatbuffer_log
26 {
27  ///The event code
28  static const flatlogs::eventCodeT eventCode = eventCodes::GIT_STATE;
29 
30  ///The default level
32 
33 
34  ///The type of the input message
35  struct messageT : public fbMessage
36  {
37  ///Construct from components
38  messageT( const std::string & repoName, ///< [in] the name of the repo
39  const std::string & sha1, ///< [in] the SHA1 hash of the repo
40  const bool modified ///< [in] the modified status (true or false)
41  )
42  {
43  auto _repoName = builder.CreateString(repoName);
44  auto _sha1 = builder.CreateString(sha1);
45 
46  uint8_t _modified = modified;
47 
48  auto gs = CreateGit_state_fb(builder, _repoName, _sha1, _modified);
49  builder.Finish(gs);
50 
51  }
52 
53  };
54 
55  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
56  flatlogs::msgLenT len ///< [in] length of msgBuffer.
57  )
58  {
59  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
60  return VerifyGit_state_fbBuffer(verifier);
61  }
62 
63  ///Get the message formatte for human consumption.
64  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
65  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
66  )
67  {
68  static_cast<void>(len);
69 
70  auto rgs = GetGit_state_fb(msgBuffer);
71 
72  std::string str;
73  if( rgs->repo()) str = rgs->repo()->c_str();
74 
75  str += " GIT: ";
76 
77  if( rgs->sha1()) str += rgs->sha1()->c_str();
78 
79  if(rgs->modified() > 0) str+= " MODIFIED";
80 
81  return str;
82  }
83 
84  /// Access the repo name field
85  static std::string repoName( void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
86  {
87  auto rgs = GetGit_state_fb(msgBuffer);
88 
89  if(rgs->repo()) return std::string(rgs->repo()->c_str());
90  else return "";
91  }
92 
93  /// Access the modified field
94  static bool modified( void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
95  {
96  auto rgs = GetGit_state_fb(msgBuffer);
97 
98  if(rgs->modified() > 0) return true;
99  else return false;
100  }
101 
102 }; //git_state
103 
104 
105 } //namespace logger
106 } //namespace MagAOX
107 
108 #endif //logger_types_git_state_hpp
109 
The MagAO-X logger flatbuffer log base type.
uint16_t eventCodeT
The type of an event code (16-bit unsigned int).
Definition: logDefs.hpp:40
msgLen2T msgLenT
The type used to refer to the message length, regardless of length.
Definition: logDefs.hpp:69
int8_t logPrioT
The type of the log priority code.
Definition: logDefs.hpp:21
static void * messageBuffer(bufferPtrT &logBuffer)
Get the message buffer address.
Definition: logHeader.hpp:621
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition: logHeader.hpp:58
Definition: dm.hpp:24
constexpr static logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
Definition: logPriority.hpp:49
Message type for resolving log messages with a f.b. builder.
flatbuffers::FlatBufferBuilder builder
Base class for logs consisting of a flatbuffer message.
The type of the input message.
Definition: git_state.hpp:36
messageT(const std::string &repoName, const std::string &sha1, const bool modified)
Construct from components.
Definition: git_state.hpp:38
Log entry recording the build-time git state.
Definition: git_state.hpp:26
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
Definition: git_state.hpp:55
static std::string repoName(void *msgBuffer)
Access the repo name field.
Definition: git_state.hpp:85
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
Definition: git_state.hpp:64
static const flatlogs::logPrioT defaultLevel
The default level.
Definition: git_state.hpp:31
static bool modified(void *msgBuffer)
Access the modified field.
Definition: git_state.hpp:94
static const flatlogs::eventCodeT eventCode
The event code.
Definition: git_state.hpp:28