Refactored hpkg implementation to provide some separation between

public and private API (still far from ideal, but a start):
* moved several HPKG-classes into the public namespace BPackageKit::HPKG
* added fImpl-wrappers around PackageReader and PackageWriter to hide
  most of the gory details
* adjusted 'package'-binary and packagefs accordingly


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40320 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2011-01-30 15:05:38 +00:00
parent 2f4d9fdbab
commit 5fb1c6ff1f
68 changed files with 4138 additions and 3637 deletions
@@ -0,0 +1,49 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
#define _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
#include <SupportDefs.h>
#include <package/hpkg/BufferCache.h>
namespace BPackageKit {
namespace BHPKG {
namespace BPrivate {
class BlockBufferCacheImpl;
}
using BPrivate::BlockBufferCacheImpl;
class BBlockBufferCache : public BBufferCache, public BBufferCacheLockable {
public:
BBlockBufferCache(size_t blockSize,
uint32 maxCachedBlocks);
virtual ~BBlockBufferCache();
virtual status_t Init();
virtual CachedBuffer* GetBuffer(size_t size,
CachedBuffer** owner = NULL,
bool* _newBuffer = NULL);
virtual void PutBufferAndCache(CachedBuffer** owner);
virtual void PutBuffer(CachedBuffer** owner);
private:
BlockBufferCacheImpl* fImpl;
};
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
+54
View File
@@ -0,0 +1,54 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__BUFFER_CACHE_H_
#define _PACKAGE__HPKG__BUFFER_CACHE_H_
#include <stddef.h>
namespace BPackageKit {
namespace BHPKG {
namespace BPrivate {
class CachedBuffer;
}
using BPrivate::CachedBuffer;
class BBufferCache {
public:
virtual ~BBufferCache();
virtual CachedBuffer* GetBuffer(size_t size,
CachedBuffer** owner = NULL,
bool* _newBuffer = NULL) = 0;
virtual void PutBufferAndCache(CachedBuffer** owner) = 0;
// caller is buffer owner and wants the
// buffer cached, if possible
virtual void PutBuffer(CachedBuffer** owner) = 0;
// puts the buffer for good, owner might
// have called PutBufferAndCache() before
// and might not own a buffer anymore
};
class BBufferCacheLockable {
public:
virtual ~BBufferCacheLockable();
virtual bool Lock() = 0;
virtual void Unlock() = 0;
};
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__BUFFER_CACHE_H_
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef DATA_OUTPUT_H
#define DATA_OUTPUT_H
#ifndef _PACKAGE__HPKG__DATA_OUTPUT_H_
#define _PACKAGE__HPKG__DATA_OUTPUT_H_
#include <SupportDefs.h>
@@ -11,22 +11,20 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
class DataOutput {
class BDataOutput {
public:
virtual ~DataOutput();
virtual ~BDataOutput();
virtual status_t WriteData(const void* buffer, size_t size) = 0;
};
class BufferDataOutput : public DataOutput {
class BBufferDataOutput : public BDataOutput {
public:
BufferDataOutput(void* buffer, size_t size);
BBufferDataOutput(void* buffer, size_t size);
size_t BytesWritten() const { return fBytesWritten; }
@@ -39,11 +37,9 @@ private:
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // DATA_OUTPUT_H
#endif // _PACKAGE__HPKG__DATA_OUTPUT_H_
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef DATA_READER_H
#define DATA_READER_H
#ifndef _PACKAGE__HPKG__DATA_READER_H_
#define _PACKAGE__HPKG__DATA_READER_H_
#include <SupportDefs.h>
@@ -11,23 +11,21 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
class DataReader {
class BDataReader {
public:
virtual ~DataReader();
virtual ~BDataReader();
virtual status_t ReadData(off_t offset, void* buffer,
size_t size) = 0;
};
class FDDataReader : public DataReader {
class BFDDataReader : public BDataReader {
public:
FDDataReader(int fd);
BFDDataReader(int fd);
virtual status_t ReadData(off_t offset, void* buffer,
size_t size);
@@ -37,9 +35,9 @@ private:
};
class AttributeDataReader : public DataReader {
class BAttributeDataReader : public BDataReader {
public:
AttributeDataReader(int fd,
BAttributeDataReader(int fd,
const char* attribute, uint32 type);
virtual status_t ReadData(off_t offset, void* buffer,
@@ -52,9 +50,9 @@ private:
};
class BufferDataReader : public DataReader {
class BBufferDataReader : public BDataReader {
public:
BufferDataReader(const void* data, size_t size);
BBufferDataReader(const void* data, size_t size);
virtual status_t ReadData(off_t offset, void* buffer,
size_t size);
@@ -65,11 +63,9 @@ private:
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // DATA_READER_H
#endif // _PACKAGE__HPKG__DATA_READER_H_
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef ERROR_OUTPUT_H
#define ERROR_OUTPUT_H
#ifndef _PACKAGE__HPKG__ERROR_OUTPUT_H_
#define _PACKAGE__HPKG__ERROR_OUTPUT_H_
#include <stdarg.h>
@@ -13,14 +13,12 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
class ErrorOutput {
class BErrorOutput {
public:
virtual ~ErrorOutput();
virtual ~BErrorOutput();
virtual void PrintErrorVarArgs(const char* format,
va_list args) = 0;
@@ -28,11 +26,9 @@ public:
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // ERROR_OUTPUT_H
#endif // _PACKAGE__HPKG__PACKAGE_OUTPUT_H_
+77
View File
@@ -0,0 +1,77 @@
/*
* Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__HPKG_DEFS_H_
#define _PACKAGE__HPKG__HPKG_DEFS_H_
#include <SupportDefs.h>
namespace BPackageKit {
namespace BHPKG {
// magic, version
enum {
B_HPKG_MAGIC = 'hpkg',
B_HPKG_VERSION = 1
};
// attribute types
enum {
// types
B_HPKG_ATTRIBUTE_TYPE_INVALID = 0,
B_HPKG_ATTRIBUTE_TYPE_INT = 1,
B_HPKG_ATTRIBUTE_TYPE_UINT = 2,
B_HPKG_ATTRIBUTE_TYPE_STRING = 3,
B_HPKG_ATTRIBUTE_TYPE_RAW = 4
};
// attribute encodings
enum {
// signed/unsigned int encodings
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT = 0,
B_HPKG_ATTRIBUTE_ENCODING_INT_16_BIT = 1,
B_HPKG_ATTRIBUTE_ENCODING_INT_32_BIT = 2,
B_HPKG_ATTRIBUTE_ENCODING_INT_64_BIT = 3,
// string encodings
B_HPKG_ATTRIBUTE_ENCODING_STRING_INLINE = 0,
// null-terminated string
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE = 1,
// unsigned LEB128 index into string table
// raw data encodings
B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE = 0,
// unsigned LEB128 size, raw bytes
B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP = 1
// unsigned LEB128 size, unsigned LEB128 offset into the heap
};
// maximum number of bytes of data to be encoded inline; more will be allocated
// on the heap
#define B_HPKG_MAX_INLINE_DATA_SIZE 8
// name of file containing package information (in package's root folder)
#define B_HPKG_PACKAGE_INFO_FILE_NAME ".PackageInfo"
// default values
enum {
B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB = 64 * 1024
};
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__HPKG_DEFS_H_
@@ -2,23 +2,21 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef PACKAGE_ATTRIBUTE_VALUE_H
#define PACKAGE_ATTRIBUTE_VALUE_H
#ifndef _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
#define _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
#include <string.h>
#include <package/hpkg/haiku_package.h>
#include <package/hpkg/HPKGDefs.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
struct PackageAttributeValue {
struct BPackageAttributeValue {
union {
int64 signedInt;
uint64 unsignedInt;
@@ -35,7 +33,7 @@ struct PackageAttributeValue {
uint8 encoding;
public:
inline PackageAttributeValue();
inline BPackageAttributeValue();
inline void SetTo(int8 value);
inline void SetTo(uint8 value);
@@ -51,7 +49,7 @@ public:
};
PackageAttributeValue::PackageAttributeValue()
BPackageAttributeValue::BPackageAttributeValue()
:
type(B_HPKG_ATTRIBUTE_TYPE_INVALID)
{
@@ -59,7 +57,7 @@ PackageAttributeValue::PackageAttributeValue()
void
PackageAttributeValue::SetTo(int8 value)
BPackageAttributeValue::SetTo(int8 value)
{
signedInt = value;
type = B_HPKG_ATTRIBUTE_TYPE_INT;
@@ -67,7 +65,7 @@ PackageAttributeValue::SetTo(int8 value)
void
PackageAttributeValue::SetTo(uint8 value)
BPackageAttributeValue::SetTo(uint8 value)
{
unsignedInt = value;
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
@@ -75,7 +73,7 @@ PackageAttributeValue::SetTo(uint8 value)
void
PackageAttributeValue::SetTo(int16 value)
BPackageAttributeValue::SetTo(int16 value)
{
signedInt = value;
type = B_HPKG_ATTRIBUTE_TYPE_INT;
@@ -83,7 +81,7 @@ PackageAttributeValue::SetTo(int16 value)
void
PackageAttributeValue::SetTo(uint16 value)
BPackageAttributeValue::SetTo(uint16 value)
{
unsignedInt = value;
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
@@ -91,7 +89,7 @@ PackageAttributeValue::SetTo(uint16 value)
void
PackageAttributeValue::SetTo(int32 value)
BPackageAttributeValue::SetTo(int32 value)
{
signedInt = value;
type = B_HPKG_ATTRIBUTE_TYPE_INT;
@@ -99,7 +97,7 @@ PackageAttributeValue::SetTo(int32 value)
void
PackageAttributeValue::SetTo(uint32 value)
BPackageAttributeValue::SetTo(uint32 value)
{
unsignedInt = value;
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
@@ -107,7 +105,7 @@ PackageAttributeValue::SetTo(uint32 value)
void
PackageAttributeValue::SetTo(int64 value)
BPackageAttributeValue::SetTo(int64 value)
{
signedInt = value;
type = B_HPKG_ATTRIBUTE_TYPE_INT;
@@ -115,7 +113,7 @@ PackageAttributeValue::SetTo(int64 value)
void
PackageAttributeValue::SetTo(uint64 value)
BPackageAttributeValue::SetTo(uint64 value)
{
unsignedInt = value;
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
@@ -123,7 +121,7 @@ PackageAttributeValue::SetTo(uint64 value)
void
PackageAttributeValue::SetTo(const char* value)
BPackageAttributeValue::SetTo(const char* value)
{
string = value;
type = B_HPKG_ATTRIBUTE_TYPE_STRING;
@@ -131,7 +129,7 @@ PackageAttributeValue::SetTo(const char* value)
void
PackageAttributeValue::SetToData(uint64 size, uint64 offset)
BPackageAttributeValue::SetToData(uint64 size, uint64 offset)
{
data.size = size;
data.offset = offset;
@@ -141,7 +139,7 @@ PackageAttributeValue::SetToData(uint64 size, uint64 offset)
void
PackageAttributeValue::SetToData(uint64 size, const void* rawData)
BPackageAttributeValue::SetToData(uint64 size, const void* rawData)
{
data.size = size;
if (size > 0)
@@ -151,11 +149,9 @@ PackageAttributeValue::SetToData(uint64 size, const void* rawData)
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // PACKAGE_ATTRIBUTE_VALUE_H
#endif // _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
@@ -0,0 +1,55 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__PACKAGE_CONTENT_HANDLER_H_
#define _PACKAGE__HPKG__PACKAGE_CONTENT_HANDLER_H_
#include <SupportDefs.h>
namespace BPackageKit {
namespace BHPKG {
class BPackageAttributeValue;
class BPackageEntry;
class BPackageEntryAttribute;
class BLowLevelPackageContentHandler {
public:
virtual ~BLowLevelPackageContentHandler();
virtual status_t HandleAttribute(const char* attributeName,
const BPackageAttributeValue& value,
void* parentToken, void*& _token) = 0;
virtual status_t HandleAttributeDone(const char* attributeName,
const BPackageAttributeValue& value,
void* token) = 0;
virtual void HandleErrorOccurred() = 0;
};
class BPackageContentHandler {
public:
virtual ~BPackageContentHandler();
virtual status_t HandleEntry(BPackageEntry* entry) = 0;
virtual status_t HandleEntryAttribute(BPackageEntry* entry,
BPackageEntryAttribute* attribute) = 0;
virtual status_t HandleEntryDone(BPackageEntry* entry) = 0;
virtual void HandleErrorOccurred() = 0;
};
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__PACKAGE_CONTENT_HANDLER_H_
@@ -2,23 +2,21 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef PACKAGE_DATA_H
#define PACKAGE_DATA_H
#ifndef _PACKAGE__HPKG__PACKAGE_DATA_H_
#define _PACKAGE__HPKG__PACKAGE_DATA_H_
#include <package/hpkg/haiku_package.h>
#include <package/hpkg/HPKGDefs.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
class PackageData {
class BPackageData {
public:
PackageData();
BPackageData();
uint64 CompressedSize() const
{ return fCompressedSize; }
@@ -56,11 +54,9 @@ private:
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // PACKAGE_DATA_H
#endif // _PACKAGE__HPKG__PACKAGE_DATA_H_
@@ -0,0 +1,61 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__PACKAGE_DATA_READER_H_
#define _PACKAGE__HPKG__PACKAGE_DATA_READER_H_
#include <package/hpkg/DataReader.h>
namespace BPackageKit {
namespace BHPKG {
class BBufferCache;
class BDataOutput;
class BPackageData;
class BPackageDataReader : public BDataReader {
public:
BPackageDataReader(BDataReader* dataReader);
virtual ~BPackageDataReader();
virtual status_t Init(const BPackageData& data) = 0;
virtual status_t ReadData(off_t offset, void* buffer,
size_t size);
virtual status_t ReadDataToOutput(off_t offset, size_t size,
BDataOutput* output) = 0;
virtual uint64 Size() const = 0;
virtual size_t BlockSize() const = 0;
protected:
BDataReader* fDataReader;
};
class BPackageDataReaderFactory {
public:
BPackageDataReaderFactory(
BBufferCache* bufferCache);
status_t CreatePackageDataReader(BDataReader* dataReader,
const BPackageData& data,
BPackageDataReader*& _reader);
private:
BBufferCache* fBufferCache;
};
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__PACKAGE_DATA_READER_H_
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef PACKAGE_ENTRY_H
#define PACKAGE_ENTRY_H
#ifndef _PACKAGE__HPKG__PACKAGE_ENTRY_H_
#define _PACKAGE__HPKG__PACKAGE_ENTRY_H_
#include <sys/stat.h>
@@ -13,17 +13,15 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
class PackageEntry {
class BPackageEntry {
public:
PackageEntry(PackageEntry* parent,
BPackageEntry(BPackageEntry* parent,
const char* name);
const PackageEntry* Parent() const { return fParent; }
const BPackageEntry* Parent() const { return fParent; }
const char* Name() const { return fName; }
void* UserToken() const { return fUserToken; }
@@ -36,7 +34,7 @@ public:
const timespec& CreationTime() const
{ return fCreationTime; }
PackageData& Data() { return fData; }
BPackageData& Data() { return fData; }
const char* SymlinkPath() const { return fSymlinkPath; }
@@ -62,37 +60,35 @@ public:
void SetSymlinkPath(const char* path)
{ fSymlinkPath = path; }
private:
PackageEntry* fParent;
BPackageEntry* fParent;
const char* fName;
void* fUserToken;
mode_t fMode;
timespec fAccessTime;
timespec fModifiedTime;
timespec fCreationTime;
PackageData fData;
BPackageData fData;
const char* fSymlinkPath;
};
inline void
PackageEntry::SetType(uint32 type)
BPackageEntry::SetType(uint32 type)
{
fMode = (fMode & ~(uint32)S_IFMT) | (type & S_IFMT);
}
inline void
PackageEntry::SetPermissions(uint32 permissions)
BPackageEntry::SetPermissions(uint32 permissions)
{
fMode = (fMode & ~(uint32)ALLPERMS) | (permissions & ALLPERMS);
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // PACKAGE_ENTRY_H
#endif // _PACKAGE__HPKG__PACKAGE_ENTRY_H_
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef PACKAGE_ENTRY_ATTRIBUTE_H
#define PACKAGE_ENTRY_ATTRIBUTE_H
#ifndef _PACKAGE__HPKG__PACKAGE_ENTRY_ATTRIBUTE_H_
#define _PACKAGE__HPKG__PACKAGE_ENTRY_ATTRIBUTE_H_
#include <package/hpkg/PackageData.h>
@@ -11,34 +11,30 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
class PackageEntryAttribute {
class BPackageEntryAttribute {
public:
PackageEntryAttribute(const char* name);
BPackageEntryAttribute(const char* name);
const char* Name() const { return fName; }
uint32 Type() const { return fType; }
PackageData& Data() { return fData; }
BPackageData& Data() { return fData; }
void SetType(uint32 type) { fType = type; }
private:
const char* fName;
uint32 fType;
PackageData fData;
BPackageData fData;
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // PACKAGE_ENTRY_ATTRIBUTE_H
#endif // _PACKAGE__HPKG__PACKAGE_ENTRY_ATTRIBUTE_H_
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__PACKAGE_READER_H_
#define _PACKAGE__HPKG__PACKAGE_READER_H_
#include <SupportDefs.h>
namespace BPackageKit {
namespace BHPKG {
namespace BPrivate {
class PackageReaderImpl;
}
using BPrivate::PackageReaderImpl;
class BErrorOutput;
class BLowLevelPackageContentHandler;
class BPackageContentHandler;
class BPackageReader {
public:
BPackageReader(
BErrorOutput* errorOutput);
~BPackageReader();
status_t Init(const char* fileName);
status_t Init(int fd, bool keepFD);
status_t ParseContent(
BPackageContentHandler* contentHandler);
status_t ParseContent(BLowLevelPackageContentHandler*
contentHandler);
int PackageFileFD();
private:
PackageReaderImpl* fImpl;
};
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_H_
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__PACKAGE_WRITER_H_
#define _PACKAGE__HPKG__PACKAGE_WRITER_H_
#include <SupportDefs.h>
namespace BPackageKit {
namespace BHPKG {
namespace BPrivate {
class PackageWriterImpl;
}
using BPrivate::PackageWriterImpl;
class BPackageWriter {
public:
BPackageWriter();
~BPackageWriter();
status_t Init(const char* fileName);
status_t AddEntry(const char* fileName);
status_t Finish();
private:
PackageWriterImpl* fImpl;
};
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__PACKAGE_WRITER_H_
@@ -1,71 +0,0 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
#define _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
#include <package/hpkg/BufferCache.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
class BlockBufferCache : public BufferCache {
public:
BlockBufferCache(size_t blockSize,
uint32 maxCachedBlocks);
virtual ~BlockBufferCache();
virtual status_t Init();
virtual CachedBuffer* GetBuffer(size_t size,
CachedBuffer** owner = NULL,
bool* _newBuffer = NULL);
virtual void PutBufferAndCache(CachedBuffer** owner);
virtual void PutBuffer(CachedBuffer** owner);
virtual bool Lock() = 0;
virtual void Unlock() = 0;
private:
typedef DoublyLinkedList<CachedBuffer> BufferList;
private:
CachedBuffer* _AllocateBuffer(size_t size,
CachedBuffer** owner, bool* _newBuffer);
// object must not be locked
private:
size_t fBlockSize;
uint32 fMaxCachedBlocks;
uint32 fAllocatedBlocks;
BufferList fUnusedBuffers;
BufferList fCachedBuffers;
};
class BlockBufferCacheNoLock : public BlockBufferCache {
public:
BlockBufferCacheNoLock(size_t blockSize,
uint32 maxCachedBlocks);
virtual ~BlockBufferCacheNoLock();
virtual bool Lock();
virtual void Unlock();
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
@@ -0,0 +1,66 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_CACHE_H_
#define _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_CACHE_H_
#include <SupportDefs.h>
#include <util/DoublyLinkedList.h>
#include <package/hpkg/BufferCache.h>
namespace BPackageKit {
namespace BHPKG {
namespace BPrivate {
class CachedBuffer;
class BlockBufferCacheImpl : public BBufferCache {
public:
BlockBufferCacheImpl(size_t blockSize,
uint32 maxCachedBlocks,
BBufferCacheLockable* lockable);
~BlockBufferCacheImpl();
status_t Init();
CachedBuffer* GetBuffer(size_t size,
CachedBuffer** owner = NULL,
bool* _newBuffer = NULL);
void PutBufferAndCache(CachedBuffer** owner);
void PutBuffer(CachedBuffer** owner);
private:
typedef DoublyLinkedList<CachedBuffer> BufferList;
private:
CachedBuffer* _AllocateBuffer(size_t size,
CachedBuffer** owner, bool* _newBuffer);
// object must not be locked
private:
size_t fBlockSize;
uint32 fMaxCachedBlocks;
uint32 fAllocatedBlocks;
BufferList fUnusedBuffers;
BufferList fCachedBuffers;
BBufferCacheLockable* fLockable;
};
} // namespace BPrivate
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_CACHE_H_
@@ -2,18 +2,20 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__HPKG__BUFFER_CACHE_H_
#define _PACKAGE__HPKG__BUFFER_CACHE_H_
#ifndef _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
#define _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
#include <stddef.h>
#include <util/DoublyLinkedList.h>
#include <package/hpkg/BufferCache.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
@@ -43,26 +45,9 @@ private:
};
class BufferCache {
public:
virtual ~BufferCache();
virtual CachedBuffer* GetBuffer(size_t size,
CachedBuffer** owner = NULL,
bool* _newBuffer = NULL) = 0;
virtual void PutBufferAndCache(CachedBuffer** owner) = 0;
// caller is buffer owner and wants the
// buffer cached, if possible
virtual void PutBuffer(CachedBuffer** owner) = 0;
// puts the buffer for good, owner might
// have called PutBufferAndCache() before
// and might not own a buffer anymore
};
class CachedBufferPutter {
public:
CachedBufferPutter(BufferCache* cache, CachedBuffer** owner)
CachedBufferPutter(BBufferCache* cache, CachedBuffer** owner)
:
fCache(cache),
fOwner(owner),
@@ -70,7 +55,7 @@ public:
{
}
CachedBufferPutter(BufferCache* cache, CachedBuffer* buffer)
CachedBufferPutter(BBufferCache* cache, CachedBuffer* buffer)
:
fCache(cache),
fOwner(NULL),
@@ -89,7 +74,7 @@ public:
}
private:
BufferCache* fCache;
BBufferCache* fCache;
CachedBuffer** fOwner;
CachedBuffer* fBuffer;
};
@@ -97,9 +82,9 @@ private:
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // _PACKAGE__HPKG__BUFFER_CACHE_H_
#endif // _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
+5 -9
View File
@@ -2,15 +2,13 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef FD_CLOSER_H
#define FD_CLOSER_H
#ifndef _PACKAGE__HPKG__FD_CLOSER_H_
#define _PACKAGE__HPKG__FD_CLOSER_H_
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
struct FDCloser {
@@ -31,11 +29,9 @@ private:
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // FD_CLOSER_H
#endif // _PACKAGE__HPKG__FD_CLOSER_H_
@@ -1,65 +0,0 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef PACKAGE_DATA_READER_H
#define PACKAGE_DATA_READER_H
#include <package/hpkg/DataReader.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
class BufferCache;
class DataOutput;
class PackageData;
class PackageDataReader : public DataReader {
public:
PackageDataReader(DataReader* dataReader);
virtual ~PackageDataReader();
virtual status_t Init(const PackageData& data) = 0;
virtual status_t ReadData(off_t offset, void* buffer,
size_t size);
virtual status_t ReadDataToOutput(off_t offset, size_t size,
DataOutput* output) = 0;
virtual uint64 Size() const = 0;
virtual size_t BlockSize() const = 0;
protected:
DataReader* fDataReader;
};
class PackageDataReaderFactory {
public:
PackageDataReaderFactory(
BufferCache* bufferCache);
status_t CreatePackageDataReader(DataReader* dataReader,
const PackageData& data,
PackageDataReader*& _reader);
private:
BufferCache* fBufferCache;
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BPackageKit
#endif // PACKAGE_DATA_READER_H
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef PACKAGE_READER_H
#define PACKAGE_READER_H
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
#include <SupportDefs.h>
@@ -11,59 +11,34 @@
#include <util/SinglyLinkedList.h>
#include <package/hpkg/PackageAttributeValue.h>
#include <package/hpkg/PackageContentHandler.h>
#include <package/hpkg/PackageReader.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
class BPackageEntry;
class BPackageEntryAttribute;
class BErrorOutput;
namespace BPrivate {
class ErrorOutput;
class PackageEntry;
class PackageEntryAttribute;
class LowLevelPackageContentHandler {
class PackageReaderImpl {
public:
virtual ~LowLevelPackageContentHandler();
virtual status_t HandleAttribute(const char* attributeName,
const PackageAttributeValue& value,
void* parentToken, void*& _token) = 0;
virtual status_t HandleAttributeDone(const char* attributeName,
const PackageAttributeValue& value,
void* token) = 0;
virtual void HandleErrorOccurred() = 0;
};
class PackageContentHandler {
public:
virtual ~PackageContentHandler();
virtual status_t HandleEntry(PackageEntry* entry) = 0;
virtual status_t HandleEntryAttribute(PackageEntry* entry,
PackageEntryAttribute* attribute) = 0;
virtual status_t HandleEntryDone(PackageEntry* entry) = 0;
virtual void HandleErrorOccurred() = 0;
};
class PackageReader {
public:
PackageReader(ErrorOutput* errorOutput);
~PackageReader();
PackageReaderImpl(
BErrorOutput* errorOutput);
~PackageReaderImpl();
status_t Init(const char* fileName);
status_t Init(int fd, bool keepFD);
status_t ParseContent(
PackageContentHandler* contentHandler);
status_t ParseContent(
LowLevelPackageContentHandler*
BPackageContentHandler* contentHandler);
status_t ParseContent(BLowLevelPackageContentHandler*
contentHandler);
int PackageFileFD() { return fFD; }
@@ -81,7 +56,7 @@ private:
struct PackageAttributeHandler;
struct PackageContentListHandler;
typedef PackageAttributeValue AttributeValue;
typedef BPackageAttributeValue AttributeValue;
typedef SinglyLinkedList<AttributeHandler> AttributeHandlerList;
private:
@@ -128,7 +103,7 @@ private:
inline AttributeHandler* _PopAttributeHandler();
private:
ErrorOutput* fErrorOutput;
BErrorOutput* fErrorOutput;
int fFD;
bool fOwnsFD;
@@ -164,7 +139,7 @@ private:
template<typename Type>
status_t
PackageReader::_Read(Type& _value)
PackageReaderImpl::_Read(Type& _value)
{
return _ReadTOCBuffer(&_value, sizeof(Type));
}
@@ -172,9 +147,9 @@ PackageReader::_Read(Type& _value)
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // PACKAGE_READER_H
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_READER_IMPL_H_
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef PACKAGE_WRITER_H
#define PACKAGE_WRITER_H
#ifndef _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
#define _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
#include <util/DoublyLinkedList.h>
@@ -14,23 +14,25 @@
namespace BPackageKit {
namespace BHaikuPackage {
class BPackageInfo;
namespace BHPKG {
class BDataReader;
namespace BPrivate {
class DataReader;
struct hpkg_header;
namespace BPackageKit {
class BPackageInfo;
}
class PackageWriter {
class PackageWriterImpl {
public:
PackageWriter();
~PackageWriter();
PackageWriterImpl();
~PackageWriterImpl();
status_t Init(const char* fileName);
status_t AddEntry(const char* fileName);
@@ -104,10 +106,10 @@ private:
AttributeType* _GetAttributeType(const char* attributeName,
uint8 type);
status_t _AddData(DataReader& dataReader, off_t size);
status_t _WriteUncompressedData(DataReader& dataReader,
status_t _AddData(BDataReader& dataReader, off_t size);
status_t _WriteUncompressedData(BDataReader& dataReader,
off_t size, uint64 writeOffset);
status_t _WriteZlibCompressedData(DataReader& dataReader,
status_t _WriteZlibCompressedData(BDataReader& dataReader,
off_t size, uint64 writeOffset,
uint64& _compressedSize);
@@ -134,9 +136,9 @@ private:
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // PACKAGE_WRITER_H
#endif // _PACKAGE__HPKG__PRIVATE__PACKAGE_WRITER_IMPL_H_
+5 -5
View File
@@ -2,13 +2,13 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef STACKER_H
#define STACKER_H
#ifndef _PACKAGE__HPKG__PRIVATE__STACKER_H_
#define _PACKAGE__HPKG__PRIVATE__STACKER_H_
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
@@ -46,9 +46,9 @@ private:
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // STACKER_H
#endif // _PACKAGE__HPKG__PRIVATE__STACKER_H_
+5 -5
View File
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef STRINGS_H
#define STRINGS_H
#ifndef _PACKAGE__HPKG__PRIVATE__STRINGS_H_
#define _PACKAGE__HPKG__PRIVATE__STRINGS_H_
#include <util/OpenHashTable.h>
@@ -11,7 +11,7 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
@@ -88,9 +88,9 @@ struct CachedStringUsageGreater {
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // STRINGS_H
#endif // _PACKAGE__HPKG__PRIVATE__STRINGS_H_
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef ZLIB_COMPRESSION_BASE_H
#define ZLIB_COMPRESSION_BASE_H
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSION_BASE_H_
#define _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSION_BASE_H_
#include <SupportDefs.h>
@@ -11,7 +11,7 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
@@ -24,9 +24,9 @@ public:
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // ZLIB_COMPRESSION_BASE_H
#endif // _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSION_BASE_H_
+11 -10
View File
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef ZLIB_COMPRESSOR_H
#define ZLIB_COMPRESSOR_H
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
#define _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
#include <zlib.h>
@@ -13,17 +13,18 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
class BDataOutput;
namespace BPrivate {
class DataOutput;
class ZlibCompressor : public ZlibCompressionBase {
public:
ZlibCompressor(DataOutput* output);
ZlibCompressor(BDataOutput* output);
~ZlibCompressor();
status_t Init();
@@ -37,16 +38,16 @@ public:
private:
z_stream fStream;
DataOutput* fOutput;
BDataOutput* fOutput;
bool fStreamInitialized;
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // ZLIB_COMPRESSOR_H
#endif // _PACKAGE__HPKG__PRIVATE__ZLIB_COMPRESSOR_H_
+11 -10
View File
@@ -2,8 +2,8 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef ZLIB_DECOMPRESSOR_H
#define ZLIB_DECOMPRESSOR_H
#ifndef _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
#define _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
#include <zlib.h>
@@ -13,17 +13,18 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
class BDataOutput;
namespace BPrivate {
class DataOutput;
class ZlibDecompressor : public ZlibCompressionBase {
public:
ZlibDecompressor(DataOutput* output);
ZlibDecompressor(BDataOutput* output);
~ZlibDecompressor();
status_t Init();
@@ -38,7 +39,7 @@ public:
private:
z_stream fStream;
DataOutput* fOutput;
BDataOutput* fOutput;
bool fStreamInitialized;
bool fFinished;
};
@@ -46,9 +47,9 @@ private:
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // ZLIB_DECOMPRESSOR_H
#endif // _PACKAGE__HPKG__PRIVATE__ZLIB_DECOMPRESSOR_H_
+7 -55
View File
@@ -2,16 +2,18 @@
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _HAIKU_PACKAGE_H
#define _HAIKU_PACKAGE_H
#ifndef _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
#define _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
#include <SupportDefs.h>
#include <package/hpkg/HPKGDefs.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
@@ -40,13 +42,6 @@ struct hpkg_header {
};
// magic, version
enum {
B_HPKG_MAGIC = 'hpkg',
B_HPKG_VERSION = 1
};
// compression types
enum {
B_HPKG_COMPRESSION_NONE = 0,
@@ -54,39 +49,6 @@ enum {
};
// attribute types
enum {
// types
B_HPKG_ATTRIBUTE_TYPE_INVALID = 0,
B_HPKG_ATTRIBUTE_TYPE_INT = 1,
B_HPKG_ATTRIBUTE_TYPE_UINT = 2,
B_HPKG_ATTRIBUTE_TYPE_STRING = 3,
B_HPKG_ATTRIBUTE_TYPE_RAW = 4
};
// attribute encodings
enum {
// signed/unsigned int encodings
B_HPKG_ATTRIBUTE_ENCODING_INT_8_BIT = 0,
B_HPKG_ATTRIBUTE_ENCODING_INT_16_BIT = 1,
B_HPKG_ATTRIBUTE_ENCODING_INT_32_BIT = 2,
B_HPKG_ATTRIBUTE_ENCODING_INT_64_BIT = 3,
// string encodings
B_HPKG_ATTRIBUTE_ENCODING_STRING_INLINE = 0,
// null-terminated string
B_HPKG_ATTRIBUTE_ENCODING_STRING_TABLE = 1,
// unsigned LEB128 index into string table
// raw data encodings
B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE = 0,
// unsigned LEB128 size, raw bytes
B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP = 1
// unsigned LEB128 size, unsigned LEB128 offset into the heap
};
// attribute tag arithmetics
#define B_HPKG_ATTRIBUTE_TAG_COMPOSE(index, encoding, hasChildren) \
(((uint64(index) << 3) | uint64(encoding) << 1 \
@@ -143,15 +105,6 @@ enum {
};
// maximum number of bytes of data to be encoded inline; more will be allocated
// on the heap
#define B_HPKG_MAX_INLINE_DATA_SIZE 8
// name of file containing package information (in package's root folder)
#define B_HPKG_PACKAGE_INFO_FILE_NAME ".PackageInfo"
// default values
enum {
B_HPKG_DEFAULT_FILE_TYPE = B_HPKG_FILE_TYPE_FILE,
@@ -159,15 +112,14 @@ enum {
B_HPKG_DEFAULT_DIRECTORY_PERMISSIONS = 0755,
B_HPKG_DEFAULT_SYMLINK_PERMISSIONS = 0777,
B_HPKG_DEFAULT_DATA_COMPRESSION = B_HPKG_COMPRESSION_NONE,
B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB = 64 * 1024
};
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
#endif // _HAIKU_PACKAGE_H
#endif // _PACKAGE__HPKG__PRIVATE__HAIKU_PACKAGE_H_
@@ -10,7 +10,7 @@
BlockBufferCacheKernel::BlockBufferCacheKernel(size_t blockSize,
uint32 maxCachedBlocks)
:
BlockBufferCache(blockSize, maxCachedBlocks)
BlockBufferCacheImpl(blockSize, maxCachedBlocks, this)
{
mutex_init(&fLock, "BlockBufferCache");
}
@@ -6,15 +6,18 @@
#define BLOCK_BUFFER_CACHE_KERNEL_H
#include <util/AutoLock.h>
#include <lock.h>
#include <package/hpkg/BlockBufferCache.h>
#include <package/hpkg/BlockBufferCacheImpl.h>
#include <package/hpkg/BufferCache.h>
using BPackageKit::BHaikuPackage::BPrivate::BlockBufferCache;
using BPackageKit::BHPKG::BBufferCacheLockable;
using BPackageKit::BHPKG::BPrivate::BlockBufferCacheImpl;
class BlockBufferCacheKernel : public BlockBufferCache {
class BlockBufferCacheKernel
: public BlockBufferCacheImpl, BBufferCacheLockable {
public:
BlockBufferCacheKernel(size_t blockSize,
uint32 maxCachedBlocks);
@@ -66,8 +66,8 @@ GlobalFactory::Default()
status_t
GlobalFactory::CreatePackageDataReader(DataReader* dataReader,
const PackageData& data, PackageDataReader*& _reader)
GlobalFactory::CreatePackageDataReader(BDataReader* dataReader,
const BPackageData& data, BPackageDataReader*& _reader)
{
return fPackageDataReaderFactory.CreatePackageDataReader(dataReader, data,
_reader);
@@ -6,13 +6,17 @@
#define GLOBAL_FACTORY_H
#include <package/hpkg/haiku_package.h>
#include <package/hpkg/HPKGDefs.h>
#include <package/hpkg/PackageDataReader.h>
#include "BlockBufferCacheKernel.h"
using namespace BPackageKit::BHaikuPackage::BPrivate;
using BPackageKit::BHPKG::BDataReader;
using BPackageKit::BHPKG::BPackageData;
using BPackageKit::BHPKG::BPackageDataReader;
using BPackageKit::BHPKG::BPackageDataReaderFactory;
using BPackageKit::BHPKG::B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB;
class GlobalFactory {
@@ -25,9 +29,9 @@ public:
static void DeleteDefault();
static GlobalFactory* Default();
status_t CreatePackageDataReader(DataReader* dataReader,
const PackageData& data,
PackageDataReader*& _reader);
status_t CreatePackageDataReader(BDataReader* dataReader,
const BPackageData& data,
BPackageDataReader*& _reader);
private:
status_t _Init();
@@ -36,7 +40,7 @@ private:
static GlobalFactory* sDefaultInstance;
BlockBufferCacheKernel fBufferCache;
PackageDataReaderFactory fPackageDataReaderFactory;
BPackageDataReaderFactory fPackageDataReaderFactory;
};
#endif // GLOBAL_FACTORY_H
@@ -29,16 +29,18 @@ HAIKU_PACKAGE_FS_SOURCES =
;
HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES =
BlockBufferCache.cpp
BlockBufferCacheImpl.cpp
BufferCache.cpp
CachedBuffer.cpp
DataOutput.cpp
DataReader.cpp
ErrorOutput.cpp
PackageEntryAttribute.cpp
PackageContentHandler.cpp
PackageData.cpp
PackageDataReader.cpp
PackageEntry.cpp
PackageReader.cpp
PackageEntryAttribute.cpp
PackageReaderImpl.cpp
# compression
ZlibCompressionBase.cpp
@@ -10,6 +10,7 @@
#include <new>
#include <fs_cache.h>
#include <util/AutoLock.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/DataReader.h>
@@ -20,13 +21,13 @@
#include "Package.h"
using namespace BPackageKit::BHaikuPackage::BPrivate;
using namespace BPackageKit::BHPKG;
// #pragma mark - DataAccessor
struct PackageFile::IORequestOutput : DataOutput {
struct PackageFile::IORequestOutput : BDataOutput {
public:
IORequestOutput(io_request* request)
:
@@ -45,7 +46,7 @@ private:
struct PackageFile::DataAccessor {
DataAccessor(PackageData* data)
DataAccessor(BPackageData* data)
:
fData(data),
fDataReader(NULL),
@@ -65,17 +66,17 @@ struct PackageFile::DataAccessor {
status_t Init(dev_t deviceID, ino_t nodeID, int fd)
{
// create a DataReader for the compressed data
// create a BDataReader for the compressed data
if (fData->IsEncodedInline()) {
fDataReader = new(std::nothrow) BufferDataReader(
fDataReader = new(std::nothrow) BBufferDataReader(
fData->InlineData(), fData->CompressedSize());
} else
fDataReader = new(std::nothrow) FDDataReader(fd);
fDataReader = new(std::nothrow) BFDDataReader(fd);
if (fDataReader == NULL)
RETURN_ERROR(B_NO_MEMORY);
// create a PackageDataReader
// create a BPackageDataReader
status_t error = GlobalFactory::Default()->CreatePackageDataReader(
fDataReader, *fData, fReader);
if (error != B_OK)
@@ -125,9 +126,9 @@ struct PackageFile::DataAccessor {
private:
mutex fLock;
PackageData* fData;
DataReader* fDataReader;
PackageDataReader* fReader;
BPackageData* fData;
BDataReader* fDataReader;
BPackageDataReader* fReader;
void* fFileCache;
};
@@ -135,7 +136,7 @@ private:
// #pragma mark - PackageFile
PackageFile::PackageFile(Package* package, mode_t mode, const PackageData& data)
PackageFile::PackageFile(Package* package, mode_t mode, const BPackageData& data)
:
PackageLeafNode(package, mode),
fData(data),
@@ -11,13 +11,13 @@
#include "PackageLeafNode.h"
using BPackageKit::BHaikuPackage::BPrivate::PackageData;
using BPackageKit::BHPKG::BPackageData;
class PackageFile : public PackageLeafNode {
public:
PackageFile(Package* package, mode_t mode,
const PackageData& data);
const BPackageData& data);
virtual ~PackageFile();
virtual status_t VFSInit(dev_t deviceID, ino_t nodeID);
@@ -34,7 +34,7 @@ private:
struct DataAccessor;
private:
PackageData fData;
BPackageData fData;
DataAccessor* fDataAccessor;
};
@@ -11,7 +11,7 @@
#include <io_requests.h>
class PackageData;
class BPackageData;
class PackageLeafNode : public PackageNode {
@@ -11,7 +11,7 @@
PackageNodeAttribute::PackageNodeAttribute(PackageNode* parent, uint32 type,
const PackageData& data)
const BPackageData& data)
:
fData(data),
fParent(parent),
@@ -11,7 +11,7 @@
#include <package/hpkg/PackageData.h>
using BPackageKit::BHaikuPackage::BPrivate::PackageData;
using BPackageKit::BHPKG::BPackageData;
class PackageNode;
@@ -20,19 +20,19 @@ class PackageNodeAttribute
: public DoublyLinkedListLinkImpl<PackageNodeAttribute> {
public:
PackageNodeAttribute(PackageNode* parent,
uint32 type, const PackageData& data);
uint32 type, const BPackageData& data);
~PackageNodeAttribute();
PackageNode* Parent() const { return fParent; }
const char* Name() const { return fName; }
uint32 Type() const { return fType; }
const PackageData& Data() const { return fData; }
const BPackageData& Data() const { return fData; }
status_t Init(const char* name);
protected:
PackageData fData;
BPackageData fData;
PackageNode* fParent;
char* fName;
uint32 fType;
@@ -27,7 +27,7 @@
#include <package/hpkg/FDCloser.h>
#include <package/hpkg/PackageEntry.h>
#include <package/hpkg/PackageEntryAttribute.h>
#include <package/hpkg/PackageReader.h>
#include <package/hpkg/PackageReaderImpl.h>
#include "DebugSupport.h"
#include "Directory.h"
@@ -38,7 +38,8 @@
#include "PackageSymlink.h"
using namespace BPackageKit::BHaikuPackage::BPrivate;
using namespace BPackageKit::BHPKG;
using BPackageKit::BHPKG::BPrivate::PackageReaderImpl;
// node ID of the root directory
@@ -131,7 +132,7 @@ private:
// #pragma mark - PackageLoaderErrorOutput
struct Volume::PackageLoaderErrorOutput : ErrorOutput {
struct Volume::PackageLoaderErrorOutput : BErrorOutput {
PackageLoaderErrorOutput(Package* package)
:
fPackage(package)
@@ -151,7 +152,7 @@ private:
// #pragma mark - PackageLoaderContentHandler
struct Volume::PackageLoaderContentHandler : PackageContentHandler {
struct Volume::PackageLoaderContentHandler : BPackageContentHandler {
PackageLoaderContentHandler(Package* package)
:
fPackage(package),
@@ -164,7 +165,7 @@ struct Volume::PackageLoaderContentHandler : PackageContentHandler {
return B_OK;
}
virtual status_t HandleEntry(PackageEntry* entry)
virtual status_t HandleEntry(BPackageEntry* entry)
{
if (fErrorOccurred)
return B_OK;
@@ -228,8 +229,8 @@ struct Volume::PackageLoaderContentHandler : PackageContentHandler {
return B_OK;
}
virtual status_t HandleEntryAttribute(PackageEntry* entry,
PackageEntryAttribute* attribute)
virtual status_t HandleEntryAttribute(BPackageEntry* entry,
BPackageEntryAttribute* attribute)
{
if (fErrorOccurred)
return B_OK;
@@ -252,7 +253,7 @@ struct Volume::PackageLoaderContentHandler : PackageContentHandler {
return B_OK;
}
virtual status_t HandleEntryDone(PackageEntry* entry)
virtual status_t HandleEntryDone(BPackageEntry* entry)
{
return B_OK;
}
@@ -604,7 +605,7 @@ Volume::_LoadPackage(Package* package)
// initialize package reader
PackageLoaderErrorOutput errorOutput(package);
PackageReader packageReader(&errorOutput);
PackageReaderImpl packageReader(&errorOutput);
status_t error = packageReader.Init(fd, false);
if (error != B_OK)
return error;
@@ -25,6 +25,10 @@
#include "Volume.h"
using BPackageKit::BHPKG::BBufferDataReader;
using BPackageKit::BHPKG::BFDDataReader;
static const uint32 kOptimalIOSize = 64 * 1024;
@@ -939,16 +943,16 @@ packagefs_free_attr_cookie(fs_volume* fsVolume, fs_vnode* fsNode, void* _cookie)
static status_t
read_package_data(const PackageData& data, DataReader* dataReader, off_t offset,
read_package_data(const BPackageData& data, BDataReader* dataReader, off_t offset,
void* buffer, size_t* bufferSize)
{
// create a PackageDataReader
PackageDataReader* reader;
// create a BPackageDataReader
BPackageDataReader* reader;
status_t error = GlobalFactory::Default()->CreatePackageDataReader(
dataReader, data, reader);
if (error != B_OK)
RETURN_ERROR(error);
ObjectDeleter<PackageDataReader> readerDeleter(reader);
ObjectDeleter<BPackageDataReader> readerDeleter(reader);
// check the offset
if (offset < 0 || (uint64)offset > data.UncompressedSize())
@@ -983,10 +987,10 @@ packagefs_read_attr(fs_volume* fsVolume, fs_vnode* fsNode, void* _cookie,
TOUCH(volume);
TOUCH(node);
const PackageData& data = cookie->attribute->Data();
const BPackageData& data = cookie->attribute->Data();
if (data.IsEncodedInline()) {
// inline data
BufferDataReader dataReader(data.InlineData(), data.CompressedSize());
BBufferDataReader dataReader(data.InlineData(), data.CompressedSize());
return read_package_data(data, &dataReader, offset, buffer, bufferSize);
}
@@ -996,7 +1000,7 @@ packagefs_read_attr(fs_volume* fsVolume, fs_vnode* fsNode, void* _cookie,
RETURN_ERROR(fd);
PackageCloser packageCloser(cookie->package);
FDDataReader dataReader(fd);
BFDDataReader dataReader(fd);
return read_package_data(data, &dataReader, offset, buffer, bufferSize);
}
@@ -0,0 +1,33 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "BlockBufferCacheNoLock.h"
BlockBufferCacheNoLock::BlockBufferCacheNoLock(size_t blockSize,
uint32 maxCachedBlocks)
:
BBlockBufferCache(blockSize, maxCachedBlocks)
{
}
BlockBufferCacheNoLock::~BlockBufferCacheNoLock()
{
}
bool
BlockBufferCacheNoLock::Lock()
{
return true;
}
void
BlockBufferCacheNoLock::Unlock()
{
}
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef BLOCK_BUFFER_CACHE_NO_LOCK_H
#define BLOCK_BUFFER_CACHE_NO_LOCK_H
#include <package/hpkg/BlockBufferCache.h>
using BPackageKit::BHPKG::BBlockBufferCache;
class BlockBufferCacheNoLock : public BBlockBufferCache {
public:
BlockBufferCacheNoLock(size_t blockSize,
uint32 maxCachedBlocks);
virtual ~BlockBufferCacheNoLock();
virtual bool Lock();
virtual void Unlock();
};
#endif // BLOCK_BUFFER_CACHE_NO_LOCK_H
+1
View File
@@ -6,6 +6,7 @@ DEFINES += B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT ;
# TODO: Remove when it is complete!
BinCommand package :
BlockBufferCacheNoLock.cpp
command_create.cpp
command_dump.cpp
command_extract.cpp
+2 -2
View File
@@ -9,10 +9,10 @@
#include <package/hpkg/ErrorOutput.h>
using BPackageKit::BHaikuPackage::BPrivate::ErrorOutput;
using BPackageKit::BHPKG::BErrorOutput;
class StandardErrorOutput : public ErrorOutput {
class StandardErrorOutput : public BErrorOutput {
virtual void PrintErrorVarArgs(const char* format,
va_list args);
};
+3 -3
View File
@@ -14,14 +14,14 @@
#include <Entry.h>
#include <package/PackageInfo.h>
#include <package/hpkg/haiku_package.h>
#include <package/hpkg/HPKGDefs.h>
#include <package/hpkg/PackageWriter.h>
#include "package.h"
using BPackageKit::BPackageInfo;
using BPackageKit::BHaikuPackage::BPrivate::PackageWriter;
using BPackageKit::BHPKG::BPackageWriter;
int
@@ -65,7 +65,7 @@ command_create(int argc, const char* const* argv)
int fileNameCount = argc - optind;
// create package
PackageWriter packageWriter;
BPackageWriter packageWriter;
status_t error = packageWriter.Init(packageFileName);
printf("Init(): %s\n", strerror(error));
if (error != B_OK)
+9 -6
View File
@@ -11,6 +11,9 @@
#include <stdlib.h>
#include <string.h>
#include <package/hpkg/HPKGDefs.h>
#include <package/hpkg/PackageAttributeValue.h>
#include <package/hpkg/PackageContentHandler.h>
#include <package/hpkg/PackageEntry.h>
#include <package/hpkg/PackageEntryAttribute.h>
#include <package/hpkg/PackageReader.h>
@@ -19,10 +22,10 @@
#include "StandardErrorOutput.h"
using namespace BPackageKit::BHaikuPackage::BPrivate;
using namespace BPackageKit::BHPKG;
struct PackageContentDumpHandler : LowLevelPackageContentHandler {
struct PackageContentDumpHandler : BLowLevelPackageContentHandler {
PackageContentDumpHandler()
:
fLevel(0),
@@ -32,7 +35,7 @@ struct PackageContentDumpHandler : LowLevelPackageContentHandler {
}
virtual status_t HandleAttribute(const char* attributeName,
const PackageAttributeValue& value, void* parentToken, void*& _token)
const BPackageAttributeValue& value, void* parentToken, void*& _token)
{
if (fErrorOccurred)
return B_OK;
@@ -47,7 +50,7 @@ struct PackageContentDumpHandler : LowLevelPackageContentHandler {
}
virtual status_t HandleAttributeDone(const char* attributeName,
const PackageAttributeValue& value, void* token)
const BPackageAttributeValue& value, void* token)
{
if (fErrorOccurred)
return B_OK;
@@ -67,7 +70,7 @@ struct PackageContentDumpHandler : LowLevelPackageContentHandler {
}
private:
void _PrintValue(const PackageAttributeValue& value)
void _PrintValue(const BPackageAttributeValue& value)
{
switch (value.type) {
case B_HPKG_ATTRIBUTE_TYPE_INT:
@@ -139,7 +142,7 @@ command_dump(int argc, const char* const* argv)
// open package
StandardErrorOutput errorOutput;
PackageReader packageReader(&errorOutput);
BPackageReader packageReader(&errorOutput);
status_t error = packageReader.Init(packageFileName);
printf("Init(): %s\n", strerror(error));
if (error != B_OK)
+19 -18
View File
@@ -21,21 +21,22 @@
#include <AutoDeleter.h>
#include <package/hpkg/BlockBufferCache.h>
#include <package/hpkg/FDCloser.h>
#include <package/hpkg/PackageContentHandler.h>
#include <package/hpkg/PackageDataReader.h>
#include <package/hpkg/PackageEntry.h>
#include <package/hpkg/PackageEntryAttribute.h>
#include <package/hpkg/PackageReader.h>
#include "BlockBufferCacheNoLock.h"
#include "package.h"
#include "StandardErrorOutput.h"
using namespace BPackageKit::BHaikuPackage::BPrivate;
using namespace BPackageKit::BHPKG;
struct PackageContentExtractHandler : PackageContentHandler {
struct PackageContentExtractHandler : BPackageContentHandler {
PackageContentExtractHandler(int packageFileFD)
:
fBufferCache(B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB, 2),
@@ -65,7 +66,7 @@ struct PackageContentExtractHandler : PackageContentHandler {
return B_OK;
}
virtual status_t HandleEntry(PackageEntry* entry)
virtual status_t HandleEntry(BPackageEntry* entry)
{
// create a token
Token* token = new(std::nothrow) Token;
@@ -124,9 +125,9 @@ struct PackageContentExtractHandler : PackageContentHandler {
// write data
status_t error;
const PackageData& data = entry->Data();
const BPackageData& data = entry->Data();
if (data.IsEncodedInline()) {
BufferDataReader dataReader(data.InlineData(),
BBufferDataReader dataReader(data.InlineData(),
data.CompressedSize());
error = _ExtractFileData(&dataReader, data, fd);
} else
@@ -183,8 +184,8 @@ struct PackageContentExtractHandler : PackageContentHandler {
return B_OK;
}
virtual status_t HandleEntryAttribute(PackageEntry* entry,
PackageEntryAttribute* attribute)
virtual status_t HandleEntryAttribute(BPackageEntry* entry,
BPackageEntryAttribute* attribute)
{
int entryFD = ((Token*)entry->UserToken())->fd;
@@ -201,9 +202,9 @@ struct PackageContentExtractHandler : PackageContentHandler {
// write data
status_t error;
const PackageData& data = attribute->Data();
const BPackageData& data = attribute->Data();
if (data.IsEncodedInline()) {
BufferDataReader dataReader(data.InlineData(),
BBufferDataReader dataReader(data.InlineData(),
data.CompressedSize());
error = _ExtractFileData(&dataReader, data, fd);
} else
@@ -215,7 +216,7 @@ struct PackageContentExtractHandler : PackageContentHandler {
return B_OK;
}
virtual status_t HandleEntryDone(PackageEntry* entry)
virtual status_t HandleEntryDone(BPackageEntry* entry)
{
if (Token* token = (Token*)entry->UserToken()) {
delete token;
@@ -248,16 +249,16 @@ private:
};
private:
status_t _ExtractFileData(DataReader* dataReader, const PackageData& data,
status_t _ExtractFileData(BDataReader* dataReader, const BPackageData& data,
int fd)
{
// create a PackageDataReader
PackageDataReader* reader;
status_t error = PackageDataReaderFactory(&fBufferCache)
// create a BPackageDataReader
BPackageDataReader* reader;
status_t error = BPackageDataReaderFactory(&fBufferCache)
.CreatePackageDataReader(dataReader, data, reader);
if (error != B_OK)
return error;
ObjectDeleter<PackageDataReader> readerDeleter(reader);
ObjectDeleter<BPackageDataReader> readerDeleter(reader);
// write the data
off_t bytesRemaining = data.UncompressedSize();
@@ -293,7 +294,7 @@ private:
private:
BlockBufferCacheNoLock fBufferCache;
FDDataReader fPackageFileReader;
BFDDataReader fPackageFileReader;
void* fDataBuffer;
size_t fDataBufferSize;
bool fErrorOccurred;
@@ -339,7 +340,7 @@ command_extract(int argc, const char* const* argv)
// open package
StandardErrorOutput errorOutput;
PackageReader packageReader(&errorOutput);
BPackageReader packageReader(&errorOutput);
status_t error = packageReader.Init(packageFileName);
printf("Init(): %s\n", strerror(error));
if (error != B_OK)
+8 -7
View File
@@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <package/hpkg/PackageContentHandler.h>
#include <package/hpkg/PackageEntry.h>
#include <package/hpkg/PackageEntryAttribute.h>
#include <package/hpkg/PackageReader.h>
@@ -19,10 +20,10 @@
#include "StandardErrorOutput.h"
using namespace BPackageKit::BHaikuPackage::BPrivate;
using namespace BPackageKit::BHPKG;
struct PackageContentListHandler : PackageContentHandler {
struct PackageContentListHandler : BPackageContentHandler {
PackageContentListHandler(bool listAttributes)
:
fLevel(0),
@@ -30,7 +31,7 @@ struct PackageContentListHandler : PackageContentHandler {
{
}
virtual status_t HandleEntry(PackageEntry* entry)
virtual status_t HandleEntry(BPackageEntry* entry)
{
fLevel++;
@@ -74,8 +75,8 @@ struct PackageContentListHandler : PackageContentHandler {
return B_OK;
}
virtual status_t HandleEntryAttribute(PackageEntry* entry,
PackageEntryAttribute* attribute)
virtual status_t HandleEntryAttribute(BPackageEntry* entry,
BPackageEntryAttribute* attribute)
{
if (!fListAttribute)
return B_OK;
@@ -97,7 +98,7 @@ struct PackageContentListHandler : PackageContentHandler {
return B_OK;
}
virtual status_t HandleEntryDone(PackageEntry* entry)
virtual status_t HandleEntryDone(BPackageEntry* entry)
{
fLevel--;
return B_OK;
@@ -167,7 +168,7 @@ command_list(int argc, const char* const* argv)
// open package
StandardErrorOutput errorOutput;
PackageReader packageReader(&errorOutput);
BPackageReader packageReader(&errorOutput);
status_t error = packageReader.Init(packageFileName);
printf("Init(): %s\n", strerror(error));
if (error != B_OK)
+5
View File
@@ -10,16 +10,21 @@ SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
HPKG_SOURCES =
BlockBufferCache.cpp
BlockBufferCacheImpl.cpp
BufferCache.cpp
CachedBuffer.cpp
DataOutput.cpp
DataReader.cpp
ErrorOutput.cpp
PackageContentHandler.cpp
PackageData.cpp
PackageDataReader.cpp
PackageEntry.cpp
PackageEntryAttribute.cpp
PackageReader.cpp
PackageReaderImpl.cpp
PackageWriter.cpp
PackageWriterImpl.cpp
Strings.cpp
# compression
+26 -176
View File
@@ -6,217 +6,67 @@
#include <package/hpkg/BlockBufferCache.h>
#include <algorithm>
#include <new>
#include <AutoLocker.h>
#include <package/hpkg/BlockBufferCacheImpl.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
// #pragma mark - BlockBufferCache
BlockBufferCache::BlockBufferCache(size_t blockSize, uint32 maxCachedBlocks)
BBlockBufferCache::BBlockBufferCache(size_t blockSize, uint32 maxCachedBlocks)
:
fBlockSize(blockSize),
fMaxCachedBlocks(maxCachedBlocks),
fAllocatedBlocks(0)
fImpl(new (std::nothrow) BlockBufferCacheImpl(blockSize, maxCachedBlocks,
this))
{
}
BlockBufferCache::~BlockBufferCache()
BBlockBufferCache::~BBlockBufferCache()
{
// delete all cached blocks
while (CachedBuffer* block = fCachedBuffers.RemoveHead())
delete block;
while (CachedBuffer* block = fUnusedBuffers.RemoveHead())
delete block;
delete fImpl;
}
status_t
BlockBufferCache::Init()
BBlockBufferCache::Init()
{
return B_OK;
if (fImpl == NULL)
return B_NO_MEMORY;
return fImpl->Init();
}
CachedBuffer*
BlockBufferCache::GetBuffer(size_t size, CachedBuffer** owner, bool* _newBuffer)
{
// for sizes greater than the block size, we always allocate a new buffer
if (size > fBlockSize)
return _AllocateBuffer(size, owner, _newBuffer);
AutoLocker<BlockBufferCache> locker(this);
// if an owner is given and the buffer is still cached, return it
if (owner != NULL && *owner != NULL) {
CachedBuffer* buffer = *owner;
fCachedBuffers.Remove(buffer);
if (_newBuffer != NULL)
*_newBuffer = false;
return buffer;
}
// we need a new buffer -- try unused ones first
CachedBuffer* buffer = fUnusedBuffers.RemoveHead();
if (buffer != NULL) {
buffer->SetOwner(owner);
if (owner != NULL)
*owner = buffer;
if (_newBuffer != NULL)
*_newBuffer = true;
return buffer;
}
// if we have already hit the max block limit, steal a cached block
if (fAllocatedBlocks >= fMaxCachedBlocks) {
buffer = fCachedBuffers.RemoveHead();
if (buffer != NULL) {
buffer->SetCached(false);
*buffer->Owner() = NULL;
buffer->SetOwner(owner);
if (owner != NULL)
*owner = buffer;
if (_newBuffer != NULL)
*_newBuffer = true;
return buffer;
}
}
// allocate a new buffer
locker.Unlock();
return _AllocateBuffer(size, owner, _newBuffer);
}
void
BlockBufferCache::PutBufferAndCache(CachedBuffer** owner)
{
CachedBuffer* buffer = *owner;
// always delete buffers with non-standard size
if (buffer->Size() != fBlockSize) {
*owner = NULL;
delete buffer;
return;
}
AutoLocker<BlockBufferCache> locker(this);
// queue the cached buffer
buffer->SetOwner(owner);
fCachedBuffers.Add(buffer);
buffer->SetCached(true);
if (fAllocatedBlocks > fMaxCachedBlocks) {
// We have exceeded the limit -- we need to free a buffer.
CachedBuffer* otherBuffer = fUnusedBuffers.RemoveHead();
if (otherBuffer == NULL) {
otherBuffer = fCachedBuffers.RemoveHead();
*otherBuffer->Owner() = NULL;
otherBuffer->SetCached(false);
}
delete otherBuffer;
}
}
void
BlockBufferCache::PutBuffer(CachedBuffer** owner)
{
AutoLocker<BlockBufferCache> locker(this);
CachedBuffer* buffer = *owner;
if (buffer == NULL)
return;
if (buffer->IsCached()) {
fCachedBuffers.Remove(buffer);
buffer->SetCached(false);
}
buffer->SetOwner(NULL);
*owner = NULL;
if (buffer->Size() == fBlockSize && fAllocatedBlocks < fMaxCachedBlocks)
fUnusedBuffers.Add(buffer);
else
delete buffer;
}
CachedBuffer*
BlockBufferCache::_AllocateBuffer(size_t size, CachedBuffer** owner,
BBlockBufferCache::GetBuffer(size_t size, CachedBuffer** owner,
bool* _newBuffer)
{
CachedBuffer* buffer = new(std::nothrow) CachedBuffer(
std::max(size, fBlockSize));
if (buffer == NULL || buffer->Buffer() == NULL) {
delete buffer;
if (fImpl == NULL)
return NULL;
}
buffer->SetOwner(owner);
if (_newBuffer != NULL)
*_newBuffer = true;
AutoLocker<BlockBufferCache> locker(this);
fAllocatedBlocks++;
if (owner != NULL)
*owner = buffer;
return buffer;
}
// #pragma mark - BlockBufferCacheNoLock
BlockBufferCacheNoLock::BlockBufferCacheNoLock(size_t blockSize,
uint32 maxCachedBlocks)
:
BlockBufferCache(blockSize, maxCachedBlocks)
{
}
BlockBufferCacheNoLock::~BlockBufferCacheNoLock()
{
}
bool
BlockBufferCacheNoLock::Lock()
{
return true;
return fImpl->GetBuffer(size, owner, _newBuffer);
}
void
BlockBufferCacheNoLock::Unlock()
BBlockBufferCache::PutBufferAndCache(CachedBuffer** owner)
{
if (fImpl != NULL)
fImpl->PutBufferAndCache(owner);
}
} // namespace BPrivate
void
BBlockBufferCache::PutBuffer(CachedBuffer** owner)
{
if (fImpl != NULL)
fImpl->PutBuffer(owner);
}
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
@@ -0,0 +1,197 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include <package/hpkg/BlockBufferCacheImpl.h>
#include <algorithm>
#include <new>
#include <AutoLocker.h>
#include <package/hpkg/CachedBuffer.h>
namespace BPackageKit {
namespace BHPKG {
namespace BPrivate {
// #pragma mark - BlockBufferCacheImpl
BlockBufferCacheImpl::BlockBufferCacheImpl(size_t blockSize,
uint32 maxCachedBlocks, BBufferCacheLockable* lockable)
:
fBlockSize(blockSize),
fMaxCachedBlocks(maxCachedBlocks),
fAllocatedBlocks(0),
fLockable(lockable)
{
}
BlockBufferCacheImpl::~BlockBufferCacheImpl()
{
// delete all cached blocks
while (CachedBuffer* block = fCachedBuffers.RemoveHead())
delete block;
while (CachedBuffer* block = fUnusedBuffers.RemoveHead())
delete block;
}
status_t
BlockBufferCacheImpl::Init()
{
return B_OK;
}
CachedBuffer*
BlockBufferCacheImpl::GetBuffer(size_t size, CachedBuffer** owner, bool* _newBuffer)
{
// for sizes greater than the block size, we always allocate a new buffer
if (size > fBlockSize)
return _AllocateBuffer(size, owner, _newBuffer);
AutoLocker<BBufferCacheLockable> locker(fLockable);
// if an owner is given and the buffer is still cached, return it
if (owner != NULL && *owner != NULL) {
CachedBuffer* buffer = *owner;
fCachedBuffers.Remove(buffer);
if (_newBuffer != NULL)
*_newBuffer = false;
return buffer;
}
// we need a new buffer -- try unused ones first
CachedBuffer* buffer = fUnusedBuffers.RemoveHead();
if (buffer != NULL) {
buffer->SetOwner(owner);
if (owner != NULL)
*owner = buffer;
if (_newBuffer != NULL)
*_newBuffer = true;
return buffer;
}
// if we have already hit the max block limit, steal a cached block
if (fAllocatedBlocks >= fMaxCachedBlocks) {
buffer = fCachedBuffers.RemoveHead();
if (buffer != NULL) {
buffer->SetCached(false);
*buffer->Owner() = NULL;
buffer->SetOwner(owner);
if (owner != NULL)
*owner = buffer;
if (_newBuffer != NULL)
*_newBuffer = true;
return buffer;
}
}
// allocate a new buffer
locker.Unlock();
return _AllocateBuffer(size, owner, _newBuffer);
}
void
BlockBufferCacheImpl::PutBufferAndCache(CachedBuffer** owner)
{
CachedBuffer* buffer = *owner;
// always delete buffers with non-standard size
if (buffer->Size() != fBlockSize) {
*owner = NULL;
delete buffer;
return;
}
AutoLocker<BBufferCacheLockable> locker(fLockable);
// queue the cached buffer
buffer->SetOwner(owner);
fCachedBuffers.Add(buffer);
buffer->SetCached(true);
if (fAllocatedBlocks > fMaxCachedBlocks) {
// We have exceeded the limit -- we need to free a buffer.
CachedBuffer* otherBuffer = fUnusedBuffers.RemoveHead();
if (otherBuffer == NULL) {
otherBuffer = fCachedBuffers.RemoveHead();
*otherBuffer->Owner() = NULL;
otherBuffer->SetCached(false);
}
delete otherBuffer;
}
}
void
BlockBufferCacheImpl::PutBuffer(CachedBuffer** owner)
{
AutoLocker<BBufferCacheLockable> locker(fLockable);
CachedBuffer* buffer = *owner;
if (buffer == NULL)
return;
if (buffer->IsCached()) {
fCachedBuffers.Remove(buffer);
buffer->SetCached(false);
}
buffer->SetOwner(NULL);
*owner = NULL;
if (buffer->Size() == fBlockSize && fAllocatedBlocks < fMaxCachedBlocks)
fUnusedBuffers.Add(buffer);
else
delete buffer;
}
CachedBuffer*
BlockBufferCacheImpl::_AllocateBuffer(size_t size, CachedBuffer** owner,
bool* _newBuffer)
{
CachedBuffer* buffer = new(std::nothrow) CachedBuffer(
std::max(size, fBlockSize));
if (buffer == NULL || buffer->Buffer() == NULL) {
delete buffer;
return NULL;
}
buffer->SetOwner(owner);
if (_newBuffer != NULL)
*_newBuffer = true;
AutoLocker<BBufferCacheLockable> locker(fLockable);
fAllocatedBlocks++;
if (owner != NULL)
*owner = buffer;
return buffer;
}
} // namespace BPrivate
} // namespace BHPKG
} // namespace BPackageKit
+4 -27
View File
@@ -6,45 +6,22 @@
#include <package/hpkg/BufferCache.h>
#include <stdlib.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
// #pragma mark - CachedBuffer
CachedBuffer::CachedBuffer(size_t size)
:
fOwner(NULL),
fBuffer(malloc(size)),
fSize(size),
fCached(false)
BBufferCache::~BBufferCache()
{
}
CachedBuffer::~CachedBuffer()
{
free(fBuffer);
}
// #pragma mark - BufferCache
BufferCache::~BufferCache()
BBufferCacheLockable::~BBufferCacheLockable()
{
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include <package/hpkg/CachedBuffer.h>
#include <stdlib.h>
namespace BPackageKit {
namespace BHPKG {
namespace BPrivate {
CachedBuffer::CachedBuffer(size_t size)
:
fOwner(NULL),
fBuffer(malloc(size)),
fSize(size),
fCached(false)
{
}
CachedBuffer::~CachedBuffer()
{
free(fBuffer);
}
} // namespace BPrivate
} // namespace BHPKG
} // namespace BPackageKit
+7 -11
View File
@@ -11,23 +11,21 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
// #pragma mark - DataOutput
// #pragma mark - BDataOutput
DataOutput::~DataOutput()
BDataOutput::~BDataOutput()
{
}
// #pragma mark - BufferDataOutput
// #pragma mark - BBufferDataOutput
BufferDataOutput::BufferDataOutput(void* buffer, size_t size)
BBufferDataOutput::BBufferDataOutput(void* buffer, size_t size)
:
fBuffer(buffer),
fSize(size),
@@ -37,7 +35,7 @@ BufferDataOutput::BufferDataOutput(void* buffer, size_t size)
status_t
BufferDataOutput::WriteData(const void* buffer, size_t size)
BBufferDataOutput::WriteData(const void* buffer, size_t size)
{
if (size == 0)
return B_OK;
@@ -51,8 +49,6 @@ BufferDataOutput::WriteData(const void* buffer, size_t size)
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
+13 -17
View File
@@ -15,23 +15,21 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
// #pragma mark - DataReader
// #pragma mark - BDataReader
DataReader::~DataReader()
BDataReader::~BDataReader()
{
}
// #pragma mark - FDDataReader
// #pragma mark - BFDDataReader
FDDataReader::FDDataReader(int fd)
BFDDataReader::BFDDataReader(int fd)
:
fFD(fd)
{
@@ -39,7 +37,7 @@ FDDataReader::FDDataReader(int fd)
status_t
FDDataReader::ReadData(off_t offset, void* buffer, size_t size)
BFDDataReader::ReadData(off_t offset, void* buffer, size_t size)
{
ssize_t bytesRead = pread(fFD, buffer, size, offset);
if (bytesRead < 0)
@@ -48,10 +46,10 @@ FDDataReader::ReadData(off_t offset, void* buffer, size_t size)
}
// #pragma mark - AttributeDataReader
// #pragma mark - BAttributeDataReader
AttributeDataReader::AttributeDataReader(int fd, const char* attribute,
BAttributeDataReader::BAttributeDataReader(int fd, const char* attribute,
uint32 type)
:
fFD(fd),
@@ -62,7 +60,7 @@ AttributeDataReader::AttributeDataReader(int fd, const char* attribute,
status_t
AttributeDataReader::ReadData(off_t offset, void* buffer, size_t size)
BAttributeDataReader::ReadData(off_t offset, void* buffer, size_t size)
{
ssize_t bytesRead = fs_read_attr(fFD, fAttribute, fType, offset, buffer,
size);
@@ -72,10 +70,10 @@ AttributeDataReader::ReadData(off_t offset, void* buffer, size_t size)
}
// #pragma mark - BufferDataReader
// #pragma mark - BBufferDataReader
BufferDataReader::BufferDataReader(const void* data, size_t size)
BBufferDataReader::BBufferDataReader(const void* data, size_t size)
:
fData(data),
fSize(size)
@@ -84,7 +82,7 @@ BufferDataReader::BufferDataReader(const void* data, size_t size)
status_t
BufferDataReader::ReadData(off_t offset, void* buffer, size_t size)
BBufferDataReader::ReadData(off_t offset, void* buffer, size_t size)
{
if (size == 0)
return B_OK;
@@ -100,8 +98,6 @@ BufferDataReader::ReadData(off_t offset, void* buffer, size_t size)
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
+4 -8
View File
@@ -11,18 +11,16 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
ErrorOutput::~ErrorOutput()
BErrorOutput::~BErrorOutput()
{
}
void
ErrorOutput::PrintError(const char* format, ...)
BErrorOutput::PrintError(const char* format, ...)
{
va_list args;
va_start(args, format);
@@ -31,8 +29,6 @@ ErrorOutput::PrintError(const char* format, ...)
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
@@ -0,0 +1,33 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include <package/hpkg/PackageContentHandler.h>
namespace BPackageKit {
namespace BHPKG {
// #pragma mark - BLowLevelPackageContentHandler
BLowLevelPackageContentHandler::~BLowLevelPackageContentHandler()
{
}
// #pragma mark - BPackageContentHandler
BPackageContentHandler::~BPackageContentHandler()
{
}
} // namespace BHPKG
} // namespace BPackageKit
+10 -9
View File
@@ -8,15 +8,18 @@
#include <string.h>
#include <package/hpkg/haiku_package.h>
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
PackageData::PackageData()
using namespace BPrivate;
BPackageData::BPackageData()
:
fCompressedSize(0),
fUncompressedSize(0),
@@ -28,7 +31,7 @@ PackageData::PackageData()
void
PackageData::SetData(uint64 size, uint64 offset)
BPackageData::SetData(uint64 size, uint64 offset)
{
fUncompressedSize = fCompressedSize = size;
fOffset = offset;
@@ -37,7 +40,7 @@ PackageData::SetData(uint64 size, uint64 offset)
void
PackageData::SetData(uint8 size, const void* data)
BPackageData::SetData(uint8 size, const void* data)
{
fUncompressedSize = fCompressedSize = size;
if (size > 0)
@@ -46,8 +49,6 @@ PackageData::SetData(uint8 size, const void* data)
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
+28 -28
View File
@@ -13,6 +13,7 @@
#include <package/hpkg/haiku_package.h>
#include <package/hpkg/BufferCache.h>
#include <package/hpkg/CachedBuffer.h>
#include <package/hpkg/DataOutput.h>
#include <package/hpkg/PackageData.h>
#include <package/hpkg/ZlibDecompressor.h>
@@ -20,9 +21,10 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
using namespace BPrivate;
// minimum/maximum zlib chunk size we consider sane
@@ -36,25 +38,25 @@ static const size_t kUncompressedReaderBufferSize
= B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB;
// #pragma mark - PackageDataReader
// #pragma mark - BPackageDataReader
PackageDataReader::PackageDataReader(DataReader* dataReader)
BPackageDataReader::BPackageDataReader(BDataReader* dataReader)
:
fDataReader(dataReader)
{
}
PackageDataReader::~PackageDataReader()
BPackageDataReader::~BPackageDataReader()
{
}
status_t
PackageDataReader::ReadData(off_t offset, void* buffer, size_t size)
BPackageDataReader::ReadData(off_t offset, void* buffer, size_t size)
{
BufferDataOutput output(buffer, size);
BBufferDataOutput output(buffer, size);
return ReadDataToOutput(offset, size, &output);
}
@@ -62,17 +64,17 @@ PackageDataReader::ReadData(off_t offset, void* buffer, size_t size)
// #pragma mark - UncompressedPackageDataReader
class UncompressedPackageDataReader : public PackageDataReader {
class UncompressedPackageDataReader : public BPackageDataReader {
public:
UncompressedPackageDataReader(DataReader* dataReader,
BufferCache* bufferCache)
UncompressedPackageDataReader(BDataReader* dataReader,
BBufferCache* bufferCache)
:
PackageDataReader(dataReader),
BPackageDataReader(dataReader),
fBufferCache(bufferCache)
{
}
status_t Init(const PackageData& data)
status_t Init(const BPackageData& data)
{
fOffset = data.Offset();
fSize = data.UncompressedSize();
@@ -105,7 +107,7 @@ public:
}
virtual status_t ReadDataToOutput(off_t offset, size_t size,
DataOutput* output)
BDataOutput* output)
{
if (size == 0)
return B_OK;
@@ -144,7 +146,7 @@ public:
}
private:
BufferCache* fBufferCache;
BBufferCache* fBufferCache;
uint64 fOffset;
uint64 fSize;
};
@@ -153,11 +155,11 @@ private:
// #pragma mark - ZlibPackageDataReader
class ZlibPackageDataReader : public PackageDataReader {
class ZlibPackageDataReader : public BPackageDataReader {
public:
ZlibPackageDataReader(DataReader* dataReader, BufferCache* bufferCache)
ZlibPackageDataReader(BDataReader* dataReader, BBufferCache* bufferCache)
:
PackageDataReader(dataReader),
BPackageDataReader(dataReader),
fBufferCache(bufferCache),
fUncompressBuffer(NULL),
fOffsetTable(NULL)
@@ -171,7 +173,7 @@ public:
fBufferCache->PutBuffer(&fUncompressBuffer);
}
status_t Init(const PackageData& data)
status_t Init(const BPackageData& data)
{
fOffset = data.Offset();
fCompressedSize = data.CompressedSize();
@@ -222,7 +224,7 @@ public:
}
virtual status_t ReadDataToOutput(off_t offset, size_t size,
DataOutput* output)
BDataOutput* output)
{
// check offset and size
if (size == 0)
@@ -398,7 +400,7 @@ private:
}
private:
BufferCache* fBufferCache;
BBufferCache* fBufferCache;
CachedBuffer* fUncompressBuffer;
int64 fUncompressedChunk;
@@ -414,10 +416,10 @@ private:
};
// #pragma mark - PackageDataReaderFactory
// #pragma mark - BPackageDataReaderFactory
PackageDataReaderFactory::PackageDataReaderFactory(BufferCache* bufferCache)
BPackageDataReaderFactory::BPackageDataReaderFactory(BBufferCache* bufferCache)
:
fBufferCache(bufferCache)
{
@@ -425,10 +427,10 @@ PackageDataReaderFactory::PackageDataReaderFactory(BufferCache* bufferCache)
status_t
PackageDataReaderFactory::CreatePackageDataReader(DataReader* dataReader,
const PackageData& data, PackageDataReader*& _reader)
BPackageDataReaderFactory::CreatePackageDataReader(BDataReader* dataReader,
const BPackageData& data, BPackageDataReader*& _reader)
{
PackageDataReader* reader;
BPackageDataReader* reader;
switch (data.Compression()) {
case B_HPKG_COMPRESSION_NONE:
@@ -457,8 +459,6 @@ PackageDataReaderFactory::CreatePackageDataReader(DataReader* dataReader,
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
+3 -7
View File
@@ -9,12 +9,10 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
PackageEntry::PackageEntry(PackageEntry* parent, const char* name)
BPackageEntry::BPackageEntry(BPackageEntry* parent, const char* name)
:
fParent(parent),
fName(name),
@@ -31,8 +29,6 @@ PackageEntry::PackageEntry(PackageEntry* parent, const char* name)
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
@@ -9,12 +9,10 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BPrivate {
namespace BHPKG {
PackageEntryAttribute::PackageEntryAttribute(const char* name)
BPackageEntryAttribute::BPackageEntryAttribute(const char* name)
:
fName(name),
fType(0)
@@ -22,8 +20,6 @@ PackageEntryAttribute::PackageEntryAttribute(const char* name)
}
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -9,7 +9,7 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
@@ -36,6 +36,6 @@ hash_string(const char* string)
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
@@ -13,7 +13,7 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
@@ -49,6 +49,6 @@ ZlibCompressionBase::TranslateZlibError(int error)
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
+3 -3
View File
@@ -14,7 +14,7 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
@@ -22,7 +22,7 @@ namespace BPrivate {
static const size_t kOutputBufferSize = 1024;
ZlibCompressor::ZlibCompressor(DataOutput* output)
ZlibCompressor::ZlibCompressor(BDataOutput* output)
:
fOutput(output),
fStreamInitialized(false)
@@ -180,6 +180,6 @@ ZlibCompressor::CompressSingleBuffer(const void* input, size_t inputSize,
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit
+3 -3
View File
@@ -14,7 +14,7 @@
namespace BPackageKit {
namespace BHaikuPackage {
namespace BHPKG {
namespace BPrivate {
@@ -23,7 +23,7 @@ namespace BPrivate {
static const size_t kOutputBufferSize = 1024;
ZlibDecompressor::ZlibDecompressor(DataOutput* output)
ZlibDecompressor::ZlibDecompressor(BDataOutput* output)
:
fOutput(output),
fStreamInitialized(false),
@@ -187,6 +187,6 @@ ZlibDecompressor::DecompressSingleBuffer(const void* input, size_t inputSize,
} // namespace BPrivate
} // namespace BHaikuPackage
} // namespace BHPKG
} // namespace BPackageKit