Skip to content

Commit

Permalink
Merge pull request #2230 from chep/chep/ftp
Browse files Browse the repository at this point in the history
Ftp: use call_user_callback
  • Loading branch information
julianoes authored Feb 22, 2024
2 parents f5e6945 + 24bf4d1 commit d88e912
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions src/mavsdk/plugins/ftp/ftp_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ void FtpImpl::download_async(
use_burst,
[callback, this](
MavlinkFtpClient::ClientResult result, MavlinkFtpClient::ProgressData progress_data) {
callback(
result_from_mavlink_ftp_result(result),
progress_data_from_mavlink_ftp_progress_data(progress_data));
if (callback) {
_system_impl->call_user_callback(
[temp_callback = callback, result, progress_data, this]() {
temp_callback(
result_from_mavlink_ftp_result(result),
progress_data_from_mavlink_ftp_progress_data(progress_data));
});
}
});
}

Expand All @@ -58,9 +63,14 @@ void FtpImpl::upload_async(
remote_folder,
[callback, this](
MavlinkFtpClient::ClientResult result, MavlinkFtpClient::ProgressData progress_data) {
callback(
result_from_mavlink_ftp_result(result),
progress_data_from_mavlink_ftp_progress_data(progress_data));
if (callback) {
_system_impl->call_user_callback(
[temp_callback = callback, result, progress_data, this]() {
temp_callback(
result_from_mavlink_ftp_result(result),
progress_data_from_mavlink_ftp_progress_data(progress_data));
});
}
});
}

Expand Down Expand Up @@ -100,7 +110,11 @@ void FtpImpl::create_directory_async(const std::string& path, Ftp::ResultCallbac
{
_system_impl->mavlink_ftp_client().create_directory_async(
path, [callback, this](MavlinkFtpClient::ClientResult result) {
callback(result_from_mavlink_ftp_result(result));
if (callback) {
_system_impl->call_user_callback([temp_callback = callback, result, this]() {
temp_callback(result_from_mavlink_ftp_result(result));
});
}
});
}

Expand All @@ -118,7 +132,11 @@ void FtpImpl::remove_directory_async(const std::string& path, Ftp::ResultCallbac
{
_system_impl->mavlink_ftp_client().remove_directory_async(
path, [callback, this](MavlinkFtpClient::ClientResult result) {
callback(result_from_mavlink_ftp_result(result));
if (callback) {
_system_impl->call_user_callback([temp_callback = callback, result, this]() {
temp_callback(result_from_mavlink_ftp_result(result));
});
}
});
}

Expand All @@ -136,7 +154,11 @@ void FtpImpl::remove_file_async(const std::string& path, Ftp::ResultCallback cal
{
_system_impl->mavlink_ftp_client().remove_file_async(
path, [callback, this](MavlinkFtpClient::ClientResult result) {
callback(result_from_mavlink_ftp_result(result));
if (callback) {
_system_impl->call_user_callback([temp_callback = callback, result, this]() {
temp_callback(result_from_mavlink_ftp_result(result));
});
}
});
}

Expand All @@ -155,7 +177,11 @@ void FtpImpl::rename_async(
{
_system_impl->mavlink_ftp_client().rename_async(
from_path, to_path, [callback, this](MavlinkFtpClient::ClientResult result) {
callback(result_from_mavlink_ftp_result(result));
if (callback) {
_system_impl->call_user_callback([temp_callback = callback, result, this]() {
temp_callback(result_from_mavlink_ftp_result(result));
});
}
});
}

Expand All @@ -181,7 +207,12 @@ void FtpImpl::are_files_identical_async(
local_path,
remote_path,
[callback, this](MavlinkFtpClient::ClientResult result, bool identical) {
callback(result_from_mavlink_ftp_result(result), identical);
if (callback) {
_system_impl->call_user_callback(
[temp_callback = callback, result, identical, this]() {
temp_callback(result_from_mavlink_ftp_result(result), identical);
});
}
});
}

Expand Down

0 comments on commit d88e912

Please sign in to comment.