Skip to content

Commit 9526318

Browse files
[ICD] Address post-merge comments for project-chip#31563 (project-chip#31811)
* address post review comments * Simplify empty optional call
1 parent 799445f commit 9526318

9 files changed

+59
-51
lines changed

src/app/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ source_set("pre-encoded-value") {
115115
}
116116

117117
source_set("subscription-manager") {
118-
sources = [ "SubscriptionManager.h" ]
118+
sources = [ "SubscriptionsInfoProvider.h" ]
119119

120120
public_deps = [ "${chip_root}/src/lib/core" ]
121121
}

src/app/InteractionModelEngine.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void InteractionModelEngine::ShutdownMatchingSubscriptions(const Optional<Fabric
330330
}
331331
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
332332

333-
bool InteractionModelEngine::SubjectHasActiveSubscription(const FabricIndex & aFabricIndex, const NodeId & subjectID)
333+
bool InteractionModelEngine::SubjectHasActiveSubscription(FabricIndex aFabricIndex, NodeId subjectID)
334334
{
335335
bool isActive = false;
336336
mReadHandlers.ForEachActiveObject([aFabricIndex, subjectID, &isActive](ReadHandler * handler) {
@@ -367,7 +367,7 @@ bool InteractionModelEngine::SubjectHasActiveSubscription(const FabricIndex & aF
367367
return isActive;
368368
}
369369

370-
bool InteractionModelEngine::SubjectHasPersistedSubscription(const FabricIndex & aFabricIndex, const NodeId & subject)
370+
bool InteractionModelEngine::SubjectHasPersistedSubscription(FabricIndex aFabricIndex, NodeId subjectID)
371371
{
372372
// TODO(#30281) : Implement persisted sub check and verify how persistent subscriptions affects this at ICDManager::Init
373373
return false;

src/app/InteractionModelEngine.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
#include <app/ReadClient.h>
4343
#include <app/ReadHandler.h>
4444
#include <app/StatusResponse.h>
45-
#include <app/SubscriptionManager.h>
4645
#include <app/SubscriptionResumptionSessionEstablisher.h>
46+
#include <app/SubscriptionsInfoProvider.h>
4747
#include <app/TimedHandler.h>
4848
#include <app/WriteClient.h>
4949
#include <app/WriteHandler.h>
@@ -80,7 +80,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
8080
public CommandHandler::Callback,
8181
public ReadHandler::ManagementCallback,
8282
public FabricTable::Delegate,
83-
public SubscriptionManager
83+
public SubscriptionsInfoProvider
8484
{
8585
public:
8686
/**
@@ -324,9 +324,9 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
324324

325325
CHIP_ERROR ResumeSubscriptions();
326326

327-
bool SubjectHasActiveSubscription(const FabricIndex & aFabricIndex, const NodeId & subject) override;
327+
bool SubjectHasActiveSubscription(FabricIndex aFabricIndex, NodeId subjectID) override;
328328

329-
bool SubjectHasPersistedSubscription(const FabricIndex & aFabricIndex, const NodeId & subject) override;
329+
bool SubjectHasPersistedSubscription(FabricIndex aFabricIndex, NodeId subjectID) override;
330330

331331
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
332332
//

src/app/SubscriptionManager.h src/app/SubscriptionsInfoProvider.h

+11-13
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
/**
2020
* @file
21-
* This file defines an interface that exposes all the public subscription management APIs.
21+
* This file defines an interface that exposes all the public subscription information APIs.
2222
* The interface is implemented by the InteractionModelEngine to avoid creating unnecessary dependencies
23-
* Since the IMEgine has more dependency than its consummers need.
24-
* By leveraging the SubscriptionManager APIs, a consummer avoids depending on the global data model functions.
23+
* since the IMEngine has more dependency than its consummers need.
24+
* By leveraging the SubscriptionInfoProvider APIs, a consumer avoids depending on the global data model functions.
2525
*/
2626

2727
#pragma once
@@ -32,35 +32,33 @@
3232
namespace chip {
3333
namespace app {
3434

35-
class SubscriptionManager
35+
class SubscriptionsInfoProvider
3636
{
3737
public:
38-
virtual ~SubscriptionManager(){};
38+
virtual ~SubscriptionsInfoProvider(){};
3939

4040
/**
4141
* @brief Check if a given subject (CAT or operational NodeId) has at least 1 active subscription.
4242
*
4343
* @param[in] aFabricIndex fabric index of the subject
44-
* @param[in] subject NodeId of the subect
44+
* @param[in] subjectID NodeId of the subject
4545
*
4646
* @return true subject has at least one active subscription with the device
47-
* false subject doesn't have any acitve subscription with the device
47+
* false subject doesn't have any active subscription with the device
4848
*/
49-
virtual bool SubjectHasActiveSubscription(const FabricIndex & aFabricIndex, const NodeId & subject) = 0;
49+
virtual bool SubjectHasActiveSubscription(FabricIndex aFabricIndex, NodeId subjectID) = 0;
5050

5151
/**
5252
* @brief Check if a given subject (CAT or operational NodeId) has at least 1 persisted subscription.
53-
* If CHIP_CONFIG_PERSIST_SUBSCRIPTIONS is not enable, function alweays returns false.
5453
* See the CHIP_CONFIG_PERSIST_SUBSCRIPTIONS for more information on persisted subscriptions.
5554
*
5655
* @param[in] aFabricIndex fabric index of the subject
57-
* @param[in] subject NodeId of the subect
56+
* @param[in] subjectID NodeId of the subject
5857
*
5958
* @return true subject has at least one persisted subscription with the device
60-
* false subject doesn't have any acitve subscription with the device
61-
* false If CHIP_CONFIG_PERSIST_SUBSCRIPTIONS is not enabled
59+
* false subject doesn't have any persisted subscription with the device
6260
*/
63-
virtual bool SubjectHasPersistedSubscription(const FabricIndex & aFabricIndex, const NodeId & subject) = 0;
61+
virtual bool SubjectHasPersistedSubscription(FabricIndex aFabricIndex, NodeId subjectID) = 0;
6462
};
6563

6664
} // namespace app

src/app/icd/server/ICDConfigurationData.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,20 @@ System::Clock::Milliseconds32 ICDConfigurationData::GetSlowPollingInterval()
3737
return mSlowPollingInterval;
3838
}
3939

40-
CHIP_ERROR ICDConfigurationData::SetModeDurations(uint32_t activeModeDuration_ms, uint32_t idleModeInterval_s)
40+
CHIP_ERROR ICDConfigurationData::SetModeDurations(Optional<uint32_t> activeModeDuration_ms, Optional<uint32_t> idleModeDuration_ms)
4141
{
42-
VerifyOrReturnError(activeModeDuration_ms <= (idleModeInterval_s * 1000), CHIP_ERROR_INVALID_ARGUMENT);
43-
VerifyOrReturnError(idleModeInterval_s <= kMaxIdleModeDuration_s, CHIP_ERROR_INVALID_ARGUMENT);
44-
VerifyOrReturnError(idleModeInterval_s >= kMinIdleModeDuration_s, CHIP_ERROR_INVALID_ARGUMENT);
42+
VerifyOrReturnError(activeModeDuration_ms.HasValue() || idleModeDuration_ms.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
4543

46-
mIdleModeDuration_s = idleModeInterval_s;
47-
mActiveModeDuration_ms = activeModeDuration_ms;
44+
uint32_t tmpIdleModeDuration_s =
45+
idleModeDuration_ms.HasValue() ? (idleModeDuration_ms.Value() / kMillisecondsPerSecond) : mIdleModeDuration_s;
46+
uint32_t tmpActiveModeDuration_ms = activeModeDuration_ms.HasValue() ? activeModeDuration_ms.Value() : mActiveModeDuration_ms;
47+
48+
VerifyOrReturnError(tmpActiveModeDuration_ms <= (tmpIdleModeDuration_s * kMillisecondsPerSecond), CHIP_ERROR_INVALID_ARGUMENT);
49+
VerifyOrReturnError(tmpIdleModeDuration_s <= kMaxIdleModeDuration_s, CHIP_ERROR_INVALID_ARGUMENT);
50+
VerifyOrReturnError(tmpIdleModeDuration_s >= kMinIdleModeDuration_s, CHIP_ERROR_INVALID_ARGUMENT);
51+
52+
mIdleModeDuration_s = tmpIdleModeDuration_s;
53+
mActiveModeDuration_ms = tmpActiveModeDuration_ms;
4854

4955
return CHIP_NO_ERROR;
5056
}

src/app/icd/server/ICDConfigurationData.h

+14-10
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717

1818
#pragma once
1919

20+
#include <lib/core/Optional.h>
21+
#include <lib/support/TimeUtils.h>
2022
#include <platform/CHIPDeviceConfig.h>
2123
#include <system/SystemClock.h>
2224

2325
namespace chip {
2426

2527
namespace app {
26-
// Forward declaration of ICDManager to allow it to be friend with ICDConfigurationData
28+
// Forward declaration of ICDManager to allow it to be friend with ICDConfigurationData.
2729
class ICDManager;
2830

29-
// Forward declaration of TestICDManager to allow it to be friend with the ICDConfigurationData
31+
// Forward declaration of TestICDManager to allow it to be friend with the ICDConfigurationData.
3032
// Used in unit tests
3133
class TestICDManager;
3234

@@ -104,19 +106,21 @@ class ICDConfigurationData
104106
static constexpr uint32_t kMinLitActiveModeThreshold_ms = 5000;
105107

106108
/**
107-
* @brief Change the ActiveModeDuration and IdleModeDuration value
108-
* To only change one value, pass the old value for the other one
109+
* @brief Change the ActiveModeDuration or the IdleModeDuration value
110+
* If only one value is provided, check will be done agaisn't the other already set value.
109111
*
110112
* @param[in] activeModeDuration_ms new ActiveModeDuration value
111-
* @param[in] idleModeDuration_s new IdleModeDuration value
112-
* @return CHIP_ERROR CHIP_ERROR_INVALID_ARGUMENT is returned if idleModeDuration_s is smaller than activeModeDuration_ms
113-
* is returned if idleModeDuration_s is greater than 64800 seconds
114-
* is returned if idleModeDuration_s is smaller than 1 seconds
113+
* @param[in] idleModeDuration_ms new IdleModeDuration value
114+
* The precision of the IdleModeDuration must be seconds.
115+
* @return CHIP_ERROR CHIP_ERROR_INVALID_ARGUMENT is returned if idleModeDuration_ms is smaller than activeModeDuration_ms
116+
* is returned if idleModeDuration_ms is greater than 64800000 ms
117+
* is returned if idleModeDuration_ms is smaller than 1000 ms
118+
* is returned if no valid values are provided
115119
* CHIP_NO_ERROR is returned if the new intervals were set
116120
*/
117-
CHIP_ERROR SetModeDurations(uint32_t activeModeDuration_ms, uint32_t idleModeDuration_s);
121+
CHIP_ERROR SetModeDurations(Optional<uint32_t> activeModeDuration_ms, Optional<uint32_t> idleModeDuration_ms);
118122

119-
static constexpr uint32_t kMaxIdleModeDuration_s = 64800;
123+
static constexpr uint32_t kMaxIdleModeDuration_s = (18 * kSecondsPerHour);
120124
static constexpr uint32_t kMinIdleModeDuration_s = 1;
121125

122126
static_assert((CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC) <= kMaxIdleModeDuration_s,

src/app/icd/server/ICDManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static_assert(UINT8_MAX >= CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS,
4040
"ICDManager::mOpenExchangeContextCount cannot hold count for the max exchange count");
4141

4242
void ICDManager::Init(PersistentStorageDelegate * storage, FabricTable * fabricTable, Crypto::SymmetricKeystore * symmetricKeystore,
43-
Messaging::ExchangeManager * exchangeManager, SubscriptionManager * manager)
43+
Messaging::ExchangeManager * exchangeManager, SubscriptionsInfoProvider * manager)
4444
{
4545
VerifyOrDie(storage != nullptr);
4646
VerifyOrDie(fabricTable != nullptr);

src/app/icd/server/ICDManager.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#pragma once
1818

1919
#include <app-common/zap-generated/cluster-enums.h>
20-
#include <app/SubscriptionManager.h>
20+
#include <app/SubscriptionsInfoProvider.h>
2121
#include <app/icd/server/ICDCheckInSender.h>
2222
#include <app/icd/server/ICDConfigurationData.h>
2323
#include <app/icd/server/ICDMonitoringTable.h>
@@ -67,7 +67,7 @@ class ICDManager : public ICDListener
6767

6868
ICDManager() {}
6969
void Init(PersistentStorageDelegate * storage, FabricTable * fabricTable, Crypto::SymmetricKeystore * symmetricKeyStore,
70-
Messaging::ExchangeManager * exchangeManager, SubscriptionManager * manager);
70+
Messaging::ExchangeManager * exchangeManager, SubscriptionsInfoProvider * manager);
7171
void Shutdown();
7272
void UpdateICDMode();
7373
void UpdateOperationState(OperationalState state);
@@ -148,7 +148,7 @@ class ICDManager : public ICDListener
148148
FabricTable * mFabricTable = nullptr;
149149
Messaging::ExchangeManager * mExchangeManager = nullptr;
150150
Crypto::SymmetricKeystore * mSymmetricKeystore = nullptr;
151-
SubscriptionManager * mSubManager = nullptr;
151+
SubscriptionsInfoProvider * mSubManager = nullptr;
152152

153153
bool mTransitionToIdleCalled = false;
154154

src/app/tests/TestICDManager.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* limitations under the License.
1717
*/
1818
#include <app/EventManagement.h>
19-
#include <app/SubscriptionManager.h>
19+
#include <app/SubscriptionsInfoProvider.h>
2020
#include <app/icd/server/ICDConfigurationData.h>
2121
#include <app/icd/server/ICDManager.h>
2222
#include <app/icd/server/ICDNotifier.h>
@@ -71,16 +71,16 @@ class TestICDStateObserver : public app::ICDStateObserver
7171
void OnICDModeChange() {}
7272
};
7373

74-
class TestSubscriptionManager : public SubscriptionManager
74+
class TestSubscriptionsInfoProvider : public SubscriptionsInfoProvider
7575
{
7676
public:
77-
TestSubscriptionManager() = default;
78-
~TestSubscriptionManager(){};
77+
TestSubscriptionsInfoProvider() = default;
78+
~TestSubscriptionsInfoProvider(){};
7979

8080
void SetReturnValue(bool value) { mReturnValue = value; };
8181

82-
bool SubjectHasActiveSubscription(const FabricIndex & aFabricIndex, const NodeId & subject) { return mReturnValue; };
83-
bool SubjectHasPersistedSubscription(const FabricIndex & aFabricIndex, const NodeId & subject) { return mReturnValue; };
82+
bool SubjectHasActiveSubscription(FabricIndex aFabricIndex, NodeId subject) { return mReturnValue; };
83+
bool SubjectHasPersistedSubscription(FabricIndex aFabricIndex, NodeId subject) { return mReturnValue; };
8484

8585
private:
8686
bool mReturnValue = false;
@@ -126,7 +126,7 @@ class TestContext : public chip::Test::AppContext
126126
System::Clock::Internal::MockClock mMockClock;
127127
TestSessionKeystoreImpl mKeystore;
128128
app::ICDManager mICDManager;
129-
TestSubscriptionManager mSubManager;
129+
TestSubscriptionsInfoProvider mSubManager;
130130
TestPersistentStorageDelegate testStorage;
131131

132132
private:
@@ -198,7 +198,7 @@ class TestICDManager
198198

199199
// Set New durations for test case
200200
uint32_t oldActiveModeDuration_ms = icdConfigData.GetActiveModeDurationMs();
201-
icdConfigData.SetModeDurations(0, icdConfigData.GetIdleModeDurationSec());
201+
icdConfigData.SetModeDurations(MakeOptional(static_cast<uint32_t>(0)), NullOptional);
202202

203203
// Verify That ICDManager starts in Idle
204204
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
@@ -256,7 +256,7 @@ class TestICDManager
256256
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
257257

258258
// Reset Old durations
259-
icdConfigData.SetModeDurations(oldActiveModeDuration_ms, icdConfigData.GetIdleModeDurationSec());
259+
icdConfigData.SetModeDurations(MakeOptional(oldActiveModeDuration_ms), NullOptional);
260260
}
261261

262262
/**
@@ -277,7 +277,7 @@ class TestICDManager
277277

278278
// Set New durations for test case
279279
uint32_t oldActiveModeDuration_ms = icdConfigData.GetActiveModeDurationMs();
280-
icdConfigData.SetModeDurations(0, icdConfigData.GetIdleModeDurationSec());
280+
icdConfigData.SetModeDurations(MakeOptional(static_cast<uint32_t>(0)), NullOptional);
281281

282282
// Verify That ICDManager starts in Idle
283283
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
@@ -346,7 +346,7 @@ class TestICDManager
346346
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
347347

348348
// Reset Old durations
349-
icdConfigData.SetModeDurations(oldActiveModeDuration_ms, icdConfigData.GetIdleModeDurationSec());
349+
icdConfigData.SetModeDurations(MakeOptional(oldActiveModeDuration_ms), NullOptional);
350350
}
351351

352352
static void TestKeepActivemodeRequests(nlTestSuite * aSuite, void * aContext)

0 commit comments

Comments
 (0)