A wrapper for an UNIX-style integer file descriptor.
More...
#include <SurgSim/Devices/MultiAxis/linux/FileDescriptor.h>
A wrapper for an UNIX-style integer file descriptor.
Allows callers to implement RAII-style resource management.
◆ FileDescriptor() [1/3]
SurgSim::Devices::FileDescriptor::FileDescriptor |
( |
| ) |
|
Default constructor.
Initializes the file descriptor to an invalid state.
◆ FileDescriptor() [2/3]
SurgSim::Devices::FileDescriptor::FileDescriptor |
( |
FileDescriptor && |
other | ) |
|
Move constructor.
- Parameters
-
[in,out] | other | The object to move. The original object will be invalidated. |
◆ ~FileDescriptor()
SurgSim::Devices::FileDescriptor::~FileDescriptor |
( |
| ) |
|
◆ FileDescriptor() [3/3]
SurgSim::Devices::FileDescriptor::FileDescriptor |
( |
const FileDescriptor & |
other | ) |
|
|
privatedelete |
◆ canRead()
bool SurgSim::Devices::FileDescriptor::canRead |
( |
| ) |
const |
Determines if the file descriptor can be read from.
- Returns
- true if the descriptor has been open for reading.
◆ canWrite()
bool SurgSim::Devices::FileDescriptor::canWrite |
( |
| ) |
const |
Determines if the file descriptor can be written to.
- Returns
- true if the descriptor has been open for writing.
◆ get()
int SurgSim::Devices::FileDescriptor::get |
( |
| ) |
const |
Gets the raw underlying OS file descriptor.
- Returns
- The raw file descriptor.
◆ hasDataToRead()
bool SurgSim::Devices::FileDescriptor::hasDataToRead |
( |
| ) |
const |
Checks whether this object has data available to be read.
- Returns
- true if there is data currently available.
◆ isValid()
bool SurgSim::Devices::FileDescriptor::isValid |
( |
| ) |
const |
Checks if the file descriptor is valid, i.e.
has been opened.
- Returns
- true if valid, false if not.
◆ openForReading()
bool SurgSim::Devices::FileDescriptor::openForReading |
( |
const std::string & |
path | ) |
|
Attempts to open the file descriptor for reading only.
- Parameters
-
path | Full pathname of the file. |
- Returns
- true if it succeeds, false if it fails.
◆ openForReadingAndMaybeWriting()
bool SurgSim::Devices::FileDescriptor::openForReadingAndMaybeWriting |
( |
const std::string & |
path | ) |
|
Attempts to open the file descriptor for reading and (if permissions allow it) writing.
- Parameters
-
path | Full pathname of the file. |
- Returns
- true if it succeeds, false if it fails.
◆ openForReadingAndWriting()
bool SurgSim::Devices::FileDescriptor::openForReadingAndWriting |
( |
const std::string & |
path | ) |
|
Attempts to open the file descriptor for reading and writing.
- Parameters
-
path | Full pathname of the file. |
- Returns
- true if it succeeds, false if it fails.
◆ openForWriting()
bool SurgSim::Devices::FileDescriptor::openForWriting |
( |
const std::string & |
path | ) |
|
Attempts to open the file descriptor for writing only.
- Parameters
-
path | Full pathname of the file. |
- Returns
- true if it succeeds, false if it fails.
◆ operator=() [1/2]
Move assignment operator.
- Parameters
-
[in,out] | other | The object to move. The original object will be invalidated. |
- Returns
- A reference to this object.
◆ operator=() [2/2]
◆ readBytes()
bool SurgSim::Devices::FileDescriptor::readBytes |
( |
void * |
dataBuffer, |
|
|
size_t |
bytesToRead, |
|
|
size_t * |
bytesActuallyRead |
|
) |
| |
Reads bytes from the file descriptor.
- Parameters
-
[out] | dataBuffer | Buffer to read into. Must have room for at least bytesToRead bytes of data. |
| bytesToRead | The number of bytes to try reading. Actual number of bytes received may be smaller. |
[out] | bytesActuallyRead | The number of bytes that were actually read into the buffer. |
- Returns
- true if it succeeds, false if it fails.
◆ reset()
void SurgSim::Devices::FileDescriptor::reset |
( |
| ) |
|
Resets the file descriptor back to an invalid state.
If the descriptor was open, it will be closed.
◆ INVALID_VALUE
const int SurgSim::Devices::FileDescriptor::INVALID_VALUE = -1 |
|
staticprivate |
◆ m_canRead
bool SurgSim::Devices::FileDescriptor::m_canRead |
|
private |
◆ m_canWrite
bool SurgSim::Devices::FileDescriptor::m_canWrite |
|
private |
◆ m_descriptor
int SurgSim::Devices::FileDescriptor::m_descriptor |
|
private |
The documentation for this class was generated from the following files: