Skip to content

Commit

Permalink
core: Call download on thread pool
Browse files Browse the repository at this point in the history
This is to avoid locking us out when doing subsequent downloads. For
some reason this locked up on certain platforms.
  • Loading branch information
julianoes committed Jul 15, 2024
1 parent 5803c22 commit f805914
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions src/mavsdk/core/mavlink_component_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,35 +197,47 @@ void MavlinkComponentMetadata::retrieve_metadata(uint8_t compid, COMP_METADATA_T

const std::filesystem::path local_path =
tmp_download_path / std::filesystem::path(download_path).filename();
_system_impl.mavlink_ftp_client().download_async(
download_path,
tmp_download_path.string(),
true,
[this, &component, local_path, compid, type, file_cache_tag](
MavlinkFtpClient::ClientResult download_result,
MavlinkFtpClient::ProgressData progress_data) {
if (download_result == MavlinkFtpClient::ClientResult::Next) {
if (_verbose_debugging) {
LogDebug()
<< "File download progress: " << progress_data.bytes_transferred
<< '/' << progress_data.total_bytes;
}
// TODO: detect slow link (e.g. telemetry), and cancel download
// (fallback to http) e.g. by estimating the remaining download time,
// and cancel if >40s
} else {
if (_verbose_debugging) {
LogDebug() << "File download ended with result " << download_result;
}
if (download_result == MavlinkFtpClient::ClientResult::Success) {
component.current_metadata_path() =
extract_and_cache_file(local_path, file_cache_tag);

_system_impl.call_user_callback([this,
download_path,
tmp_download_path,
&component,
target_compid,
local_path,
compid,
type,
file_cache_tag]() {
_system_impl.mavlink_ftp_client().download_async(
download_path,
tmp_download_path.string(),
true,
[this, &component, local_path, compid, type, file_cache_tag](
MavlinkFtpClient::ClientResult download_result,
MavlinkFtpClient::ProgressData progress_data) {
if (download_result == MavlinkFtpClient::ClientResult::Next) {
if (_verbose_debugging) {
LogDebug() << "File download progress: "
<< progress_data.bytes_transferred << '/'
<< progress_data.total_bytes;
}
// TODO: detect slow link (e.g. telemetry), and cancel download
// (fallback to http) e.g. by estimating the remaining download
// time, and cancel if >40s
} else {
if (_verbose_debugging) {
LogDebug()
<< "File download ended with result " << download_result;
}
if (download_result == MavlinkFtpClient::ClientResult::Success) {
component.current_metadata_path() =
extract_and_cache_file(local_path, file_cache_tag);
}
// Move on to the next uri or type
retrieve_metadata(compid, type);
}
// Move on to the next uri or type
retrieve_metadata(compid, type);
}
},
target_compid);
},
target_compid);
});

} else {
// http(s) download
Expand Down

0 comments on commit f805914

Please sign in to comment.