Skip to content

Commit

Permalink
use getters instead of extern
Browse files Browse the repository at this point in the history
  • Loading branch information
sxb427 committed Feb 24, 2025
1 parent 154ae8d commit 80ce709
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
11 changes: 8 additions & 3 deletions examples/chef/common/chef-rvc-mode-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::T
using namespace chip::app::Clusters::RvcRunMode;

static std::unique_ptr<RvcRunModeDelegate> gRvcRunModeDelegate;
std::unique_ptr<ModeBase::Instance> gRvcRunModeInstance;
static std::unique_ptr<ModeBase::Instance> gRvcRunModeInstance;

chip::app::Clusters::ModeBase::Instance * getRvcRunModeInstance()
{
return gRvcRunModeInstance.get();
}

CHIP_ERROR RvcRunModeDelegate::Init()
{
Expand All @@ -63,15 +68,15 @@ void RvcRunModeDelegate::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands:
if (currentMode != RvcRunMode::ModeIdle)
{ // Stop existing cycle when going from cleaning/mapping to idle.
ChipLogProgress(DeviceLayer, "Stopping RVC cycle: %d", currentMode);
gRvcOperationalStateDelegate->HandleStopStateCallback(err);
getRvcOperationalStateDelegate()->HandleStopStateCallback(err);
}
}
else
{
if (currentMode == RvcRunMode::ModeIdle)
{ // Start a new cycle when going from idle to clening/mapping.
ChipLogProgress(DeviceLayer, "Starting new RVC cycle: %d", NewMode);
gRvcOperationalStateDelegate->HandleStartStateCallback(err);
getRvcOperationalStateDelegate()->HandleStartStateCallback(err);
}
}
if (err.IsEqual(OperationalState::GenericOperationalError(to_underlying(OperationalState::ErrorStateEnum::kNoError))))
Expand Down
2 changes: 1 addition & 1 deletion examples/chef/common/chef-rvc-mode-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void Shutdown();
} // namespace chip

#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
extern std::unique_ptr<chip::app::Clusters::ModeBase::Instance> gRvcRunModeInstance;
chip::app::Clusters::ModeBase::Instance * getRvcRunModeInstance();

chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
Expand Down
9 changes: 7 additions & 2 deletions examples/chef/common/chef-rvc-operational-state-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ using chip::Protocols::InteractionModel::Status;
#include <chef-rvc-mode-delegate.h>
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER

std::unique_ptr<RvcOperationalStateDelegate> gRvcOperationalStateDelegate;
static std::unique_ptr<RvcOperationalStateDelegate> gRvcOperationalStateDelegate;
static std::unique_ptr<RvcOperationalState::Instance> gRvcOperationalStateInstance;

RvcOperationalStateDelegate * getRvcOperationalStateDelegate()
{
return gRvcOperationalStateDelegate.get();
}

static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data);

DataModel::Nullable<uint32_t> RvcOperationalStateDelegate::GetCountdownTime()
Expand Down Expand Up @@ -234,7 +239,7 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
gRvcOperationalStateDelegate->mCountdownTime.SetNull();

#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
gRvcRunModeInstance->UpdateCurrentMode(RvcRunMode::ModeIdle);
getRvcRunModeInstance()->UpdateCurrentMode(RvcRunMode::ModeIdle);
#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/chef/common/chef-rvc-operational-state-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void Shutdown();
} // namespace app
} // namespace chip

extern std::unique_ptr<chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate> gRvcOperationalStateDelegate;
chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate * getRvcOperationalStateDelegate();

chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
const EmberAfAttributeMetadata * attributeMetadata,
Expand Down

0 comments on commit 80ce709

Please sign in to comment.