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.
|
|
|
|
*/
|
2011-01-30 18:05:38 +03:00
|
|
|
#ifndef _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
|
|
|
|
#define _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
|
2009-11-18 18:26:11 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include <util/DoublyLinkedList.h>
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
#include <package/hpkg/BufferCache.h>
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
|
2009-11-18 18:26:11 +03:00
|
|
|
class CachedBuffer : public DoublyLinkedListLinkImpl<CachedBuffer> {
|
|
|
|
public:
|
|
|
|
CachedBuffer(size_t size);
|
|
|
|
~CachedBuffer();
|
|
|
|
|
|
|
|
void* Buffer() const { return fBuffer; }
|
|
|
|
size_t Size() const { return fSize; }
|
|
|
|
|
|
|
|
|
|
|
|
// implementation private
|
|
|
|
CachedBuffer** Owner() const { return fOwner; }
|
|
|
|
void SetOwner(CachedBuffer** owner)
|
|
|
|
{ fOwner = owner; }
|
|
|
|
|
|
|
|
void SetCached(bool cached) { fCached = cached; }
|
|
|
|
bool IsCached() const { return fCached; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
CachedBuffer** fOwner;
|
|
|
|
void* fBuffer;
|
|
|
|
size_t fSize;
|
|
|
|
bool fCached;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CachedBufferPutter {
|
|
|
|
public:
|
2011-01-30 18:05:38 +03:00
|
|
|
CachedBufferPutter(BBufferCache* cache, CachedBuffer** owner)
|
2009-11-18 18:26:11 +03:00
|
|
|
:
|
|
|
|
fCache(cache),
|
|
|
|
fOwner(owner),
|
|
|
|
fBuffer(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
CachedBufferPutter(BBufferCache* cache, CachedBuffer* buffer)
|
2009-11-18 18:26:11 +03:00
|
|
|
:
|
|
|
|
fCache(cache),
|
|
|
|
fOwner(NULL),
|
|
|
|
fBuffer(buffer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~CachedBufferPutter()
|
|
|
|
{
|
|
|
|
if (fCache != NULL) {
|
|
|
|
if (fOwner != NULL)
|
|
|
|
fCache->PutBufferAndCache(fOwner);
|
|
|
|
else if (fBuffer != NULL)
|
|
|
|
fCache->PutBuffer(&fBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-01-30 18:05:38 +03:00
|
|
|
BBufferCache* fCache;
|
2009-11-18 18:26:11 +03:00
|
|
|
CachedBuffer** fOwner;
|
|
|
|
CachedBuffer* fBuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
#endif // _PACKAGE__HPKG__PRIVATE__BUFFER_CACHE_H_
|