Skip to content

Commit

Permalink
Merge 056fffc into 445173b
Browse files Browse the repository at this point in the history
  • Loading branch information
julianoes committed Mar 19, 2019
2 parents 445173b + 056fffc commit d7d19c8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions plugins/mission/mission_impl.cpp
Expand Up @@ -1132,18 +1132,21 @@ void MissionImpl::copy_mission_item_vector(
void MissionImpl::report_mission_result(const Mission::result_callback_t &callback,
Mission::Result result)
{
if (callback == nullptr) {
const auto temp_callback = callback;

if (temp_callback == nullptr) {
LogWarn() << "Callback is not set";
return;
}

_parent->call_user_callback([callback, result]() { callback(result); });
_parent->call_user_callback([temp_callback, result]() { temp_callback(result); });
}

void MissionImpl::report_mission_items_and_result(
const Mission::mission_items_and_result_callback_t &callback, Mission::Result result)
{
if (callback == nullptr) {
const auto temp_callback = callback;
if (temp_callback == nullptr) {
LogWarn() << "Callback is not set";
return;
}
Expand All @@ -1153,15 +1156,16 @@ void MissionImpl::report_mission_items_and_result(
// Don't return garbage, better clear it.
_mission_data.mission_items.clear();
}
_parent->call_user_callback([callback, result, this]() {
_parent->call_user_callback([temp_callback, result, this]() {
// This one is tricky because we keep the lock of the mission data during the callback.
callback(result, _mission_data.mission_items);
temp_callback(result, _mission_data.mission_items);
});
}

void MissionImpl::report_progress()
{
if (_mission_data.progress_callback == nullptr) {
const auto temp_callback = _mission_data.progress_callback;
if (temp_callback == nullptr) {
return;
}

Expand All @@ -1183,7 +1187,6 @@ void MissionImpl::report_progress()

if (should_report) {
std::lock_guard<std::recursive_mutex> lock(_mission_data.mutex);
auto temp_callback = _mission_data.progress_callback;
_parent->call_user_callback([temp_callback, current, total]() {
LogDebug() << "current: " << current << ", total: " << total;
temp_callback(current, total);
Expand Down

0 comments on commit d7d19c8

Please sign in to comment.