From 5fab9d81e890703d05a1b7fe36403e9c94ce6c1c Mon Sep 17 00:00:00 2001 From: Nivedita Sarkar Date: Sun, 15 Oct 2023 20:45:50 -0700 Subject: [PATCH] Wrote shell of the provider delegate in the example app --- examples/log-source-app/linux/BUILD.gn | 6 +- .../DiagnosticLogsProvider.cpp | 58 +++++++++++++++++++ .../DiagnosticLogsProvider.h | 52 +++++++++++++++++ .../bdx/DiagnosticLogsBDXTransferHandler.h | 2 +- .../diagnostic-logs-provider-delegate.h | 8 +-- 5 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 examples/log-source-app/log-source-common/DiagnosticLogsProvider.cpp create mode 100644 examples/log-source-app/log-source-common/DiagnosticLogsProvider.h diff --git a/examples/log-source-app/linux/BUILD.gn b/examples/log-source-app/linux/BUILD.gn index 4cc6b31dbe97d8..e093c28344c3e4 100644 --- a/examples/log-source-app/linux/BUILD.gn +++ b/examples/log-source-app/linux/BUILD.gn @@ -16,7 +16,11 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") executable("chip-log-source-app") { - sources = [ "main.cpp" ] + sources = [ + "main.cpp", + "${chip_root}/examples/log-source-app/log-source-common/DiagnosticLogsProvider.cpp", + "${chip_root}/examples/log-source-app/log-source-common/DiagnosticLogsProvider.h", + ] deps = [ "${chip_root}/examples/log-source-app/log-source-common", diff --git a/examples/log-source-app/log-source-common/DiagnosticLogsProvider.cpp b/examples/log-source-app/log-source-common/DiagnosticLogsProvider.cpp new file mode 100644 index 00000000000000..ed6664862b4c4b --- /dev/null +++ b/examples/log-source-app/log-source-common/DiagnosticLogsProvider.cpp @@ -0,0 +1,58 @@ +/** + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "DiagnosticLogsProvider.h" + +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters::DiagnosticLogs; + +LogSessionHandle DiagnosticLogsProvider::StartLogCollection(IntentEnum logType) +{ + if (mIsInLogSession) + { + return kInvalidLogSessionHandle; + } + mIsInLogSession = true; + + // use the log type to maybe read a different file + mLogType = logType; + + // open a log file for reading + return ++(Instance().mLogSessionHandle); +} + +void DiagnosticLogsProvider::GetNextChunk(LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF) +{ + // check if the file is valid and return chunks. maintain numberofbytesread and skip that much into the file +} + +void DiagnosticLogsProvider::EndLogCollection(LogSessionHandle logSessionHandle) +{ + // close the file + mTotalNumberOfBytesConsumed = 0; + mIsInLogSession = false; +} + +uint32_t DiagnosticLogsProvider::GetTotalNumberOfBytesConsumed() +{ + return mTotalNumberOfBytesConsumed; +} diff --git a/examples/log-source-app/log-source-common/DiagnosticLogsProvider.h b/examples/log-source-app/log-source-common/DiagnosticLogsProvider.h new file mode 100644 index 00000000000000..0188330a36fa57 --- /dev/null +++ b/examples/log-source-app/log-source-common/DiagnosticLogsProvider.h @@ -0,0 +1,52 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +class DiagnosticLogsProvider : public chip::app::Clusters::DiagnosticLogs::Delegate +{ + +public: + DiagnosticLogsProvider() { } + + chip::app::Clusters::DiagnosticLogs::LogSessionHandle StartLogCollection(chip::app::Clusters::DiagnosticLogs::IntentEnum logType); + + void GetNextChunk(chip::app::Clusters::DiagnosticLogs::LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF); + + void EndLogCollection(chip::app::Clusters::DiagnosticLogs::LogSessionHandle logSessionHandle); + + uint32_t GetTotalNumberOfBytesConsumed(); + + static DiagnosticLogsProvider & Instance() + { + static DiagnosticLogsProvider instance; + return instance; + } + + ~DiagnosticLogsProvider() = default; + +protected: + + chip::app::Clusters::DiagnosticLogs::IntentEnum mLogType; + chip::app::Clusters::DiagnosticLogs::LogSessionHandle mLogSessionHandle; + uint32_t mTotalNumberOfBytesConsumed; + + bool mIsInLogSession; +}; \ No newline at end of file diff --git a/src/app/bdx/DiagnosticLogsBDXTransferHandler.h b/src/app/bdx/DiagnosticLogsBDXTransferHandler.h index 339fec00332b63..2982acc370bdf7 100644 --- a/src/app/bdx/DiagnosticLogsBDXTransferHandler.h +++ b/src/app/bdx/DiagnosticLogsBDXTransferHandler.h @@ -61,7 +61,7 @@ class DiagnosticLogsBDXTransferHandler : public chip::bdx::Initiator bool mInitialized; - uint32_t mNumBytesSent = 0; + uint32_t mNumBytesSent; LogSessionHandle mLogSessionHandle; diff --git a/src/app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h b/src/app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h index bba645567e54f9..f57f0af354d8ae 100644 --- a/src/app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h +++ b/src/app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h @@ -66,15 +66,9 @@ class Delegate virtual void EndLogCollection(LogSessionHandle logSessionHandle); - virtual uint16_t GetTotalNumberOfBytesConsumed(); + virtual uint32_t GetTotalNumberOfBytesConsumed(); virtual ~Delegate() = default; - -private: - - IntentEnum mLogType; - LogSessionHandle mLogSessionHandle; - uint16_t mTotalNumberOfBytesConsumed; }; } // namespace DiagnosticLogs