Skip to content

Commit 19a6d8f

Browse files
committed
esp32_diagnostic_trace: Review changes
1 parent d83dc21 commit 19a6d8f

File tree

3 files changed

+72
-40
lines changed

3 files changed

+72
-40
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <lib/core/CHIPError.h>
22+
#include <lib/core/TLVCircularBuffer.h>
23+
#include <lib/support/Span.h>
24+
25+
namespace chip {
26+
namespace Tracing {
27+
namespace Diagnostics {
28+
29+
class DiagnosticEntry
30+
{
31+
public:
32+
virtual ~DiagnosticEntry() = default;
33+
virtual CHIP_ERROR Encode(chip::TLV::CircularTLVWriter & writer) = 0;
34+
};
35+
36+
/**
37+
* @brief Interface for storing and retrieving diagnostic data.
38+
*/
39+
class DiagnosticStorageInterface
40+
{
41+
public:
42+
/**
43+
* @brief Virtual destructor for the interface.
44+
*/
45+
virtual ~DiagnosticStorageInterface() = default;
46+
47+
/**
48+
* @brief Stores a diagnostic entry.
49+
* @param diagnostic Reference to a DiagnosticEntry object containing the
50+
* diagnostic data to store.
51+
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success, or an appropriate error code on failure.
52+
*/
53+
virtual CHIP_ERROR Store(DiagnosticEntry & diagnostic) = 0;
54+
55+
/**
56+
* @brief Retrieves diagnostic data as a payload.
57+
* @param payload Reference to a MutableByteSpan where the retrieved
58+
* diagnostic data will be stored.
59+
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success, or an appropriate error code on failure.
60+
*/
61+
virtual CHIP_ERROR Retrieve(MutableByteSpan & payload) = 0;
62+
};
63+
64+
} // namespace Diagnostics
65+
66+
} // namespace Tracing
67+
68+
} // namespace chip

src/tracing/esp32_diagnostic_trace/DiagnosticStorageManager.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <lib/support/logging/CHIPLogging.h>
2222
#include <tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h>
2323

24+
#define TLV_CLOSING_BYTES 4
25+
2426
namespace chip {
2527
namespace Tracing {
2628
using namespace chip::TLV;
@@ -105,7 +107,7 @@ CHIP_ERROR DiagnosticStorageImpl::Retrieve(MutableByteSpan & payload)
105107
(reader.GetTag() == ContextTag(DIAGNOSTICS_TAG::METRIC) || reader.GetTag() == ContextTag(DIAGNOSTICS_TAG::TRACE) ||
106108
reader.GetTag() == ContextTag(DIAGNOSTICS_TAG::COUNTER)))
107109
{
108-
if ((reader.GetLengthRead() - writer.GetLengthWritten()) < writer.GetRemainingFreeLength())
110+
if ((reader.GetLengthRead() - writer.GetLengthWritten()) < (writer.GetRemainingFreeLength() + TLV_CLOSING_BYTES))
109111
{
110112
err = writer.CopyElement(reader);
111113
if (err == CHIP_ERROR_BUFFER_TOO_SMALL)

src/tracing/esp32_diagnostic_trace/Diagnostics.h

+1-39
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
*/
1818

1919
#pragma once
20-
21-
#include <lib/core/CHIPError.h>
22-
#include <lib/core/TLVCircularBuffer.h>
23-
#include <lib/support/Span.h>
20+
#include <tracing/esp32_diagnostic_trace/DiagnosticInterface.h>
2421

2522
namespace chip {
2623
namespace Tracing {
@@ -38,13 +35,6 @@ enum class DIAGNOSTICS_TAG
3835
TIMESTAMP = 6
3936
};
4037

41-
class DiagnosticEntry
42-
{
43-
public:
44-
virtual ~DiagnosticEntry() = default;
45-
virtual CHIP_ERROR Encode(chip::TLV::CircularTLVWriter & writer) = 0;
46-
};
47-
4838
template <typename T>
4939
class Metric : public DiagnosticEntry
5040
{
@@ -188,34 +178,6 @@ class Counter : public DiagnosticEntry
188178
uint32_t timestamp_;
189179
};
190180

191-
/**
192-
* @brief Interface for storing and retrieving diagnostic data.
193-
*/
194-
class DiagnosticStorageInterface
195-
{
196-
public:
197-
/**
198-
* @brief Virtual destructor for the interface.
199-
*/
200-
virtual ~DiagnosticStorageInterface() = default;
201-
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;
217-
};
218-
219181
} // namespace Diagnostics
220182
} // namespace Tracing
221183
} // namespace chip

0 commit comments

Comments
 (0)