API
telem_observer.hpp
Go to the documentation of this file.
1 /** \file telem_observer.hpp
2  * \brief The MagAO-X logger telem_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_telem_observer_hpp
11 #define logger_types_telem_observer_hpp
12 
13 #include "generated/telem_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 build-time git state.
25 /** \ingroup logger_types
26  */
28 {
29  ///The event code
30  static const flatlogs::eventCodeT eventCode = eventCodes::TELEM_OBSERVER;
31 
32  ///The default level
34 
35  static timespec lastRecord; ///< The time of the last time this log was recorded. Used by the telemetry system.
36 
37 
38  ///The type of the input message
39  struct messageT : public fbMessage
40  {
41  ///Construct from components
42  messageT( const std::string & email, /// <[in] observer email
43  const std::string & obsName, /// <[in] observer email
44  const bool & observing /// <[in] status of observing
45  )
46  {
47  auto _email = builder.CreateString(email);
48  auto _obsName = builder.CreateString(obsName);
49 
50  auto fp = CreateTelem_observer_fb(builder, _email, _obsName, observing);
51  builder.Finish(fp);
52  }
53 
54  };
55 
56  static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
57  flatlogs::msgLenT len ///< [in] length of msgBuffer.
58  )
59  {
60  auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
61 
62  bool ok = VerifyTelem_observer_fbBuffer(verifier);
63  if(!ok) return ok;
64 
65  auto fbs = GetTelem_observer_fb(static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)));
66 
67  if(fbs->email())
68  {
69  std::string email = fbs->email()->c_str();
70  for(size_t n = 0; n < email.size(); ++n)
71  {
72  if(!isprint(email[n]))
73  {
74  return false;
75  }
76  }
77  }
78 
79  if(fbs->obsName())
80  {
81  std::string obsn = fbs->obsName()->c_str();
82  for(size_t n = 0; n < obsn.size(); ++n)
83  {
84  if(!isprint(obsn[n]))
85  {
86  return false;
87  }
88  }
89  }
90 
91  return ok;
92  }
93 
94  ///Get the message formattd for human consumption.
95  static std::string msgString( void * msgBuffer, ///< [in] Buffer containing the flatbuffer serialized message.
96  flatlogs::msgLenT len ///< [in] [unused] length of msgBuffer.
97  )
98  {
99  static_cast<void>(len);
100 
101  auto fbs = GetTelem_observer_fb(msgBuffer);
102 
103  std::string msg = "[observer] ";
104 
105  if(fbs->email())
106  {
107  msg += "email: ";
108  msg += fbs->email()->c_str();
109  msg += " ";
110  }
111 
112  if(fbs->obsName())
113  {
114  msg += "obs: ";
115  msg += fbs->obsName()->c_str();
116  msg += " ";
117  }
118 
119  msg += std::to_string(fbs->observing());
120 
121  return msg;
122 
123  }
124 
125  static std::string email( void * msgBuffer )
126  {
127  auto fbs = GetTelem_observer_fb(msgBuffer);
128  if(fbs->email() != nullptr)
129  {
130  return std::string(fbs->email()->c_str());
131  }
132  else return "";
133  }
134 
135  static std::string obsName( void * msgBuffer )
136  {
137  auto fbs = GetTelem_observer_fb(msgBuffer);
138  if(fbs->email() != nullptr)
139  {
140  return std::string(fbs->obsName()->c_str());
141  }
142  else return "";
143  }
144 
145  static bool observing( void * msgBuffer )
146  {
147  auto fbs = GetTelem_observer_fb(msgBuffer);
148  return fbs->observing();
149  }
150 
151  /// Get the logMetaDetail for a member by name
152  /**
153  * \returns the a logMetaDetail filled in with the appropriate details
154  * \returns an empty logmegaDetail if member not recognized
155  */
156  static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
157  {
158  if( member == "email") return logMetaDetail({"OBSERVER", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&email), false});
159  else if(member == "obsName") return logMetaDetail({"OBS-NAME", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&obsName), false});
160  else if(member == "observing") return logMetaDetail({"OBSERVING", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&observing)});
161  else
162  {
163  std::cerr << "No string member " << member << " in telem_observer\n";
164  return logMetaDetail();
165  }
166  }
167 
168 
169 
170 }; //telem_observer
171 
172 
173 
174 } //namespace logger
175 } //namespace MagAOX
176 
177 #endif //logger_types_telem_observer_hpp
178 
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
std::ostream & cerr()
std::stringstream msg
Definition: dm.hpp:24
constexpr static logPrioT LOG_TELEM
A telemetry recording.
Definition: logPriority.hpp:58
Message type for resolving log messages with a f.b. builder.
flatbuffers::FlatBufferBuilder builder
Base class for logs consisting of a flatbuffer message.
The type of the input message.
messageT(const std::string &email, const std::string &obsName, const bool &observing)
Construct from components.
Log entry recording the build-time git state.
static std::string obsName(void *msgBuffer)
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
static logMetaDetail getAccessor(const std::string &member)
Get the logMetaDetail for a member by name.
static std::string email(void *msgBuffer)
static const flatlogs::logPrioT defaultLevel
The default level.
static bool observing(void *msgBuffer)
static const flatlogs::eventCodeT eventCode
The event code.
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formattd for human consumption.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)