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 PackageWriterImpl; 26 27 28 class PackageReaderImpl : public ReaderImplBase { 29 typedef ReaderImplBase inherited; 30 public: 31 PackageReaderImpl(BErrorOutput* errorOutput); 32 ~PackageReaderImpl(); 33 34 status_t Init(const char* fileName, uint32 flags); 35 status_t Init(int fd, bool keepFD, uint32 flags); 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 46 PackageFileHeapReader* RawHeapReader() const 47 { return inherited::RawHeapReader(); } 48 BAbstractBufferedDataReader* HeapReader() const 49 { return inherited::HeapReader(); } 50 51 inline const PackageFileSection& TOCSection() const 52 { return fTOCSection; } 53 54 protected: 55 // from ReaderImplBase 56 virtual status_t ReadAttributeValue(uint8 type, uint8 encoding, 57 AttributeValue& _value); 58 59 private: 60 struct AttributeAttributeHandler; 61 struct EntryAttributeHandler; 62 struct RootAttributeHandler; 63 64 friend class PackageWriterImpl; 65 66 private: 67 status_t _ParseTOC(AttributeHandlerContext* context, 68 AttributeHandler* rootAttributeHandler); 69 70 status_t _GetTOCBuffer(size_t size, 71 const void*& _buffer); 72 private: 73 uint64 fHeapOffset; 74 uint64 fHeapSize; 75 76 PackageFileSection fTOCSection; 77 }; 78 79 80 inline int 81 PackageReaderImpl::PackageFileFD() const 82 { 83 return FD(); 84 } 85 86 87 inline uint64 88 PackageReaderImpl::HeapOffset() const 89 { 90 return fHeapOffset; 91 } 92 93 94 inline uint64 95 PackageReaderImpl::HeapSize() const 96 { 97 return fHeapSize; 98 } 99 100 101 } // namespace BPrivate 102 103 } // namespace BHPKG 104 105 } // namespace BPackageKit 106 107 108 #endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_ 109