Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Protected Member Functions
Stream Class Referenceabstract

File stream. More...

#include <Stream.h>

Inheritance diagram for Stream:
FileLike NonCopyable< Stream > FileHandle FileBase NonCopyable< FileLike > NonCopyable< FileHandle > NonCopyable< FileBase > Serial

Public Member Functions

virtual off_t lseek (off_t offset, int whence)
 Move the file position to a given offset from a given location. More...
 
virtual int fsync ()
 Flush any buffers associated with the FileHandle, ensuring it is up to date on disk. More...
 
virtual off_t flen ()
 Find the length of the file. More...
 
virtual int set_blocking (bool blocking)
 Set blocking or nonblocking mode of the file operation like read/write. More...
 
virtual bool is_blocking () const
 Check current blocking or nonblocking mode for file operations. More...
 
virtual short poll (short events) const
 Check for poll event flags You can use or ignore the input parameter. More...
 
bool writable () const
 Definition depends on the subclass implementing FileHandle. More...
 
bool readable () const
 Definition depends on the subclass implementing FileHandle. More...
 
virtual void sigio (Callback< void()> func)
 Register a callback on state change of the file. More...
 

Protected Member Functions

virtual int close ()
 Close a file. More...
 
virtual ssize_t write (const void *buffer, size_t length)
 Write the contents of a buffer to a file. More...
 
virtual ssize_t read (void *buffer, size_t length)
 Read the contents of a file into a buffer. More...
 
virtual off_t seek (off_t offset, int whence)
 Move the file position to a given offset from from a given location. More...
 
virtual off_t tell ()
 Get the file position of the file. More...
 
virtual void rewind ()
 Rewind the file position to the beginning of the file. More...
 
virtual int isatty ()
 Check if the file in an interactive terminal device. More...
 
virtual int sync ()
 Flush any buffers associated with the file. More...
 
virtual off_t size ()
 Get the size of the file. More...
 
virtual void lock ()
 Acquire exclusive access to this object. More...
 
virtual void unlock ()
 Release exclusive access to this object. More...
 

Detailed Description

File stream.

Note
Synchronization level: Set by subclass

Definition at line 42 of file Stream.h.

Member Function Documentation

virtual int close ( )
protectedvirtual

Close a file.

Returns
0 on success, negative error code on failure

Implements FileHandle.

virtual off_t flen ( )
virtualinherited

Find the length of the file.

Returns
Length of the file
Deprecated:
Replaced by `off_t FileHandle::size()'

Definition at line 180 of file FileHandle.h.

virtual int fsync ( )
virtualinherited

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

Definition at line 168 of file FileHandle.h.

virtual bool is_blocking ( ) const
virtualinherited

Check current blocking or nonblocking mode for file operations.

Returns
true for blocking mode, false for nonblocking mode.

Reimplemented in UARTSerial.

Definition at line 203 of file FileHandle.h.

virtual int isatty ( )
protectedvirtual

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 from FileHandle.

virtual void lock ( void  )
protectedvirtual

Acquire exclusive access to this object.

Definition at line 80 of file Stream.h.

virtual off_t lseek ( off_t  offset,
int  whence 
)
virtualinherited

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)'

Definition at line 154 of file FileHandle.h.

virtual short poll ( short  events) const
virtualinherited

Check for poll event flags You can use or ignore the input parameter.

You can return all events or check just the events listed in events. Call is nonblocking - 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 UARTSerial.

Definition at line 218 of file FileHandle.h.

virtual ssize_t read ( void *  buffer,
size_t  size 
)
protectedvirtual

Read the contents of a file into a buffer.

Devices acting as FileHandles should follow POSIX semantics:

  • if no data is available, and nonblocking 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

Implements FileHandle.

bool readable ( ) const
inherited

Definition depends on 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.

Definition at line 241 of file FileHandle.h.

virtual void rewind ( )
protectedvirtual

Rewind the file position to the beginning of the file.

Note
This is equivalent to seek(0, SEEK_SET)

Reimplemented from FileHandle.

virtual off_t seek ( off_t  offset,
int  whence 
)
protectedvirtual

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

Implements FileHandle.

virtual int set_blocking ( bool  blocking)
virtualinherited

Set blocking or nonblocking mode of the file operation like read/write.

Definition depends on the subclass implementing FileHandle. The default is blocking.

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

Reimplemented in UARTSerial.

Definition at line 194 of file FileHandle.h.

virtual void sigio ( Callback< void()>  func)
virtualinherited

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 is 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 UARTSerial.

Definition at line 263 of file FileHandle.h.

virtual off_t size ( )
protectedvirtual

Get the size of the file.

Returns
Size of the file in bytes

Reimplemented from FileHandle.

virtual int sync ( )
protectedvirtual

Flush any buffers associated with the file.

Returns
0 on success, negative error code on failure

Reimplemented from FileHandle.

virtual off_t tell ( )
protectedvirtual

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 from FileHandle.

virtual void unlock ( void  )
protectedvirtual

Release exclusive access to this object.

Definition at line 87 of file Stream.h.

bool writable ( ) const
inherited

Definition depends on 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.

Definition at line 230 of file FileHandle.h.

virtual ssize_t write ( const void *  buffer,
size_t  size 
)
protectedvirtual

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 nonblocking set, return -EAGAIN
  • if some data can be written, and nonblocking 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

Implements FileHandle.

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.