-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmavlink_command_transfer.cpp
61 lines (47 loc) · 1.39 KB
/
mavlink_command_transfer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iomanip>
#include "mavlink_command_transfer.h"
namespace mavsdk {
MAVLinkCommandTransfer::MAVLinkCommandTransfer(
Sender& sender, MAVLinkMessageHandler& message_handler, TimeoutHandler& timeout_handler) :
_sender(sender),
_message_handler(message_handler),
_timeout_handler(timeout_handler)
{}
MAVLinkCommandTransfer::~MAVLinkCommandTransfer() {}
void MAVLinkCommandTransfer::do_work()
{
LockedQueue<WorkItem>::Guard work_queue_guard(_work_queue);
auto work = work_queue_guard.get_front();
if (!work) {
return;
}
if (!work->has_started()) {
work->start();
}
if (work->is_done()) {
work_queue_guard.pop_front();
}
}
bool MAVLinkCommandTransfer::is_idle()
{
LockedQueue<WorkItem>::Guard work_queue_guard(_work_queue);
return (work_queue_guard.get_front() == nullptr);
}
MAVLinkCommandTransfer::WorkItem::WorkItem(
Sender& sender, MAVLinkMessageHandler& message_handler, TimeoutHandler& timeout_handler) :
_sender(sender),
_message_handler(message_handler),
_timeout_handler(timeout_handler)
{}
MAVLinkCommandTransfer::WorkItem::~WorkItem() {}
bool MAVLinkCommandTransfer::WorkItem::has_started()
{
std::lock_guard<std::mutex> lock(_mutex);
return _started;
}
bool MAVLinkCommandTransfer::WorkItem::is_done()
{
std::lock_guard<std::mutex> lock(_mutex);
return _done;
}
} // namespace mavsdk