-
Notifications
You must be signed in to change notification settings - Fork 0
/
udp_connection.h
58 lines (44 loc) · 1.3 KB
/
udp_connection.h
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
#pragma once
#include <string>
#include <mutex>
#include <thread>
#include <atomic>
#include <vector>
#include <cstdint>
#include "connection.h"
namespace mavsdk {
class UdpConnection : public Connection {
public:
explicit UdpConnection(
Connection::receiver_callback_t receiver_callback,
const std::string& local_ip,
int local_port);
~UdpConnection();
ConnectionResult start() override;
ConnectionResult stop() override;
bool send_message(const mavlink_message_t& message) override;
void add_remote(const std::string& remote_ip, const int remote_port);
// Non-copyable
UdpConnection(const UdpConnection&) = delete;
const UdpConnection& operator=(const UdpConnection&) = delete;
private:
ConnectionResult setup_port();
void start_recv_thread();
void receive();
std::string _local_ip;
int _local_port_number;
std::mutex _remote_mutex{};
struct Remote {
std::string ip{};
int port_number{0};
bool operator==(const UdpConnection::Remote& other)
{
return ip == other.ip && port_number == other.port_number;
}
};
std::vector<Remote> _remotes{};
int _socket_fd{-1};
std::thread* _recv_thread{nullptr};
std::atomic_bool _should_exit{false};
};
} // namespace mavsdk