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

@@ -28,7 +28,6 @@
#include "../ArchiveVisitor.hxx"
#include "input/InputStream.hxx"
#include "input/LocalOpen.hxx"
#include "thread/Cond.hxx"
#include "fs/Path.hxx"
#include <bzlib.h>
@@ -54,7 +53,7 @@ public:
}
InputStreamPtr OpenStream(const char *path,
Mutex &mutex, Cond &cond) override;
Mutex &mutex) override;
};
class Bzip2InputStream final : public InputStream {
@@ -69,7 +68,7 @@ class Bzip2InputStream final : public InputStream {
public:
Bzip2InputStream(const std::shared_ptr<InputStream> &_input,
const char *uri,
Mutex &mutex, Cond &cond);
Mutex &mutex);
~Bzip2InputStream();
/* virtual methods from InputStream */
@@ -106,8 +105,7 @@ static std::unique_ptr<ArchiveFile>
bz2_open(Path pathname)
{
static Mutex mutex;
static Cond cond;
auto is = OpenLocalInputStream(pathname, mutex, cond);
auto is = OpenLocalInputStream(pathname, mutex);
return std::make_unique<Bzip2ArchiveFile>(pathname, std::move(is));
}
@@ -115,8 +113,8 @@ bz2_open(Path pathname)
Bzip2InputStream::Bzip2InputStream(const std::shared_ptr<InputStream> &_input,
const char *_uri,
Mutex &_mutex, Cond &_cond)
:InputStream(_uri, _mutex, _cond),
Mutex &_mutex)
:InputStream(_uri, _mutex),
input(_input)
{
Open();
@@ -129,9 +127,9 @@ Bzip2InputStream::~Bzip2InputStream()
InputStreamPtr
Bzip2ArchiveFile::OpenStream(const char *path,
Mutex &mutex, Cond &cond)
Mutex &mutex)
{
return std::make_unique<Bzip2InputStream>(istream, path, mutex, cond);
return std::make_unique<Bzip2InputStream>(istream, path, mutex);
}
inline bool

View File

@@ -75,7 +75,7 @@ public:
virtual void Visit(ArchiveVisitor &visitor) override;
InputStreamPtr OpenStream(const char *path,
Mutex &mutex, Cond &cond) override;
Mutex &mutex) override;
};
/* archive open && listing routine */
@@ -144,9 +144,9 @@ class Iso9660InputStream final : public InputStream {
public:
Iso9660InputStream(const std::shared_ptr<Iso9660> &_iso,
const char *_uri,
Mutex &_mutex, Cond &_cond,
Mutex &_mutex,
iso9660_stat_t *_statbuf)
:InputStream(_uri, _mutex, _cond),
:InputStream(_uri, _mutex),
iso(_iso), statbuf(_statbuf) {
size = statbuf->size;
SetReady();
@@ -163,14 +163,14 @@ public:
InputStreamPtr
Iso9660ArchiveFile::OpenStream(const char *pathname,
Mutex &mutex, Cond &cond)
Mutex &mutex)
{
auto statbuf = iso9660_ifs_stat_translate(iso->iso, pathname);
if (statbuf == nullptr)
throw FormatRuntimeError("not found in the ISO file: %s",
pathname);
return std::make_unique<Iso9660InputStream>(iso, pathname, mutex, cond,
return std::make_unique<Iso9660InputStream>(iso, pathname, mutex,
statbuf);
}

View File

@@ -60,7 +60,7 @@ public:
virtual void Visit(ArchiveVisitor &visitor) override;
InputStreamPtr OpenStream(const char *path,
Mutex &mutex, Cond &cond) override;
Mutex &mutex) override;
};
/* archive open && listing routine */
@@ -92,9 +92,9 @@ class ZzipInputStream final : public InputStream {
public:
ZzipInputStream(const std::shared_ptr<ZzipDir> _dir, const char *_uri,
Mutex &_mutex, Cond &_cond,
Mutex &_mutex,
ZZIP_FILE *_file)
:InputStream(_uri, _mutex, _cond),
:InputStream(_uri, _mutex),
dir(_dir), file(_file) {
//we are seekable (but its not recommendent to do so)
seekable = true;
@@ -118,7 +118,7 @@ public:
InputStreamPtr
ZzipArchiveFile::OpenStream(const char *pathname,
Mutex &mutex, Cond &cond)
Mutex &mutex)
{
ZZIP_FILE *_file = zzip_file_open(dir->dir, pathname, 0);
if (_file == nullptr)
@@ -126,7 +126,7 @@ ZzipArchiveFile::OpenStream(const char *pathname,
pathname);
return std::make_unique<ZzipInputStream>(dir, pathname,
mutex, cond,
mutex,
_file);
}