Skip to content
Snippets Groups Projects
Commit 9452be1f authored by François-Simon Fauteux-Chapleau's avatar François-Simon Fauteux-Chapleau
Browse files

mapping: fix bug when NotifyCallback is null

The change made in commit 41d80670 to
prevent a mapping's NotifyCallback from being called more than once
unnecessarily didn't correctly handle the case where the callback is
null. As a result, the callback would sometimes not be called at all in
situations where it should have been.
https://git.jami.net/savoirfairelinux/jami-client-ios/-/issues/410

Change-Id: Icce78210b8be873be244e93e430d8c6123619db9
parent 41d80670
No related branches found
No related tags found
No related merge requests found
......@@ -299,6 +299,8 @@ Mapping::notify(sharedPtr_t mapping)
NotifyCallback cb;
{
std::lock_guard lock(mapping->mutex_);
if (!mapping->notifyCb_)
return;
if (mapping->state_ != mapping->lastNotifiedState_) {
mapping->lastNotifiedState_ = mapping->state_;
cb = mapping->notifyCb_;
......@@ -320,6 +322,13 @@ Mapping::setNotifyCallback(NotifyCallback cb)
{
std::lock_guard lock(mutex_);
notifyCb_ = std::move(cb);
if (!notifyCb_) {
// When a mapping is released by a controller, its NotifyCallback is set
// to null (see UPnPContext::releaseMapping). We need to reset
// lastNotifiedState_ when this happens to make sure the mapping isn't
// in a incorrect state if it's later reused by a different controller.
lastNotifiedState_ = std::nullopt;
}
}
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment