diff options
Diffstat (limited to 'src/components/policy/src/policy/usage_statistics/src/counter.cc')
-rw-r--r-- | src/components/policy/src/policy/usage_statistics/src/counter.cc | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/components/policy/src/policy/usage_statistics/src/counter.cc b/src/components/policy/src/policy/usage_statistics/src/counter.cc index 6375db8f8..070de140b 100644 --- a/src/components/policy/src/policy/usage_statistics/src/counter.cc +++ b/src/components/policy/src/policy/usage_statistics/src/counter.cc @@ -83,33 +83,41 @@ AppStopwatch::AppStopwatch(utils::SharedPtr<usage_statistics::StatisticsManager> : app_id_(app_id), stopwatch_type_(SECONDS_HMI_NONE), statistics_manager_(statistics_manager), - start_time_() { + timer_(new Timer("HMI levels timer",this, &AppStopwatch::WriteTime, true)), + time_out_(60) { +} + +AppStopwatch::AppStopwatch(utils::SharedPtr<StatisticsManager> statistics_manager, + const std::string& app_id, + std::uint32_t time_out) + : app_id_(app_id), + stopwatch_type_(SECONDS_HMI_NONE), + statistics_manager_(statistics_manager), + timer_(new Timer("HMI levels timer",this, &AppStopwatch::WriteTime, true)), + time_out_(time_out) { + } AppStopwatch::~AppStopwatch() { - if (start_time_) { - Stop(); + if (NULL != timer_) { + timer_->stop(); + delete timer_; } } void AppStopwatch::Start(AppStopwatchId stopwatch_type) { - assert(0 == start_time_); stopwatch_type_ = stopwatch_type; - start_time_ = time(NULL); + timer_->start(time_out_); } void AppStopwatch::Switch(AppStopwatchId stopwatch_type) { - Stop(); Start(stopwatch_type); } -void AppStopwatch::Stop() { - assert(start_time_ != 0); - double difference = difftime(time(NULL), start_time_); +void AppStopwatch::WriteTime() { if (statistics_manager_) { - statistics_manager_->Add(app_id_, stopwatch_type_, int32_t(difference)); + statistics_manager_->Add(app_id_, stopwatch_type_, time_out_); } - start_time_ = 0; } } // namespace usage_statistics |