LCOV - code coverage report
Current view: top level - libMagAOX/logger/types - git_state.hpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 65.8 % 38 25
Test Date: 2026-01-03 21:03:39 Functions: 57.1 % 7 4

            Line data    Source code
       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
      31              :    static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_INFO;
      32              : 
      33              : 
      34              :    ///The type of the input message
      35              :    struct messageT : public fbMessage
      36              :    {
      37              :       ///Construct from components
      38          891 :       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          891 :       {
      43          891 :          auto _repoName = builder.CreateString(repoName);
      44          891 :          auto _sha1 = builder.CreateString(sha1);
      45              : 
      46          891 :          uint8_t _modified = modified;
      47              : 
      48          891 :          auto gs = CreateGit_state_fb(builder, _repoName, _sha1, _modified);
      49          891 :          builder.Finish(gs);
      50              : 
      51          891 :       }
      52              : 
      53              :    };
      54              : 
      55            1 :    static bool verify( flatlogs::bufferPtrT & logBuff,  ///< [in] Buffer containing the flatbuffer serialized message.
      56              :                        flatlogs::msgLenT len            ///< [in] length of msgBuffer.
      57              :                      )
      58              :    {
      59            1 :       auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
      60            2 :       return VerifyGit_state_fbBuffer(verifier);
      61              :    }
      62              : 
      63              :    ///Get the message formatte for human consumption.
      64          451 :    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          451 :       auto rgs = GetGit_state_fb(msgBuffer);
      71              : 
      72          451 :       std::string str;
      73          451 :       if( rgs->repo()) str = rgs->repo()->c_str();
      74              : 
      75          451 :       str += " GIT: ";
      76              : 
      77          451 :       if( rgs->sha1()) str += rgs->sha1()->c_str();
      78              : 
      79          451 :       if(rgs->modified() > 0) str+= " MODIFIED";
      80              : 
      81          451 :       return str;
      82            0 :    }
      83              : 
      84              :    /// Access the repo name field
      85            0 :    static std::string repoName( void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
      86              :    {
      87            0 :       auto rgs = GetGit_state_fb(msgBuffer);
      88              : 
      89            0 :       if(rgs->repo()) return std::string(rgs->repo()->c_str());
      90            0 :       else return "";
      91              :    }
      92              : 
      93              :    /// Access the sha1 field
      94            0 :    static std::string sha1( void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
      95              :    {
      96            0 :       auto rgs = GetGit_state_fb(msgBuffer);
      97              : 
      98            0 :       if(rgs->sha1()) return std::string(rgs->sha1()->c_str());
      99            0 :       else return "";
     100              :    }
     101              : 
     102              :    /// Access the modified field
     103            0 :    static bool modified( void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/ )
     104              :    {
     105            0 :       auto rgs = GetGit_state_fb(msgBuffer);
     106              : 
     107            0 :       if(rgs->modified() > 0) return true;
     108            0 :       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            1 :    static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
     117              :    {
     118            1 :       if(     member == "repoName") return logMetaDetail({"GIT REPO NAME", "git repository name", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&repoName), false});
     119            1 :       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            1 :       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            1 :          std::cerr << "No member " << member << " in git_state\n";
     124            1 :          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              : 
        

Generated by: LCOV version 2.0-1