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