mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 15:46:42 +02:00
Remove unused shared_from_this
This commit is contained in:
parent
a01f61b3c8
commit
7b268b83df
8 changed files with 30 additions and 39 deletions
|
@ -62,9 +62,8 @@ void PublishAvahi::publish(const std::vector<mDNSService>& services)
|
||||||
|
|
||||||
void PublishAvahi::poll()
|
void PublishAvahi::poll()
|
||||||
{
|
{
|
||||||
auto self = shared_from_this();
|
|
||||||
timer_.expires_after(std::chrono::milliseconds(50));
|
timer_.expires_after(std::chrono::milliseconds(50));
|
||||||
timer_.async_wait([self, this](const boost::system::error_code& ec) {
|
timer_.async_wait([this](const boost::system::error_code& ec) {
|
||||||
if (!ec && (avahi_simple_poll_iterate(simple_poll, 0) == 0))
|
if (!ec && (avahi_simple_poll_iterate(simple_poll, 0) == 0))
|
||||||
poll();
|
poll();
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,7 +36,7 @@ class PublishAvahi;
|
||||||
|
|
||||||
#include "publish_mdns.hpp"
|
#include "publish_mdns.hpp"
|
||||||
|
|
||||||
class PublishAvahi : public PublishmDNS, public std::enable_shared_from_this<PublishAvahi>
|
class PublishAvahi : public PublishmDNS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PublishAvahi(const std::string& serviceName, boost::asio::io_context& ioc);
|
PublishAvahi(const std::string& serviceName, boost::asio::io_context& ioc);
|
||||||
|
|
|
@ -239,7 +239,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
boost::asio::io_context io_context;
|
boost::asio::io_context io_context;
|
||||||
#if defined(HAS_AVAHI) || defined(HAS_BONJOUR)
|
#if defined(HAS_AVAHI) || defined(HAS_BONJOUR)
|
||||||
auto publishZeroConfg = std::make_shared<PublishZeroConf>("Snapcast", io_context);
|
auto publishZeroConfg = std::make_unique<PublishZeroConf>("Snapcast", io_context);
|
||||||
vector<mDNSService> dns_services;
|
vector<mDNSService> dns_services;
|
||||||
dns_services.emplace_back("_snapcast._tcp", settings.stream.port);
|
dns_services.emplace_back("_snapcast._tcp", settings.stream.port);
|
||||||
dns_services.emplace_back("_snapcast-stream._tcp", settings.stream.port);
|
dns_services.emplace_back("_snapcast-stream._tcp", settings.stream.port);
|
||||||
|
|
|
@ -168,8 +168,7 @@ void StreamSession::send_next()
|
||||||
|
|
||||||
void StreamSession::sendAsync(shared_const_buffer const_buf, bool send_now)
|
void StreamSession::sendAsync(shared_const_buffer const_buf, bool send_now)
|
||||||
{
|
{
|
||||||
auto self = shared_from_this();
|
strand_.post([this, const_buf, send_now]() {
|
||||||
strand_.post([this, self, const_buf, send_now]() {
|
|
||||||
if (send_now)
|
if (send_now)
|
||||||
messages_.push_front(const_buf);
|
messages_.push_front(const_buf);
|
||||||
else
|
else
|
||||||
|
|
|
@ -166,8 +166,7 @@ void AirplayStream::pipeReadLine()
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string delimiter = "\n";
|
const std::string delimiter = "\n";
|
||||||
auto self = shared_from_this();
|
boost::asio::async_read_until(*pipe_fd_, streambuf_pipe_, delimiter, [this, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
||||||
boost::asio::async_read_until(*pipe_fd_, streambuf_pipe_, delimiter, [this, self, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error while reading from pipe: " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error while reading from pipe: " << ec.message() << "\n";
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace streamreader
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename ReadStream>
|
template <typename ReadStream>
|
||||||
class AsioStream : public PcmStream, public std::enable_shared_from_this<AsioStream<ReadStream>>
|
class AsioStream : public PcmStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// ctor. Encoded PCM data is passed to the PipeListener
|
/// ctor. Encoded PCM data is passed to the PipeListener
|
||||||
|
@ -66,9 +66,8 @@ template <typename ReadStream>
|
||||||
template <typename Timer, typename Rep, typename Period>
|
template <typename Timer, typename Rep, typename Period>
|
||||||
void AsioStream<ReadStream>::wait(Timer& timer, const std::chrono::duration<Rep, Period>& duration, std::function<void()> handler)
|
void AsioStream<ReadStream>::wait(Timer& timer, const std::chrono::duration<Rep, Period>& duration, std::function<void()> handler)
|
||||||
{
|
{
|
||||||
auto self = this->shared_from_this();
|
|
||||||
timer.expires_after(duration);
|
timer.expires_after(duration);
|
||||||
timer.async_wait([ self, handler = std::move(handler) ](const boost::system::error_code& ec) {
|
timer.async_wait([handler = std::move(handler)](const boost::system::error_code& ec) {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, "AsioStream") << "Error during async wait: " << ec.message() << "\n";
|
LOG(ERROR, "AsioStream") << "Error during async wait: " << ec.message() << "\n";
|
||||||
|
@ -161,9 +160,8 @@ template <typename ReadStream>
|
||||||
void AsioStream<ReadStream>::do_read()
|
void AsioStream<ReadStream>::do_read()
|
||||||
{
|
{
|
||||||
// LOG(DEBUG, "AsioStream") << "do_read\n";
|
// LOG(DEBUG, "AsioStream") << "do_read\n";
|
||||||
auto self = this->shared_from_this();
|
|
||||||
boost::asio::async_read(
|
boost::asio::async_read(
|
||||||
*stream_, boost::asio::buffer(chunk_->payload, chunk_->payloadSize), [this, self](boost::system::error_code ec, std::size_t length) mutable {
|
*stream_, boost::asio::buffer(chunk_->payload, chunk_->payloadSize), [this](boost::system::error_code ec, std::size_t length) mutable {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, "AsioStream") << "Error reading message: " << ec.message() << ", length: " << length << "\n";
|
LOG(ERROR, "AsioStream") << "Error reading message: " << ec.message() << ", length: " << length << "\n";
|
||||||
|
@ -203,7 +201,7 @@ void AsioStream<ReadStream>::do_read()
|
||||||
if (nextTick_ >= currentTick)
|
if (nextTick_ >= currentTick)
|
||||||
{
|
{
|
||||||
read_timer_.expires_after(std::chrono::milliseconds(nextTick_ - currentTick));
|
read_timer_.expires_after(std::chrono::milliseconds(nextTick_ - currentTick));
|
||||||
read_timer_.async_wait([self, this](const boost::system::error_code& ec) {
|
read_timer_.async_wait([this](const boost::system::error_code& ec) {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, "AsioStream") << "Error during async wait: " << ec.message() << "\n";
|
LOG(ERROR, "AsioStream") << "Error during async wait: " << ec.message() << "\n";
|
||||||
|
|
|
@ -147,9 +147,7 @@ void ProcessStream::onStderrMsg(const std::string& line)
|
||||||
void ProcessStream::stderrReadLine()
|
void ProcessStream::stderrReadLine()
|
||||||
{
|
{
|
||||||
const std::string delimiter = "\n";
|
const std::string delimiter = "\n";
|
||||||
auto self(shared_from_this());
|
boost::asio::async_read_until(*stream_stderr_, streambuf_stderr_, delimiter, [this, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
||||||
boost::asio::async_read_until(
|
|
||||||
*stream_stderr_, streambuf_stderr_, delimiter, [this, self, delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error while reading from stderr: " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error while reading from stderr: " << ec.message() << "\n";
|
||||||
|
|
|
@ -68,11 +68,9 @@ void TcpStream::do_connect()
|
||||||
if (!active_)
|
if (!active_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto self = shared_from_this();
|
|
||||||
|
|
||||||
if (is_server_)
|
if (is_server_)
|
||||||
{
|
{
|
||||||
acceptor_->async_accept([this, self](boost::system::error_code ec, tcp::socket socket) {
|
acceptor_->async_accept([this](boost::system::error_code ec, tcp::socket socket) {
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
LOG(DEBUG) << "New client connection\n";
|
LOG(DEBUG) << "New client connection\n";
|
||||||
|
@ -89,7 +87,7 @@ void TcpStream::do_connect()
|
||||||
{
|
{
|
||||||
stream_ = make_unique<tcp::socket>(ioc_);
|
stream_ = make_unique<tcp::socket>(ioc_);
|
||||||
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(host_), port_);
|
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(host_), port_);
|
||||||
stream_->async_connect(endpoint, [self, this](const boost::system::error_code& ec) {
|
stream_->async_connect(endpoint, [this](const boost::system::error_code& ec) {
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
LOG(DEBUG) << "Connected\n";
|
LOG(DEBUG) << "Connected\n";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue