Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: debounce_timeout compare different iterators #739

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 40 additions & 25 deletions implementation/routing/src/routing_manager_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,41 +50,56 @@ routing_manager_base::routing_manager_base(routing_manager_host *_host) :
}
}

void routing_manager_base::debounce_timeout_update_cbk(const boost::system::error_code &_error, const std::shared_ptr<vsomeip_v3::event> &_event, client_t _client, const std::shared_ptr<debounce_filter_impl_t> &_filter) {
void routing_manager_base::debounce_timeout_update_cbk(const boost::system::error_code &_error,
const std::shared_ptr<vsomeip_v3::event> &_event,
client_t _client,
const std::shared_ptr<debounce_filter_impl_t> &_filter) {
if (!_error) {
std::lock_guard<std::mutex> its_lock(debounce_mutex_);
if (_event && (_event->get_subscribers().find(_client) != _event->get_subscribers().end()) && _filter) {
bool is_elapsed{false};
auto its_current = std::chrono::steady_clock::now();

int64_t elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
its_current - _filter->last_forwarded_).count();
is_elapsed = (_filter->last_forwarded_ == std::chrono::steady_clock::time_point::max()
|| elapsed >= _filter->interval_);

auto debounce_client = debounce_clients_.begin();
auto event_id = std::get<3>(debounce_client->second);
bool has_update = std::get<1>(debounce_client->second);
if (is_elapsed) {
if (std::get<0>(debounce_client->second) == _client && has_update) {
_event->notify_one(_client, false);
has_update = false;
if (_event) {
std::set<client_t> its_subscribers;
its_subscribers = _event->get_subscribers();

if ((its_subscribers.find(_client) != its_subscribers.end()) && _filter) {
bool is_elapsed{false};
auto its_current = std::chrono::steady_clock::now();

int64_t elapsed =
std::chrono::duration_cast<std::chrono::milliseconds>(its_current - _filter->last_forwarded_)
.count();
is_elapsed = (_filter->last_forwarded_ == std::chrono::steady_clock::time_point::max() ||
elapsed >= _filter->interval_);

auto debounce_client = debounce_clients_.begin();
auto event_id = std::get<3>(debounce_client->second);
bool has_update = std::get<1>(debounce_client->second);
if (is_elapsed) {
if (std::get<0>(debounce_client->second) == _client && has_update) {
_event->notify_one(_client, false);
has_update = false;
}
elapsed = 0;
}
elapsed = 0;
}

debounce_clients_.erase(debounce_client);
debounce_clients_.erase(debounce_client);

auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(_filter->interval_ - elapsed);
debounce_clients_.emplace(timeout, std::make_tuple(_client, has_update, std::bind(&routing_manager_base::debounce_timeout_update_cbk, shared_from_this(),
std::placeholders::_1, _event, _client, _filter), event_id));
auto timeout =
std::chrono::steady_clock::now() + std::chrono::milliseconds(_filter->interval_ - elapsed);
debounce_clients_.emplace(
timeout,
std::make_tuple(_client, has_update,
std::bind(&routing_manager_base::debounce_timeout_update_cbk, shared_from_this(),
std::placeholders::_1, _event, _client, _filter),
event_id));
}
}

if (debounce_clients_.size() > 0) {
debounce_timer.expires_from_now(std::chrono::duration_cast<std::chrono::milliseconds>(debounce_clients_.begin()->first - std::chrono::steady_clock::now()));
debounce_timer.expires_from_now(std::chrono::duration_cast<std::chrono::milliseconds>(
debounce_clients_.begin()->first - std::chrono::steady_clock::now()));
debounce_timer.async_wait(std::get<2>(debounce_clients_.begin()->second));
}
}
}
}

void routing_manager_base::register_debounce(const std::shared_ptr<debounce_filter_impl_t> &_filter, client_t _client, const std::shared_ptr<vsomeip_v3::event> &_event) {
Expand Down
Loading