Pyro higlevel API
Classes | Public Types | Public Member Functions | List of all members
os::File Class Reference
Inheritance diagram for os::File:
os::SeekableIO os::FSNode os::StreamableIO os::TempFile

Classes

class  Private
 

Public Types

enum  { DEFAULT_BUFFER_SIZE =32768 }
 

Public Member Functions

 File ()
 Default constructor. More...
 
 File (const String &cPath, int nOpenMode=O_RDONLY)
 Construct a file from a regular path. More...
 
 File (const Directory &cDir, const String &cName, int nOpenMode=O_RDONLY)
 Open a file addressed as a name inside a specified directory. More...
 
 File (const FileReference &cRef, int nOpenMode=O_RDONLY)
 Open a file referred to by a os::FileReference. More...
 
 File (const FSNode &cNode)
 Construct a file from a FSNode. More...
 
 File (int nFD)
 Construct a file object from a open filedescriptor. More...
 
 File (const File &cFile)
 Copy constructor. More...
 
virtual ~File ()
 
virtual status_t FDChanged (int nNewFD, const struct stat &sStat)
 
virtual off_t GetSize (bool bUpdateCache=true) const
 
virtual ssize_t Read (void *pBuffer, ssize_t nSize)
 
virtual ssize_t Write (const void *pBuffer, ssize_t nSize)
 
virtual ssize_t ReadPos (off_t nPos, void *pBuffer, ssize_t nSize)
 
virtual ssize_t WritePos (off_t nPos, const void *pBuffer, ssize_t nSize)
 
virtual off_t Seek (off_t nPos, int nMode)
 Move the file pointer. More...
 
status_t SetBufferSize (int nSize)
 Set the size of the files caching buffer. More...
 
int GetBufferSize () const
 Obtain the files buffer size. More...
 
status_t Flush ()
 Write unwritten data to the underlying file. More...
 
- Public Member Functions inherited from os::SeekableIO
virtual ~SeekableIO ()
 
- Public Member Functions inherited from os::StreamableIO
virtual ~StreamableIO ()
 
- Public Member Functions inherited from os::FSNode
 FSNode ()
 Default contructor. More...
 
 FSNode (const String &cPath, int nOpenMode=O_RDONLY)
 Construct a FSNode from a file path. More...
 
 FSNode (const Directory &cDir, const String &cName, int nOpenMode=O_RDONLY)
 Construct a FSNode from directory and a name inside that directory. More...
 
 FSNode (const FileReference &cRef, int nOpenMode=O_RDONLY)
 Construct a FSNode from a file reference. More...
 
 FSNode (int nFD)
 Construct a FSNode from a file descriptor. More...
 
 FSNode (const FSNode &cNode)
 Copy contructor. More...
 
virtual ~FSNode ()
 Destructor. More...
 
virtual status_t SetTo (const String &cPath, int nOpenMode=O_RDONLY)
 Open a node using a path. More...
 
virtual status_t SetTo (const Directory &cDir, const String &cPath, int nOpenMode=O_RDONLY)
 Open a node using a dir/path pair. More...
 
virtual status_t SetTo (const FileReference &cRef, int nOpenMode=O_RDONLY)
 Open the node referred to by the given os::FileReference. More...
 
virtual status_t SetTo (int nFD)
 Make the FSNode represent an already open file. More...
 
virtual status_t SetTo (const FSNode &cNode)
 Copy another FSNode. More...
 
virtual void Unset ()
 Reset the FSNode. More...
 
virtual bool IsValid () const
 Check if the node has been properly initialized. More...
 
virtual status_t GetStat (struct stat *psStat, bool bUpdateCache=true) const
 
virtual ino_t GetInode () const
 
virtual dev_t GetDev () const
 
virtual int GetMode (bool bUpdateCache=false) const
 
virtual time_t GetCTime (bool bUpdateCache=true) const
 
virtual time_t GetMTime (bool bUpdateCache=true) const
 
virtual time_t GetATime (bool bUpdateCache=true) const
 
bool IsDir () const
 
bool IsLink () const
 
bool IsFile () const
 
bool IsCharDev () const
 
bool IsBlockDev () const
 
bool IsFIFO () const
 
virtual status_t GetNextAttrName (String *pcName)
 Read the node's attribute directory. More...
 
virtual status_t RewindAttrdir ()
 Reset the attribute directory iterator. More...
 
virtual ssize_t WriteAttr (const String &cAttrName, int nFlags, int nType, const void *pBuffer, off_t nPos, size_t nLen)
 Add/update an attribute. More...
 
virtual ssize_t ReadAttr (const String &cAttrName, int nType, void *pBuffer, off_t nPos, size_t nLen)
 Read the data held by an attribute. More...
 
virtual status_t RemoveAttr (const String &cName)
 Remove an attribute from an FS node. More...
 
virtual status_t StatAttr (const String &cName, struct::attr_info *psBuffer)
 Get extended info about an attribute. More...
 
virtual int GetFileDescriptor () const
 

Detailed Description

Description:
See Also
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

Member Enumeration Documentation

anonymous enum
Enumerator
DEFAULT_BUFFER_SIZE 

Constructor & Destructor Documentation

File::File ( )
Description:
Initialize the instance to a known but invalid state. The instance must be successfully initialized with one of the SetTo() members before it can be used.
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)
File::File ( const String cPath,
int  nOpenMode = O_RDONLY 
)
Description:
Open the file pointed to by cPath. The node must be a regular file or a symlink pointing at a regular file. Anything else will cause and errno_exception(EINVAL) exception to be thrown.
Parameters
cPathThe file to open. The path can eigther be absolute (starting with "/") or relative to the current working directory.
nOpenMode
 Flags controling how the file should be opened. The value
 should be one of the O_RDONLY, O_WRONLY, or O_RDWR. In addition
 the following flags can be bitwise or'd in to further control
 the operation:

 - O_TRUNC  trunate the size to 0.
 - O_APPEND automatically move the file-pointer to the end
            of the file before each write (only valid for files)
 - O_NONBLOCK       open the file in non-blocking mode. This is only
            relevant for named pipes and PTY's.
 - O_NOCTTY Don't make the file controlling TTY even if \p cPath
            points to a PTY.
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

