blocxx
Public Types | Public Member Functions | Private Attributes

BLOCXX_NAMESPACE::File Class Reference

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>

List of all members.

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.
Fileoperator= (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

Detailed Description

The purpose of the File class is to provide an abstraction layer over the platform dependant functionality related to a file.

Definition at line 54 of file File.hpp.


Member Enumeration Documentation

Enumerator:
E_READ_LOCK 

Flag to place a read / shared lock.

More than one process may hold a shared lock for a given file at a given time.

E_WRITE_LOCK 

Flag to place an write / exclusive lock.

Only one process may hold an exclusive lock for a given file at a given time.

Definition at line 57 of file File.hpp.


Constructor & Destructor Documentation

BLOCXX_NAMESPACE::File::File ( ) [inline]

Create a NULL File object.

Definition at line 76 of file File.hpp.

BLOCXX_NAMESPACE::File::File ( const File x)

Copy constructor.

Parameters:
xThe 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]

Definition at line 244 of file File.hpp.


Member Function Documentation

int BLOCXX_NAMESPACE::File::close ( ) [inline]
int BLOCXX_NAMESPACE::File::flush ( ) [inline]

Flush any buffered data to the file.

Returns:
0 on success. Otherwise -1.

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.

Parameters:
typeWhether to acquire a read (shared) or a write (exclusive) lock. Default is a write lock.
Returns:
0 on sucess. On error, -1 is returned, and errno is set appropriately. errno may be one of: EBADF, EDEADLK, EINVAL, ENOLCK.

Definition at line 159 of file PosixFile.cpp.

References E_WRITE_LOCK, and m_hdl.

File& BLOCXX_NAMESPACE::File::operator= ( const File x) [inline]

Assignment operator.

Parameters:
xThe File object to copy.
Returns:
A reference to this File object.

Definition at line 93 of file File.hpp.

References swap().

bool BLOCXX_NAMESPACE::File::operator== ( const File rhs) [inline]

Equality operator.

Returns:
true if this is a valid File object.
Parameters:
rhsThe File object to compare this object to.
Returns:
true if this File represents the same file as rhs.

Definition at line 239 of file File.hpp.

size_t BLOCXX_NAMESPACE::File::read ( void *  bfr,
size_t  numberOfBytes,
Int64  offset = -1L 
) const [inline]

Read from the underlying file.

Parameters:
bfrThe location where the read operation will place what is read.
numberOfBytesThe number of bytes to read.
offsetThe offset to seek to in the file before the read operation is done or -1 to use the current offset.
Returns:
The number of bytes read. If an error occurs, size_t(-1) is returned and 0 on EOF.

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.

Parameters:
offsetThe offset to seek to relative to the whence parm.
whenceCan 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).
Returns:
The current location in the file relative to the beginning of the file on success. Other -1.

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]
void BLOCXX_NAMESPACE::File::swap ( File x) [inline]
Int64 BLOCXX_NAMESPACE::File::tell ( ) const [inline]
Returns:
The current position in the file relative to the beginning of the file on success. Otherwise -1.

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.

Parameters:
typeWhether to try to acquire a read (shared) or a write (exclusive) lock. Default is a write lock.
Returns:
0 on sucess. On error, -1 is returned, and errno is set appropriately. errno may be one of: EACCES, EAGAIN, EBADF, EDEADLK, EINVAL, ENOLCK. EACCES or EAGAIN signifies the file is already locked.

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.

Returns:
0 on sucess. On error, -1 is returned, and errno is set appropriately. errno may be one of: EAGAIN, EBADF, EDEADLK, EINVAL, ENOLCK.

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.

Parameters:
bfrThe locaction to get the contents to write.
numberOfBytesThe number of bytes to write.
offsetThe offset to seek to in the file before the write operation is done or -1 to use the current offset.
Returns:
The number of bytes written. If an error occurs, size_t(-1) is returned.

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().


Member Data Documentation

Definition at line 250 of file File.hpp.

Referenced by getLock(), swap(), tryLock(), unlock(), and ~File().


The documentation for this class was generated from the following files: