PackageReaderImpl.h revision 8f5130ed
1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
7#define _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
8
9
10#include <package/hpkg/ReaderImplBase.h>
11
12
13namespace BPackageKit {
14
15namespace BHPKG {
16
17
18class BPackageEntry;
19class BPackageEntryAttribute;
20
21
22namespace BPrivate {
23
24
25struct hpkg_header;
26class PackageWriterImpl;
27
28
29class PackageReaderImpl : public ReaderImplBase {
30	typedef	ReaderImplBase		inherited;
31public:
32								PackageReaderImpl(BErrorOutput* errorOutput);
33								~PackageReaderImpl();
34
35			status_t			Init(const char* fileName, uint32 flags);
36			status_t			Init(int fd, bool keepFD, uint32 flags);
37			status_t			Init(BPositionIO* file, bool keepFile,
38									uint32 flags, hpkg_header* _header = NULL);
39			status_t			ParseContent(
40									BPackageContentHandler* contentHandler);
41			status_t			ParseContent(BLowLevelPackageContentHandler*
42										contentHandler);
43
44			BPositionIO*		PackageFile() const;
45
46			uint64				HeapOffset() const;
47			uint64				HeapSize() const;
48
49			PackageFileHeapReader* RawHeapReader() const
50									{ return inherited::RawHeapReader(); }
51			BAbstractBufferedDataReader* HeapReader() const
52									{ return inherited::HeapReader(); }
53
54	inline	const PackageFileSection& TOCSection() const
55									{ return fTOCSection; }
56
57protected:
58								// from ReaderImplBase
59	virtual	status_t			ReadAttributeValue(uint8 type, uint8 encoding,
60									AttributeValue& _value);
61
62private:
63			struct AttributeAttributeHandler;
64			struct EntryAttributeHandler;
65			struct RootAttributeHandler;
66
67			friend class PackageWriterImpl;
68
69private:
70			status_t			_ParseTOC(AttributeHandlerContext* context,
71									AttributeHandler* rootAttributeHandler);
72
73			status_t			_GetTOCBuffer(size_t size,
74									const void*& _buffer);
75private:
76			uint64				fHeapOffset;
77			uint64				fHeapSize;
78
79			PackageFileSection	fTOCSection;
80};
81
82
83inline BPositionIO*
84PackageReaderImpl::PackageFile() const
85{
86	return File();
87}
88
89
90inline uint64
91PackageReaderImpl::HeapOffset() const
92{
93	return fHeapOffset;
94}
95
96
97inline uint64
98PackageReaderImpl::HeapSize() const
99{
100	return fHeapSize;
101}
102
103
104}	// namespace BPrivate
105
106}	// namespace BHPKG
107
108}	// namespace BPackageKit
109
110
111#endif	// _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
112