28 lines
762 B
C++
28 lines
762 B
C++
#ifndef AIRPORT_TCP_DATA_SOURCE_H
|
|
#define AIRPORT_TCP_DATA_SOURCE_H
|
|
|
|
#include "DataSource.h"
|
|
#include "ConnectionConfig.h"
|
|
#include <boost/asio.hpp>
|
|
|
|
class TCPDataSource : public DataSource {
|
|
public:
|
|
explicit TCPDataSource(const ConnectionConfig& config);
|
|
~TCPDataSource() override;
|
|
|
|
bool isAvailable() const override;
|
|
bool connect() override;
|
|
void disconnect() override;
|
|
std::optional<VehicleData> getData() override;
|
|
|
|
private:
|
|
ConnectionConfig config_;
|
|
boost::asio::io_context io_context_;
|
|
std::unique_ptr<boost::asio::ip::tcp::socket> socket_;
|
|
bool connected_{false};
|
|
|
|
bool readData(std::vector<char>& buffer);
|
|
VehicleData parseData(const std::vector<char>& buffer);
|
|
};
|
|
|
|
#endif // AIRPORT_TCP_DATA_SOURCE_H
|