aboutsummaryrefslogtreecommitdiffstats
path: root/src/input/plugins/FileInputPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-05-11 17:14:49 +0200
committerMax Kellermann <max@duempel.org>2014-05-11 17:14:49 +0200
commitd4b625b48e6bbac61b4128aeeaf44911b2e3e03b (patch)
tree67389c99a559c1b65bf6465c2361a4e3c01d4287 /src/input/plugins/FileInputPlugin.cxx
parent82337dec44347017ca04fe975e85e6d9e4edb635 (diff)
downloadmpd-d4b625b48e6bbac61b4128aeeaf44911b2e3e03b.tar.gz
mpd-d4b625b48e6bbac61b4128aeeaf44911b2e3e03b.tar.xz
mpd-d4b625b48e6bbac61b4128aeeaf44911b2e3e03b.zip
InputStream: make various methods abstract
Replace InputPlugin attributes.
Diffstat (limited to 'src/input/plugins/FileInputPlugin.cxx')
-rw-r--r--src/input/plugins/FileInputPlugin.cxx50
1 files changed, 20 insertions, 30 deletions
diff --git a/src/input/plugins/FileInputPlugin.cxx b/src/input/plugins/FileInputPlugin.cxx
index e96347c6e..7c7b4e85f 100644
--- a/src/input/plugins/FileInputPlugin.cxx
+++ b/src/input/plugins/FileInputPlugin.cxx
@@ -48,6 +48,15 @@ struct FileInputStream final : public InputStream {
~FileInputStream() {
close(fd);
}
+
+ /* virtual methods from InputStream */
+
+ bool IsEOF() override {
+ return GetOffset() >= GetSize();
+ }
+
+ size_t Read(void *ptr, size_t size, Error &error) override;
+ bool Seek(offset_type offset, int whence, Error &error) override;
};
static InputStream *
@@ -89,56 +98,37 @@ input_file_open(const char *filename,
return new FileInputStream(filename, fd, st.st_size, mutex, cond);
}
-static bool
-input_file_seek(InputStream *is, InputPlugin::offset_type offset,
- int whence,
- Error &error)
+bool
+FileInputStream::Seek(InputPlugin::offset_type new_offset, int whence,
+ Error &error)
{
- FileInputStream *fis = (FileInputStream *)is;
-
- offset = (InputPlugin::offset_type)lseek(fis->fd, (off_t)offset, whence);
- if (offset < 0) {
+ new_offset = (InputPlugin::offset_type)lseek(fd, (off_t)new_offset,
+ whence);
+ if (new_offset < 0) {
error.SetErrno("Failed to seek");
return false;
}
- is->offset = offset;
+ offset = new_offset;
return true;
}
-static size_t
-input_file_read(InputStream *is, void *ptr, size_t size,
- Error &error)
+size_t
+FileInputStream::Read(void *ptr, size_t read_size, Error &error)
{
- FileInputStream *fis = (FileInputStream *)is;
- ssize_t nbytes;
-
- nbytes = read(fis->fd, ptr, size);
+ ssize_t nbytes = read(fd, ptr, read_size);
if (nbytes < 0) {
error.SetErrno("Failed to read");
return 0;
}
- is->offset += nbytes;
+ offset += nbytes;
return (size_t)nbytes;
}
-static bool
-input_file_eof(InputStream *is)
-{
- return is->GetOffset() >= is->GetSize();
-}
-
const InputPlugin input_plugin_file = {
"file",
nullptr,
nullptr,
input_file_open,
- nullptr,
- nullptr,
- nullptr,
- nullptr,
- input_file_read,
- input_file_eof,
- input_file_seek,
};