Switch stream readers to use asio event loop

This commit is contained in:
badaix 2020-01-03 22:40:34 +01:00
parent 3eab397543
commit 6d7e25e9af
30 changed files with 630 additions and 583 deletions

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2019 Johannes Pohl
Copyright (C) 2014-2020 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -16,16 +16,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef PROCESS_STREAM_H
#define PROCESS_STREAM_H
#ifndef PROCESS_STREAM_HPP
#define PROCESS_STREAM_HPP
#include <memory>
#include <string>
#include "pcm_stream.hpp"
#include "posix_stream.hpp"
#include "process.hpp"
#include "watchdog.hpp"
// TODO: switch to AsioStream, maybe use boost::process library
namespace streamreader
{
/// Starts an external process and reads and PCM data from stdout
/**
@ -33,33 +35,39 @@
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
*/
class ProcessStream : public PcmStream
class ProcessStream : public PosixStream, public WatchdogListener
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
ProcessStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const StreamUri& uri);
~ProcessStream() override;
void start() override;
void stop() override;
~ProcessStream() override = default;
protected:
void do_connect() override;
void do_disconnect() override;
std::string exe_;
std::string path_;
std::string params_;
std::unique_ptr<Process> process_;
std::thread stderrReaderThread_;
bool logStderr_;
size_t dryoutMs_;
void worker() override;
virtual void stderrReader();
virtual void onStderrMsg(const char* buffer, size_t n);
bool logStderr_;
boost::asio::streambuf streambuf_stderr_;
std::unique_ptr<stream_descriptor> stream_stderr_;
// void worker() override;
virtual void stderrReadLine();
virtual void onStderrMsg(const std::string& line);
virtual void initExeAndPath(const std::string& filename);
bool fileExists(const std::string& filename);
std::string findExe(const std::string& filename);
size_t wd_timeout_sec_;
std::unique_ptr<Watchdog> watchdog_;
void onTimeout(const Watchdog& watchdog, std::chrono::milliseconds ms) override;
};
} // namespace streamreader
#endif