API
state_change.hpp
Go to the documentation of this file.
1 /** \file state_change.hpp
2  * \brief The MagAO-X logger state_change 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_state_change_hpp
11 #define logger_types_state_change_hpp
12 
13 #include "../../app/stateCodes.hpp"
14 
15 #include "generated/state_change_generated.h"
16 #include "flatbuffer_log.hpp"
17 
18 namespace MagAOX
19 {
20 namespace logger
21 {
22 
23 
24 ///Application State Change
25 /** \ingroup logger_types
26  */
28 {
29  //The event code
30  static const flatlogs::eventCodeT eventCode = eventCodes::STATE_CHANGE;
31 
32  //The default level
34 
35  ///The type of the message
36  struct messageT : public fbMessage
37  {
38  messageT( int16_t from,
39  int16_t to
40  )
41  {
42  auto gs = CreateState_change_fb(builder, from, to);
43  builder.Finish(gs);
44  }
45  };
46 
47  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
48  flatlogs::msgLenT len ///< [in] length of msgBuffer.
49  )
50  {
51  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
52  return VerifyState_change_fbBuffer(verifier);
53  }
54 
55  /// Format the message for text output, including translation of state codes to text form.
56  /**
57  * \returns the message formatted as "State changed from UNINITIALIZED to INITIALIZED"
58  */
59  static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
60  flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
61  )
62  {
63  static_cast<void>(len);
64 
65  auto rgs = GetState_change_fb(msgBuffer);
66 
67  std::stringstream s;
68  s << "State changed from " << app::stateCodes::codeText(rgs->from()) << " to " << app::stateCodes::codeText(rgs->to());
69  return s.str();
70  }
71 
72 };
73 
74 } //namespace logger
75 } //namespace MagAOX
76 
77 #endif //logger_types_state_change_hpp
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
static std::string codeText(stateCodeT stateCode)
Get an ASCII string corresponding to an application stateCode.
Definition: stateCodes.cpp:16
Message type for resolving log messages with a f.b. builder.
flatbuffers::FlatBufferBuilder builder
Base class for logs consisting of a flatbuffer message.
messageT(int16_t from, int16_t to)
Application State Change.
static const flatlogs::eventCodeT eventCode
static const flatlogs::logPrioT defaultLevel
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Format the message for text output, including translation of state codes to text form.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)