blocxx
|
The purpose of the File class is to provide an abstraction layer over the platform dependant functionality related to a file. More...
#include <File.hpp>
Public Types | |
enum | ELockType { E_READ_LOCK, E_WRITE_LOCK } |
Public Member Functions | |
File () | |
Create a NULL File object. | |
File (const File &x) | |
Copy constructor. | |
~File () | |
Destructor. | |
File & | operator= (const File &x) |
Assignment operator. | |
void | swap (File &x) |
size_t | read (void *bfr, size_t numberOfBytes, Int64 offset=-1L) const |
Read from the underlying file. | |
size_t | write (const void *bfr, size_t numberOfBytes, Int64 offset=-1L) |
Write to the underlying file. | |
Int64 | seek (Int64 offset, int whence) const |
Seek to a given offset within the file. | |
Int64 | tell () const |
void | rewind () const |
Position the file pointer to the beginning of the file. | |
UInt64 | size () const |
Current size of file. | |
int | close () |
Close the underlying file object. | |
int | flush () |
Flush any buffered data to the file. | |
int | getLock (ELockType type=E_WRITE_LOCK) |
Acquire a kernel lock on the file. | |
int | tryLock (ELockType type=E_WRITE_LOCK) |
Acquire a kernel lock on the file. | |
int | unlock () |
Release a lock on the file. | |
bool | operator== (const File &rhs) |
Equality operator. | |
File (FileHandle hdl) | |
Private Attributes | |
FileHandle | m_hdl |
The purpose of the File class is to provide an abstraction layer over the platform dependant functionality related to a file.
BLOCXX_NAMESPACE::File::File | ( | ) | [inline] |
BLOCXX_NAMESPACE::File::File | ( | const File & | x | ) |
Copy constructor.
x | The File object to copy. |
Definition at line 136 of file PosixFile.cpp.
BLOCXX_NAMESPACE::File::~File | ( | ) |
Destructor.
Definition at line 180 of file PosixFile.cpp.
References BLOCXX_LOG_ERROR, close(), and m_hdl.
BLOCXX_NAMESPACE::File::File | ( | FileHandle | hdl | ) | [inline] |
int BLOCXX_NAMESPACE::File::close | ( | ) | [inline] |
Close the underlying file object.
Definition at line 171 of file File.hpp.
References BLOCXX_INVALID_FILEHANDLE, and BLOCXX_NAMESPACE::FileSystem::close().
Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::close(), BLOCXX_NAMESPACE::MultiProcessFileAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::TempFileEnumerationImplBase::readSize(), BLOCXX_NAMESPACE::TempFileBuffer::reset(), and ~File().
int BLOCXX_NAMESPACE::File::flush | ( | ) | [inline] |
Flush any buffered data to the file.
Definition at line 185 of file File.hpp.
References BLOCXX_NAMESPACE::FileSystem::flush().
Referenced by BLOCXX_NAMESPACE::MultiProcessFileAppender::doProcessLogMessage().
int BLOCXX_NAMESPACE::File::getLock | ( | ELockType | type = E_WRITE_LOCK | ) |
Acquire a kernel lock on the file.
This call may block.
The lock may be released by calling unlock(). The lock will also be released on when the file is closed or when locking application exits. This is only an advisory lock and will not prevent non-coordinated access to the file.
type | Whether to acquire a read (shared) or a write (exclusive) lock. Default is a write lock. |
Definition at line 159 of file PosixFile.cpp.
References E_WRITE_LOCK, and m_hdl.
bool BLOCXX_NAMESPACE::File::operator== | ( | const File & | rhs | ) | [inline] |
size_t BLOCXX_NAMESPACE::File::read | ( | void * | bfr, |
size_t | numberOfBytes, | ||
Int64 | offset = -1L |
||
) | const [inline] |
Read from the underlying file.
bfr | The location where the read operation will place what is read. |
numberOfBytes | The number of bytes to read. |
offset | The offset to seek to in the file before the read operation is done or -1 to use the current offset. |
Definition at line 113 of file File.hpp.
References BLOCXX_NAMESPACE::BinarySerialization::read().
Referenced by BLOCXX_NAMESPACE::TempFileBuffer::buffer_from_device(), and BLOCXX_NAMESPACE::TempFileEnumerationImplBase::readSize().
void BLOCXX_NAMESPACE::File::rewind | ( | ) | const [inline] |
Position the file pointer to the beginning of the file.
Definition at line 156 of file File.hpp.
References BLOCXX_NAMESPACE::FileSystem::rewind().
Int64 BLOCXX_NAMESPACE::File::seek | ( | Int64 | offset, |
int | whence | ||
) | const [inline] |
Seek to a given offset within the file.
offset | The offset to seek to relative to the whence parm. |
whence | Can be one of the follwing values: SEEK_SET - Seek relative to the beginning of the file. SEEK_CUR - Seek relative to the current position. SEEK_END - Seek relative to the end of the file (bwd). |
Definition at line 141 of file File.hpp.
References BLOCXX_NAMESPACE::FileSystem::seek().
Referenced by BLOCXX_NAMESPACE::TempFileBuffer::overflow(), BLOCXX_NAMESPACE::TempFileEnumerationImplBase::readSize(), BLOCXX_NAMESPACE::TempFileBuffer::rewind(), and BLOCXX_NAMESPACE::TempFileBuffer::underflow().
UInt64 BLOCXX_NAMESPACE::File::size | ( | ) | const [inline] |
Current size of file.
Definition at line 163 of file File.hpp.
References BLOCXX_NAMESPACE::FileSystem::fileSize().
Referenced by BLOCXX_NAMESPACE::MultiProcessFileAppender::doProcessLogMessage(), and BLOCXX_NAMESPACE::TempFileBuffer::getSize().
void BLOCXX_NAMESPACE::File::swap | ( | File & | x | ) | [inline] |
Definition at line 98 of file File.hpp.
References m_hdl, and BLOCXX_NAMESPACE::swap().
Referenced by BLOCXX_NAMESPACE::MultiProcessFileAppender::doProcessLogMessage(), and operator=().
Int64 BLOCXX_NAMESPACE::File::tell | ( | ) | const [inline] |
Definition at line 149 of file File.hpp.
References BLOCXX_NAMESPACE::FileSystem::tell().
Referenced by BLOCXX_NAMESPACE::TempFileBuffer::overflow(), and BLOCXX_NAMESPACE::TempFileBuffer::underflow().
int BLOCXX_NAMESPACE::File::tryLock | ( | ELockType | type = E_WRITE_LOCK | ) |
Acquire a kernel lock on the file.
This call won't block.
The lock may be released by calling unlock(). The lock will also be released when the locking application exits. This is only an advisory lock and will not prevent non-coordinated access to the file.
type | Whether to try to acquire a read (shared) or a write (exclusive) lock. Default is a write lock. |
Definition at line 166 of file PosixFile.cpp.
References E_WRITE_LOCK, and m_hdl.
Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListenUDS().
int BLOCXX_NAMESPACE::File::unlock | ( | ) |
Release a lock on the file.
This call will not block.
Definition at line 173 of file PosixFile.cpp.
References m_hdl.
Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::close().
size_t BLOCXX_NAMESPACE::File::write | ( | const void * | bfr, |
size_t | numberOfBytes, | ||
Int64 | offset = -1L |
||
) | [inline] |
Write to the underlying file.
bfr | The locaction to get the contents to write. |
numberOfBytes | The number of bytes to write. |
offset | The offset to seek to in the file before the write operation is done or -1 to use the current offset. |
Definition at line 127 of file File.hpp.
References BLOCXX_NAMESPACE::BinarySerialization::write().
Referenced by BLOCXX_NAMESPACE::TempFileBuffer::buffer_to_device(), and BLOCXX_NAMESPACE::MultiProcessFileAppender::doProcessLogMessage().
FileHandle BLOCXX_NAMESPACE::File::m_hdl [private] |