API
 
Loading...
Searching...
No Matches
observer.hpp
Go to the documentation of this file.
1/** \file observer.hpp
2 * \brief The MagAO-X logger 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_observer_hpp
11#define logger_types_observer_hpp
12
13#include "generated/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 observer.
25/** \ingroup logger_types
26 */
27struct observer : public flatbuffer_log
28{
29 ///The event code
30 static const flatlogs::eventCodeT eventCode = eventCodes::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 ///The type of the input message
38 struct messageT : public fbMessage
39 {
40 ///Construct from components
41 messageT( const std::string & fullName, ///< [in] the observer's full name
42 const std::string & pfoa, ///< [in] the observer's preferred form of address
43 const std::string & email, ///< [in] the observer's email
44 const std::string & institution ///< [in] the observer's institution
45 )
46 {
47 auto _fullName = builder.CreateString(fullName);
48 auto _pfoa = builder.CreateString(pfoa);
49 auto _email = builder.CreateString(email);
50 auto _institution = builder.CreateString(institution);
51
52 auto fp = CreateObserver_fb(builder, _fullName, _pfoa, _email, _institution);
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 return VerifyObserver_fbBuffer(verifier);
64 }
65
66 ///Get the message formatte for human consumption.
67 static std::string msgString( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
68 flatlogs::msgLenT len /**< [in] [unused] length of msgBuffer.*/
69 )
70 {
71 static_cast<void>(len);
72
73 auto fbs = GetObserver_fb(msgBuffer);
74
75 std::string msg = "Observer Loaded: ";
76
77 if(fbs->fullName())
78 {
79 msg += fbs->fullName()->c_str();
80 if(!fbs->pfoa()) msg += ", ";
81 else msg += " ";
82 }
83
84 if(fbs->pfoa())
85 {
86 msg += "(";
87 msg += fbs->pfoa()->c_str();
88 msg += "), ";
89 }
90
91 if(fbs->email())
92 {
93 msg += fbs->email()->c_str();
94 if(fbs->institution()) msg += ", ";
95 else msg += " ";
96 }
97
98 if(fbs->institution())
99 {
100 msg += fbs->institution()->c_str();
101 }
102
103 return msg;
104
105 }
106
107}; //observer
108
109
110} //namespace logger
111} //namespace MagAOX
112
113#endif //logger_types_observer_hpp
114
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_INFO
Informational. The info log level is the lowest level recorded during normal operations.
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.
Definition observer.hpp:39
messageT(const std::string &fullName, const std::string &pfoa, const std::string &email, const std::string &institution)
Construct from components.
Definition observer.hpp:41
Log entry recording the observer.
Definition observer.hpp:28
static timespec lastRecord
The time of the last time this log was recorded. Used by the telemetry system.
Definition observer.hpp:35
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
Definition observer.hpp:58
static const flatlogs::logPrioT defaultLevel
The default level.
Definition observer.hpp:33
static const flatlogs::eventCodeT eventCode
The event code.
Definition observer.hpp:30
static std::string msgString(void *msgBuffer, flatlogs::msgLenT len)
Get the message formatte for human consumption.
Definition observer.hpp:67