Skip to content

Commit

Permalink
fix ordering of inits
Browse files Browse the repository at this point in the history
replace pointer with instance call
  • Loading branch information
mkardous-silabs committed Nov 28, 2023
1 parent 83e9207 commit ea2d1ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
43 changes: 21 additions & 22 deletions src/app/icd/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ void ICDManager::Init(PersistentStorageDelegate * storage, FabricTable * fabricT
mStorage = storage;
mFabricTable = fabricTable;
VerifyOrDie(ICDNotifier::GetInstance().Subscribe(this) == CHIP_NO_ERROR);
mSymmetricKeystore = symmetricKeystore;
mExchangeManager = exchangeManager;
mICDConfigurationData = &ICDConfigurationData::GetInstance();
mSymmetricKeystore = symmetricKeystore;
mExchangeManager = exchangeManager;

// Removing the check for now since it is possible for the Fast polling
// to be larger than the ActiveModeDuration for now
// uint32_t activeModeDuration = mICDConfigurationData->GetActiveModeDurationMs();
// uint32_t activeModeDuration = ICDConfigurationData::GetInstance().GetActiveModeDurationMs();
// VerifyOrDie(kFastPollingInterval.count() < activeModeDuration);

UpdateICDMode();
Expand All @@ -81,11 +80,10 @@ void ICDManager::Shutdown()
DeviceLayer::SystemLayer().CancelTimer(OnIdleModeDone, this);
DeviceLayer::SystemLayer().CancelTimer(OnActiveModeDone, this);
DeviceLayer::SystemLayer().CancelTimer(OnTransitionToIdle, this);
mICDConfigurationData->SetICDMode(ICDConfigurationData::ICDMode::SIT);
mOperationalState = OperationalState::ActiveMode;
mStorage = nullptr;
mFabricTable = nullptr;
mICDConfigurationData = nullptr;
ICDConfigurationData::GetInstance().SetICDMode(ICDConfigurationData::ICDMode::SIT);
mOperationalState = OperationalState::ActiveMode;
mStorage = nullptr;
mFabricTable = nullptr;
mStateObserverPool.ReleaseAll();
mICDSenderPool.ReleaseAll();
}
Expand Down Expand Up @@ -179,18 +177,18 @@ void ICDManager::UpdateICDMode()
}
}

if (mICDConfigurationData->GetICDMode() != tempMode)
if (ICDConfigurationData::GetInstance().GetICDMode() != tempMode)
{
mICDConfigurationData->SetICDMode(tempMode);
ICDConfigurationData::GetInstance().SetICDMode(tempMode);
postObserverEvent(ObserverEventType::ICDModeChange);
}

// When in SIT mode, the slow poll interval SHOULDN'T be greater than the SIT mode polling threshold, per spec.
if (mICDConfigurationData->GetICDMode() == ICDConfigurationData::ICDMode::SIT &&
mICDConfigurationData->GetSlowPollingInterval() > mICDConfigurationData->GetSITPollingThreshold())
if (ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::SIT &&
ICDConfigurationData::GetInstance().GetSlowPollingInterval() > ICDConfigurationData::GetInstance().GetSITPollingThreshold())
{
ChipLogDetail(AppServer, "The Slow Polling Interval of an ICD in SIT mode should be <= %" PRIu32 " seconds",
(mICDConfigurationData->GetSITPollingThreshold().count() / 1000));
(ICDConfigurationData::GetInstance().GetSITPollingThreshold().count() / 1000));
}
}

Expand All @@ -205,17 +203,17 @@ void ICDManager::UpdateOperationState(OperationalState state)
mOperationalState = OperationalState::IdleMode;

// When the active mode interval is 0, we stay in idleMode until a notification brings the icd into active mode
if (mICDConfigurationData->GetActiveModeDurationMs() > 0)
if (ICDConfigurationData::GetInstance().GetActiveModeDurationMs() > 0)
{
uint32_t idleModeDuration = mICDConfigurationData->GetIdleModeDurationSec();
uint32_t idleModeDuration = ICDConfigurationData::GetInstance().GetIdleModeDurationSec();
DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(idleModeDuration), OnIdleModeDone, this);
}

System::Clock::Milliseconds32 slowPollInterval = mICDConfigurationData->GetSlowPollingInterval();
System::Clock::Milliseconds32 slowPollInterval = ICDConfigurationData::GetInstance().GetSlowPollingInterval();

