diff options
author | Max Kellermann <max@duempel.org> | 2013-11-24 22:41:23 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-11-24 22:41:23 +0100 |
commit | dbda35ffe178da0b012a52368367c7dbf1811540 (patch) | |
tree | 1933a4bd57d12acc025ec3e4b92f4d3ad8ddff48 /src/archive/Iso9660ArchivePlugin.cxx | |
parent | 6396e23a2a0446093e995e563bd447d99c14b22a (diff) | |
download | mpd-dbda35ffe178da0b012a52368367c7dbf1811540.tar.gz mpd-dbda35ffe178da0b012a52368367c7dbf1811540.tar.xz mpd-dbda35ffe178da0b012a52368367c7dbf1811540.zip |
archive/iso9660: convert structs to classes
Diffstat (limited to 'src/archive/Iso9660ArchivePlugin.cxx')
-rw-r--r-- | src/archive/Iso9660ArchivePlugin.cxx | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/src/archive/Iso9660ArchivePlugin.cxx b/src/archive/Iso9660ArchivePlugin.cxx index 0fbd9743b..2d0105a59 100644 --- a/src/archive/Iso9660ArchivePlugin.cxx +++ b/src/archive/Iso9660ArchivePlugin.cxx @@ -41,11 +41,11 @@ #define CEILING(x, y) ((x+(y-1))/y) class Iso9660ArchiveFile final : public ArchiveFile { -public: RefCount ref; iso9660_t *iso; +public: Iso9660ArchiveFile(iso9660_t *_iso) :ArchiveFile(iso9660_archive_plugin), iso(_iso) {} @@ -53,11 +53,19 @@ public: iso9660_close(iso); } + void Ref() { + ref.Increment(); + } + void Unref() { if (ref.Decrement()) delete this; } + long SeekRead(void *ptr, lsn_t start, long int i_size) const { + return iso9660_iso_seek_read(iso, ptr, start, i_size); + } + void Visit(const char *path, ArchiveVisitor &visitor); virtual void Close() override { @@ -131,31 +139,35 @@ Iso9660ArchiveFile::Visit(ArchiveVisitor &visitor) /* single archive handling */ -struct Iso9660InputStream { +class Iso9660InputStream { InputStream base; Iso9660ArchiveFile *archive; iso9660_stat_t *statbuf; - size_t max_blocks; +public: Iso9660InputStream(Iso9660ArchiveFile &_archive, const char *uri, Mutex &mutex, Cond &cond, iso9660_stat_t *_statbuf) :base(iso9660_input_plugin, uri, mutex, cond), - archive(&_archive), statbuf(_statbuf), - max_blocks(CEILING(statbuf->size, ISO_BLOCKSIZE)) { - + archive(&_archive), statbuf(_statbuf) { base.ready = true; base.size = statbuf->size; - archive->ref.Increment(); + archive->Ref(); } ~Iso9660InputStream() { free(statbuf); archive->Unref(); } + + InputStream *Get() { + return &base; + } + + size_t Read(void *ptr, size_t size, Error &error); }; InputStream * @@ -173,7 +185,7 @@ Iso9660ArchiveFile::OpenStream(const char *pathname, Iso9660InputStream *iis = new Iso9660InputStream(*this, pathname, mutex, cond, statbuf); - return &iis->base; + return iis->Get(); } static void @@ -184,15 +196,12 @@ iso9660_input_close(InputStream *is) delete iis; } - -static size_t -iso9660_input_read(InputStream *is, void *ptr, size_t size, - Error &error) +inline size_t +Iso9660InputStream::Read(void *ptr, size_t size, Error &error) { - Iso9660InputStream *iis = (Iso9660InputStream *)is; int readed = 0; int no_blocks, cur_block; - size_t left_bytes = iis->statbuf->size - is->offset; + size_t left_bytes = statbuf->size - base.offset; size = (size * ISO_BLOCKSIZE) / ISO_BLOCKSIZE; @@ -205,10 +214,10 @@ iso9660_input_read(InputStream *is, void *ptr, size_t size, if (no_blocks == 0) return 0; - cur_block = is->offset / ISO_BLOCKSIZE; + cur_block = base.offset / ISO_BLOCKSIZE; - readed = iso9660_iso_seek_read (iis->archive->iso, ptr, - iis->statbuf->lsn + cur_block, no_blocks); + readed = archive->SeekRead(ptr, statbuf->lsn + cur_block, + no_blocks); if (readed != no_blocks * ISO_BLOCKSIZE) { error.Format(iso9660_domain, @@ -220,10 +229,18 @@ iso9660_input_read(InputStream *is, void *ptr, size_t size, readed = left_bytes; } - is->offset += readed; + base.offset += readed; return readed; } +static size_t +iso9660_input_read(InputStream *is, void *ptr, size_t size, + Error &error) +{ + Iso9660InputStream *iis = (Iso9660InputStream *)is; + return iis->Read(ptr, size, error); +} + static bool iso9660_input_eof(InputStream *is) { |