Line data Source code
1 : /** \file empty_log.hpp
2 : * \brief The MagAO-X logger empty log base 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_empty_log_hpp
11 : #define logger_types_empty_log_hpp
12 :
13 : #include "../logMeta.hpp"
14 :
15 : namespace MagAOX
16 : {
17 : namespace logger
18 : {
19 :
20 :
21 : ///Empty type for resolving logs with no message.
22 : /**
23 : * \ingroup logger_types_basic
24 : */
25 : struct emptyMessage
26 : {
27 : };
28 :
29 :
30 : /// Base class for logs consisting of an empty message.
31 : /** Such logs are used to log events. Does not have eventCode or defaultLevel,
32 : * so this can not be used as a log type directly.
33 : *
34 : *
35 : * \ingroup logger_types_basic
36 : */
37 : template<class derivedT>
38 : struct empty_log
39 : {
40 : ///The type of the message
41 : typedef emptyMessage messageT;
42 :
43 : ///Get the length of the message.
44 18 : static flatlogs::msgLenT length( const messageT & msg)
45 : {
46 : static_cast<void>(msg);
47 :
48 18 : return 0;
49 : }
50 :
51 : ///Format the buffer given a message -- a no-op since the message is an emptyMessage.
52 : /**
53 : * \returns 0
54 : */
55 12 : static int format( void * msgBuffer, ///< [out] the buffer, which is ignored.
56 : const messageT & msg ///< [in] an emptyMessage.
57 : )
58 : {
59 : static_cast<void>(msgBuffer);
60 : static_cast<void>(msg);
61 :
62 12 : return 0;
63 : }
64 :
65 : ///Extract the message from a buffer -- a no-op since it is an emptyMessage.
66 : /**
67 : * \returns 0
68 : */
69 : static int extract( messageT & msg, ///< [out] an emptyMessage to which nothing is done.
70 : void * msgBuffer, ///< [in] the empty buffer. Is ignored.
71 : flatlogs::msgLenT len ///< [in] ignored length of the empty buffer.
72 : )
73 : {
74 : static_cast<void>(msg);
75 : static_cast<void>(msgBuffer);
76 : static_cast<void>(len);
77 :
78 :
79 : return 0;
80 : }
81 :
82 6 : static bool verify( flatlogs::bufferPtrT & logBuff, ///< [in] Buffer containing the flatbuffer serialized message.
83 : flatlogs::msgLenT len ///< [in] length of msgBuffer.
84 : )
85 : {
86 : static_cast<void>(logBuff);
87 6 : return (len == 0);
88 : }
89 :
90 6 : static std::string msgString( void * msgBuffer, flatlogs::msgLenT len)//messageT & msg /**< [in] [unused] the empty message */)
91 : {
92 : static_cast<void>(msgBuffer);
93 : static_cast<void>(len);
94 :
95 12 : return derivedT::msg();
96 : }
97 :
98 0 : static std::string msgJSON( void * msgBuffer, /**< [in] Buffer containing the flatbuffer serialized message.*/
99 : flatlogs::msgLenT len, /**< [in] [unused] length of msgBuffer.*/
100 : const uint8_t * binarySchema, /**< [in] [unused] */
101 : const unsigned int binarySchemaLength /**< [in] [unused] */
102 : )
103 : {
104 : static_cast<void>(len);
105 : static_cast<void>(msgBuffer);
106 : static_cast<void>(binarySchema);
107 : static_cast<void>(binarySchemaLength);
108 0 : return "{}";
109 : }
110 :
111 : /// Get an empty logMetaDetail because meta data doesn't make sense for this log
112 : /**
113 : * \returns an empty logMetaDetail
114 : */
115 5 : static logMetaDetail getAccessor( const std::string & member /**< [in] the name of the member */ )
116 : {
117 : static_cast<void>(member);
118 :
119 5 : std::cerr << "meta data doesn't make sense for " << eventCodeName(derivedT::eventCode) << "\n";
120 5 : return logMetaDetail();
121 : }
122 : };
123 :
124 : } //namespace logger
125 : } //namespace MagAOX
126 :
127 : #endif //logger_types_empty_log_hpp
|