aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-08-06 10:35:22 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-08-06 10:35:22 +0200
commite95946831f8ef53d29590735a2df661385edb008 (patch)
treee179b6beed4a5a0dd108f078a529ae9f8107ed8e /src
parent8bc01ff60629d9096f4b57cfb574ace672a6ef0e (diff)
downloaddabmod-e95946831f8ef53d29590735a2df661385edb008.tar.gz
dabmod-e95946831f8ef53d29590735a2df661385edb008.tar.bz2
dabmod-e95946831f8ef53d29590735a2df661385edb008.zip
Replace boost by the standalone asio library
Diffstat (limited to 'src')
-rw-r--r--src/ConfigParser.cpp2
-rw-r--r--src/RemoteControl.cpp67
-rw-r--r--src/RemoteControl.h33
-rw-r--r--src/output/UHD.cpp1
4 files changed, 40 insertions, 63 deletions
diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp
index c90b150..69655b4 100644
--- a/src/ConfigParser.cpp
+++ b/src/ConfigParser.cpp
@@ -79,7 +79,6 @@ static void parse_configfile(
}
// remote controller interfaces:
-#if defined(HAVE_BOOST)
if (pt.GetInteger("remotecontrol.telnet", 0) == 1) {
try {
int telnetport = pt.GetInteger("remotecontrol.telnetport", 0);
@@ -92,7 +91,6 @@ static void parse_configfile(
throw std::runtime_error("Configuration error");
}
}
-#endif
#if defined(HAVE_ZEROMQ)
if (pt.GetInteger("remotecontrol.zmqctrl", 0) == 1) {
try {
diff --git a/src/RemoteControl.cpp b/src/RemoteControl.cpp
index 3940ecd..9515e85 100644
--- a/src/RemoteControl.cpp
+++ b/src/RemoteControl.cpp
@@ -29,21 +29,15 @@
#include <iostream>
#include <string>
#include <thread>
-#if defined(HAVE_BOOST)
-# include <boost/asio.hpp>
-# include <boost/thread.hpp>
-#endif
+#include <asio.hpp>
#include "RemoteControl.h"
-#if defined(HAVE_BOOST)
-using boost::asio::ip::tcp;
-#endif
+using asio::ip::tcp;
using namespace std;
RemoteControllers rcs;
-#if defined(HAVE_BOOST)
RemoteControllerTelnet::~RemoteControllerTelnet()
{
m_active = false;
@@ -68,7 +62,6 @@ void RemoteControllerTelnet::restart()
&RemoteControllerTelnet::restart_thread,
this, 0);
}
-#endif
RemoteControllable::~RemoteControllable() {
rcs.remove_controllable(this);
@@ -112,7 +105,6 @@ void RemoteControllers::set_param(
}
}
-#if defined(HAVE_BOOST)
// This runs in a separate thread, because
// it would take too long to be done in the main loop
// thread.
@@ -129,9 +121,8 @@ void RemoteControllerTelnet::restart_thread(long)
}
void RemoteControllerTelnet::handle_accept(
- const boost::system::error_code& boost_error,
- boost::shared_ptr< boost::asio::ip::tcp::socket > socket,
- boost::asio::ip::tcp::acceptor& acceptor)
+ std::shared_ptr<asio::ip::tcp::socket> socket,
+ const asio::error_code& asio_error)
{
const std::string welcome = "ODR-DabMod Remote Control CLI\n"
@@ -142,8 +133,7 @@ void RemoteControllerTelnet::handle_accept(
std::string in_message;
size_t length;
- if (boost_error)
- {
+ if (asio_error) {
etiLog.level(error) << "RC: Error accepting connection";
return;
}
@@ -151,21 +141,21 @@ void RemoteControllerTelnet::handle_accept(
try {
etiLog.level(info) << "RC: Accepted";
- boost::system::error_code ignored_error;
+ asio::error_code ignored_error;
- boost::asio::write(*socket, boost::asio::buffer(welcome),
- boost::asio::transfer_all(),
+ asio::write(*socket, asio::buffer(welcome),
+ asio::transfer_all(),
ignored_error);
while (m_active && in_message != "quit") {
- boost::asio::write(*socket, boost::asio::buffer(prompt),
- boost::asio::transfer_all(),
+ asio::write(*socket, asio::buffer(prompt),
+ asio::transfer_all(),
ignored_error);
in_message = "";
- boost::asio::streambuf buffer;
- length = boost::asio::read_until(*socket, buffer, "\n", ignored_error);
+ asio::streambuf buffer;
+ length = asio::read_until(*socket, buffer, "\n", ignored_error);
std::istream str(&buffer);
std::getline(str, in_message);
@@ -206,22 +196,18 @@ void RemoteControllerTelnet::process(long)
m_io_service.reset();
tcp::acceptor acceptor(m_io_service, tcp::endpoint(
- boost::asio::ip::address::from_string("127.0.0.1"), m_port) );
-
+ asio::ip::address::from_string("127.0.0.1"), m_port) );
// Add a job to start accepting connections.
- boost::shared_ptr<tcp::socket> socket(
- new tcp::socket(acceptor.get_io_service()));
+ auto socket = make_shared<tcp::socket>(acceptor.get_io_service());
// Add an accept call to the service. This will prevent io_service::run()
// from returning.
etiLog.level(info) << "RC: Waiting for connection on port " << m_port;
acceptor.async_accept(*socket,
- boost::bind(&RemoteControllerTelnet::handle_accept,
- this,
- boost::asio::placeholders::error,
+ bind(&RemoteControllerTelnet::handle_accept, this,
socket,
- boost::ref(acceptor)));
+ std::placeholders::_1));
// Process event loop.
m_io_service.run();
@@ -231,9 +217,21 @@ void RemoteControllerTelnet::process(long)
m_fault = true;
}
+static std::vector<std::string> tokenise(const std::string& message) {
+ stringstream ss(message);
+ std::vector<std::string> all_tokens;
+ std::string item;
+
+ while (std::getline(ss, item, ' ')) {
+ all_tokens.push_back(move(item));
+ }
+ return all_tokens;
+}
+
+
void RemoteControllerTelnet::dispatch_command(tcp::socket& socket, string command)
{
- vector<string> cmd = tokenise_(command);
+ vector<string> cmd = tokenise(command);
if (cmd[0] == "help") {
reply(socket,
@@ -338,14 +336,13 @@ void RemoteControllerTelnet::dispatch_command(tcp::socket& socket, string comman
void RemoteControllerTelnet::reply(tcp::socket& socket, string message)
{
- boost::system::error_code ignored_error;
+ asio::error_code ignored_error;
stringstream ss;
ss << message << "\r\n";
- boost::asio::write(socket, boost::asio::buffer(ss.str()),
- boost::asio::transfer_all(),
+ asio::write(socket, asio::buffer(ss.str()),
+ asio::transfer_all(),
ignored_error);
}
-#endif
#if defined(HAVE_ZEROMQ)
diff --git a/src/RemoteControl.h b/src/RemoteControl.h
index 1d9ea52..733ee2d 100644
--- a/src/RemoteControl.h
+++ b/src/RemoteControl.h
@@ -3,7 +3,7 @@
Her Majesty the Queen in Right of Canada (Communications Research
Center Canada)
- Copyright (C) 2016
+ Copyright (C) 2018
Matthias P. Braendli, matthias.braendli@mpb.li
http://www.opendigitalradio.org
@@ -44,13 +44,7 @@
#include <atomic>
#include <iostream>
#include <thread>
-#if defined(HAVE_BOOST)
-#include <boost/bind.hpp>
-#include <boost/asio.hpp>
-#include <boost/foreach.hpp>
-#include <boost/tokenizer.hpp>
-#include <boost/thread.hpp>
-#endif
+#include <asio.hpp>
#include <stdexcept>
#include "Log.h"
@@ -195,7 +189,6 @@ class RemoteControllers {
extern RemoteControllers rcs;
-#if defined(HAVE_BOOST)
/* Implements a Remote controller based on a simple telnet CLI
* that listens on localhost
*/
@@ -231,29 +224,18 @@ class RemoteControllerTelnet : public BaseRemoteController {
void process(long);
- void dispatch_command(boost::asio::ip::tcp::socket& socket,
+ void dispatch_command(asio::ip::tcp::socket& socket,
std::string command);
- void reply(boost::asio::ip::tcp::socket& socket, std::string message);
+ void reply(asio::ip::tcp::socket& socket, std::string message);
void handle_accept(
- const boost::system::error_code& boost_error,
- boost::shared_ptr< boost::asio::ip::tcp::socket > socket,
- boost::asio::ip::tcp::acceptor& acceptor);
- std::vector<std::string> tokenise_(std::string message) {
- std::vector<std::string> all_tokens;
-
- boost::char_separator<char> sep(" ");
- boost::tokenizer< boost::char_separator<char> > tokens(message, sep);
- BOOST_FOREACH (const std::string& t, tokens) {
- all_tokens.push_back(t);
- }
- return all_tokens;
- }
+ std::shared_ptr<asio::ip::tcp::socket> socket,
+ const asio::error_code& asio_error);
std::atomic<bool> m_active;
- boost::asio::io_service m_io_service;
+ asio::io_service m_io_service;
/* This is set to true if a fault occurred */
std::atomic<bool> m_fault;
@@ -263,7 +245,6 @@ class RemoteControllerTelnet : public BaseRemoteController {
int m_port;
};
-#endif
#if defined(HAVE_ZEROMQ)
/* Implements a Remote controller using zmq transportlayer
diff --git a/src/output/UHD.cpp b/src/output/UHD.cpp
index e4b578e..1106fe0 100644
--- a/src/output/UHD.cpp
+++ b/src/output/UHD.cpp
@@ -37,6 +37,7 @@
#include "Utils.h"
#include <thread>
+#include <iomanip>
#include <uhd/version.hpp>
// 3.11.0.0 introduces the API breaking change, where