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