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__V1__PRIVATE__PACKAGE_READER_IMPL_H_
7#define _PACKAGE__HPKG__V1__PRIVATE__PACKAGE_READER_IMPL_H_
8
9
10#include <package/hpkg/v1/ReaderImplBase.h>
11
12
13namespace BPackageKit {
14
15namespace BHPKG {
16
17namespace V1 {
18
19
20class BPackageEntry;
21class BPackageEntryAttribute;
22
23
24namespace BPrivate {
25
26
27class PackageReaderImpl : public ReaderImplBase {
28	typedef	ReaderImplBase		inherited;
29public:
30								PackageReaderImpl(
31									BErrorOutput* errorOutput);
32								~PackageReaderImpl();
33
34			status_t			Init(const char* fileName);
35			status_t			Init(int fd, bool keepFD);
36			status_t			ParseContent(
37									BPackageContentHandler* contentHandler);
38			status_t			ParseContent(BLowLevelPackageContentHandler*
39										contentHandler);
40
41			int					PackageFileFD() const;
42
43			uint64				HeapOffset() const;
44			uint64				HeapSize() const;
45
46protected:
47								// from ReaderImplBase
48	virtual	status_t			ReadAttributeValue(uint8 type, uint8 encoding,
49									AttributeValue& _value);
50
51private:
52			struct DataAttributeHandler;
53			struct AttributeAttributeHandler;
54			struct EntryAttributeHandler;
55			struct RootAttributeHandler;
56
57private:
58			status_t			_ParseTOC(AttributeHandlerContext* context,
59									AttributeHandler* rootAttributeHandler);
60
61			status_t			_GetTOCBuffer(size_t size,
62									const void*& _buffer);
63private:
64			uint64				fTotalSize;
65			uint64				fHeapOffset;
66			uint64				fHeapSize;
67
68			SectionInfo			fTOCSection;
69};
70
71
72inline int
73PackageReaderImpl::PackageFileFD() const
74{
75	return FD();
76}
77
78
79inline uint64
80PackageReaderImpl::HeapOffset() const
81{
82	return fHeapOffset;
83}
84
85
86inline uint64
87PackageReaderImpl::HeapSize() const
88{
89	return fHeapSize;
90}
91
92
93}	// namespace BPrivate
94
95}	// namespace V1
96
97}	// namespace BHPKG
98
99}	// namespace BPackageKit
100
101
102#endif	// _PACKAGE__HPKG__V1__PRIVATE__PACKAGE_READER_IMPL_H_
103