Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions
mbed::FileHandle Class Referenceabstract

#include <FileHandle.h>

Inheritance diagram for mbed::FileHandle:
mbed::NonCopyable< FileHandle > DirectSerial mbed::File mbed::FileHandle_stub mbed::FileLike mbed::SerialWireOutput mbed::UARTSerial Sink mbed::Stream mbed::Serial

Public Member Functions

virtual ssize_t read (void *buffer, size_t size)=0
 
virtual ssize_t write (const void *buffer, size_t size)=0
 
virtual off_t seek (off_t offset, int whence=SEEK_SET)=0
 
virtual int close ()=0
 
virtual int sync ()
 
virtual int isatty ()
 
virtual off_t tell ()
 
virtual void rewind ()
 
virtual off_t size ()
 
virtual off_t lseek (off_t offset, int whence)
 
virtual int fsync ()
 
virtual off_t flen ()
 
virtual int set_blocking (bool blocking)
 
virtual bool is_blocking () const
 
virtual short poll (short events) const
 
bool writable () const
 
bool readable () const
 
virtual void sigio (Callback< void()> func)
 

Detailed Description

Class FileHandle

An abstract interface that represents operations on a file-like object. The core functions are read, write, and seek, but only a subset of these operations can be provided.

Note
to create a file,
See also
File
Note
Synchronization level: Set by subclass

Member Function Documentation

virtual int mbed::FileHandle::close ( )
pure virtual

Close a file

Returns
0 on success, negative error code on failure

Implemented in Sink, DirectSerial, mbed::UARTSerial, mbed::FileHandle_stub, mbed::File, mbed::SerialWireOutput, and mbed::Stream.

virtual off_t mbed::FileHandle::flen ( )
inlinevirtual

Find the length of the file

Returns
Length of the file
Deprecated:
Replaced by `off_t FileHandle::size()'
virtual int mbed::FileHandle::fsync ( )
inlinevirtual

Flush any buffers associated with the FileHandle, ensuring it is up to date on disk

Returns
0 on success or un-needed, -1 on error
Deprecated:
Replaced by `int FileHandle::sync()'
virtual bool mbed::FileHandle::is_blocking ( ) const
inlinevirtual

Check current blocking or non-blocking mode for file operations.

Returns
true for blocking mode, false for non-blocking mode.

Reimplemented in mbed::UARTSerial.

virtual int mbed::FileHandle::isatty ( )
inlinevirtual

Check if the file in an interactive terminal device

Returns
True if the file is a terminal
False if the file is not a terminal
Negative error code on failure

Reimplemented in Sink, DirectSerial, mbed::UARTSerial, mbed::File, mbed::Stream, and mbed::SerialWireOutput.

virtual off_t mbed::FileHandle::lseek ( off_t  offset,
int  whence 
)
inlinevirtual

Move the file position to a given offset from a given location.

