API
outlet_channel_state.hpp
Go to the documentation of this file.
1 /** \file outlet_channel_state.hpp
2  * \brief The MagAO-X logger outlet_channel_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_outlet_channel_state_hpp
11 #define logger_types_outlet_channel_state_hpp
12 
13 #include "generated/outlet_channel_state_generated.h"
14 #include "flatbuffer_log.hpp"
15 
16 namespace MagAOX
17 {
18 namespace logger
19 {
20 
21 
22 ///Application State Change
23 /** \ingroup logger_types
24  */
26 {
27  //The event code
28  static const flatlogs::eventCodeT eventCode = eventCodes::OUTLET_CHANNEL_STATE;
29 
30  //The default level
32 
33  ///The type of the message
34  struct messageT : public fbMessage
35  {
36  messageT( const std::string & channel,
37  uint8_t state
38  )
39  {
40  auto _channel = builder.CreateString(channel);
41 
42  auto gs = CreateOutlet_channel_state_fb(builder, _channel, state);
43  builder.Finish(gs);
44 
45  }
46  };
47 
48  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
49  flatlogs::msgLenT len ///< [in] length of msgBuffer.
50  )
51  {
52  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
53  return VerifyOutlet_channel_state_fbBuffer(verifier);
54  }
55 
56  /// Format the message for text output, including translation of state codes to text form.
57  /**
58  * \returns the message formatted as "State changed from UNINITIALIZED to INITIALIZED"
59  */
60  static std::string msgString(void * msgBuffer, flatlogs::msgLenT len)
61  {
62  static_cast<void>(len);
63 
64  auto rgs = GetOutlet_channel_state_fb(msgBuffer);
65 
66  std::stringstream s;
67  s << "Channel: ";
68 
69  if(rgs->channel() != nullptr) s << rgs->channel()->c_str() << " ";
70  else s << "????" << " ";
71 
72  if(rgs->state()==2)
73  {
74  s << "ON";
75  }
76  else if(rgs->state()==1)
77  {
78  s << "INT";
79  }
80  else if(rgs->state()==0)
81  {
82  s << "OFF";
83  }
84  else s << "UNK";
85 
86  return s.str();
87  }
88 
89 };
90 
91 } //namespace logger
92 } //namespace MagAOX
93 
94 #endif //logger_types_outlet_channel_state_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_NOTICE
A normal but significant condition.
Definition: logPriority.hpp:46
Message type for resolving log messages with a f.b. builder.
flatbuffers::FlatBufferBuilder builder
Base class for logs consisting of a flatbuffer message.
messageT(const std::string &channel, uint8_t state)
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Format the message for text output, including translation of state codes to text form.
static const flatlogs::eventCodeT eventCode
static const flatlogs::logPrioT defaultLevel
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)