#if ICD_ENFORCE_SIT_SLOW_POLL_LIMIT
// When in SIT mode, the slow poll interval SHOULDN'T be greater than the SIT mode polling threshold, per spec.
if (mICDConfigurationData->GetICDMode() == ICDConfigurationData::ICDMode::SIT &&
if (ICDConfigurationData::GetInstance().GetICDMode() == ICDConfigurationData::ICDMode::SIT &&
GetSlowPollingInterval() > GetSITPollingThreshold())
{
slowPollInterval = GetSITPollingThreshold();
Expand All @@ -240,13 +238,13 @@ void ICDManager::UpdateOperationState(OperationalState state)
DeviceLayer::SystemLayer().CancelTimer(OnIdleModeDone, this);

mOperationalState = OperationalState::ActiveMode;
uint32_t activeModeDuration = mICDConfigurationData->GetActiveModeDurationMs();
uint32_t activeModeDuration = ICDConfigurationData::GetInstance().GetActiveModeDurationMs();

if (activeModeDuration == 0 && !mKeepActiveFlags.HasAny())
{
// A Network Activity triggered the active mode and activeModeDuration is 0.
// Stay active for at least Active Mode Threshold.
activeModeDuration = mICDConfigurationData->GetActiveModeThresholdMs();
activeModeDuration = ICDConfigurationData::GetInstance().GetActiveModeThresholdMs();
}

DeviceLayer::SystemLayer().StartTimer(System::Clock::Timeout(activeModeDuration), OnActiveModeDone, this);
Expand All @@ -255,7 +253,8 @@ void ICDManager::UpdateOperationState(OperationalState state)
(activeModeDuration >= ICD_ACTIVE_TIME_JITTER_MS) ? activeModeDuration - ICD_ACTIVE_TIME_JITTER_MS : 0;
DeviceLayer::SystemLayer().StartTimer(System::Clock::Timeout(activeModeJitterInterval), OnTransitionToIdle, this);

CHIP_ERROR err = DeviceLayer::ConnectivityMgr().SetPollingInterval(mICDConfigurationData->GetFastPollingInterval());
CHIP_ERROR err =
DeviceLayer::ConnectivityMgr().SetPollingInterval(ICDConfigurationData::GetInstance().GetFastPollingInterval());
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Failed to set Fast Polling Interval: err %" CHIP_ERROR_FORMAT, err.Format());
Expand All @@ -270,7 +269,7 @@ void ICDManager::UpdateOperationState(OperationalState state)
}
else
{
uint16_t activeModeThreshold = mICDConfigurationData->GetActiveModeThresholdMs();
uint16_t activeModeThreshold = ICDConfigurationData::GetInstance().GetActiveModeThresholdMs();
DeviceLayer::SystemLayer().ExtendTimerTo(System::Clock::Timeout(activeModeThreshold), OnActiveModeDone, this);
uint16_t activeModeJitterThreshold =
(activeModeThreshold >= ICD_ACTIVE_TIME_JITTER_MS) ? activeModeThreshold - ICD_ACTIVE_TIME_JITTER_MS : 0;
Expand Down
3 changes: 1 addition & 2 deletions src/app/icd/ICDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ICDManager : public ICDListener
void SetKeepActiveModeRequirements(KeepActiveFlags flag, bool state);
bool IsKeepActive() { return mKeepActiveFlags.HasAny(); }
bool SupportsFeature(Clusters::IcdManagement::Feature feature);
ICDConfigurationData::ICDMode GetICDMode() { return mICDConfigurationData->GetICDMode(); };
ICDConfigurationData::ICDMode GetICDMode() { return ICDConfigurationData::GetInstance().GetICDMode(); };
/**
* @brief Adds the referenced observer in parameters to the mStateObserverPool
* A maximum of CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE observers can be concurrently registered
Expand Down Expand Up @@ -131,7 +131,6 @@ class ICDManager : public ICDListener
PersistentStorageDelegate * mStorage = nullptr;
FabricTable * mFabricTable = nullptr;
Messaging::ExchangeManager * mExchangeManager = nullptr;
ICDConfigurationData * mICDConfigurationData = nullptr;
bool mTransitionToIdleCalled = false;
Crypto::SymmetricKeystore * mSymmetricKeystore = nullptr;
ObjectPool<ObserverPointer, CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE> mStateObserverPool;
Expand Down
15 changes: 11 additions & 4 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
app::DnssdServer::Instance().SetUnsecuredPort(mUserDirectedCommissioningPort);
app::DnssdServer::Instance().SetInterfaceId(mInterfaceId);

#if CHIP_CONFIG_ENABLE_ICD_SERVER
// We set the ICDManager reference betfore calling the ICDManager init due to the init ordering limitations.
// DnssdServer will use the default value initially and will update advertisement once ICDManager
// init is called.
app::DnssdServer::Instance().SetICDManager(&mICDManager);
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

if (GetFabricTable().FabricCount() != 0)
{
// The device is already commissioned, proactively disable BLE advertisement.
Expand Down Expand Up @@ -321,14 +328,14 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)

// ICD Init needs to be after data model init and InteractionModel Init
#if CHIP_CONFIG_ENABLE_ICD_SERVER
mICDManager.Init(mDeviceStorage, &GetFabricTable(), mSessionKeystore, &mExchangeMgr);

// Register the ICDStateObservers. All observers are released at mICDManager.Shutdown()
// They can be released individually with ReleaseObserver
// Register the ICDStateObservers.
// Call register before init so that observers are notified of any state change during the init.
// All observers are released at mICDManager.Shutdown(). They can be released individually with ReleaseObserver
mICDManager.RegisterObserver(mReportScheduler);
mICDManager.RegisterObserver(&app::DnssdServer::Instance());

app::DnssdServer::Instance().SetICDManager(&mICDManager);
mICDManager.Init(mDeviceStorage, &GetFabricTable(), mSessionKeystore, &mExchangeMgr);
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

// This code is necessary to restart listening to existing groups after a reboot
Expand Down

0 comments on commit ea2d1ae

Please sign in to comment.