input/Stream: remove attribute "cond", replace with handler interface

This adds a bit of overhead, but also adds flexibility to the API,
because arbitrary triggers may be invoked from that virtual method
implementation, not just Cond::signal().

The motivation for this is to make the handlers more dynamic, for the
upcoming buffering class utilizing ProxyInputStream.
This commit is contained in:
Max Kellermann
2018-06-22 19:37:18 +02:00
parent 01d8eb6290
commit d0fbf6db59
66 changed files with 403 additions and 280 deletions

View File

@@ -73,7 +73,7 @@ DumpDecoderClient::SeekError()
InputStreamPtr
DumpDecoderClient::OpenUri(const char *uri)
{
return InputStream::OpenReady(uri, mutex, cond);
return InputStream::OpenReady(uri, mutex);
}
size_t

View File

@@ -23,7 +23,6 @@
#include "check.h"
#include "decoder/Client.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
/**
* A #DecoderClient implementation which dumps metadata to stderr and
@@ -36,7 +35,6 @@ class DumpDecoderClient final : public DecoderClient {
public:
Mutex mutex;
Cond cond;
bool IsInitialized() const noexcept {
return initialized;

View File

@@ -20,7 +20,6 @@
#include "config.h"
#include "tag/ApeLoader.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "fs/Path.hxx"
#include "Log.hxx"
#include "input/InputStream.hxx"
@@ -62,9 +61,8 @@ try {
const Path path = Path::FromFS(argv[1]);
Mutex mutex;
Cond cond;
auto is = OpenLocalInputStream(path, mutex, cond);
auto is = OpenLocalInputStream(path, mutex);
if (!tag_ape_scan(*is, MyApeTagCallback)) {
fprintf(stderr, "error\n");

View File

@@ -74,14 +74,13 @@ try {
/* open the playlist */
Mutex mutex;
Cond cond;
InputStreamPtr is;
auto playlist = playlist_list_open_uri(uri, mutex, cond);
auto playlist = playlist_list_open_uri(uri, mutex);
if (playlist == NULL) {
/* open the stream and wait until it becomes ready */
is = InputStream::OpenReady(uri, mutex, cond);
is = InputStream::OpenReady(uri, mutex);
/* open the playlist */

View File

@@ -23,7 +23,6 @@
#include "ReplayGainInfo.hxx"
#include "config/ConfigGlobal.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "fs/Path.hxx"
#include "input/InputStream.hxx"
#include "input/LocalOpen.hxx"
@@ -75,9 +74,8 @@ try {
const Path path = Path::FromFS(argv[1]);
Mutex mutex;
Cond cond;
auto is = OpenLocalInputStream(path, mutex, cond);
auto is = OpenLocalInputStream(path, mutex);
const auto tag = tag_id3_load(*is);
if (tag == NULL) {

View File

@@ -23,7 +23,6 @@
#include "input/InputStream.hxx"
#include "input/TextInputStream.hxx"
#include "config/ConfigGlobal.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
#ifdef ENABLE_ARCHIVE
@@ -94,9 +93,8 @@ try {
/* open the stream and dump it */
Mutex mutex;
Cond cond;
auto is = InputStream::OpenReady(argv[1], mutex, cond);
auto is = InputStream::OpenReady(argv[1], mutex);
return dump_input_stream(std::move(is));
} catch (const std::exception &e) {
LogError(e);

View File

@@ -26,7 +26,6 @@
#include "tag/Handler.hxx"
#include "tag/Generic.hxx"
#include "fs/Path.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
#include "util/ScopeExit.hxx"
@@ -110,11 +109,10 @@ try {
}
Mutex mutex;
Cond cond;
InputStreamPtr is;
if (!success && plugin->scan_stream != NULL) {
is = InputStream::OpenReady(path.c_str(), mutex, cond);
is = InputStream::OpenReady(path.c_str(), mutex);
success = plugin->ScanStream(*is, print_handler, nullptr);
}

View File

@@ -123,8 +123,7 @@ try {
if (plugin->file_decode != nullptr) {
plugin->FileDecode(client, Path::FromFS(c.uri));
} else if (plugin->stream_decode != nullptr) {
auto is = InputStream::OpenReady(c.uri, client.mutex,
client.cond);
auto is = InputStream::OpenReady(c.uri, client.mutex);
plugin->StreamDecode(client, *is);
} else {
fprintf(stderr, "Decoder plugin is not usable\n");

View File

@@ -239,8 +239,7 @@ try {
/* open the stream and dump it */
Mutex mutex;
Cond cond;
auto is = InputStream::OpenReady(c.uri, mutex, cond);
auto is = InputStream::OpenReady(c.uri, mutex);
return dump_input_stream(is.get());
} catch (const std::exception &e) {
LogError(e);

View File

@@ -6,7 +6,6 @@
#include "input/RewindInputStream.hxx"
#include "input/InputStream.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -24,9 +23,9 @@ class StringInputStream final : public InputStream {
public:
StringInputStream(const char *_uri,
Mutex &_mutex, Cond &_cond,
Mutex &_mutex,
const char *_data)
:InputStream(_uri, _mutex, _cond),
:InputStream(_uri, _mutex),
data(_data), remaining(strlen(data)) {
SetReady();
}
@@ -54,10 +53,9 @@ class RewindTest : public CppUnit::TestFixture {
public:
void TestRewind() {
Mutex mutex;
Cond cond;
StringInputStream *sis =
new StringInputStream("foo://", mutex, cond,
new StringInputStream("foo://", mutex,
"foo bar");
CPPUNIT_ASSERT(sis->IsReady());