1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-02-15 10:30:09 +00:00

Merge remote-tracking branch 'cf/io-service' into next

Replace boost::asio::io_service (deprecated since Boost 1.66) by boost::asio::io_context when Boost is 1.66 or above.

boost::asio::io_service is now deprecated and eventually will be removed from future Boost versions. This fix avoids a future compilation break.
This commit is contained in:
Carles Fernandez 2019-05-08 20:42:08 +02:00
commit a5f9c3ac36
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
16 changed files with 93 additions and 22 deletions

View File

@ -37,6 +37,7 @@
- Usage of clang-tidy integrated into CMake scripts. New option -DENABLE_CLANG_TIDY=ON executes clang-tidy along with compilation. Requires clang compiler. - Usage of clang-tidy integrated into CMake scripts. New option -DENABLE_CLANG_TIDY=ON executes clang-tidy along with compilation. Requires clang compiler.
- Applied clang-tidy checks and fixes related to readability: readability-container-size-empty, readability-identifier-naming, readability-inconsistent-declaration-parameter-name, readability-named-parameter, readability-non-const-parameter, readability-string-compare. - Applied clang-tidy checks and fixes related to readability: readability-container-size-empty, readability-identifier-naming, readability-inconsistent-declaration-parameter-name, readability-named-parameter, readability-non-const-parameter, readability-string-compare.
- Improved includes selection following suggestions by include-what-you-use (see https://include-what-you-use.org/), allowing faster compiles, fewer recompiles and making refactoring easier. - Improved includes selection following suggestions by include-what-you-use (see https://include-what-you-use.org/), allowing faster compiles, fewer recompiles and making refactoring easier.
- Deprecated boost::asio::io_service replaced by boost::asio::io_context if Boost > 1.65
### Improvements in Portability: ### Improvements in Portability:

View File

@ -87,6 +87,13 @@ target_include_directories(pvt_libs
target_compile_definitions(pvt_libs PRIVATE -DGNSS_SDR_VERSION="${VERSION}") target_compile_definitions(pvt_libs PRIVATE -DGNSS_SDR_VERSION="${VERSION}")
if(Boost_VERSION VERSION_GREATER "106500")
target_compile_definitions(pvt_libs
PUBLIC
-DBOOST_GREATER_1_65
)
endif()
if(OS_IS_MACOSX) if(OS_IS_MACOSX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # not AppleClang if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # not AppleClang
target_compile_definitions(pvt_libs target_compile_definitions(pvt_libs

View File

@ -35,7 +35,7 @@
#include <sstream> #include <sstream>
Monitor_Pvt_Udp_Sink::Monitor_Pvt_Udp_Sink(std::vector<std::string> addresses, const uint16_t& port, bool protobuf_enabled) : socket{io_service} Monitor_Pvt_Udp_Sink::Monitor_Pvt_Udp_Sink(std::vector<std::string> addresses, const uint16_t& port, bool protobuf_enabled) : socket{io_context}
{ {
for (const auto& address : addresses) for (const auto& address : addresses)
{ {

View File

@ -36,6 +36,12 @@
#include "serdes_monitor_pvt.h" #include "serdes_monitor_pvt.h"
#include <boost/asio.hpp> #include <boost/asio.hpp>
#if BOOST_GREATER_1_65
using b_io_context = boost::asio::io_context;
#else
using b_io_context = boost::asio::io_service;
#endif
class Monitor_Pvt_Udp_Sink class Monitor_Pvt_Udp_Sink
{ {
public: public:
@ -43,7 +49,7 @@ public:
bool write_monitor_pvt(const Monitor_Pvt &monitor_pvt); bool write_monitor_pvt(const Monitor_Pvt &monitor_pvt);
private: private:
boost::asio::io_service io_service; b_io_context io_context;
boost::asio::ip::udp::socket socket; boost::asio::ip::udp::socket socket;
boost::system::error_code error; boost::system::error_code error;
std::vector<boost::asio::ip::udp::endpoint> endpoints; std::vector<boost::asio::ip::udp::endpoint> endpoints;

View File

@ -56,6 +56,12 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#if BOOST_GREATER_1_65
using b_io_context = boost::asio::io_context;
#else
using b_io_context = boost::asio::io_service;
#endif
/*! /*!
* \brief This class implements the generation and reading of some Message Types * \brief This class implements the generation and reading of some Message Types
@ -757,7 +763,7 @@ private:
: public std::enable_shared_from_this<Tcp_Internal_Client> : public std::enable_shared_from_this<Tcp_Internal_Client>
{ {
public: public:
Tcp_Internal_Client(boost::asio::io_service& io_context, Tcp_Internal_Client(b_io_context& io_context,
boost::asio::ip::tcp::resolver::iterator endpoint_iterator) boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
: io_context_(io_context), socket_(io_context) : io_context_(io_context), socket_(io_context)
{ {
@ -835,7 +841,7 @@ private:
}); });
} }
boost::asio::io_service& io_context_; b_io_context& io_context_;
boost::asio::ip::tcp::socket socket_; boost::asio::ip::tcp::socket socket_;
Rtcm_Message read_msg_; Rtcm_Message read_msg_;
std::deque<Rtcm_Message> write_msgs_; std::deque<Rtcm_Message> write_msgs_;
@ -845,7 +851,7 @@ private:
class Queue_Reader class Queue_Reader
{ {
public: public:
Queue_Reader(boost::asio::io_service& io_context, std::shared_ptr<Concurrent_Queue<std::string> >& queue, int32_t port) : queue_(queue) Queue_Reader(b_io_context& io_context, std::shared_ptr<Concurrent_Queue<std::string> >& queue, int32_t port) : queue_(queue)
{ {
boost::asio::ip::tcp::resolver resolver(io_context); boost::asio::ip::tcp::resolver resolver(io_context);
std::string host("localhost"); std::string host("localhost");
@ -883,7 +889,7 @@ private:
class Tcp_Server class Tcp_Server
{ {
public: public:
Tcp_Server(boost::asio::io_service& io_context, const boost::asio::ip::tcp::endpoint& endpoint) Tcp_Server(b_io_context& io_context, const boost::asio::ip::tcp::endpoint& endpoint)
: acceptor_(io_context), socket_(io_context) : acceptor_(io_context), socket_(io_context)
{ {
acceptor_.open(endpoint.protocol()); acceptor_.open(endpoint.protocol());
@ -950,7 +956,7 @@ private:
bool start_session = true; bool start_session = true;
}; };
boost::asio::io_service io_context; b_io_context io_context;
std::shared_ptr<Concurrent_Queue<std::string> > rtcm_message_queue; std::shared_ptr<Concurrent_Queue<std::string> > rtcm_message_queue;
std::thread t; std::thread t;
std::thread tq; std::thread tq;

View File

@ -85,6 +85,13 @@ if(OS_IS_MACOSX)
endif() endif()
endif() endif()
if(Boost_VERSION VERSION_GREATER "106500")
target_compile_definitions(signal_source_gr_blocks
PUBLIC
-DBOOST_GREATER_1_65
)
endif()
if(ENABLE_CLANG_TIDY) if(ENABLE_CLANG_TIDY)
if(CLANG_TIDY_EXE) if(CLANG_TIDY_EXE)
set_target_properties(signal_source_gr_blocks set_target_properties(signal_source_gr_blocks

View File

@ -65,7 +65,7 @@ rtl_tcp_signal_source_c::rtl_tcp_signal_source_c(const std::string &address,
: gr::sync_block("rtl_tcp_signal_source_c", : gr::sync_block("rtl_tcp_signal_source_c",
gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0),
gr::io_signature::make(1, 1, sizeof(gr_complex))), gr::io_signature::make(1, 1, sizeof(gr_complex))),
socket_(io_service_), socket_(io_context_),
data_(RTL_TCP_PAYLOAD_SIZE), data_(RTL_TCP_PAYLOAD_SIZE),
flip_iq_(flip_iq), flip_iq_(flip_iq),
buffer_(RTL_TCP_BUFFER_SIZE), buffer_(RTL_TCP_BUFFER_SIZE),
@ -147,14 +147,14 @@ rtl_tcp_signal_source_c::rtl_tcp_signal_source_c(const std::string &address,
boost::asio::async_read(socket_, boost::asio::buffer(data_), boost::asio::async_read(socket_, boost::asio::buffer(data_),
boost::bind(&rtl_tcp_signal_source_c::handle_read, boost::bind(&rtl_tcp_signal_source_c::handle_read,
this, _1, _2)); this, _1, _2));
boost::thread(boost::bind(&boost::asio::io_service::run, &io_service_)); boost::thread(boost::bind(&b_io_context::run, &io_context_));
} }
rtl_tcp_signal_source_c::~rtl_tcp_signal_source_c() // NOLINT(modernize-use-equals-default) rtl_tcp_signal_source_c::~rtl_tcp_signal_source_c() // NOLINT(modernize-use-equals-default)
{ {
mutex_.unlock(); mutex_.unlock();
io_service_.stop(); io_context_.stop();
not_empty_.notify_one(); not_empty_.notify_one();
not_full_.notify_one(); not_full_.notify_one();
} }
@ -289,7 +289,7 @@ void rtl_tcp_signal_source_c::handle_read(const boost::system::error_code &ec,
std::cout << "Error during read: " << ec << std::endl; std::cout << "Error during read: " << ec << std::endl;
LOG(WARNING) << "Error during read: " << ec; LOG(WARNING) << "Error during read: " << ec;
boost::mutex::scoped_lock lock(mutex_); boost::mutex::scoped_lock lock(mutex_);
io_service_.stop(); io_context_.stop();
not_empty_.notify_one(); not_empty_.notify_one();
} }
else else
@ -334,7 +334,7 @@ int rtl_tcp_signal_source_c::work(int noutput_items,
{ {
auto *out = reinterpret_cast<gr_complex *>(output_items[0]); auto *out = reinterpret_cast<gr_complex *>(output_items[0]);
int i = 0; int i = 0;
if (io_service_.stopped()) if (io_context_.stopped())
{ {
return -1; return -1;
} }

View File

@ -52,6 +52,12 @@ class rtl_tcp_signal_source_c;
using rtl_tcp_signal_source_c_sptr = boost::shared_ptr<rtl_tcp_signal_source_c>; using rtl_tcp_signal_source_c_sptr = boost::shared_ptr<rtl_tcp_signal_source_c>;
#if BOOST_GREATER_1_65
using b_io_context = boost::asio::io_context;
#else
using b_io_context = boost::asio::io_service;
#endif
rtl_tcp_signal_source_c_sptr rtl_tcp_signal_source_c_sptr
rtl_tcp_make_signal_source_c(const std::string &address, rtl_tcp_make_signal_source_c(const std::string &address,
int16_t port, int16_t port,
@ -91,7 +97,7 @@ private:
Rtl_Tcp_Dongle_Info info_; Rtl_Tcp_Dongle_Info info_;
// IO members // IO members
boost::asio::io_service io_service_; b_io_context io_context_;
boost::asio::ip::tcp::socket socket_; boost::asio::ip::tcp::socket socket_;
std::vector<unsigned char> data_; std::vector<unsigned char> data_;
bool flip_iq_; bool flip_iq_;
@ -117,7 +123,7 @@ private:
inline bool not_empty() const inline bool not_empty() const
{ {
return unread_ > 0 || io_service_.stopped(); return unread_ > 0 || io_context_.stopped();
} }
}; };

View File

@ -93,6 +93,13 @@ target_include_directories(tracking_libs
${OPT_TRACKING_INCLUDES} ${OPT_TRACKING_INCLUDES}
) )
if(Boost_VERSION VERSION_GREATER "106500")
target_compile_definitions(tracking_libs
PUBLIC
-DBOOST_GREATER_1_65
)
endif()
if(OS_IS_MACOSX) if(OS_IS_MACOSX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # not AppleClang if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # not AppleClang
target_compile_definitions(tracking_libs target_compile_definitions(tracking_libs

View File

@ -35,7 +35,7 @@
#include <string> #include <string>
Tcp_Communication::Tcp_Communication() : tcp_socket_(io_service_) {} // NOLINT Tcp_Communication::Tcp_Communication() : tcp_socket_(io_context_) {} // NOLINT
Tcp_Communication::~Tcp_Communication() = default; Tcp_Communication::~Tcp_Communication() = default;
@ -47,7 +47,7 @@ int Tcp_Communication::listen_tcp_connection(size_t d_port_, size_t d_port_ch0_)
{ {
// Specify IP type and port // Specify IP type and port
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), d_port_); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), d_port_);
boost::asio::ip::tcp::acceptor acceptor(io_service_, endpoint); boost::asio::ip::tcp::acceptor acceptor(io_context_, endpoint);
if (d_port_ == d_port_ch0_) if (d_port_ == d_port_ch0_)
{ {

View File

@ -36,6 +36,12 @@
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#if BOOST_GREATER_1_65
using b_io_context = boost::asio::io_context;
#else
using b_io_context = boost::asio::io_service;
#endif
#define NUM_TX_VARIABLES_GALILEO_E1 13 #define NUM_TX_VARIABLES_GALILEO_E1 13
#define NUM_TX_VARIABLES_GPS_L1_CA 9 #define NUM_TX_VARIABLES_GPS_L1_CA 9
#define NUM_RX_VARIABLES 4 #define NUM_RX_VARIABLES 4
@ -55,7 +61,7 @@ public:
void close_tcp_connection(size_t d_port_); void close_tcp_connection(size_t d_port_);
private: private:
boost::asio::io_service io_service_; b_io_context io_context_;
boost::asio::ip::tcp::socket tcp_socket_; boost::asio::ip::tcp::socket tcp_socket_;
}; };

View File

@ -59,6 +59,15 @@ target_include_directories(core_monitor
${PROTO_INCLUDE_HEADERS} ${PROTO_INCLUDE_HEADERS}
) )
if(Boost_VERSION VERSION_GREATER "106500")
target_compile_definitions(core_monitor
PUBLIC
-DBOOST_GREATER_1_65
)
endif()
if(OS_IS_MACOSX) if(OS_IS_MACOSX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # not AppleClang if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # not AppleClang
target_compile_definitions(core_monitor target_compile_definitions(core_monitor

View File

@ -35,7 +35,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
Gnss_Synchro_Udp_Sink::Gnss_Synchro_Udp_Sink(std::vector<std::string> addresses, const uint16_t& port, bool enable_protobuf) : socket{io_service} Gnss_Synchro_Udp_Sink::Gnss_Synchro_Udp_Sink(std::vector<std::string> addresses, const uint16_t& port, bool enable_protobuf) : socket{io_context}
{ {
use_protobuf = enable_protobuf; use_protobuf = enable_protobuf;
if (enable_protobuf) if (enable_protobuf)

View File

@ -40,6 +40,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#if BOOST_GREATER_1_65
using b_io_context = boost::asio::io_context;
#else
using b_io_context = boost::asio::io_service;
#endif
/*! /*!
* \brief This class sends serialized Gnss_Synchro objects * \brief This class sends serialized Gnss_Synchro objects
@ -52,7 +57,7 @@ public:
bool write_gnss_synchro(const std::vector<Gnss_Synchro>& stocks); bool write_gnss_synchro(const std::vector<Gnss_Synchro>& stocks);
private: private:
boost::asio::io_service io_service; b_io_context io_context;
boost::asio::ip::udp::socket socket; boost::asio::ip::udp::socket socket;
boost::system::error_code error; boost::system::error_code error;
std::vector<boost::asio::ip::udp::endpoint> endpoints; std::vector<boost::asio::ip::udp::endpoint> endpoints;

View File

@ -129,6 +129,12 @@ if(ENABLE_CUDA)
target_compile_definitions(core_receiver PRIVATE -DCUDA_GPU_ACCEL=1) target_compile_definitions(core_receiver PRIVATE -DCUDA_GPU_ACCEL=1)
endif() endif()
if(Boost_VERSION VERSION_GREATER "106500")
target_compile_definitions(core_receiver
PRIVATE
-DBOOST_GREATER_1_65
)
endif()
target_link_libraries(core_receiver target_link_libraries(core_receiver
PUBLIC PUBLIC

View File

@ -39,6 +39,11 @@
#include <sstream> // for stringstream #include <sstream> // for stringstream
#include <utility> // for move #include <utility> // for move
#if BOOST_GREATER_1_65
using b_io_context = boost::asio::io_context;
#else
using b_io_context = boost::asio::io_service;
#endif
TcpCmdInterface::TcpCmdInterface() TcpCmdInterface::TcpCmdInterface()
{ {
@ -305,10 +310,10 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
boost::system::error_code not_throw; boost::system::error_code not_throw;
// Socket and acceptor // Socket and acceptor
boost::asio::io_service service; b_io_context context;
try try
{ {
boost::asio::ip::tcp::acceptor acceptor(service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)); boost::asio::ip::tcp::acceptor acceptor(context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port));
while (keep_running_) while (keep_running_)
{ {
@ -316,7 +321,7 @@ void TcpCmdInterface::run_cmd_server(int tcp_port)
{ {
std::cout << "TcpCmdInterface: Telecommand TCP interface listening on port " << tcp_port << std::endl; std::cout << "TcpCmdInterface: Telecommand TCP interface listening on port " << tcp_port << std::endl;
boost::asio::ip::tcp::socket socket(service); boost::asio::ip::tcp::socket socket(context);
acceptor.accept(socket, not_throw); acceptor.accept(socket, not_throw);
if (not_throw) if (not_throw)
{ {