Parameters
offsetThe offset from whence to move to
whenceSEEK_SET for the start of the file, SEEK_CUR for the current file position, or SEEK_END for the end of the file.
Returns
new file position on success, -1 on failure or unsupported
Deprecated:
Replaced by `off_t FileHandle::seek(off_t offset, int whence = SEEK_SET)'
virtual short mbed::FileHandle::poll ( short  events) const
inlinevirtual

Check for poll event flags The input parameter can be used or ignored - the could always return all events, or could check just the events listed in events. Call is non-blocking - returns instantaneous state of events. Whenever an event occurs, the derived class should call the sigio() callback).

Parameters
eventsbitmask of poll events we're interested in - POLLIN/POLLOUT etc.
Returns
bitmask of poll events that have occurred.

Reimplemented in DirectSerial, mbed::FileHandle_stub, and mbed::UARTSerial.

virtual ssize_t mbed::FileHandle::read ( void *  buffer,
size_t  size 
)
pure virtual

Read the contents of a file into a buffer

Devices acting as FileHandles should follow POSIX semantics:

  • if no data is available, and non-blocking set return -EAGAIN
  • if no data is available, and blocking set, wait until some data is available
  • If any data is available, call returns immediately
Parameters
bufferThe buffer to read in to
sizeThe number of bytes to read
Returns
The number of bytes read, 0 at end of file, negative error on failure

Implemented in Sink, DirectSerial, mbed::UARTSerial, mbed::File, mbed::Stream, mbed::SerialWireOutput, and mbed::FileHandle_stub.

bool mbed::FileHandle::readable ( ) const
inline

Definition depends upon the subclass implementing FileHandle. For example, if the FileHandle is of type Stream, readable() could return true when there is something available to read.

Returns
true when there is something available to read.
virtual void mbed::FileHandle::rewind ( )
inlinevirtual

Rewind the file position to the beginning of the file

Note
This is equivalent to seek(0, SEEK_SET)

Reimplemented in mbed::File, and mbed::Stream.

virtual off_t mbed::FileHandle::seek ( off_t  offset,
int  whence = SEEK_SET 
)
pure virtual

Move the file position to a given offset from from a given location

Parameters
offsetThe offset from whence to move to
whenceThe start of where to seek SEEK_SET to start from beginning of file, SEEK_CUR to start from current position in file, SEEK_END to start from end of file
Returns
The new offset of the file, negative error code on failure

Implemented in Sink, DirectSerial, mbed::UARTSerial, mbed::File, mbed::FileHandle_stub, mbed::Stream, and mbed::SerialWireOutput.

virtual int mbed::FileHandle::set_blocking ( bool  blocking)
inlinevirtual

Set blocking or non-blocking mode of the file operation like read/write. Definition depends upon the subclass implementing FileHandle. The default is blocking.

Parameters
blockingtrue for blocking mode, false for non-blocking mode.
Returns
0 on success
Negative error code on failure

Reimplemented in mbed::UARTSerial.

virtual void mbed::FileHandle::sigio ( Callback< void()>  func)
inlinevirtual

Register a callback on state change of the file.

The specified callback will be called on state changes such as when the file can be written to or read from.

The callback may be called in an interrupt context and should not perform expensive operations.

Note! This is not intended as an attach-like asynchronous api, but rather as a building block for constructing such functionality.

The exact timing of when the registered function is called is not guaranteed and susceptible to change. It should be used as a cue to make read/write/poll calls to find the current state.

Parameters
funcFunction to call on state change

Reimplemented in mbed::UARTSerial, and mbed::FileHandle_stub.

off_t FileHandle::size ( )
virtual

Get the size of the file

Returns
Size of the file in bytes

Reimplemented in Sink, DirectSerial, mbed::File, mbed::Stream, and mbed::SerialWireOutput.

virtual int mbed::FileHandle::sync ( )
inlinevirtual

Flush any buffers associated with the file

Returns
0 on success, negative error code on failure

Reimplemented in mbed::UARTSerial, mbed::File, and mbed::Stream.

virtual off_t mbed::FileHandle::tell ( )
inlinevirtual

Get the file position of the file

Note
This is equivalent to seek(0, SEEK_CUR)
Returns
The current offset in the file, negative error code on failure

Reimplemented in mbed::File, and mbed::Stream.

bool mbed::FileHandle::writable ( ) const
inline

Definition depends upon the subclass implementing FileHandle. For example, if the FileHandle is of type Stream, writable() could return true when there is ample buffer space available for write() calls.

Returns
true if the FileHandle is writable.
virtual ssize_t mbed::FileHandle::write ( const void *  buffer,
size_t  size 
)
pure virtual

Write the contents of a buffer to a file

Devices acting as FileHandles should follow POSIX semantics:

  • if blocking, block until all data is written
  • if no data can be written, and non-blocking set, return -EAGAIN
  • if some data can be written, and non-blocking set, write partial

    Parameters
    bufferThe buffer to write from
    sizeThe number of bytes to write
    Returns
    The number of bytes written, negative error on failure

Implemented in Sink, DirectSerial, mbed::File, mbed::UARTSerial, mbed::Stream, mbed::FileHandle_stub, and mbed::SerialWireOutput.


The documentation for this class was generated from the following files:
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.