• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 4578731844

pending completion
4578731844

push

github

GitHub
Merge pull request #2012 from mavlink/rename-parent

885 of 885 new or added lines in 31 files covered. (100.0%)

7416 of 24250 relevant lines covered (30.58%)

21.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/mavsdk/plugins/ftp/ftp_impl.cpp
1
#include <functional>
2
#include <iostream>
3

4
#if defined(WINDOWS)
5
#include "tronkko_dirent.h"
6
#include "stackoverflow_unistd.h"
7
// Fix MSVC error C4003
8
// https://stackoverflow.com/a/6884102/8548472
9
#ifdef max
10
#undef max
11
#endif
12
#else
13
#include <dirent.h>
14
#include <unistd.h>
15
#endif
16
#include <fcntl.h>
17
#include <sys/stat.h>
18
#include <algorithm>
19

20
#include "crc32.h"
21
#include "fs.h"
22
#include "ftp_impl.h"
23
#include "system.h"
24

25
namespace mavsdk {
26

27
FtpImpl::FtpImpl(System& system) : PluginImplBase(system)
×
28
{
29
    _system_impl->register_plugin(this);
×
30
}
×
31

32
FtpImpl::FtpImpl(std::shared_ptr<System> system) : PluginImplBase(std::move(system))
×
33
{
34
    _system_impl->register_plugin(this);
×
35
}
×
36

37
FtpImpl::~FtpImpl()
×
38
{
39
    _system_impl->unregister_plugin(this);
×
40
}
×
41

42
void FtpImpl::init() {}
×
43

44
void FtpImpl::deinit() {}
×
45

46
void FtpImpl::enable() {}
×
47

48
void FtpImpl::disable() {}
×
49

50
void FtpImpl::reset_async(Ftp::ResultCallback callback)
×
51
{
52
    _system_impl->mavlink_ftp().reset_async([callback, this](MavlinkFtp::ClientResult result) {
×
53
        callback(result_from_mavlink_ftp_result(result));
×
54
    });
×
55
}
×
56

57
void FtpImpl::download_async(
×
58
    const std::string& remote_path, const std::string& local_folder, Ftp::DownloadCallback callback)
59
{
60
    _system_impl->mavlink_ftp().download_async(
×
61
        remote_path,
62
        local_folder,
63
        [callback, this](MavlinkFtp::ClientResult result, MavlinkFtp::ProgressData progress_data) {
×
64
            callback(
×
65
                result_from_mavlink_ftp_result(result),
66
                progress_data_from_mavlink_ftp_progress_data(progress_data));
67
        });
×
68
}
×
69

70
void FtpImpl::upload_async(
×
71
    const std::string& local_file_path,
72
    const std::string& remote_folder,
73
    Ftp::UploadCallback callback)
74
{
75
    _system_impl->mavlink_ftp().upload_async(
×
76
        local_file_path,
77
        remote_folder,
78
        [callback, this](MavlinkFtp::ClientResult result, MavlinkFtp::ProgressData progress_data) {
×
79
            callback(
×
80
                result_from_mavlink_ftp_result(result),
81
                progress_data_from_mavlink_ftp_progress_data(progress_data));
82
        });
×
83
}
×
84

85
std::pair<Ftp::Result, std::vector<std::string>> FtpImpl::list_directory(const std::string& path)
×
86
{
87
    auto ret = _system_impl->mavlink_ftp().list_directory(path);
×
88
    return std::pair{result_from_mavlink_ftp_result(ret.first), ret.second};
×
89
}
90

91
void FtpImpl::list_directory_async(
×
92
    const std::string& path, Ftp::ListDirectoryCallback callback, uint32_t offset)
93
{
94
    _system_impl->mavlink_ftp().list_directory_async(
×
95
        path,
96
        [callback, this](MavlinkFtp::ClientResult result, auto&& dirs) {
×
97
            callback(result_from_mavlink_ftp_result(result), dirs);
×
98
        },
×
99
        offset);
100
}
×
101

102
Ftp::Result FtpImpl::create_directory(const std::string& path)
×
103
{
104
    return result_from_mavlink_ftp_result(_system_impl->mavlink_ftp().create_directory(path));
×
105
}
106

107
void FtpImpl::create_directory_async(const std::string& path, Ftp::ResultCallback callback)
×
108
{
109
    _system_impl->mavlink_ftp().create_directory_async(
×
110
        path, [callback, this](MavlinkFtp::ClientResult result) {
×
111
            callback(result_from_mavlink_ftp_result(result));
×
112
        });
×
113
}
×
114

115
Ftp::Result FtpImpl::remove_directory(const std::string& path)
×
116
{
117
    return result_from_mavlink_ftp_result(_system_impl->mavlink_ftp().remove_directory(path));
×
118
}
119

120
void FtpImpl::remove_directory_async(const std::string& path, Ftp::ResultCallback callback)
×
121
{
122
    _system_impl->mavlink_ftp().remove_directory_async(
×
123
        path, [callback, this](MavlinkFtp::ClientResult result) {
×
124
            callback(result_from_mavlink_ftp_result(result));
×
125
        });
×
126
}
×
127

128
Ftp::Result FtpImpl::remove_file(const std::string& path)
×
129
{
130
    return result_from_mavlink_ftp_result(_system_impl->mavlink_ftp().remove_file(path));
×
131
}
132

133
void FtpImpl::remove_file_async(const std::string& path, Ftp::ResultCallback callback)
×
134
{
135
    _system_impl->mavlink_ftp().remove_file_async(
×
136
        path, [callback, this](MavlinkFtp::ClientResult result) {
×
137
            callback(result_from_mavlink_ftp_result(result));
×
138
        });
×
139
}
×
140

141
Ftp::Result FtpImpl::rename(const std::string& from_path, const std::string& to_path)
×
142
{
143
    return result_from_mavlink_ftp_result(_system_impl->mavlink_ftp().rename(from_path, to_path));
×
144
}
145

146
void FtpImpl::rename_async(
×
147
    const std::string& from_path, const std::string& to_path, Ftp::ResultCallback callback)
148
{
149
    _system_impl->mavlink_ftp().rename_async(
×
150
        from_path, to_path, [callback, this](MavlinkFtp::ClientResult result) {
×
151
            callback(result_from_mavlink_ftp_result(result));
×
152
        });
×
153
}
×
154

155
std::pair<Ftp::Result, bool>
156
FtpImpl::are_files_identical(const std::string& local_path, const std::string& remote_path)
×
157
{
158
    auto ret = _system_impl->mavlink_ftp().are_files_identical(local_path, remote_path);
×
159
    return std::pair<Ftp::Result, bool>{result_from_mavlink_ftp_result(ret.first), ret.second};
×
160
}
161

162
void FtpImpl::are_files_identical_async(
×
163
    const std::string& local_path,
164
    const std::string& remote_path,
165
    Ftp::AreFilesIdenticalCallback callback)
166
{
167
    _system_impl->mavlink_ftp().are_files_identical_async(
×
168
        local_path, remote_path, [callback, this](MavlinkFtp::ClientResult result, bool identical) {
×
169
            callback(result_from_mavlink_ftp_result(result), identical);
×
170
        });
×
171
}
×
172

173
Ftp::Result FtpImpl::set_root_directory(const std::string& root_dir)
×
174
{
175
    return result_from_mavlink_ftp_result(_system_impl->mavlink_ftp().set_root_directory(root_dir));
×
176
}
177

178
void FtpImpl::set_retries(uint32_t retries)
×
179
{
180
    _system_impl->mavlink_ftp().set_retries(retries);
×
181
}
×
182

183
Ftp::Result FtpImpl::set_target_compid(uint8_t component_id)
×
184
{
185
    return result_from_mavlink_ftp_result(
×
186
        _system_impl->mavlink_ftp().set_target_compid(component_id));
×
187
}
188

189
Ftp::Result FtpImpl::result_from_mavlink_ftp_result(MavlinkFtp::ClientResult result)
×
190
{
191
    switch (result) {
×
192
        case MavlinkFtp::ClientResult::Unknown:
×
193
            return Ftp::Result::Unknown;
×
194
        case MavlinkFtp::ClientResult::Success:
×
195
            return Ftp::Result::Success;
×
196
        case MavlinkFtp::ClientResult::Next:
×
197
            return Ftp::Result::Next;
×
198
        case MavlinkFtp::ClientResult::Timeout:
×
199
            return Ftp::Result::Timeout;
×
200
        case MavlinkFtp::ClientResult::Busy:
×
201
            return Ftp::Result::Busy;
×
202
        case MavlinkFtp::ClientResult::FileIoError:
×
203
            return Ftp::Result::FileIoError;
×
204
        case MavlinkFtp::ClientResult::FileExists:
×
205
            return Ftp::Result::FileExists;
×
206
        case MavlinkFtp::ClientResult::FileDoesNotExist:
×
207
            return Ftp::Result::FileDoesNotExist;
×
208
        case MavlinkFtp::ClientResult::FileProtected:
×
209
            return Ftp::Result::FileProtected;
×
210
        case MavlinkFtp::ClientResult::InvalidParameter:
×
211
            return Ftp::Result::InvalidParameter;
×
212
        case MavlinkFtp::ClientResult::Unsupported:
×
213
            return Ftp::Result::Unsupported;
×
214
        case MavlinkFtp::ClientResult::ProtocolError:
×
215
            return Ftp::Result::ProtocolError;
×
216
        case MavlinkFtp::ClientResult::NoSystem:
×
217
            return Ftp::Result::NoSystem;
×
218
        default:
×
219
            return Ftp::Result::Unknown;
×
220
    }
221
}
222

223
Ftp::ProgressData
224
FtpImpl::progress_data_from_mavlink_ftp_progress_data(MavlinkFtp::ProgressData progress_data)
×
225
{
226
    return {progress_data.bytes_transferred, progress_data.total_bytes};
×
227
}
228

229
} // namespace mavsdk
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc