SurgSim::Devices::FileDescriptor Class Reference

A wrapper for an UNIX-style integer file descriptor. More...

`#include <SurgSim/Devices/MultiAxis/linux/FileDescriptor.h>`

## Public Member Functions

| FileDescriptor ()
| Default constructor. More...
| FileDescriptor (FileDescriptor &&other)
| Move constructor. More...
FileDescriptor & | operator= (FileDescriptor &&other)
| Move assignment operator. More...
| ~FileDescriptor ()
| Destructor. More...
bool | isValid () const
| Checks if the file descriptor is valid, i.e. More...
bool | canRead () const
| Determines if the file descriptor can be read from. More...
bool | canWrite () const
| Determines if the file descriptor can be written to. More...
bool | hasDataToRead () const
| Checks whether this object has data available to be read. More...
bool | readBytes (void *dataBuffer, size_t bytesToRead, size_t *bytesActuallyRead)
| Reads bytes from the file descriptor. More...
int | get () const
| Gets the raw underlying OS file descriptor. More...
bool | openForReadingAndWriting (const std::string &path)
| Attempts to open the file descriptor for reading and writing. More...
bool | openForReading (const std::string &path)
| Attempts to open the file descriptor for reading only. More...
bool | openForWriting (const std::string &path)
| Attempts to open the file descriptor for writing only. More...
bool | openForReadingAndMaybeWriting (const std::string &path)
| Attempts to open the file descriptor for reading and (if permissions allow it) writing. More...
void | reset ()
| Resets the file descriptor back to an invalid state. More...

## Private Member Functions

| FileDescriptor (const FileDescriptor &other)=delete
FileDescriptor & | operator= (const FileDescriptor &other)=delete

## Private Attributes

int | m_descriptor
bool | m_canRead
bool | m_canWrite

## Static Private Attributes

static const int | INVALID_VALUE = -1

## Detailed Description

A wrapper for an UNIX-style integer file descriptor.

Allows callers to implement RAII-style resource management.

## Constructor & Destructor Documentation

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

Destructor.

## FileDescriptor() [3/3]

SurgSim::Devices::FileDescriptor::FileDescriptor | ( | const FileDescriptor & | other | ) |

private delete

## Member Function Documentation

## 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]

FileDescriptor & SurgSim::Devices::FileDescriptor::operator= | ( | FileDescriptor && | other | ) |

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]

FileDescriptor& SurgSim::Devices::FileDescriptor::operator= | ( | const FileDescriptor & | other | ) |

private delete

## 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.

## Member Data Documentation

## INVALID_VALUE

const int SurgSim::Devices::FileDescriptor::INVALID_VALUE = -1

static private

## 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:

- SurgSim/Devices/MultiAxis/linux/FileDescriptor.h
- SurgSim/Devices/MultiAxis/linux/FileDescriptor.cpp