19
19
#pragma once
20
20
21
21
#include < lib/core/CHIPError.h>
22
- #include < lib/support/Span.h>
23
22
#include < lib/core/TLVCircularBuffer.h>
23
+ #include < lib/support/Span.h>
24
24
25
25
namespace chip {
26
26
namespace Tracing {
@@ -30,34 +30,36 @@ using namespace chip::TLV;
30
30
31
31
enum class DIAGNOSTICS_TAG
32
32
{
33
- METRIC = 0 ,
34
- TRACE = 1 ,
35
- COUNTER = 2 ,
36
- LABEL = 3 ,
37
- GROUP = 4 ,
38
- VALUE = 5 ,
39
- TIMESTAMP = 6
33
+ METRIC = 0 ,
34
+ TRACE = 1 ,
35
+ COUNTER = 2 ,
36
+ LABEL = 3 ,
37
+ GROUP = 4 ,
38
+ VALUE = 5 ,
39
+ TIMESTAMP = 6
40
40
};
41
41
42
- class DiagnosticEntry {
42
+ class DiagnosticEntry
43
+ {
43
44
public:
44
- virtual ~DiagnosticEntry () = default ;
45
- virtual CHIP_ERROR Encode (CircularTLVWriter &writer) = 0;
45
+ virtual ~DiagnosticEntry () = default ;
46
+ virtual CHIP_ERROR Encode (CircularTLVWriter & writer) = 0;
46
47
};
47
48
48
- template <typename T>
49
- class Metric : public DiagnosticEntry {
49
+ template <typename T>
50
+ class Metric : public DiagnosticEntry
51
+ {
50
52
public:
51
- Metric (const char * label, T value, uint32_t timestamp)
52
- : label_(label), value_(value), timestamp_(timestamp) {}
53
+ Metric (const char * label, T value, uint32_t timestamp) : label_(label), value_(value), timestamp_(timestamp) {}
53
54
54
55
Metric () {}
55
56
56
- const char * GetLabel () const { return label_; }
57
+ const char * GetLabel () const { return label_; }
57
58
T GetValue () const { return value_; }
58
59
uint32_t GetTimestamp () const { return timestamp_; }
59
60
60
- CHIP_ERROR Encode (CircularTLVWriter &writer) override {
61
+ CHIP_ERROR Encode (CircularTLVWriter & writer) override
62
+ {
61
63
CHIP_ERROR err = CHIP_NO_ERROR;
62
64
TLVType metricContainer;
63
65
err = writer.StartContainer (ContextTag (DIAGNOSTICS_TAG::METRIC), kTLVType_Structure , metricContainer);
@@ -87,23 +89,24 @@ class Metric : public DiagnosticEntry {
87
89
}
88
90
89
91
private:
90
- const char * label_;
92
+ const char * label_;
91
93
T value_;
92
94
uint32_t timestamp_;
93
95
};
94
96
95
- class Trace : public DiagnosticEntry {
97
+ class Trace : public DiagnosticEntry
98
+ {
96
99
public:
97
- Trace (const char * label, const char * group, uint32_t timestamp)
98
- : label_(label), group_(group), timestamp_(timestamp) {}
100
+ Trace (const char * label, const char * group, uint32_t timestamp) : label_(label), group_(group), timestamp_(timestamp) {}
99
101
100
102
Trace () {}
101
103
102
- const char * GetLabel () const { return label_; }
104
+ const char * GetLabel () const { return label_; }
103
105
uint32_t GetTimestamp () const { return timestamp_; }
104
- const char * GetGroup () const { return group_; }
106
+ const char * GetGroup () const { return group_; }
105
107
106
- CHIP_ERROR Encode (CircularTLVWriter &writer) override {
108
+ CHIP_ERROR Encode (CircularTLVWriter & writer) override
109
+ {
107
110
CHIP_ERROR err = CHIP_NO_ERROR;
108
111
TLVType traceContainer;
109
112
err = writer.StartContainer (ContextTag (DIAGNOSTICS_TAG::TRACE), kTLVType_Structure , traceContainer);
@@ -133,23 +136,24 @@ class Trace : public DiagnosticEntry {
133
136
}
134
137
135
138
private:
136
- const char * label_;
137
- const char * group_;
139
+ const char * label_;
140
+ const char * group_;
138
141
uint32_t timestamp_;
139
142
};
140
143
141
- class Counter : public DiagnosticEntry {
144
+ class Counter : public DiagnosticEntry
145
+ {
142
146
public:
143
- Counter (const char * label, uint32_t count, uint32_t timestamp)
144
- : label_(label), count_(count), timestamp_(timestamp) {}
147
+ Counter (const char * label, uint32_t count, uint32_t timestamp) : label_(label), count_(count), timestamp_(timestamp) {}
145
148
146
149
Counter () {}
147
150
148
151
uint32_t GetCount () const { return count_; }
149
152
150
153
uint32_t GetTimestamp () const { return timestamp_; }
151
154
152
- CHIP_ERROR Encode (CircularTLVWriter &writer) override {
155
+ CHIP_ERROR Encode (CircularTLVWriter & writer) override
156
+ {
153
157
CHIP_ERROR err = CHIP_NO_ERROR;
154
158
TLVType counterContainer;
155
159
err = writer.StartContainer (ContextTag (DIAGNOSTICS_TAG::COUNTER), kTLVType_Structure , counterContainer);
@@ -179,18 +183,37 @@ class Counter : public DiagnosticEntry {
179
183
}
180
184
181
185
private:
182
- const char * label_;
186
+ const char * label_;
183
187
uint32_t count_;
184
188
uint32_t timestamp_;
185
189
};
186
190
187
- class DiagnosticStorageInterface {
191
+ /* *
192
+ * @brief Interface for storing and retrieving diagnostic data.
193
+ */
194
+ class DiagnosticStorageInterface
195
+ {
188
196
public:
197
+ /* *
198
+ * @brief Virtual destructor for the interface.
199
+ */
189
200
virtual ~DiagnosticStorageInterface () = default ;
190
201
191
- virtual CHIP_ERROR Store (DiagnosticEntry& diagnostic) = 0;
192
-
193
- virtual CHIP_ERROR Retrieve (MutableByteSpan &payload) = 0;
202
+ /* *
203
+ * @brief Stores a diagnostic entry.
204
+ * @param diagnostic Reference to a DiagnosticEntry object containing the
205
+ * diagnostic data to store.
206
+ * @return CHIP_ERROR Returns CHIP_NO_ERROR on success, or an appropriate error code on failure.
207
+ */
208
+ virtual CHIP_ERROR Store (DiagnosticEntry & diagnostic) = 0;
209
+
210
+ /* *
211
+ * @brief Retrieves diagnostic data as a payload.
212
+ * @param payload Reference to a MutableByteSpan where the retrieved
213
+ * diagnostic data will be stored.
214
+ * @return CHIP_ERROR Returns CHIP_NO_ERROR on success, or an appropriate error code on failure.
215
+ */
216
+ virtual CHIP_ERROR Retrieve (MutableByteSpan & payload) = 0;
194
217
};
195
218
196
219
} // namespace Diagnostics
0 commit comments