API
 
Loading...
Searching...
No Matches
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
14#include "flatbuffer_log.hpp"
15
16namespace MagAOX
17{
18namespace logger
19{
20
21
22/// Log entry recording the build-time git state.
23/** \ingroup logger_types
24 */
26{
27 ///The event code
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 sha1 field
94 static std::string sha1( void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
95 {
96 auto rgs = GetGit_state_fb(msgBuffer);
97
98 if(rgs->sha1()) return std::string(rgs->sha1()->c_str());
99 else return "";
100 }
101
102 /// Access the modified field
103 static bool modified( void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
104 {
105 auto rgs = GetGit_state_fb(msgBuffer);
106
107 if(rgs->modified() > 0) return true;
108 else return false;
109 }
110
111 /// Get the logMetaDetail for a member by name
112 /**
113 * \returns the a logMetaDetail filled in with the appropriate details
114 * \returns an empty logMetaDetail if member not recognized
115 */
116 static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
117 {
118 if( member == "repoName") return logMetaDetail({"GIT REPO NAME", "git repository name", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&repoName), false});
119 else if(member == "sha1") return logMetaDetail({"GIT REPO SHA1", "git repo sha1 hash", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&sha1), false});
120 else if(member == "modified") return logMetaDetail({"GIT REPO MODIFIED", "git repo modified state", logMeta::valTypes::Bool, logMeta::metaTypes::Continuous, reinterpret_cast<void*>(&modified), false});
121 else
122 {
123 std::cerr << "No member " << member << " in git_state\n";
124 return logMetaDetail();
125 }
126 }
127
128}; //git_state
129
130
131} //namespace logger
132} //namespace MagAOX
133
134#endif //logger_types_git_state_hpp
135
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.
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition logHeader.hpp:58
static constexpr flatlogs::eventCodeT GIT_STATE
Definition logCodes.hpp:10
inline ::flatbuffers::Offset< Git_state_fb > CreateGit_state_fb(::flatbuffers::FlatBufferBuilder &_fbb, ::flatbuffers::Offset<::flatbuffers::String > repo=0, ::flatbuffers::Offset<::flatbuffers::String > sha1=0, uint8_t modified=0)
const MagAOX::logger::Git_state_fb * GetGit_state_fb(const void *buf)
bool VerifyGit_state_fbBuffer(::flatbuffers::Verifier &verifier)
Definition dm.hpp:28
static constexpr logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
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 std::string sha1(void *msgBuffer)
Access the sha1 field.
Definition git_state.hpp:94
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 logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static bool modified(void *msgBuffer)
Access the modified field.
static const flatlogs::eventCodeT eventCode
The event code.
Definition git_state.hpp:28