23
23
24
24
namespace chip {
25
25
namespace Tracing {
26
+ using namespace chip ::TLV;
26
27
27
28
namespace Diagnostics {
28
- DiagnosticStorageImpl::DiagnosticStorageImpl (uint8_t * buffer, size_t bufferSize)
29
- : mEndUserCircularBuffer (buffer, bufferSize) {}
29
+ DiagnosticStorageImpl::DiagnosticStorageImpl (uint8_t * buffer, size_t bufferSize) : mEndUserCircularBuffer (buffer, bufferSize) {}
30
30
31
- DiagnosticStorageImpl & DiagnosticStorageImpl::GetInstance (uint8_t * buffer, size_t bufferSize) {
31
+ DiagnosticStorageImpl & DiagnosticStorageImpl::GetInstance (uint8_t * buffer, size_t bufferSize)
32
+ {
32
33
static DiagnosticStorageImpl instance (buffer, bufferSize);
33
34
return instance;
34
35
}
@@ -42,7 +43,6 @@ CHIP_ERROR DiagnosticStorageImpl::Store(DiagnosticEntry & diagnostic)
42
43
CircularTLVWriter writer;
43
44
writer.Init (mEndUserCircularBuffer );
44
45
45
- // Start a TLV structure container (Anonymous)
46
46
TLVType outerContainer;
47
47
err = writer.StartContainer (AnonymousTag (), kTLVType_Structure , outerContainer);
48
48
VerifyOrReturnError (err == CHIP_NO_ERROR, err,
@@ -98,21 +98,25 @@ CHIP_ERROR DiagnosticStorageImpl::Retrieve(MutableByteSpan & payload)
98
98
ChipLogError (DeviceLayer, " Failed to enter outer TLV container: %s" , ErrorStr (err)));
99
99
100
100
err = reader.Next ();
101
- VerifyOrReturnError (err == CHIP_NO_ERROR, err, ChipLogError (DeviceLayer, " Failed to read next TLV element in outer container: %s" , ErrorStr (err)));
101
+ VerifyOrReturnError (err == CHIP_NO_ERROR, err,
102
+ ChipLogError (DeviceLayer, " Failed to read next TLV element in outer container: %s" , ErrorStr (err)));
102
103
103
- // Check if the current element is a METRIC or TRACE container
104
104
if ((reader.GetType () == kTLVType_Structure ) &&
105
- (reader.GetTag () == ContextTag (DIAGNOSTICS_TAG::METRIC) || reader.GetTag () == ContextTag (DIAGNOSTICS_TAG::TRACE) || reader.GetTag () == ContextTag (DIAGNOSTICS_TAG::COUNTER)))
105
+ (reader.GetTag () == ContextTag (DIAGNOSTICS_TAG::METRIC) || reader.GetTag () == ContextTag (DIAGNOSTICS_TAG::TRACE) ||
106
+ reader.GetTag () == ContextTag (DIAGNOSTICS_TAG::COUNTER)))
106
107
{
107
- if ((reader.GetLengthRead () - writer.GetLengthWritten ()) < writer.GetRemainingFreeLength ()) {
108
+ if ((reader.GetLengthRead () - writer.GetLengthWritten ()) < writer.GetRemainingFreeLength ())
109
+ {
108
110
err = writer.CopyElement (reader);
109
- if (err == CHIP_ERROR_BUFFER_TOO_SMALL) {
111
+ if (err == CHIP_ERROR_BUFFER_TOO_SMALL)
112
+ {
110
113
ChipLogProgress (DeviceLayer, " Buffer too small to occupy current element" );
111
114
break ;
112
115
}
113
116
VerifyOrReturnError (err == CHIP_NO_ERROR, err, ChipLogError (DeviceLayer, " Failed to copy TLV element" ));
114
117
}
115
- else {
118
+ else
119
+ {
116
120
ChipLogProgress (DeviceLayer, " Buffer too small to occupy current TLV" );
117
121
break ;
118
122
}
@@ -123,7 +127,6 @@ CHIP_ERROR DiagnosticStorageImpl::Retrieve(MutableByteSpan & payload)
123
127
reader.ExitContainer (outerReaderContainer);
124
128
return CHIP_ERROR_WRONG_TLV_TYPE;
125
129
}
126
- // Exit the outer container
127
130
err = reader.ExitContainer (outerReaderContainer);
128
131
VerifyOrReturnError (err == CHIP_NO_ERROR, err,
129
132
ChipLogError (DeviceLayer, " Failed to exit outer TLV container: %s" , ErrorStr (err)));
@@ -136,11 +139,11 @@ CHIP_ERROR DiagnosticStorageImpl::Retrieve(MutableByteSpan & payload)
136
139
137
140
err = writer.EndContainer (outWriterContainer);
138
141
VerifyOrReturnError (err == CHIP_NO_ERROR, err, ChipLogError (DeviceLayer, " Failed to close outer container" ));
139
- // Finalize the writing process
140
142
err = writer.Finalize ();
141
143
VerifyOrReturnError (err == CHIP_NO_ERROR, err, ChipLogError (DeviceLayer, " Failed to finalize TLV writing" ));
142
144
payload.reduce_size (writer.GetLengthWritten ());
143
- ChipLogProgress (DeviceLayer, " ---------------Total written bytes successfully : %ld----------------\n " , writer.GetLengthWritten ());
145
+ ChipLogProgress (DeviceLayer, " ---------------Total written bytes successfully : %ld----------------\n " ,
146
+ writer.GetLengthWritten ());
144
147
ChipLogProgress (DeviceLayer, " Retrieval successful" );
145
148
return CHIP_NO_ERROR;
146
149
}
0 commit comments