API
 
Loading...
Searching...
No Matches
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
16#include "flatbuffer_log.hpp"
17
18namespace MagAOX
19{
20namespace logger
21{
22
23
24///Application State Change
25/** \ingroup logger_types
26 */
28{
29 //The event code
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 {
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 /// Access the from field
73 static std::string from(void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/)
74 {
75 auto rgs = GetState_change_fb(msgBuffer);
76 return app::stateCodes::codeText(rgs->from());
77 }
78
79 /// Access the to field
80 static std::string to(void * msgBuffer /**< [in] Buffer containing the flatbuffer serialized message.*/)
81 {
82 auto rgs = GetState_change_fb(msgBuffer);
83 return app::stateCodes::codeText(rgs->to());
84 }
85
86 /// Get an empty logMetaDetail because meta data doesn't make sense for this log
87 /**
88 * \returns an empty logMetaDetail
89 */
90 static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
91 {
92 static_cast<void>(member);
93
94 std::cerr << "meta data doesn't make sense for state_change.\n";
95 return logMetaDetail();
96 }
97
98};
99
100} //namespace logger
101} //namespace MagAOX
102
103#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.
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition logHeader.hpp:58
static constexpr flatlogs::eventCodeT STATE_CHANGE
Definition logCodes.hpp:13
bool VerifyState_change_fbBuffer(::flatbuffers::Verifier &verifier)
inline ::flatbuffers::Offset< State_change_fb > CreateState_change_fb(::flatbuffers::FlatBufferBuilder &_fbb, int16_t from=0, int16_t to=0)
const MagAOX::logger::State_change_fb * GetState_change_fb(const void *buf)
Definition dm.hpp:28
static constexpr logPrioT LOG_INFO
Informational. The info log level is the lowest level recorded during normal operations.
static std::string codeText(const stateCodeT &stateCode)
Get an ASCII string corresponding to an application stateCode.
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 from(void *msgBuffer)
Access the from field.
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Format the message for text output, including translation of state codes to text form.
static logMetaDetail getAccessor(const std::string &member)
Get an empty logMetaDetail because meta data doesn't make sense for this log.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static std::string to(void *msgBuffer)
Access the to field.