1919#pragma once
2020
2121#include < app/clusters/tls-client-management-server/tls-client-management-server.h>
22+ #include < app/storage/FabricTableImpl.h>
2223#include < app/util/config.h>
2324#include < vector>
2425
2526namespace chip {
2627namespace app {
2728namespace Clusters {
2829
30+ // / @brief struct used to identify a TLS Endpoint
31+ inline constexpr uint16_t kUndefinedTlsEndpointId = 0xffff ;
32+ static constexpr uint8_t kMaxProvisionedEndpoints = 254 ;
33+
34+ struct TlsEndpointId
35+ {
36+ uint16_t mEndpointId = kUndefinedTlsEndpointId ;
37+
38+ TlsEndpointId () = default ;
39+ TlsEndpointId (uint16_t id) : mEndpointId (id) {}
40+
41+ uint16_t & Value () { return mEndpointId ; }
42+ const uint16_t & Value () const { return mEndpointId ; }
43+
44+ void Clear () { mEndpointId = kUndefinedTlsEndpointId ; }
45+
46+ bool IsValid () { return (mEndpointId != kUndefinedTlsEndpointId ); }
47+
48+ bool operator ==(const TlsEndpointId & other) const { return (mEndpointId == other.mEndpointId ); }
49+ };
50+
51+ class EndpointTable : public app ::Storage::FabricTableImpl<TlsEndpointId, TlsClientManagementDelegate::EndpointStructType>
52+ {
53+ public:
54+ using Super = app::Storage::FabricTableImpl<TlsEndpointId, TlsClientManagementDelegate::EndpointStructType>;
55+
56+ EndpointTable () : Super(kMaxProvisionedEndpoints , UINT16_MAX) {}
57+ ~EndpointTable () { Finish (); };
58+ };
59+
2960/* *
3061 * The application delegate to define the options & implement commands.
3162 */
@@ -38,24 +69,26 @@ class TlsClientManagementCommandDelegate : public TlsClientManagementDelegate
3869 };
3970
4071 static TlsClientManagementCommandDelegate instance;
41- std::vector<Provisioned> mProvisioned ;
42- uint16_t mNextId = 1 ;
72+ EndpointTable mProvisioned ;
73+ PersistentStorageDelegate * mStorage = nullptr ;
74+
75+ CHIP_ERROR GetEndpointId (FabricIndex fabric, uint16_t & id);
4376
4477public:
4578 TlsClientManagementCommandDelegate () {}
4679 ~TlsClientManagementCommandDelegate () = default ;
4780
48- CHIP_ERROR GetProvisionedEndpointByIndex (EndpointId matterEndpoint, FabricIndex fabric, size_t index,
49- EndpointStructType & endpoint) const override ;
81+ CHIP_ERROR Init (PersistentStorageDelegate & storage) override ;
82+
83+ CHIP_ERROR ForEachEndpoint (EndpointId matterEndpoint, FabricIndex fabric, LoadedEndpointCallback callback) override ;
5084
5185 Protocols::InteractionModel::ClusterStatusCode
5286 ProvisionEndpoint (EndpointId matterEndpoint, FabricIndex fabric,
5387 const TlsClientManagement::Commands::ProvisionEndpoint::DecodableType & provisionReq,
5488 uint16_t & endpointID) override ;
5589
56- Protocols::InteractionModel::Status FindProvisionedEndpointByID (EndpointId matterEndpoint, FabricIndex fabric,
57- uint16_t endpointID,
58- EndpointStructType & endpoint) const override ;
90+ CHIP_ERROR FindProvisionedEndpointByID (EndpointId matterEndpoint, FabricIndex fabric, uint16_t endpointID,
91+ LoadedEndpointCallback callback) override ;
5992
6093 Protocols::InteractionModel::Status RemoveProvisionedEndpointByID (EndpointId matterEndpoint, FabricIndex fabric,
6194 uint16_t endpointID) override ;
@@ -65,9 +98,10 @@ class TlsClientManagementCommandDelegate : public TlsClientManagementDelegate
6598
6699 void RemoveFabric (FabricIndex fabric) override ;
67100
68- static inline TlsClientManagementCommandDelegate & GetInstance () { return instance; }
101+ CHIP_ERROR MutateEndpointReferenceCount (EndpointId matterEndpoint, FabricIndex fabric, uint16_t endpointID,
102+ int8_t delta) override ;
69103
70- uint16_t GetEndpointId (Provisioned * provisioned);
104+ static inline TlsClientManagementCommandDelegate & GetInstance () { return instance; }
71105};
72106
73107} // namespace Clusters
0 commit comments