Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Sep 18, 2023
1 parent 68a1d9a commit b634f42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ InsightsSystemMetrics & InsightsSystemMetrics::GetInstance()
return instance;
}

void InsightsSystemMetrics::SamplingIntervalHandler(Layer * systemLayer, void * context)
void InsightsSystemMetrics::SamplingHandler(Layer * systemLayer, void * context)
{
auto instance = static_cast<InsightsSystemMetrics *>(context);
count_t * highwatermarks = GetHighWatermarks();
Expand All @@ -45,7 +45,7 @@ void InsightsSystemMetrics::SamplingIntervalHandler(Layer * systemLayer, void *
ESP_LOGE(kTag, "Failed to add the metric:%s, err:%d", instance->mLabels[i], err);
}
}
DeviceLayer::SystemLayer().StartTimer(instance->GetSamplingInterval(), SamplingIntervalHandler, instance);
DeviceLayer::SystemLayer().StartTimer(instance->GetSamplingInterval(), SamplingHandler, instance);
}

CHIP_ERROR InsightsSystemMetrics::Unregister()
Expand All @@ -70,34 +70,33 @@ CHIP_ERROR InsightsSystemMetrics::Unregister()
return CHIP_NO_ERROR;
}

void InsightsSystemMetrics::CancelSamplingInterval(intptr_t arg)
void InsightsSystemMetrics::SetSamplingHandler(intptr_t arg)
{
auto instance = static_cast<InsightsSystemMetrics *>(reinterpret_cast<void *>(arg));
DeviceLayer::SystemLayer().CancelTimer(SamplingIntervalHandler, instance);
}

CHIP_ERROR InsightsSystemMetrics::SetSamplingInterval(chip::System::Clock::Timeout aTimeout)
{
if (!mRegistered)
{
return CHIP_ERROR_INCORRECT_STATE;
}

if (aTimeout == System::Clock::kZero)
if (instance->mTimeout == System::Clock::kZero)
{
DeviceLayer::PlatformMgr().ScheduleWork(CancelSamplingInterval, reinterpret_cast<intptr_t>(this));
DeviceLayer::SystemLayer().CancelTimer(SamplingHandler, instance);
}
else if (aTimeout != mTimeout)
else
{
DeviceLayer::PlatformMgr().ScheduleWork(CancelSamplingInterval, reinterpret_cast<intptr_t>(this));
mTimeout = aTimeout;
CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(mTimeout, SamplingIntervalHandler, this);
DeviceLayer::SystemLayer().CancelTimer(SamplingHandler, instance);
CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(instance->mTimeout, SamplingHandler, instance);
if (err != CHIP_NO_ERROR)
{
ESP_LOGE(kTag, "Failed to start the new timer %" CHIP_ERROR_FORMAT, err.Format());
return err;
}
}
}

CHIP_ERROR InsightsSystemMetrics::SetSamplingInterval(chip::System::Clock::Timeout aTimeout)
{
if (!mRegistered)
{
return CHIP_ERROR_INCORRECT_STATE;
}
mTimeout = aTimeout;
DeviceLayer::PlatformMgr().ScheduleWork(SetSamplingHandler, reinterpret_cast<intptr_t>(this));

return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -144,7 +143,7 @@ CHIP_ERROR InsightsSystemMetrics::RegisterAndEnable(chip::System::Clock::Timeout

mTimeout = System::Clock::Milliseconds32(aTimeout);

CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(GetSamplingInterval(), SamplingIntervalHandler, this);
CHIP_ERROR err = DeviceLayer::SystemLayer().StartTimer(GetSamplingInterval(), SamplingHandler, this);
if (err != CHIP_NO_ERROR)
{
ESP_LOGE(kTag, "Failed to start the timer, err:%" CHIP_ERROR_FORMAT, err.Format());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class InsightsSystemMetrics
System::Clock::Timeout mTimeout;
char * mLabels[chip::System::Stats::kNumEntries];

static void SamplingIntervalHandler(System::Layer * systemLayer, void * context);
static void CancelSamplingInterval(intptr_t arg);
static void SamplingHandler(System::Layer * systemLayer, void * context);
static void SetSamplingHandler(intptr_t arg);
};

} // namespace Stats
Expand Down

0 comments on commit b634f42

Please sign in to comment.