Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
Stream Class Reference
[Stream class]
#include <Stream.h>
Inherits mbed::FileLike, and NonCopyable< Stream >.
Inherited by USBKeyboard, USBMouseKeyboard, and USBSerial.
Public Member Functions | |
virtual int | close () |
Close a file. | |
virtual ssize_t | write (const void *buffer, size_t length) |
Write the contents of a buffer to a file. | |
virtual ssize_t | read (void *buffer, size_t length) |
Read the contents of a file into a buffer. | |
virtual off_t | seek (off_t offset, int whence) |
Move the file position to a given offset from from a given location. | |
virtual off_t | tell () |
Get the file position of the file. | |
virtual void | rewind () |
Rewind the file position to the beginning of the file. | |
virtual int | isatty () |
Check if the file in an interactive terminal device. | |
virtual int | sync () |
Flush any buffers associated with the file. | |
virtual off_t | size () |
Get the size of the file. | |
virtual int | truncate (off_t length) |
Truncate or extend a file. | |
MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::seek") virtual off_t lseek(off_t offset | |
Move the file position to a given offset from a given location. | |
MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::sync") virtual int fsync() | |
Flush any buffers associated with the FileHandle, ensuring it is up to date on disk. | |
MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::size") virtual off_t flen() | |
Find the length of the file. | |
virtual int | set_blocking (bool blocking) |
Set blocking or nonblocking mode of the file operation like read/write. | |
virtual bool | is_blocking () const |
Check current blocking or nonblocking mode for file operations. | |
virtual int | enable_input (bool enabled) |
Enable or disable input. | |
virtual int | enable_output (bool enabled) |
Enable or disable output. | |
virtual short | poll (short events) const |
Check for poll event flags You can use or ignore the input parameter. | |
bool | writable () const |
Definition depends on the subclass implementing FileHandle. | |
bool | readable () const |
Definition depends on the subclass implementing FileHandle. | |
virtual void | sigio (Callback< void()> func) |
Register a callback on state change of the file. | |
Protected Member Functions | |
virtual void | lock () |
Acquire exclusive access to this object. | |
virtual void | unlock () |
Release exclusive access to this object. | |
MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &) | |
NonCopyable copy constructor. | |
MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator | |
NonCopyable copy assignment operator. | |
Private Member Functions | |
MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &) | |
NonCopyable copy constructor. | |
MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator | |
NonCopyable copy assignment operator. |
Detailed Description
File stream.
- Note:
- Synchronization level: Set by subclass
Definition at line 42 of file Stream.h.
Member Function Documentation
int close | ( | ) | [virtual] |
Close a file.
- Returns:
- 0 on success, negative error code on failure
Implements FileHandle.
Definition at line 87 of file Stream.cpp.
virtual int enable_input | ( | bool | enabled ) | [virtual, inherited] |
Enable or disable input.
Control enabling of device for input. This is primarily intended for temporary power-saving; the overall ability of the device to operate for input and/or output may be fixed at creation time, but this call can allow input to be temporarily disabled to permit power saving without losing device state.
- Parameters:
-
enabled true to enable input, false to disable.
- Returns:
- 0 on success
- Negative error code on failure
Reimplemented in UARTSerial.
Definition at line 236 of file FileHandle.h.
virtual int enable_output | ( | bool | enabled ) | [virtual, inherited] |
Enable or disable output.
Control enabling of device for output. This is primarily intended for temporary power-saving; the overall ability of the device to operate for input and/or output may be fixed at creation time, but this call can allow output to be temporarily disabled to permit power saving without losing device state.
- Parameters:
-
enabled true to enable output, false to disable.
- Returns:
- 0 on success
- Negative error code on failure
Reimplemented in UARTSerial.
Definition at line 254 of file FileHandle.h.
virtual bool is_blocking | ( | ) | const [virtual, inherited] |
Check current blocking or nonblocking mode for file operations.
- Returns:
- true for blocking mode, false for nonblocking mode.
Reimplemented in UARTSerial.
Definition at line 218 of file FileHandle.h.
int isatty | ( | ) | [virtual] |
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.
Definition at line 140 of file Stream.cpp.
virtual void lock | ( | void | ) | [protected, virtual] |
MBED_DEPRECATED | ( | "Invalid copy assignment of a NonCopyable< FileBase > resource." | ) | [protected, inherited] |
NonCopyable copy assignment operator.
A compile time warning is issued when this function is used, and a runtime warning is printed when the copy construction of the noncopyable happens.
If you see this warning, your code is probably doing something unspecified. Copying of noncopyable resources can lead to resource leak and random error.
MBED_DEPRECATED | ( | "Invalid copy construction of a NonCopyable< FileBase > resource." | ) | const [protected, inherited] |
NonCopyable copy constructor.
A compile time warning is issued when this function is used, and a runtime warning is printed when the copy construction of the noncopyable happens.
If you see this warning, your code is probably doing something unspecified. Copying of noncopyable resources can lead to resource leak and random error.
Definition at line 191 of file NonCopyable.h.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.4" | , |
"Replaced by FileHandle::sync" | |||
) | [inherited] |
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
Definition at line 182 of file FileHandle.h.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.4" | , |
"Replaced by FileHandle::size" | |||
) | [inherited] |
Find the length of the file.
- Returns:
- Length of the file
Definition at line 194 of file FileHandle.h.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.4" | , |
"Replaced by FileHandle::seek" | |||
) | [inherited] |
Move the file position to a given offset from a given location.
- Parameters:
-
offset The offset from whence to move to whence SEEK_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
virtual short poll | ( | short | events ) | const [virtual, inherited] |
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:
-
events bitmask of poll events we're interested in - POLLIN/POLLOUT etc.
- Returns:
- bitmask of poll events that have occurred.
Reimplemented in UARTSerial, and UnbufferedSerial.
Definition at line 269 of file FileHandle.h.
ssize_t read | ( | void * | buffer, |
size_t | size | ||
) | [virtual] |
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:
-
buffer The buffer to read in to size The number of bytes to read
- Returns:
- The number of bytes read, 0 at end of file, negative error on failure
Implements FileHandle.
Definition at line 108 of file Stream.cpp.
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 292 of file FileHandle.h.
void rewind | ( | ) | [virtual] |
Rewind the file position to the beginning of the file.
- Note:
- This is equivalent to seek(0, SEEK_SET)
Reimplemented from FileHandle.
Definition at line 136 of file Stream.cpp.
off_t seek | ( | off_t | offset, |
int | whence | ||
) | [virtual] |
Move the file position to a given offset from from a given location.
- Parameters:
-
offset The offset from whence to move to whence The 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.
Definition at line 126 of file Stream.cpp.
virtual int set_blocking | ( | bool | blocking ) | [virtual, inherited] |
Set blocking or nonblocking mode of the file operation like read/write.
Definition depends on the subclass implementing FileHandle. The default is blocking.
- Parameters:
-
blocking true for blocking mode, false for nonblocking mode.
- Returns:
- 0 on success
- Negative error code on failure
Reimplemented in UARTSerial.
Definition at line 209 of file FileHandle.h.
virtual void sigio | ( | Callback< void()> | func ) | [virtual, inherited] |
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:
-
func Function to call on state change
Reimplemented in UARTSerial.
Definition at line 314 of file FileHandle.h.
off_t size | ( | ) | [virtual] |
Get the size of the file.
- Returns:
- Size of the file in bytes
Reimplemented from FileHandle.
Definition at line 150 of file Stream.cpp.
int sync | ( | ) | [virtual] |
Flush any buffers associated with the file.
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileHandle.
Definition at line 145 of file Stream.cpp.
off_t tell | ( | ) | [virtual] |
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.
Definition at line 131 of file Stream.cpp.
virtual int truncate | ( | off_t | length ) | [virtual, inherited] |
Truncate or extend a file.
The file's length is set to the specified value. The seek pointer is not changed. If the file is extended, the extended area appears as if it were zero-filled.
- Parameters:
-
length The requested new length for the file
- Returns:
- Zero on success, negative error code on failure
Reimplemented in File.
Definition at line 151 of file FileHandle.h.
virtual void unlock | ( | void | ) | [protected, virtual] |
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 281 of file FileHandle.h.
ssize_t write | ( | const void * | buffer, |
size_t | size | ||
) | [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 nonblocking set, return -EAGAIN * if some data can be written, and nonblocking set, write partial
- Parameters:
-
buffer The buffer to write from size The number of bytes to write
- Returns:
- The number of bytes written, negative error on failure
Implements FileHandle.
Definition at line 92 of file Stream.cpp.
Generated on Tue Jul 12 2022 13:55:44 by
