Skip to content

Commit

Permalink
Merge pull request #2141 from mavlink/fix-camera-subscription-conflict
Browse files Browse the repository at this point in the history
camera: fix conflict between subscribe_status and subscribe_information
  • Loading branch information
julianoes authored Sep 14, 2023
2 parents 1bac5a1 + 777b923 commit 48f1ad0
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions src/mavsdk/plugins/camera/camera_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ void CameraImpl::manual_enable()
_system_impl->add_call_every(
[this]() { request_camera_information(); }, 10.0, &_camera_information_call_every_cookie);

_system_impl->add_call_every([this]() { request_status(); }, 5.0, &_status.call_every_cookie);

// for backwards compatibility with Yuneec drones
if (_system_impl->has_autopilot()) {
request_flight_information();
Expand All @@ -232,6 +234,7 @@ void CameraImpl::manual_disable()
{
invalidate_params();
_system_impl->remove_call_every(_camera_information_call_every_cookie);
_system_impl->remove_call_every(_status.call_every_cookie);

if (_flight_information_call_every_cookie) {
_system_impl->remove_call_every(_flight_information_call_every_cookie);
Expand Down Expand Up @@ -597,21 +600,6 @@ CameraImpl::subscribe_information(const Camera::InformationCallback& callback)
std::lock_guard<std::mutex> lock(_information.mutex);
auto handle = _information.subscription_callbacks.subscribe(callback);

// If there was already a subscription, cancel the call
if (_status.call_every_cookie) {
_system_impl->remove_call_every(_status.call_every_cookie);
}

if (callback) {
if (_status.call_every_cookie == nullptr) {
_system_impl->add_call_every(
[this]() { request_status(); }, 5.0, &_status.call_every_cookie);
}
} else {
_system_impl->remove_call_every(_status.call_every_cookie);
_status.call_every_cookie = nullptr;
}

return handle;
}

Expand Down Expand Up @@ -889,19 +877,8 @@ void CameraImpl::request_status()
Camera::StatusHandle CameraImpl::subscribe_status(const Camera::StatusCallback& callback)
{
std::lock_guard<std::mutex> lock(_status.mutex);

auto handle = _status.subscription_callbacks.subscribe(callback);

if (callback) {
if (_status.call_every_cookie == nullptr) {
_system_impl->add_call_every(
[this]() { request_status(); }, 5.0, &_status.call_every_cookie);
}
} else {
_system_impl->remove_call_every(_status.call_every_cookie);
_status.call_every_cookie = nullptr;
}

return handle;
}

Expand Down

0 comments on commit 48f1ad0

Please sign in to comment.