Class FileHandle. More...
#include <FileHandle.h>
Public Member Functions | |
virtual ssize_t | read (void *buffer, size_t size)=0 |
Read the contents of a file into a buffer. More... | |
virtual ssize_t | write (const void *buffer, size_t size)=0 |
Write the contents of a buffer to a file. More... | |
virtual off_t | seek (off_t offset, int whence=SEEK_SET)=0 |
Move the file position to a given offset from from a given location. More... | |
virtual int | close ()=0 |
Close a file. More... | |
virtual int | sync () |
Flush any buffers associated with the file. More... | |
virtual int | isatty () |
Check if the file in an interactive terminal device. 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 off_t | size () |
Get the size of the file. More... | |
virtual int | truncate (off_t length) |
Truncate or extend a 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 int | enable_input (bool enabled) |
Enable or disable input. More... | |
virtual int | enable_output (bool enabled) |
Enable or disable output. 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... | |
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.
Definition at line 46 of file FileHandle.h.
|
pure virtual |
Close a file.
Implemented in UnbufferedSerial, BufferedSerial, TestFile< FILE_SIZE >, File, SerialWireOutput, and Stream.
|
virtual |
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.
enabled | true to enable input, false to disable. |
Reimplemented in BufferedSerial, and UnbufferedSerial.
Definition at line 192 of file FileHandle.h.
|
virtual |
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.
enabled | true to enable output, false to disable. |
Reimplemented in BufferedSerial, and UnbufferedSerial.
Definition at line 210 of file FileHandle.h.
|
virtual |
Check current blocking or nonblocking mode for file operations.
Reimplemented in BufferedSerial.
Definition at line 174 of file FileHandle.h.
|
virtual |
Check if the file in an interactive terminal device.
Reimplemented in BufferedSerial, UnbufferedSerial, File, Stream, and SerialWireOutput.
Definition at line 110 of file FileHandle.h.
|
virtual |
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).
events | bitmask of poll events we're interested in - POLLIN/POLLOUT etc. |
Reimplemented in UnbufferedSerial, and BufferedSerial.
Definition at line 225 of file FileHandle.h.
|
pure virtual |
Read the contents of a file into a buffer.
Devices acting as FileHandles should follow POSIX semantics:
buffer | The buffer to read in to |
size | The number of bytes to read |
Implemented in BufferedSerial, UnbufferedSerial, File, Stream, SerialWireOutput, and TestFile< FILE_SIZE >.
bool readable | ( | ) | const |
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.
Definition at line 248 of file FileHandle.h.
|
virtual |
Rewind the file position to the beginning of the file.
Reimplemented in File, and Stream.
Definition at line 130 of file FileHandle.h.
|
pure virtual |
Move the file position to a given offset from from a given location.
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 |
Implemented in BufferedSerial, UnbufferedSerial, File, TestFile< FILE_SIZE >, Stream, and SerialWireOutput.
|
virtual |
Set blocking or nonblocking mode of the file operation like read/write.
Definition depends on the subclass implementing FileHandle. The default is blocking.
blocking | true for blocking mode, false for nonblocking mode. |
Reimplemented in BufferedSerial.
Definition at line 165 of file FileHandle.h.
|
virtual |
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.
func | Function to call on state change |
Reimplemented in BufferedSerial.
Definition at line 270 of file FileHandle.h.
|
virtual |
Get the size of the file.
Reimplemented in File, UnbufferedSerial, TestFile< FILE_SIZE >, Stream, and SerialWireOutput.
|
virtual |
Flush any buffers associated with the file.
Reimplemented in BufferedSerial, File, and Stream.
Definition at line 99 of file FileHandle.h.
|
virtual |
Get the file position of the file.
Reimplemented in File, and Stream.
Definition at line 121 of file FileHandle.h.
|
virtual |
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.
length | The requested new length for the file |
Reimplemented in File, and TestFile< FILE_SIZE >.
Definition at line 151 of file FileHandle.h.
bool writable | ( | ) | const |
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.
Definition at line 237 of file FileHandle.h.
|
pure virtual |
Write the contents of a buffer to a file.
Devices acting as FileHandles should follow POSIX semantics:
if some data can be written, and nonblocking set, write partial
buffer | The buffer to write from |
size | The number of bytes to write |
Implemented in BufferedSerial, UnbufferedSerial, File, Stream, TestFile< FILE_SIZE >, and SerialWireOutput.