From ed14abb6680c99bcd7bbda468ec18fd233d1ea0b Mon Sep 17 00:00:00 2001 From: mahesh Date: Fri, 15 Nov 2024 13:03:10 +0530 Subject: [PATCH] backend: Add description for diagnosticstorage interface, remove unncessary comments, format files, namespace changes --- ...diagnostic-logs-provider-delegate-impl.cpp | 61 +++++---- src/tracing/esp32_diagnostic_trace/BUILD.gn | 4 +- .../esp32_diagnostic_trace/Counter.cpp | 12 +- src/tracing/esp32_diagnostic_trace/Counter.h | 10 +- .../DiagnosticStorageManager.cpp | 29 ++-- .../DiagnosticStorageManager.h | 13 +- .../DiagnosticTracing.cpp | 20 +-- .../DiagnosticTracing.h | 18 +-- .../esp32_diagnostic_trace/Diagnostics.h | 125 +++++++++++------- 9 files changed, 159 insertions(+), 133 deletions(-) diff --git a/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp b/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp index 16df89e9b8d837..a0046804e82167 100644 --- a/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp +++ b/examples/temperature-measurement-app/esp32/main/diagnostic-logs-provider-delegate-impl.cpp @@ -75,15 +75,14 @@ size_t LogProvider::GetSizeForIntent(IntentEnum intent) { switch (intent) { - case IntentEnum::kEndUserSupport: - { - #if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE - return DIAGNOSTIC_BUFFER_SIZE; - #else - return static_cast(endUserSupportLogEnd - endUserSupportLogStart); - #endif - } - break; + case IntentEnum::kEndUserSupport: { +#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE + return DIAGNOSTIC_BUFFER_SIZE; +#else + return static_cast(endUserSupportLogEnd - endUserSupportLogStart); +#endif + } + break; case IntentEnum::kNetworkDiag: return static_cast(networkDiagnosticLogEnd - networkDiagnosticLogStart); case IntentEnum::kCrashLogs: @@ -115,28 +114,28 @@ CHIP_ERROR LogProvider::PrepareLogContextForIntent(LogContext * context, IntentE switch (intent) { case IntentEnum::kEndUserSupport: { - #if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE - DiagnosticStorageImpl & diagnosticStorage = DiagnosticStorageImpl::GetInstance(); - MutableByteSpan endUserSupportSpan(endUserBuffer, DIAGNOSTIC_BUFFER_SIZE); - - if (diagnosticStorage.IsEmptyBuffer()) - { - ChipLogError(DeviceLayer, "Empty Diagnostic buffer"); - return CHIP_ERROR_NOT_FOUND; - } - // Retrieve data from the diagnostic storage - CHIP_ERROR err = diagnosticStorage.Retrieve(endUserSupportSpan); - if (err != CHIP_NO_ERROR) - { - ChipLogError(DeviceLayer, "Failed to retrieve data: %s", chip::ErrorStr(err)); - return err; - } - // Now, assign the span to the EndUserSupport object or whatever is required - context->EndUserSupport.span = endUserSupportSpan; - #else - context->EndUserSupport.span = - ByteSpan(&endUserSupportLogStart[0], static_cast(endUserSupportLogEnd - endUserSupportLogStart)); - #endif +#if CONFIG_ENABLE_ESP_DIAGNOSTICS_TRACE + DiagnosticStorageImpl & diagnosticStorage = DiagnosticStorageImpl::GetInstance(); + MutableByteSpan endUserSupportSpan(endUserBuffer, DIAGNOSTIC_BUFFER_SIZE); + + if (diagnosticStorage.IsEmptyBuffer()) + { + ChipLogError(DeviceLayer, "Empty Diagnostic buffer"); + return CHIP_ERROR_NOT_FOUND; + } + // Retrieve data from the diagnostic storage + CHIP_ERROR err = diagnosticStorage.Retrieve(endUserSupportSpan); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to retrieve data: %s", chip::ErrorStr(err)); + return err; + } + // Now, assign the span to the EndUserSupport object or whatever is required + context->EndUserSupport.span = endUserSupportSpan; +#else + context->EndUserSupport.span = + ByteSpan(&endUserSupportLogStart[0], static_cast(endUserSupportLogEnd - endUserSupportLogStart)); +#endif } break; diff --git a/src/tracing/esp32_diagnostic_trace/BUILD.gn b/src/tracing/esp32_diagnostic_trace/BUILD.gn index 60d425af9497cb..c0b9e845c17b5a 100644 --- a/src/tracing/esp32_diagnostic_trace/BUILD.gn +++ b/src/tracing/esp32_diagnostic_trace/BUILD.gn @@ -27,10 +27,10 @@ static_library("backend") { sources = [ "Counter.cpp", "Counter.h", - "DiagnosticTracing.cpp", - "DiagnosticTracing.h", "DiagnosticStorageManager.cpp", "DiagnosticStorageManager.h", + "DiagnosticTracing.cpp", + "DiagnosticTracing.h", "Diagnostics.h", ] diff --git a/src/tracing/esp32_diagnostic_trace/Counter.cpp b/src/tracing/esp32_diagnostic_trace/Counter.cpp index 77948129a8e8fe..73116ed9a04acd 100644 --- a/src/tracing/esp32_diagnostic_trace/Counter.cpp +++ b/src/tracing/esp32_diagnostic_trace/Counter.cpp @@ -19,8 +19,8 @@ #include #include -using namespace chip; - +namespace chip { +namespace Tracing { namespace Diagnostics { // This is a one time allocation for counters. It is not supposed to be freed. @@ -45,8 +45,8 @@ ESPDiagnosticCounter * ESPDiagnosticCounter::GetInstance(const char * label) VerifyOrDie(ptr != nullptr); ESPDiagnosticCounter * newInstance = new (ptr) ESPDiagnosticCounter(label); - newInstance->mNext = mHead; - mHead = newInstance; + newInstance->mNext = mHead; + mHead = newInstance; return newInstance; } @@ -61,8 +61,10 @@ void ESPDiagnosticCounter::ReportMetrics() CHIP_ERROR err = CHIP_NO_ERROR; Counter counter(label, instanceCount, esp_log_timestamp()); DiagnosticStorageImpl & diagnosticStorage = DiagnosticStorageImpl::GetInstance(); - err = diagnosticStorage.Store(counter); + err = diagnosticStorage.Store(counter); VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(DeviceLayer, "Failed to store Counter diagnostic data")); } } // namespace Diagnostics +} // namespace Tracing +} // namespace chip diff --git a/src/tracing/esp32_diagnostic_trace/Counter.h b/src/tracing/esp32_diagnostic_trace/Counter.h index 4e58975999712f..6d8e23bd6d85e6 100644 --- a/src/tracing/esp32_diagnostic_trace/Counter.h +++ b/src/tracing/esp32_diagnostic_trace/Counter.h @@ -18,15 +18,15 @@ #pragma once +#include "tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h" #include #include #include #include #include -#include "tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h" - -using namespace chip::Tracing::Diagnostics; +namespace chip { +namespace Tracing { namespace Diagnostics { /** @@ -41,7 +41,7 @@ class ESPDiagnosticCounter { private: static ESPDiagnosticCounter * mHead; // head of the counter list - const char * label; // unique key ,it is used as a static string. + const char * label; // unique key ,it is used as a static string. int32_t instanceCount; ESPDiagnosticCounter * mNext; // pointer to point to the next entry in the list @@ -56,3 +56,5 @@ class ESPDiagnosticCounter }; } // namespace Diagnostics +} // namespace Tracing +} // namespace chip diff --git a/src/tracing/esp32_diagnostic_trace/DiagnosticStorageManager.cpp b/src/tracing/esp32_diagnostic_trace/DiagnosticStorageManager.cpp index 98046d5523582b..d16430ce2f4ffe 100644 --- a/src/tracing/esp32_diagnostic_trace/DiagnosticStorageManager.cpp +++ b/src/tracing/esp32_diagnostic_trace/DiagnosticStorageManager.cpp @@ -23,12 +23,13 @@ namespace chip { namespace Tracing { +using namespace chip::TLV; namespace Diagnostics { -DiagnosticStorageImpl::DiagnosticStorageImpl(uint8_t * buffer, size_t bufferSize) - : mEndUserCircularBuffer(buffer, bufferSize) {} +DiagnosticStorageImpl::DiagnosticStorageImpl(uint8_t * buffer, size_t bufferSize) : mEndUserCircularBuffer(buffer, bufferSize) {} -DiagnosticStorageImpl & DiagnosticStorageImpl::GetInstance(uint8_t * buffer, size_t bufferSize) { +DiagnosticStorageImpl & DiagnosticStorageImpl::GetInstance(uint8_t * buffer, size_t bufferSize) +{ static DiagnosticStorageImpl instance(buffer, bufferSize); return instance; } @@ -42,7 +43,6 @@ CHIP_ERROR DiagnosticStorageImpl::Store(DiagnosticEntry & diagnostic) CircularTLVWriter writer; writer.Init(mEndUserCircularBuffer); - // Start a TLV structure container (Anonymous) TLVType outerContainer; err = writer.StartContainer(AnonymousTag(), kTLVType_Structure, outerContainer); VerifyOrReturnError(err == CHIP_NO_ERROR, err, @@ -98,21 +98,25 @@ CHIP_ERROR DiagnosticStorageImpl::Retrieve(MutableByteSpan & payload) ChipLogError(DeviceLayer, "Failed to enter outer TLV container: %s", ErrorStr(err))); err = reader.Next(); - VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to read next TLV element in outer container: %s", ErrorStr(err))); + VerifyOrReturnError(err == CHIP_NO_ERROR, err, + ChipLogError(DeviceLayer, "Failed to read next TLV element in outer container: %s", ErrorStr(err))); - // Check if the current element is a METRIC or TRACE container if ((reader.GetType() == kTLVType_Structure) && - (reader.GetTag() == ContextTag(DIAGNOSTICS_TAG::METRIC) || reader.GetTag() == ContextTag(DIAGNOSTICS_TAG::TRACE) || reader.GetTag() == ContextTag(DIAGNOSTICS_TAG::COUNTER))) + (reader.GetTag() == ContextTag(DIAGNOSTICS_TAG::METRIC) || reader.GetTag() == ContextTag(DIAGNOSTICS_TAG::TRACE) || + reader.GetTag() == ContextTag(DIAGNOSTICS_TAG::COUNTER))) { - if ((reader.GetLengthRead() - writer.GetLengthWritten()) < writer.GetRemainingFreeLength()) { + if ((reader.GetLengthRead() - writer.GetLengthWritten()) < writer.GetRemainingFreeLength()) + { err = writer.CopyElement(reader); - if (err == CHIP_ERROR_BUFFER_TOO_SMALL) { + if (err == CHIP_ERROR_BUFFER_TOO_SMALL) + { ChipLogProgress(DeviceLayer, "Buffer too small to occupy current element"); break; } VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to copy TLV element")); } - else { + else + { ChipLogProgress(DeviceLayer, "Buffer too small to occupy current TLV"); break; } @@ -123,7 +127,6 @@ CHIP_ERROR DiagnosticStorageImpl::Retrieve(MutableByteSpan & payload) reader.ExitContainer(outerReaderContainer); return CHIP_ERROR_WRONG_TLV_TYPE; } - // Exit the outer container err = reader.ExitContainer(outerReaderContainer); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to exit outer TLV container: %s", ErrorStr(err))); @@ -136,11 +139,11 @@ CHIP_ERROR DiagnosticStorageImpl::Retrieve(MutableByteSpan & payload) err = writer.EndContainer(outWriterContainer); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to close outer container")); - // Finalize the writing process err = writer.Finalize(); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to finalize TLV writing")); payload.reduce_size(writer.GetLengthWritten()); - ChipLogProgress(DeviceLayer, "---------------Total written bytes successfully : %ld----------------\n", writer.GetLengthWritten()); + ChipLogProgress(DeviceLayer, "---------------Total written bytes successfully : %ld----------------\n", + writer.GetLengthWritten()); ChipLogProgress(DeviceLayer, "Retrieval successful"); return CHIP_NO_ERROR; } diff --git a/src/tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h b/src/tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h index 1b21a6cb54ed5c..d35f745130f343 100644 --- a/src/tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h +++ b/src/tracing/esp32_diagnostic_trace/DiagnosticStorageManager.h @@ -19,26 +19,23 @@ #pragma once #include "Diagnostics.h" -#include #include +#include namespace chip { namespace Tracing { namespace Diagnostics { -using namespace chip::Platform; -using chip::TLV::TLVType; class DiagnosticStorageImpl : public DiagnosticStorageInterface { public: + static DiagnosticStorageImpl & GetInstance(uint8_t * buffer = nullptr, size_t bufferSize = 0); - static DiagnosticStorageImpl& GetInstance(uint8_t * buffer = nullptr, size_t bufferSize = 0); - - DiagnosticStorageImpl(const DiagnosticStorageImpl &) = delete; + DiagnosticStorageImpl(const DiagnosticStorageImpl &) = delete; DiagnosticStorageImpl & operator=(const DiagnosticStorageImpl &) = delete; CHIP_ERROR Store(DiagnosticEntry & diagnostic) override; - CHIP_ERROR Retrieve(MutableByteSpan &payload) override; + CHIP_ERROR Retrieve(MutableByteSpan & payload) override; bool IsEmptyBuffer(); @@ -47,7 +44,7 @@ class DiagnosticStorageImpl : public DiagnosticStorageInterface DiagnosticStorageImpl(); ~DiagnosticStorageImpl(); - TLVCircularBuffer mEndUserCircularBuffer; + chip::TLV::TLVCircularBuffer mEndUserCircularBuffer; }; } // namespace Diagnostics } // namespace Tracing diff --git a/src/tracing/esp32_diagnostic_trace/DiagnosticTracing.cpp b/src/tracing/esp32_diagnostic_trace/DiagnosticTracing.cpp index 174eac0625f44f..f620abf65407a6 100644 --- a/src/tracing/esp32_diagnostic_trace/DiagnosticTracing.cpp +++ b/src/tracing/esp32_diagnostic_trace/DiagnosticTracing.cpp @@ -111,7 +111,7 @@ void ESP32Diagnostics::LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo & info) {} void ESP32Diagnostics::LogMetricEvent(const MetricEvent & event) { DiagnosticStorageImpl & diagnosticStorage = DiagnosticStorageImpl::GetInstance(); - CHIP_ERROR err = CHIP_NO_ERROR; + CHIP_ERROR err = CHIP_NO_ERROR; switch (event.ValueType()) { case ValueType::kInt32: { @@ -146,24 +146,28 @@ void ESP32Diagnostics::LogMetricEvent(const MetricEvent & event) void ESP32Diagnostics::TraceCounter(const char * label) { - ::Diagnostics::ESPDiagnosticCounter::GetInstance(label)->ReportMetrics(); + ESPDiagnosticCounter::GetInstance(label)->ReportMetrics(); } -void ESP32Diagnostics::TraceBegin(const char * label, const char * group) { +void ESP32Diagnostics::TraceBegin(const char * label, const char * group) +{ StoreDiagnostics(label, group); } -void ESP32Diagnostics::TraceEnd(const char * label, const char * group) { +void ESP32Diagnostics::TraceEnd(const char * label, const char * group) +{ StoreDiagnostics(label, group); } -void ESP32Diagnostics::TraceInstant(const char * label, const char * group) { +void ESP32Diagnostics::TraceInstant(const char * label, const char * group) +{ StoreDiagnostics(label, group); } -void ESP32Diagnostics::StoreDiagnostics(const char* label, const char* group) { - CHIP_ERROR err = CHIP_NO_ERROR; - HashValue hashValue = MurmurHash(group); +void ESP32Diagnostics::StoreDiagnostics(const char * label, const char * group) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + HashValue hashValue = MurmurHash(group); DiagnosticStorageImpl & diagnosticStorage = DiagnosticStorageImpl::GetInstance(); if (IsPermitted(hashValue)) { diff --git a/src/tracing/esp32_diagnostic_trace/DiagnosticTracing.h b/src/tracing/esp32_diagnostic_trace/DiagnosticTracing.h index 6188f7b6b9c95e..a94aa2d232d8a8 100644 --- a/src/tracing/esp32_diagnostic_trace/DiagnosticTracing.h +++ b/src/tracing/esp32_diagnostic_trace/DiagnosticTracing.h @@ -18,12 +18,11 @@ * limitations under the License. */ +#include #include #include -#include #include -#include - +#include #include namespace chip { @@ -35,14 +34,11 @@ namespace Diagnostics { class ESP32Diagnostics : public ::chip::Tracing::Backend { public: - ESP32Diagnostics(uint8_t *buffer, size_t buffer_size) - { - DiagnosticStorageImpl::GetInstance(buffer, buffer_size); - } + ESP32Diagnostics(uint8_t * buffer, size_t buffer_size) { DiagnosticStorageImpl::GetInstance(buffer, buffer_size); } // Deleted copy constructor and assignment operator to prevent copying - ESP32Diagnostics(const ESP32Diagnostics&) = delete; - ESP32Diagnostics& operator=(const ESP32Diagnostics&) = delete; + ESP32Diagnostics(const ESP32Diagnostics &) = delete; + ESP32Diagnostics & operator=(const ESP32Diagnostics &) = delete; void TraceBegin(const char * label, const char * group) override; @@ -60,7 +56,7 @@ class ESP32Diagnostics : public ::chip::Tracing::Backend void LogNodeDiscovered(NodeDiscoveredInfo &) override; void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) override; void LogMetricEvent(const MetricEvent &) override; - void StoreDiagnostics(const char* label, const char* group); + void StoreDiagnostics(const char * label, const char * group); private: using ValueType = MetricEvent::Value::Type; @@ -68,4 +64,4 @@ class ESP32Diagnostics : public ::chip::Tracing::Backend } // namespace Diagnostics } // namespace Tracing -} // namespace chip \ No newline at end of file +} // namespace chip diff --git a/src/tracing/esp32_diagnostic_trace/Diagnostics.h b/src/tracing/esp32_diagnostic_trace/Diagnostics.h index a824f4a0457559..c4b31dd34c84e5 100644 --- a/src/tracing/esp32_diagnostic_trace/Diagnostics.h +++ b/src/tracing/esp32_diagnostic_trace/Diagnostics.h @@ -19,63 +19,64 @@ #pragma once #include -#include #include +#include namespace chip { namespace Tracing { namespace Diagnostics { -using namespace chip::TLV; enum class DIAGNOSTICS_TAG { - METRIC = 0, - TRACE = 1, - COUNTER = 2, - LABEL = 3, - GROUP = 4, - VALUE = 5, - TIMESTAMP = 6 + METRIC = 0, + TRACE = 1, + COUNTER = 2, + LABEL = 3, + GROUP = 4, + VALUE = 5, + TIMESTAMP = 6 }; -class DiagnosticEntry { +class DiagnosticEntry +{ public: - virtual ~DiagnosticEntry() = default; - virtual CHIP_ERROR Encode(CircularTLVWriter &writer) = 0; + virtual ~DiagnosticEntry() = default; + virtual CHIP_ERROR Encode(chip::TLV::CircularTLVWriter & writer) = 0; }; -template -class Metric : public DiagnosticEntry { +template +class Metric : public DiagnosticEntry +{ public: - Metric(const char* label, T value, uint32_t timestamp) - : label_(label), value_(value), timestamp_(timestamp) {} + Metric(const char * label, T value, uint32_t timestamp) : label_(label), value_(value), timestamp_(timestamp) {} Metric() {} - const char* GetLabel() const { return label_; } + const char * GetLabel() const { return label_; } T GetValue() const { return value_; } uint32_t GetTimestamp() const { return timestamp_; } - CHIP_ERROR Encode(CircularTLVWriter &writer) override { + CHIP_ERROR Encode(chip::TLV::CircularTLVWriter & writer) override + { CHIP_ERROR err = CHIP_NO_ERROR; - TLVType metricContainer; - err = writer.StartContainer(ContextTag(DIAGNOSTICS_TAG::METRIC), kTLVType_Structure, metricContainer); + chip::TLV::TLVType metricContainer; + err = writer.StartContainer(chip::TLV::ContextTag(DIAGNOSTICS_TAG::METRIC), chip::TLV::kTLVType_Structure, metricContainer); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to start TLV container for metric : %s", ErrorStr(err))); // TIMESTAMP - err = writer.Put(ContextTag(DIAGNOSTICS_TAG::TIMESTAMP), timestamp_); + err = writer.Put(chip::TLV::ContextTag(DIAGNOSTICS_TAG::TIMESTAMP), timestamp_); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to write TIMESTAMP for METRIC : %s", ErrorStr(err))); // LABEL - err = writer.PutString(ContextTag(DIAGNOSTICS_TAG::LABEL), label_); + err = writer.PutString(chip::TLV::ContextTag(DIAGNOSTICS_TAG::LABEL), label_); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to write LABEL for METRIC : %s", ErrorStr(err))); // VALUE - err = writer.Put(ContextTag(DIAGNOSTICS_TAG::VALUE), value_); + err = writer.Put(chip::TLV::ContextTag(DIAGNOSTICS_TAG::VALUE), value_); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to write VALUE for METRIC : %s", ErrorStr(err))); @@ -87,41 +88,42 @@ class Metric : public DiagnosticEntry { } private: - const char* label_; + const char * label_; T value_; uint32_t timestamp_; }; -class Trace : public DiagnosticEntry { +class Trace : public DiagnosticEntry +{ public: - Trace(const char* label, const char* group, uint32_t timestamp) - : label_(label), group_(group), timestamp_(timestamp) {} + Trace(const char * label, const char * group, uint32_t timestamp) : label_(label), group_(group), timestamp_(timestamp) {} Trace() {} - const char* GetLabel() const { return label_; } + const char * GetLabel() const { return label_; } uint32_t GetTimestamp() const { return timestamp_; } - const char* GetGroup() const { return group_; } + const char * GetGroup() const { return group_; } - CHIP_ERROR Encode(CircularTLVWriter &writer) override { + CHIP_ERROR Encode(chip::TLV::CircularTLVWriter & writer) override + { CHIP_ERROR err = CHIP_NO_ERROR; - TLVType traceContainer; - err = writer.StartContainer(ContextTag(DIAGNOSTICS_TAG::TRACE), kTLVType_Structure, traceContainer); + chip::TLV::TLVType traceContainer; + err = writer.StartContainer(chip::TLV::ContextTag(DIAGNOSTICS_TAG::TRACE), chip::TLV::kTLVType_Structure, traceContainer); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to start TLV container for Trace: %s", ErrorStr(err))); // TIMESTAMP - err = writer.Put(ContextTag(DIAGNOSTICS_TAG::TIMESTAMP), timestamp_); + err = writer.Put(chip::TLV::ContextTag(DIAGNOSTICS_TAG::TIMESTAMP), timestamp_); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to write TIMESTAMP for METRIC : %s", ErrorStr(err))); // GROUP - err = writer.PutString(ContextTag(DIAGNOSTICS_TAG::GROUP), group_); + err = writer.PutString(chip::TLV::ContextTag(DIAGNOSTICS_TAG::GROUP), group_); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to write GROUP for TRACE : %s", ErrorStr(err))); // LABEL - err = writer.PutString(ContextTag(DIAGNOSTICS_TAG::LABEL), label_); + err = writer.PutString(chip::TLV::ContextTag(DIAGNOSTICS_TAG::LABEL), label_); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to write LABEL for TRACE : %s", ErrorStr(err))); @@ -133,15 +135,15 @@ class Trace : public DiagnosticEntry { } private: - const char* label_; - const char* group_; + const char * label_; + const char * group_; uint32_t timestamp_; }; -class Counter : public DiagnosticEntry { +class Counter : public DiagnosticEntry +{ public: - Counter(const char* label, uint32_t count, uint32_t timestamp) - : label_(label), count_(count), timestamp_(timestamp) {} + Counter(const char * label, uint32_t count, uint32_t timestamp) : label_(label), count_(count), timestamp_(timestamp) {} Counter() {} @@ -149,25 +151,27 @@ class Counter : public DiagnosticEntry { uint32_t GetTimestamp() const { return timestamp_; } - CHIP_ERROR Encode(CircularTLVWriter &writer) override { + CHIP_ERROR Encode(chip::TLV::CircularTLVWriter & writer) override + { CHIP_ERROR err = CHIP_NO_ERROR; - TLVType counterContainer; - err = writer.StartContainer(ContextTag(DIAGNOSTICS_TAG::COUNTER), kTLVType_Structure, counterContainer); + chip::TLV::TLVType counterContainer; + err = + writer.StartContainer(chip::TLV::ContextTag(DIAGNOSTICS_TAG::COUNTER), chip::TLV::kTLVType_Structure, counterContainer); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to start TLV container for Counter: %s", ErrorStr(err))); // TIMESTAMP - err = writer.Put(ContextTag(DIAGNOSTICS_TAG::TIMESTAMP), timestamp_); + err = writer.Put(chip::TLV::ContextTag(DIAGNOSTICS_TAG::TIMESTAMP), timestamp_); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to write TIMESTAMP for COUNTER : %s", ErrorStr(err))); // LABEL - err = writer.PutString(ContextTag(DIAGNOSTICS_TAG::LABEL), label_); + err = writer.PutString(chip::TLV::ContextTag(DIAGNOSTICS_TAG::LABEL), label_); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to write LABEL for COUNTER : %s", ErrorStr(err))); // COUNT - err = writer.Put(ContextTag(DIAGNOSTICS_TAG::COUNTER), count_); + err = writer.Put(chip::TLV::ContextTag(DIAGNOSTICS_TAG::COUNTER), count_); VerifyOrReturnError(err == CHIP_NO_ERROR, err, ChipLogError(DeviceLayer, "Failed to write VALUE for COUNTER : %s", ErrorStr(err))); @@ -179,18 +183,37 @@ class Counter : public DiagnosticEntry { } private: - const char* label_; + const char * label_; uint32_t count_; uint32_t timestamp_; }; -class DiagnosticStorageInterface { +/** + * @brief Interface for storing and retrieving diagnostic data. + */ +class DiagnosticStorageInterface +{ public: + /** + * @brief Virtual destructor for the interface. + */ virtual ~DiagnosticStorageInterface() = default; - virtual CHIP_ERROR Store(DiagnosticEntry& diagnostic) = 0; - - virtual CHIP_ERROR Retrieve(MutableByteSpan &payload) = 0; + /** + * @brief Stores a diagnostic entry. + * @param diagnostic Reference to a DiagnosticEntry object containing the + * diagnostic data to store. + * @return CHIP_ERROR Returns CHIP_NO_ERROR on success, or an appropriate error code on failure. + */ + virtual CHIP_ERROR Store(DiagnosticEntry & diagnostic) = 0; + + /** + * @brief Retrieves diagnostic data as a payload. + * @param payload Reference to a MutableByteSpan where the retrieved + * diagnostic data will be stored. + * @return CHIP_ERROR Returns CHIP_NO_ERROR on success, or an appropriate error code on failure. + */ + virtual CHIP_ERROR Retrieve(MutableByteSpan & payload) = 0; }; } // namespace Diagnostics