Split package kit DataReader.cpp

Pull AttributeDataReader and FDDataReader implementations out of
DataReader.cpp into own source files. Thus we can avoid dependencies
(e.g. to fs_attr code) we don't need/want.
This commit is contained in:
Ingo Weinhold 2011-06-19 13:46:51 +02:00
parent caa4217eb5
commit fab5eddca9
6 changed files with 85 additions and 49 deletions

View File

@ -35,6 +35,7 @@ HAIKU_PACKAGE_FS_PACKAGE_READER_SOURCES =
DataOutput.cpp
DataReader.cpp
ErrorOutput.cpp
FDDataReader.cpp
PackageContentHandler.cpp
PackageData.cpp
PackageDataReader.cpp

View File

@ -19,6 +19,7 @@ USES_BE_API on libpackage_build.so = true ;
HPKG_SOURCES =
AttributeDataReader.cpp
BlockBufferCache.cpp
BlockBufferCacheImpl.cpp
BufferCache.cpp
@ -26,6 +27,7 @@ HPKG_SOURCES =
DataOutput.cpp
DataReader.cpp
ErrorOutput.cpp
FDDataReader.cpp
PackageContentHandler.cpp
PackageData.cpp
PackageDataReader.cpp

View File

@ -9,6 +9,7 @@ UsePrivateHeaders
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
HPKG_SOURCES =
AttributeDataReader.cpp
BlockBufferCache.cpp
BlockBufferCacheImpl.cpp
BufferCache.cpp
@ -16,6 +17,7 @@ HPKG_SOURCES =
DataOutput.cpp
DataReader.cpp
ErrorOutput.cpp
FDDataReader.cpp
PackageContentHandler.cpp
PackageData.cpp
PackageDataReader.cpp

View File

@ -0,0 +1,42 @@
/*
* Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include <package/hpkg/DataReader.h>
#include <errno.h>
#include <fs_attr.h>
namespace BPackageKit {
namespace BHPKG {
BAttributeDataReader::BAttributeDataReader(int fd, const char* attribute,
uint32 type)
:
fFD(fd),
fType(type),
fAttribute(attribute)
{
}
status_t
BAttributeDataReader::ReadData(off_t offset, void* buffer, size_t size)
{
ssize_t bytesRead = fs_read_attr(fFD, fAttribute, fType, offset, buffer,
size);
if (bytesRead < 0)
return errno;
return (size_t)bytesRead == size ? B_OK : B_ERROR;
}
} // namespace BHPKG
} // namespace BPackageKit

View File

@ -1,16 +1,12 @@
/*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include <package/hpkg/DataReader.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fs_attr.h>
namespace BPackageKit {
@ -26,50 +22,6 @@ BDataReader::~BDataReader()
}
// #pragma mark - BFDDataReader
BFDDataReader::BFDDataReader(int fd)
:
fFD(fd)
{
}
status_t
BFDDataReader::ReadData(off_t offset, void* buffer, size_t size)
{
ssize_t bytesRead = pread(fFD, buffer, size, offset);
if (bytesRead < 0)
return errno;
return (size_t)bytesRead == size ? B_OK : B_ERROR;
}
// #pragma mark - BAttributeDataReader
BAttributeDataReader::BAttributeDataReader(int fd, const char* attribute,
uint32 type)
:
fFD(fd),
fType(type),
fAttribute(attribute)
{
}
status_t
BAttributeDataReader::ReadData(off_t offset, void* buffer, size_t size)
{
ssize_t bytesRead = fs_read_attr(fFD, fAttribute, fType, offset, buffer,
size);
if (bytesRead < 0)
return errno;
return (size_t)bytesRead == size ? B_OK : B_ERROR;
}
// #pragma mark - BBufferDataReader

View File

@ -0,0 +1,37 @@
/*
* Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include <package/hpkg/DataReader.h>
#include <errno.h>
#include <unistd.h>
namespace BPackageKit {
namespace BHPKG {
BFDDataReader::BFDDataReader(int fd)
:
fFD(fd)
{
}
status_t
BFDDataReader::ReadData(off_t offset, void* buffer, size_t size)
{
ssize_t bytesRead = pread(fFD, buffer, size, offset);
if (bytesRead < 0)
return errno;
return (size_t)bytesRead == size ? B_OK : B_ERROR;
}
} // namespace BHPKG
} // namespace BPackageKit