LCOV - code coverage report
Current view: top level - libMagAOX/logger/types - observer.hpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 44.1 % 34 15
Test Date: 2026-01-03 21:03:39 Functions: 75.0 % 4 3

            Line data    Source code
       1              : /** \file observer.hpp
       2              :   * \brief The MagAO-X logger observer log type.
       3              :   * \author Jared R. Males (jaredmales@gmail.com)
       4              :   *
       5              :   * \ingroup logger_types_files
       6              :   *
       7              :   * History:
       8              :   * - 2018-09-06 created by JRM
       9              :   */
      10              : #ifndef logger_types_observer_hpp
      11              : #define logger_types_observer_hpp
      12              : 
      13              : #include "generated/observer_generated.h"
      14              : #include "flatbuffer_log.hpp"
      15              : 
      16              : #include <cmath>
      17              : 
      18              : namespace MagAOX
      19              : {
      20              : namespace logger
      21              : {
      22              : 
      23              : 
      24              : /// Log entry recording the observer.
      25              : /** \ingroup logger_types
      26              :   */
      27              : struct observer : public flatbuffer_log
      28              : {
      29              :    ///The event code
      30              :    static const flatlogs::eventCodeT eventCode = eventCodes::OBSERVER;
      31              : 
      32              :    ///The default level
      33              :    static const flatlogs::logPrioT defaultLevel = flatlogs::logPrio::LOG_INFO;
      34              : 
      35              :    static timespec lastRecord; ///< The time of the last time this log was recorded.  Used by the telemetry system.
      36              : 
      37              :    ///The type of the input message
      38              :    struct messageT : public fbMessage
      39              :    {
      40              :       ///Construct from components
      41            2 :       messageT( const std::string & fullName,   ///< [in] the observer's full name
      42              :                 const std::string & pfoa,       ///< [in] the observer's preferred form of address
      43              :                 const std::string & email,      ///< [in] the observer's email
      44              :                 const std::string & institution ///< [in] the observer's institution
      45              :               )
      46            2 :       {
      47            2 :          auto _fullName = builder.CreateString(fullName);
      48            2 :          auto _pfoa = builder.CreateString(pfoa);
      49            2 :          auto _email = builder.CreateString(email);
      50            2 :          auto _institution = builder.CreateString(institution);
      51              : 
      52            2 :          auto fp = CreateObserver_fb(builder, _fullName, _pfoa, _email, _institution);
      53            2 :          builder.Finish(fp);
      54            2 :       }
      55              : 
      56              :    };
      57              : 
      58            2 :    static bool verify( flatlogs::bufferPtrT & logBuff,  ///< [in] Buffer containing the flatbuffer serialized message.
      59              :                        flatlogs::msgLenT len            ///< [in] length of msgBuffer.
      60              :                      )
      61              :    {
      62            2 :       auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
      63            4 :       return VerifyObserver_fbBuffer(verifier);
      64              :    }
      65              : 
      66              :    ///Get the message formatte for human consumption.
      67            0 :    static std::string msgString( void * msgBuffer,  /**< [in] Buffer containing the flatbuffer serialized message.*/
      68              :                                  flatlogs::msgLenT len  /**< [in] [unused] length of msgBuffer.*/
      69              :                                )
      70              :    {
      71              :       static_cast<void>(len);
      72              : 
      73            0 :       auto fbs = GetObserver_fb(msgBuffer);
      74              : 
      75            0 :       std::string msg = "Observer Loaded: ";
      76              : 
      77            0 :       if(fbs->fullName())
      78              :       {
      79            0 :          msg += fbs->fullName()->c_str();
      80            0 :          if(!fbs->pfoa()) msg += ", ";
      81            0 :          else msg += " ";
      82              :       }
      83              : 
      84            0 :       if(fbs->pfoa())
      85              :       {
      86            0 :          msg += "(";
      87            0 :          msg += fbs->pfoa()->c_str();
      88            0 :          msg += "), ";
      89              :       }
      90              : 
      91            0 :       if(fbs->email())
      92              :       {
      93            0 :          msg += fbs->email()->c_str();
      94            0 :          if(fbs->institution()) msg += ", ";
      95            0 :          else msg += " ";
      96              :       }
      97              : 
      98            0 :       if(fbs->institution())
      99              :       {
     100            0 :          msg += fbs->institution()->c_str();
     101              :       }
     102              : 
     103            0 :       return msg;
     104              : 
     105            0 :    }
     106              : 
     107              :    /// Get an empty logMetaDetail because meta data doesn't make sense for this log
     108              :    /**
     109              :      * \returns an empty logMetaDetail
     110              :      */
     111            1 :    static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
     112              :    {
     113              :       static_cast<void>(member);
     114              : 
     115            1 :       std::cerr << "meta data doesn't make sense for state_change.\n";
     116            1 :       return logMetaDetail();
     117              :    }
     118              : 
     119              : }; //observer
     120              : 
     121              : 
     122              : } //namespace logger
     123              : } //namespace MagAOX
     124              : 
     125              : #endif //logger_types_observer_hpp
     126              : 
        

Generated by: LCOV version 2.0-1