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

mavlink / MAVSDK / 6739182515

02 Nov 2023 11:04PM UTC coverage: 36.952% (+5.7%) from 31.229%
6739182515

push

github

web-flow
Merge pull request #2060 from mavlink/pr-split-ftp

Split Ftp plugin into Ftp and FtpServer

2002 of 2573 new or added lines in 26 files covered. (77.81%)

3 existing lines in 3 files now uncovered.

9920 of 26846 relevant lines covered (36.95%)

112.43 hits per line

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

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

5
#include "ftp_impl.h"
6
#include "system.h"
7

8
namespace mavsdk {
9

10
FtpImpl::FtpImpl(System& system) : PluginImplBase(system)
×
11
{
12
    _system_impl->register_plugin(this);
×
13
}
×
14

15
FtpImpl::FtpImpl(std::shared_ptr<System> system) : PluginImplBase(std::move(system))
24✔
16
{
17
    _system_impl->register_plugin(this);
24✔
18
}
24✔
19

20
FtpImpl::~FtpImpl()
24✔
21
{
22
    _system_impl->unregister_plugin(this);
24✔
23
}
24✔
24

25
void FtpImpl::init() {}
24✔
26

27
void FtpImpl::deinit() {}
24✔
28

29
void FtpImpl::enable() {}
24✔
30

31
void FtpImpl::disable() {}
24✔
32

33
void FtpImpl::download_async(
14✔
34
    const std::string& remote_path,
35
    const std::string& local_folder,
36
    bool use_burst,
37
    Ftp::DownloadCallback callback)
38
{
39
    _system_impl->mavlink_ftp_client().download_async(
14✔
40
        remote_path,
41
        local_folder,
42
        use_burst,
43
        [callback, this](
532✔
44
            MavlinkFtpClient::ClientResult result, MavlinkFtpClient::ProgressData progress_data) {
1,064✔
45
            callback(
532✔
46
                result_from_mavlink_ftp_result(result),
47
                progress_data_from_mavlink_ftp_progress_data(progress_data));
48
        });
532✔
49
}
14✔
50

51
void FtpImpl::upload_async(
7✔
52
    const std::string& local_file_path,
53
    const std::string& remote_folder,
54
    Ftp::UploadCallback callback)
55
{
56
    _system_impl->mavlink_ftp_client().upload_async(
7✔
57
        local_file_path,
58
        remote_folder,
59
        [callback, this](
104✔
60
            MavlinkFtpClient::ClientResult result, MavlinkFtpClient::ProgressData progress_data) {
208✔
61
            callback(
104✔
62
                result_from_mavlink_ftp_result(result),
63
                progress_data_from_mavlink_ftp_progress_data(progress_data));
64
        });
104✔
65
}
7✔
66

67
std::pair<Ftp::Result, std::vector<std::string>> FtpImpl::list_directory(const std::string& path)
2✔
68
{
69
    std::promise<std::pair<Ftp::Result, std::vector<std::string>>> prom;
4✔
70
    auto fut = prom.get_future();
4✔
71

72
    list_directory_async(path, [&](Ftp::Result result, std::vector<std::string> list) {
2✔
73
        prom.set_value(std::pair<Ftp::Result, std::vector<std::string>>{result, list});
2✔
74
    });
2✔
75
    return fut.get();
2✔
76
}
77

78
void FtpImpl::list_directory_async(const std::string& path, Ftp::ListDirectoryCallback callback)
2✔
79
{
80
    _system_impl->mavlink_ftp_client().list_directory_async(
2✔
81
        path, [callback, this](MavlinkFtpClient::ClientResult result, auto&& dirs) {
6✔
82
            if (callback) {
2✔
83
                _system_impl->call_user_callback([temp_callback = callback, result, dirs, this]() {
4✔
84
                    temp_callback(result_from_mavlink_ftp_result(result), dirs);
85
                });
86
            }
87
        });
2✔
88
}
2✔
89

90
Ftp::Result FtpImpl::create_directory(const std::string& path)
3✔
91
{
92
    std::promise<Ftp::Result> prom{};
6✔
93
    auto fut = prom.get_future();
6✔
94

95
    create_directory_async(path, [&](Ftp::Result result) { prom.set_value(result); });
6✔
96
    return fut.get();
3✔
97
}
98

99
void FtpImpl::create_directory_async(const std::string& path, Ftp::ResultCallback callback)
3✔
100
{
101
    _system_impl->mavlink_ftp_client().create_directory_async(
3✔
102
        path, [callback, this](MavlinkFtpClient::ClientResult result) {
3✔
103
            callback(result_from_mavlink_ftp_result(result));
3✔
104
        });
3✔
105
}
3✔
106

107
Ftp::Result FtpImpl::remove_directory(const std::string& path)
2✔
108
{
109
    std::promise<Ftp::Result> prom{};
4✔
110
    auto fut = prom.get_future();
4✔
111

112
    remove_directory_async(path, [&](Ftp::Result result) { prom.set_value(result); });
4✔
113

114
    return fut.get();
2✔
115
}
116

117
void FtpImpl::remove_directory_async(const std::string& path, Ftp::ResultCallback callback)
2✔
118
{
119
    _system_impl->mavlink_ftp_client().remove_directory_async(
2✔
120
        path, [callback, this](MavlinkFtpClient::ClientResult result) {
2✔
121
            callback(result_from_mavlink_ftp_result(result));
2✔
122
        });
2✔
123
}
2✔
124

125
Ftp::Result FtpImpl::remove_file(const std::string& path)
4✔
126
{
127
    std::promise<Ftp::Result> prom;
8✔
128
    auto fut = prom.get_future();
8✔
129

130
    remove_file_async(path, [&](Ftp::Result result) { prom.set_value(result); });
8✔
131

132
    return fut.get();
4✔
133
}
134

135
void FtpImpl::remove_file_async(const std::string& path, Ftp::ResultCallback callback)
4✔
136
{
137
    _system_impl->mavlink_ftp_client().remove_file_async(
4✔
138
        path, [callback, this](MavlinkFtpClient::ClientResult result) {
4✔
139
            callback(result_from_mavlink_ftp_result(result));
4✔
140
        });
4✔
141
}
4✔
142

143
Ftp::Result FtpImpl::rename(const std::string& from_path, const std::string& to_path)
2✔
144
{
145
    std::promise<Ftp::Result> prom{};
4✔
146
    auto fut = prom.get_future();
4✔
147

148
    rename_async(from_path, to_path, [&](Ftp::Result result) { prom.set_value(result); });
4✔
149

150
    return fut.get();
2✔
151
}
152

153
void FtpImpl::rename_async(
2✔
154
    const std::string& from_path, const std::string& to_path, Ftp::ResultCallback callback)
155
{
156
    _system_impl->mavlink_ftp_client().rename_async(
2✔
157
        from_path, to_path, [callback, this](MavlinkFtpClient::ClientResult result) {
2✔
158
            callback(result_from_mavlink_ftp_result(result));
2✔
159
        });
2✔
160
}
2✔
161

162
std::pair<Ftp::Result, bool>
163
FtpImpl::are_files_identical(const std::string& local_path, const std::string& remote_path)
3✔
164
{
165
    std::promise<std::pair<Ftp::Result, bool>> prom{};
6✔
166
    auto fut = prom.get_future();
6✔
167

168
    are_files_identical_async(local_path, remote_path, [&](Ftp::Result result, bool identical) {
3✔
169
        prom.set_value(std::pair<Ftp::Result, bool>{result, identical});
3✔
170
    });
3✔
171

172
    return fut.get();
3✔
173
}
174

175
void FtpImpl::are_files_identical_async(
3✔
176
    const std::string& local_path,
177
    const std::string& remote_path,
178
    Ftp::AreFilesIdenticalCallback callback)
179
{
180
    _system_impl->mavlink_ftp_client().are_files_identical_async(
3✔
181
        local_path,
182
        remote_path,
183
        [callback, this](MavlinkFtpClient::ClientResult result, bool identical) {
3✔
184
            callback(result_from_mavlink_ftp_result(result), identical);
3✔
185
        });
3✔
186
}
3✔
187

188
Ftp::Result FtpImpl::set_target_compid(uint8_t component_id)
×
189
{
190
    return result_from_mavlink_ftp_result(
×
NEW
191
        _system_impl->mavlink_ftp_client().set_target_compid(component_id));
×
192
}
193

194
Ftp::Result FtpImpl::result_from_mavlink_ftp_result(MavlinkFtpClient::ClientResult result)
652✔
195
{
196
    switch (result) {
652✔
NEW
197
        case MavlinkFtpClient::ClientResult::Unknown:
×
198
            return Ftp::Result::Unknown;
×
199
        case MavlinkFtpClient::ClientResult::Success:
19✔
200
            return Ftp::Result::Success;
19✔
201
        case MavlinkFtpClient::ClientResult::Next:
615✔
202
            return Ftp::Result::Next;
615✔
203
        case MavlinkFtpClient::ClientResult::Timeout:
3✔
204
            return Ftp::Result::Timeout;
3✔
NEW
205
        case MavlinkFtpClient::ClientResult::Busy:
×
206
            return Ftp::Result::Busy;
×
NEW
207
        case MavlinkFtpClient::ClientResult::FileIoError:
×
208
            return Ftp::Result::FileIoError;
×
NEW
209
        case MavlinkFtpClient::ClientResult::FileExists:
×
210
            return Ftp::Result::FileExists;
×
211
        case MavlinkFtpClient::ClientResult::FileDoesNotExist:
1✔
212
            return Ftp::Result::FileDoesNotExist;
1✔
NEW
213
        case MavlinkFtpClient::ClientResult::FileProtected:
×
214
            return Ftp::Result::FileProtected;
×
NEW
215
        case MavlinkFtpClient::ClientResult::InvalidParameter:
×
216
            return Ftp::Result::InvalidParameter;
×
NEW
217
        case MavlinkFtpClient::ClientResult::Unsupported:
×
218
            return Ftp::Result::Unsupported;
×
219
        case MavlinkFtpClient::ClientResult::ProtocolError:
14✔
220
            return Ftp::Result::ProtocolError;
14✔
NEW
221
        case MavlinkFtpClient::ClientResult::NoSystem:
×
222
            return Ftp::Result::NoSystem;
×
223
        default:
×
224
            return Ftp::Result::Unknown;
×
225
    }
226
}
227

228
Ftp::ProgressData
229
FtpImpl::progress_data_from_mavlink_ftp_progress_data(MavlinkFtpClient::ProgressData progress_data)
636✔
230
{
231
    return {progress_data.bytes_transferred, progress_data.total_bytes};
636✔
232
}
233

234
} // 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

© 2025 Coveralls, Inc