Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions DeviceAdapters/SerialManager/AsioClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,14 @@
#include <vector>


#include <boost/version.hpp>
#if BOOST_VERSION >= 104700
typedef boost::asio::serial_port::native_handle_type SerialNativeHandle;
#else
typedef boost::asio::serial_port::native_type SerialNativeHandle;
#endif


class AsioClient
{
public:
// Construct from an already open native handle.
AsioClient(boost::asio::io_service& ioService,
AsioClient(boost::asio::io_context& ioContext,
const std::string& deviceName,
SerialNativeHandle nativeHandle,
unsigned int baud,
Expand All @@ -58,8 +53,8 @@ class AsioClient
unsigned dataBits,
SerialPort* pPort) :
active_(true),
io_service_(ioService),
serialPortImplementation_(ioService, nativeHandle),
io_context_(ioContext),
serialPortImplementation_(ioContext, nativeHandle),
pSerialPortAdapter_(pPort),
device_(deviceName),
shutDownInProgress_(false)
Expand All @@ -68,7 +63,7 @@ class AsioClient
}

// Construct and open the given device name.
AsioClient(boost::asio::io_service& ioService,
AsioClient(boost::asio::io_context& ioContext,
unsigned int baud,
const std::string& deviceName,
boost::asio::serial_port::flow_control::type flow,
Expand All @@ -77,8 +72,8 @@ class AsioClient
unsigned dataBits,
SerialPort* pPort) :
active_(true),
io_service_(ioService),
serialPortImplementation_(ioService, deviceName),
io_context_(ioContext),
serialPortImplementation_(ioContext, deviceName),
pSerialPortAdapter_(pPort),
device_(deviceName),
shutDownInProgress_(false)
Expand Down Expand Up @@ -251,13 +246,13 @@ class AsioClient

void WriteOneCharacterAsynchronously(const char ch)
{
io_service_.post(boost::bind(&AsioClient::DoWriteCh, this, ch));
boost::asio::post(io_context_, boost::bind(&AsioClient::DoWriteCh, this, ch));
}

void WriteCharactersAsynchronously(const char* pmsg, size_t len)
{
std::vector<char> msg(pmsg, pmsg + len);
io_service_.post(boost::bind(&AsioClient::DoWriteMsg, this, msg));
boost::asio::post(io_context_, boost::bind(&AsioClient::DoWriteMsg, this, msg));
}


Expand Down Expand Up @@ -295,7 +290,7 @@ class AsioClient
{
if (active_)
{
io_service_.post(boost::bind(&AsioClient::DoClose, this, boost::system::error_code()));
boost::asio::post(io_context_, boost::bind(&AsioClient::DoClose, this, boost::system::error_code()));
}
}

Expand Down Expand Up @@ -458,7 +453,7 @@ class AsioClient

private:
bool active_; // remains true while this object is still operating
boost::asio::io_service& io_service_; // the main IO service that runs this connection
boost::asio::io_context& io_context_; // the main IO context that runs this connection
boost::asio::serial_port serialPortImplementation_; // the serial port this instance is connected to
char read_msg_[max_read_length]; // data read from the socket
std::deque< std::vector<char> > write_msgs_; // buffered write data
Expand Down
8 changes: 3 additions & 5 deletions DeviceAdapters/SerialManager/SerialManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <dirent.h>
#endif

#include <boost/bind/bind.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -100,7 +99,7 @@ bool SerialPortLister::portAccessible(const char* portName)
{
try
{
boost::asio::io_service service;
boost::asio::io_context service;
boost::asio::serial_port sp(service, portName);

if (sp.is_open()) {
Expand Down Expand Up @@ -509,7 +508,7 @@ int SerialPort::Initialize()
ret = GetCurrentPropertyData(MM::g_Keyword_Handshaking, handshake);
assert(ret == DEVICE_OK);

pService_ = new boost::asio::io_service();
pService_ = new boost::asio::io_context();

try
{
Expand Down Expand Up @@ -557,8 +556,7 @@ int SerialPort::Initialize()

try
{
pThread_ = new boost::thread(boost::bind(
&boost::asio::io_service::run, pService_));
pThread_ = new boost::thread([this] { pService_->run(); });
}
catch (std::exception& what)
{
Expand Down
2 changes: 1 addition & 1 deletion DeviceAdapters/SerialManager/SerialManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class SerialPort : public CSerialBase<SerialPort>
std::string parity_;

// create these varaiable in the order of declaration
boost::asio::io_service* pService_;
boost::asio::io_context* pService_;
AsioClient* pPort_;
// the worker thread
boost::thread* pThread_;
Expand Down
Loading