API
 
Loading...
Searching...
No Matches
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
18namespace MagAOX
19{
20namespace 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 const std::string & tgtName ///< [in] the target name
46 )
47 {
48 auto _email = builder.CreateString(email);
49 auto _obsName = builder.CreateString(obsName);
50 auto _tgtName = builder.CreateString(tgtName);
51
52 auto fp = CreateTelem_observer_fb(builder, _email, _obsName, observing, _tgtName);
53 builder.Finish(fp);
54 }
55
56 };
57
58 static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
59 flatlogs::msgLenT len ///< [in] length of msgBuffer.
60 )
61 {
62 auto verifier = flatbuffers::Verifier( static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)), static_cast<size_t>(len));
63
64 bool ok = VerifyTelem_observer_fbBuffer(verifier);
65 if(!ok) return ok;
66
67 auto fbs = GetTelem_observer_fb(static_cast<uint8_t*>(flatlogs::logHeader::messageBuffer(logBuff)));
68
69 if(fbs->email())
70 {
71 std::string email = fbs->email()->c_str();
72 for(size_t n = 0; n < email.size(); ++n)
73 {
74 if(!isprint(email[n]))
75 {
76 return false;
77 }
78 }
79 }
80
81 if(fbs->obsName())
82 {
83 std::string obsn = fbs->obsName()->c_str();
84 for(size_t n = 0; n < obsn.size(); ++n)
85 {
86 if(!isprint(obsn[n]))
87 {
88 return false;
89 }
90 }
91 }
92
93 if(fbs->tgt_name())
94 {
95 std::string tgtn = fbs->tgt_name()->c_str();
96 for(size_t n = 0; n < tgtn.size(); ++n)
97 {
98 if(!isprint(tgtn[n]))
99 {
100 return false;
101 }
102 }
103 }
104
105 return ok;
106 }
107
108 ///Get the message formatted for human consumption.
109 static std::string msgString( void * msgBuffer, ///< [in] Buffer containing the flatbuffer serialized message.
110 flatlogs::msgLenT len ///< [in] [unused] length of msgBuffer.
111 )
112 {
113 static_cast<void>(len);
114
115 auto fbs = GetTelem_observer_fb(msgBuffer);
116
117 std::string msg = "[observer] ";
118
119 if(fbs->email())
120 {
121 msg += "email: ";
122 msg += fbs->email()->c_str();
123 msg += " ";
124 }
125
126 if(fbs->obsName())
127 {
128 msg += "obs: ";
129 msg += fbs->obsName()->c_str();
130 msg += " ";
131 }
132
133 msg += std::to_string(fbs->observing());
134
135 if(fbs->tgt_name())
136 {
137 msg += " tgt: ";
138 msg += fbs->tgt_name()->c_str();
139 msg += " ";
140 }
141 else
142 {
143 msg += " tgt: notimpl";
144 }
145
146 return msg;
147
148 }
149
150 static std::string email( void * msgBuffer )
151 {
152 auto fbs = GetTelem_observer_fb(msgBuffer);
153 if(fbs->email() != nullptr)
154 {
155 return std::string(fbs->email()->c_str());
156 }
157 else return "";
158 }
159
160 static std::string obsName( void * msgBuffer )
161 {
162 auto fbs = GetTelem_observer_fb(msgBuffer);
163 if(fbs->email() != nullptr)
164 {
165 return std::string(fbs->obsName()->c_str());
166 }
167 else return "";
168 }
169
170 static bool observing( void * msgBuffer )
171 {
172 auto fbs = GetTelem_observer_fb(msgBuffer);
173 return fbs->observing();
174 }
175
176 static std::string tgtName( void * msgBuffer )
177 {
178 auto fbs = GetTelem_observer_fb(msgBuffer);
179 if(fbs->tgt_name() != nullptr)
180 {
181 return std::string(fbs->tgt_name()->c_str());
182 }
183 else return "notimpl";
184 }
185
186 /// Get the logMetaDetail for a member by name
187 /**
188 * \returns the a logMetaDetail filled in with the appropriate details
189 * \returns an empty logmegaDetail if member not recognized
190 */
191 static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
192 {
193 if( member == "email") return logMetaDetail({"OBSERVER", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&email), false});
194 else if(member == "obsName") return logMetaDetail({"OBSERVATION NAME", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&obsName), false});
195 else if(member == "observing") return logMetaDetail({"OBSERVING", logMeta::valTypes::Bool, logMeta::metaTypes::State, reinterpret_cast<void*>(&observing)});
196 else if(member == "tgtName") return logMetaDetail({"TARGET NAME", logMeta::valTypes::String, logMeta::metaTypes::State, reinterpret_cast<void*>(&tgtName), false});
197 else
198 {
199 std::cerr << "No string member " << member << " in telem_observer\n";
200 return logMetaDetail();
201 }
202 }
203
204
205
206}; //telem_observer
207
208
209
210} //namespace logger
211} //namespace MagAOX
212
213#endif //logger_types_telem_observer_hpp
214
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
Definition dm.hpp:24
static constexpr logPrioT LOG_TELEM
A telemetry recording.
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, const std::string &tgtName)
Construct from components.
Log entry recording the build-time git state.
static std::string tgtName(void *msgBuffer)
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 formatted for human consumption.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)