Skip to content

Commit

Permalink
Refactor ProvisionManager and ProvisionProtocol to use Storage pointe…
Browse files Browse the repository at this point in the history
…rs in Execute methods
  • Loading branch information
rosahay-silabs committed Dec 16, 2024
1 parent 5906e6a commit 797aad2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
7 changes: 0 additions & 7 deletions src/platform/silabs/provision/ProvisionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 7 additions & 13 deletions src/platform/silabs/provision/ProvisionProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

//------------------------------------------------------------------------------
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/platform/silabs/provision/ProvisionStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 797aad2

Please sign in to comment.