46122852f1
* ReaderImplBase: - Add virtual CreateCachedHeapReader() which can create a cached reader based on the given heap reader. - Rename HeapReader() to RawHeapReader() and add HeapReader() for the cached heap reader. - Add DetachHeapReader() to allow a clients to remove the heap reader(s) after deleting the ReaderImplBase object. * packagefs: - Add CachedDataReader class, which wraps a given BAbstractBufferedDataReader and provides caching for it using a VMCache. The implementation is based on the IOCache implementation. - Use CachedDataReader to wrap the heap reader. For file data that means they are cached twice -- in the heap reader cache and in the file cache -- but due to the heap reader using a VMCache as well, the pages will be recycled automatically anyway. For attribute data the cache should be very helpful, since they weren't cached at all before.
101 lines
2.1 KiB
C++
101 lines
2.1 KiB
C++
/*
|
|
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
|
|
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
|
|
|
|
|
|
#include <package/hpkg/ReaderImplBase.h>
|
|
|
|
|
|
namespace BPackageKit {
|
|
|
|
namespace BHPKG {
|
|
|
|
|
|
class BPackageEntry;
|
|
class BPackageEntryAttribute;
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
|
|
class PackageReaderImpl : public ReaderImplBase {
|
|
typedef ReaderImplBase inherited;
|
|
public:
|
|
PackageReaderImpl(BErrorOutput* errorOutput);
|
|
~PackageReaderImpl();
|
|
|
|
status_t Init(const char* fileName, uint32 flags);
|
|
status_t Init(int fd, bool keepFD, uint32 flags);
|
|
status_t ParseContent(
|
|
BPackageContentHandler* contentHandler);
|
|
status_t ParseContent(BLowLevelPackageContentHandler*
|
|
contentHandler);
|
|
|
|
int PackageFileFD() const;
|
|
|
|
uint64 HeapOffset() const;
|
|
uint64 HeapSize() const;
|
|
|
|
PackageFileHeapReader* RawHeapReader() const
|
|
{ return inherited::RawHeapReader(); }
|
|
BAbstractBufferedDataReader* HeapReader() const
|
|
{ return inherited::HeapReader(); }
|
|
|
|
protected:
|
|
// from ReaderImplBase
|
|
virtual status_t ReadAttributeValue(uint8 type, uint8 encoding,
|
|
AttributeValue& _value);
|
|
|
|
private:
|
|
struct AttributeAttributeHandler;
|
|
struct EntryAttributeHandler;
|
|
struct RootAttributeHandler;
|
|
|
|
private:
|
|
status_t _ParseTOC(AttributeHandlerContext* context,
|
|
AttributeHandler* rootAttributeHandler);
|
|
|
|
status_t _GetTOCBuffer(size_t size,
|
|
const void*& _buffer);
|
|
private:
|
|
uint64 fHeapOffset;
|
|
uint64 fHeapSize;
|
|
|
|
PackageFileSection fTOCSection;
|
|
};
|
|
|
|
|
|
inline int
|
|
PackageReaderImpl::PackageFileFD() const
|
|
{
|
|
return FD();
|
|
}
|
|
|
|
|
|
inline uint64
|
|
PackageReaderImpl::HeapOffset() const
|
|
{
|
|
return fHeapOffset;
|
|
}
|
|
|
|
|
|
inline uint64
|
|
PackageReaderImpl::HeapSize() const
|
|
{
|
|
return fHeapSize;
|
|
}
|
|
|
|
|
|
} // namespace BPrivate
|
|
|
|
} // namespace BHPKG
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
|