From 797aad22635ca5a2104fd32d111b5f3a317ca1d3 Mon Sep 17 00:00:00 2001 From: Rohan Sahay <103027015+rosahay-silabs@users.noreply.github.com> Date: Tue, 17 Dec 2024 02:36:06 +0530 Subject: [PATCH] Refactor ProvisionManager and ProvisionProtocol to use Storage pointers in Execute methods --- .../silabs/provision/ProvisionManager.h | 7 ------- .../silabs/provision/ProvisionProtocol.h | 20 +++++++------------ .../silabs/provision/ProvisionStorage.h | 2 +- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/platform/silabs/provision/ProvisionManager.h b/src/platform/silabs/provision/ProvisionManager.h index c73e920c34..16e4592ce1 100644 --- a/src/platform/silabs/provision/ProvisionManager.h +++ b/src/platform/silabs/provision/ProvisionManager.h @@ -29,13 +29,6 @@ namespace Provision { class Manager { public: - Manager() : -#ifdef SILABS_PROVISION_PROTOCOL_V1 - mProtocol1(mStore), -#endif - mProtocol2(mStore) - {} - CHIP_ERROR Init(); bool Step(); bool IsProvisionRequired(); diff --git a/src/platform/silabs/provision/ProvisionProtocol.h b/src/platform/silabs/provision/ProvisionProtocol.h index 03182b59af..7f986217bf 100644 --- a/src/platform/silabs/provision/ProvisionProtocol.h +++ b/src/platform/silabs/provision/ProvisionProtocol.h @@ -37,12 +37,8 @@ class Protocol /** * Must hold the header plus complete argument value */ - Protocol(Storage & store) : mStore(store) {} virtual ~Protocol() = default; virtual bool Execute(ByteSpan & request, MutableByteSpan & response) = 0; - -protected: - Storage & mStore; }; //------------------------------------------------------------------------------ @@ -55,15 +51,14 @@ class Protocol1 : public Protocol public: static constexpr size_t kVersion = 1; - Protocol1(Storage & store) : Protocol(store) {} - virtual bool Execute(ByteSpan & request, MutableByteSpan & response); + virtual bool Execute(Storage * store, ByteSpan & request, MutableByteSpan & response); private: - CHIP_ERROR Init(Encoding::Buffer & in, Encoding::Buffer & out); - CHIP_ERROR GenerateCSR(Encoding::Buffer & in, Encoding::Buffer & out); - CHIP_ERROR Import(Encoding::Buffer & in, Encoding::Buffer & out); - CHIP_ERROR Setup(Encoding::Buffer & in, Encoding::Buffer & out); - CHIP_ERROR Read(Encoding::Buffer & in, Encoding::Buffer & out); + CHIP_ERROR Init(Storage * store, Encoding::Buffer & in, Encoding::Buffer & out); + CHIP_ERROR GenerateCSR(Storage * store, Encoding::Buffer & in, Encoding::Buffer & out); + CHIP_ERROR Import(Storage * store, Encoding::Buffer & in, Encoding::Buffer & out); + CHIP_ERROR Setup(Storage * store, Encoding::Buffer & in, Encoding::Buffer & out); + CHIP_ERROR Read(Storage * store, Encoding::Buffer & in, Encoding::Buffer & out); }; #endif // SILABS_PROVISION_PROTOCOL_V1 @@ -97,8 +92,7 @@ class Protocol2 : public Protocol static constexpr size_t kResponseHeaderSize = 8; static_assert(kPackageSizeMax > (kResponseHeaderSize + kChecksumSize)); - Protocol2(Storage & store) : Protocol(store) {} - virtual bool Execute(ByteSpan & request, MutableByteSpan & response); + virtual bool Execute(Storage * store, ByteSpan & request, MutableByteSpan & response); }; } // namespace Provision diff --git a/src/platform/silabs/provision/ProvisionStorage.h b/src/platform/silabs/provision/ProvisionStorage.h index b7123a7369..c710f8cb09 100644 --- a/src/platform/silabs/provision/ProvisionStorage.h +++ b/src/platform/silabs/provision/ProvisionStorage.h @@ -247,7 +247,7 @@ struct Storage : public GenericStorage, #endif // SL_MATTER_TEST_EVENT_TRIGGER_ENABLED void SetBufferSize(size_t size) { mBufferSize = size > 0 ? size : kArgumentSizeMax; } - size_t GetBufferSize() { return mBufferSize; } + size_t GetBufferSize() { return mBufferSize > 0 ? mBufferSize : kArgumentSizeMax; } private: // Generic Interface