References os::FSNode::GetMode().

File::File ( const Directory cDir,
const String cPath,
int  nOpenMode = O_RDONLY 
)
Description:
Look at File( const std::string& cPath, int nOpenMode ) for a more detailed description.
Parameters
cDirThe directory to use as a base for cPath
cPathPath relative to cPath.
nOpenModeFlags controlling how to open the file. See File( const std::string& cPath, int nOpenMode ) for a full description.
See Also
File( const std::string& cPath, int nOpenMode )
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

References os::FSNode::GetMode().

File::File ( const FileReference cRef,
int  nOpenMode = O_RDONLY 
)
Description:
Look at File( const std::string& cPath, int nOpenMode ) for a more detailed description.
Parameters
cRefReference to the file to open.
nOpenModeFlags controlling how to open the file. See File( const std::string& cPath, int nOpenMode ) for a full description.
See Also
File( const std::string& cPath, int nOpenMode )
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

References os::FSNode::GetMode().

File::File ( const FSNode cNode)
Description:
This constructor can be used to "downcast" an os::FSNode to a os::File. The FSNode must represent a regular file, pipe, or PTY. Attempts to convert symlinks and directories will cause an errno_exception(EINVAL) exception to be thrown.
Parameters
cNodeThe FSNode to downcast.
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

References os::FSNode::GetMode().

File::File ( int  nFD)
Description:
Construct a file object from a open filedescriptor.
Note
The file descriptor will be close when the object is deleted.
Warning:
Parameters
\return
Error codes:
Since
0.3.7
See Also
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

References os::FSNode::GetMode().

File::File ( const File cFile)
Description:
This constructor will make an independent copy of cFile. The copy and original will have their own file pointers and they will have their own attribute directory iterators (see note).
Note:
The attribute directory iterator will not be cloned so when FSNode::GetNextAttrName() is called for the first time it will return the first attribute name even if the iterator was not located at the beginning of the originals attribute directory.
Parameters
cFileThe file object to copy.
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

References os::File::Private::m_nBufferSize, and os::File::Private::m_nPosition.

File::~File ( )
virtual

Member Function Documentation

status_t File::FDChanged ( int  nNewFD,
const struct stat &  sStat 
)
virtual
status_t File::Flush ( void  )
Note:
Flush() will be called automatically by the destructor if there is unwritten data in the buffer.
Returns
On success 0 will be returned. On failure -1 will be returned and a error code will be stored in the global variable "errno".
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

References os::FSNode::GetFileDescriptor(), os::File::Private::m_bDirty, os::File::Private::m_cMutex, os::File::Private::m_nBufPos, os::File::Private::m_nValidBufSize, and os::File::Private::m_pBuffer.

Referenced by FDChanged(), os::RegistrarManager::RegisterTypeIconFromRes(), SetBufferSize(), WritePos(), and ~File().

int File::GetBufferSize ( ) const
Returns
The files buffer size in bytes. A value of 0 means the file is unbuffered.
See Also
SetBufferSize()
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

References os::File::Private::m_nBufferSize.

off_t File::GetSize ( bool  bUpdateCache = true) const
virtual
ssize_t File::Read ( void *  pBuffer,
ssize_t  nSize 
)
virtual
ssize_t File::ReadPos ( off_t  nPos,
void *  pBuffer,
ssize_t  nSize 
)
virtual
off_t File::Seek ( off_t  nPos,
int  nMode 
)
virtual
Description:
Note:
Warning:
Parameters
\return
Error codes:
See Also
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

Implements os::SeekableIO.

References GetSize(), os::File::Private::m_cMutex, and os::File::Private::m_nPosition.

status_t File::SetBufferSize ( int  nBufferSize)
Description:
By default the os::File class use a 32KB internal memory buffer to cache resently read/written data. Normally you the buffer can greatly increase the performance since it reduce the number of kernel-calls when doing multiple small reads or writes on the file. There is cases however where it is beneficial to increase the buffer size or even to disabling buffering entirely.

If you read/write large chunks of data at the time the buffer might impose more overhead than gain and it could be a good idea to disable the buffering entirely by setting the buffer size to 0. When for example streaming video the amount of data read are probably going to be much larger than the buffer anyway and each byte is only read once by the application and if the application read the file in reasonably sized chunks the extra copy imposed by reading the data into the internal buffer and then copy it to the callers buffer will only decrease the performance.

Parameters
nBufferSizeThe buffer size in bytes. If the size is set to 0 the file will be unbuffered and each call to Read()/Write() and ReadPos()/WritePos() will translate directly to kernel calls.
Returns
On success 0 is returned. If there was not enough memory for the new buffer -1 will be returned and the global variable "errno" will be set to ENOMEM.
See Also
GetBufferSize()
Author
Kurt Skauen (kurt@.nosp@m.athe.nosp@m.os.cx)

References Flush(), os::File::Private::m_bDirty, os::File::Private::m_cMutex, os::File::Private::m_nBufferSize, os::File::Private::m_nValidBufSize, and os::File::Private::m_pBuffer.

ssize_t File::Write ( const void *  pBuffer,
ssize_t  nSize 
)
virtual
ssize_t File::WritePos ( off_t  nPos,
const void *  pBuffer,
ssize_t  nSize 
)
virtual