2009-11-18 18:26:11 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
2011-01-30 18:15:33 +03:00
|
|
|
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
2009-11-18 18:26:11 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2013-05-14 20:59:57 +04:00
|
|
|
#ifndef _PACKAGE__HPKG__PRIVATE__POOL_BUFFER_H_
|
|
|
|
#define _PACKAGE__HPKG__PRIVATE__POOL_BUFFER_H_
|
2009-11-18 18:26:11 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include <util/DoublyLinkedList.h>
|
|
|
|
|
2013-05-14 20:59:57 +04:00
|
|
|
#include <package/hpkg/BufferPool.h>
|
2011-01-30 18:05:38 +03:00
|
|
|
|
2009-11-18 18:26:11 +03:00
|
|
|
|
2011-01-28 02:17:03 +03:00
|
|
|
namespace BPackageKit {
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
namespace BHPKG {
|
2011-01-28 02:17:03 +03:00
|
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
|
|
|
|
|
2013-05-14 20:59:57 +04:00
|
|
|
class PoolBuffer : public DoublyLinkedListLinkImpl<PoolBuffer> {
|
2009-11-18 18:26:11 +03:00
|
|
|
public:
|
2013-05-14 20:59:57 +04:00
|
|
|
PoolBuffer(size_t size);
|
|
|
|
~PoolBuffer();
|
2009-11-18 18:26:11 +03:00
|
|
|
|
|
|
|
void* Buffer() const { return fBuffer; }
|
|
|
|
size_t Size() const { return fSize; }
|
|
|
|
|
|
|
|
|
|
|
|
// implementation private
|
2013-05-14 20:59:57 +04:00
|
|
|
PoolBuffer** Owner() const { return fOwner; }
|
|
|
|
void SetOwner(PoolBuffer** owner)
|
2009-11-18 18:26:11 +03:00
|
|
|
{ fOwner = owner; }
|
|
|
|
|
|
|
|
void SetCached(bool cached) { fCached = cached; }
|
|
|
|
bool IsCached() const { return fCached; }
|
|
|
|
|
|
|
|
private:
|
2013-05-14 20:59:57 +04:00
|
|
|
PoolBuffer** fOwner;
|
2009-11-18 18:26:11 +03:00
|
|
|
void* fBuffer;
|
|
|
|
size_t fSize;
|
|
|
|
bool fCached;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-05-14 20:59:57 +04:00
|
|
|
class PoolBufferPutter {
|
2009-11-18 18:26:11 +03:00
|
|
|
public:
|
2013-05-14 20:59:57 +04:00
|
|
|
PoolBufferPutter(BBufferPool* pool, PoolBuffer** owner)
|
2009-11-18 18:26:11 +03:00
|
|
|
:
|
2013-05-14 20:59:57 +04:00
|
|
|
fPool(pool),
|
2009-11-18 18:26:11 +03:00
|
|
|
fOwner(owner),
|
|
|
|
fBuffer(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-14 20:59:57 +04:00
|
|
|
PoolBufferPutter(BBufferPool* pool, PoolBuffer* buffer)
|
2009-11-18 18:26:11 +03:00
|
|
|
:
|
2013-05-14 20:59:57 +04:00
|
|
|
fPool(pool),
|
2009-11-18 18:26:11 +03:00
|
|
|
fOwner(NULL),
|
|
|
|
fBuffer(buffer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-14 20:59:57 +04:00
|
|
|
~PoolBufferPutter()
|
2009-11-18 18:26:11 +03:00
|
|
|
{
|
2013-05-14 20:59:57 +04:00
|
|
|
if (fPool != NULL) {
|
2009-11-18 18:26:11 +03:00
|
|
|
if (fOwner != NULL)
|
2013-05-14 20:59:57 +04:00
|
|
|
fPool->PutBufferAndCache(fOwner);
|
2009-11-18 18:26:11 +03:00
|
|
|
else if (fBuffer != NULL)
|
2013-05-14 20:59:57 +04:00
|
|
|
fPool->PutBuffer(&fBuffer);
|
2009-11-18 18:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-05-14 20:59:57 +04:00
|
|
|
BBufferPool* fPool;
|
|
|
|
PoolBuffer** fOwner;
|
|
|
|
PoolBuffer* fBuffer;
|
2009-11-18 18:26:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-28 02:17:03 +03:00
|
|
|
} // namespace BPrivate
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
} // namespace BHPKG
|
2011-01-28 02:17:03 +03:00
|
|
|
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
|
|
|
2013-05-14 20:59:57 +04:00
|
|
|
#endif // _PACKAGE__HPKG__PRIVATE__POOL_BUFFER_H_
|