F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Os::Posix::File::PosixFile Class Reference

posix implementation of Os::File More...

#include <Os/Posix/File.hpp>

Inheritance diagram for Os::Posix::File::PosixFile:
Os::FileInterface

Public Member Functions

 PosixFile ()=default
 constructor More...
 
 PosixFile (const PosixFile &other)
 copy constructor More...
 
PosixFileoperator= (const PosixFile &other)
 assignment operator that copies the internal representation More...
 
 ~PosixFile () override=default
 destructor More...
 
Os::FileInterface::Status open (const char *path, Mode mode, OverwriteType overwrite) override
 open file with supplied path and mode More...
 
void close () override
 close the file, if not opened then do nothing More...
 
Status size (FwSizeType &size_result) override
 get size of currently open file More...
 
Status position (FwSizeType &position_result) override
 get file pointer position of the currently open file More...
 
Status preallocate (FwSizeType offset, FwSizeType length) override
 pre-allocate file storage More...
 
Status seek (FwSignedSizeType offset, SeekType seekType) override
 seek the file pointer to the given offset More...
 
Status flush () override
 flush file contents to storage More...
 
Status read (U8 *buffer, FwSizeType &size, WaitType wait) override
 read data from this file into supplied buffer bounded by size More...
 
Status write (const U8 *buffer, FwSizeType &size, WaitType wait) override
 read data from this file into supplied buffer bounded by size More...
 
FileHandlegetHandle () override
 returns the raw file handle More...
 
- Public Member Functions inherited from Os::FileInterface
virtual ~FileInterface ()=default
 

Additional Inherited Members

- Public Types inherited from Os::FileInterface
enum  Mode {
  OPEN_NO_MODE, OPEN_READ, OPEN_CREATE, OPEN_WRITE,
  OPEN_SYNC_WRITE, OPEN_APPEND, MAX_OPEN_MODE
}
 
enum  Status {
  OP_OK, DOESNT_EXIST, NO_SPACE, NO_PERMISSION,
  BAD_SIZE, NOT_OPENED, FILE_EXISTS, NOT_SUPPORTED,
  INVALID_MODE, INVALID_ARGUMENT, NO_MORE_RESOURCES, OTHER_ERROR,
  MAX_STATUS
}
 
enum  OverwriteType { NO_OVERWRITE, OVERWRITE, MAX_OVERWRITE_TYPE }
 
enum  SeekType { RELATIVE, ABSOLUTE, MAX_SEEK_TYPE }
 
enum  WaitType { NO_WAIT, WAIT, MAX_WAIT_TYPE }
 
- Static Public Member Functions inherited from Os::FileInterface
static FileInterfacegetDelegate (FileHandleStorage &aligned_placement_new_memory, const FileInterface *to_copy=nullptr)
 provide a pointer to a file delegate object More...
 

Detailed Description

posix implementation of Os::File

Posix implementation of FileInterface for use as a delegate class handling posix file operations. Posix files use standard open, read, and write posix calls. The handle is represented as a PosixFileHandle which wraps a single int type file descriptor used in those API calls.

Definition at line 29 of file File.hpp.

Constructor & Destructor Documentation

◆ PosixFile() [1/2]

Os::Posix::File::PosixFile::PosixFile ( )
default

constructor

◆ PosixFile() [2/2]

Os::Posix::File::PosixFile::PosixFile ( const PosixFile other)

copy constructor

default copy constructor

Definition at line 61 of file File.cpp.

◆ ~PosixFile()

Os::Posix::File::PosixFile::~PosixFile ( )
overridedefault

destructor

Member Function Documentation

◆ close()

void Os::Posix::File::PosixFile::close ( )
overridevirtual

close the file, if not opened then do nothing

Closes the file, if open. Otherwise this function does nothing. Delegates to the chosen implementation's closeInternal function. mode is set to OPEN_NO_MODE.

Implements Os::FileInterface.

Definition at line 108 of file File.cpp.

◆ flush()

PosixFile::Status Os::Posix::File::PosixFile::flush ( )
overridevirtual

flush file contents to storage

Flushes the file contents to storage (i.e. out of the OS cache to disk). Does nothing in implementations that do not support flushing.

Returns
OP_OK on success otherwise error status

Implements Os::FileInterface.

Definition at line 224 of file File.cpp.

◆ getHandle()

FileHandle * Os::Posix::File::PosixFile::getHandle ( )
overridevirtual

returns the raw file handle

Gets the raw file handle from the implementation. Note: users must include the implementation specific header to make any real use of this handle. Otherwise it//!must* be passed as an opaque type.

Returns
raw file handle

Implements Os::FileInterface.

Definition at line 314 of file File.cpp.

◆ open()

PosixFile::Status Os::Posix::File::PosixFile::open ( const char *  path,
PosixFile::Mode  requested_mode,
PosixFile::OverwriteType  overwrite 
)
overridevirtual

open file with supplied path and mode

Open the file passed in with the given mode. If overwrite is set to OVERWRITE, then opening files in OPEN_CREATE mode will clobber existing files. Set overwrite to NO_OVERWRITE to preserve existing files. The status of the open request is returned from the function call. Delegates to the chosen implementation's open function.

It is invalid to send nullptr as the path. It is invalid to supply mode as a non-enumerated value. It is invalid to supply overwrite as a non-enumerated value.

Parameters
pathc-string of path to open
modefile operation mode
overwriteoverwrite existing file on create
Returns
: status of the open

Implements Os::FileInterface.

Definition at line 73 of file File.cpp.

◆ operator=()

PosixFile & Os::Posix::File::PosixFile::operator= ( const PosixFile other)

assignment operator that copies the internal representation

Definition at line 66 of file File.cpp.

◆ position()

PosixFile::Status Os::Posix::File::PosixFile::position ( FwSizeType position_result)
overridevirtual

get file pointer position of the currently open file

Get the current position of the read/write pointer of the open file.

Parameters
positionoutput parameter for size.
Returns
OP_OK on success otherwise error status

Implements Os::FileInterface.

Definition at line 136 of file File.cpp.

◆ preallocate()

PosixFile::Status Os::Posix::File::PosixFile::preallocate ( FwSizeType  offset,
FwSizeType  length 
)
overridevirtual

pre-allocate file storage

Pre-allocates file storage with at least length storage starting at offset. No-op on implementations that cannot pre-allocate.

It is invalid to pass a negative offset. It is invalid to pass a negative length.

Parameters
offsetoffset into file
lengthlength after offset to preallocate
Returns
OP_OK on success otherwise error status

Implements Os::FileInterface.

Definition at line 149 of file File.cpp.

◆ read()

PosixFile::Status Os::Posix::File::PosixFile::read ( U8 buffer,
FwSizeType size,
PosixFile::WaitType  wait 
)
overridevirtual

read data from this file into supplied buffer bounded by size

Read data from this file up to the size and store it in buffer. When wait is set to WAIT, this will block until the requested size has been read successfully read or the end of the file has been reached. When wait is set to NO_WAIT it will return whatever data is currently available.

size will be updated to the count of bytes actually read. Status will reflect the success/failure of the read operation.

It is invalid to pass nullptr to this function call. It is invalid to pass a negative size. It is invalid to supply wait as a non-enumerated value.

Parameters
buffermemory location to store data read from file
sizesize of data to read
waitWAIT to wait for data, NO_WAIT to return what is currently available
Returns
OP_OK on success otherwise error status

Implements Os::FileInterface.

Definition at line 233 of file File.cpp.

◆ seek()

PosixFile::Status Os::Posix::File::PosixFile::seek ( FwSignedSizeType  offset,
PosixFile::SeekType  seekType 
)
overridevirtual

seek the file pointer to the given offset

Seek the file pointer to the given offset. If seekType is set to ABSOLUTE then the offset is calculated from the start of the file, and if it is set to RELATIVE it is calculated from the current position.

Parameters
offsetoffset to seek to
seekTypeABSOLUTE for seeking from beginning of file, RELATIVE to use current position.
Returns
OP_OK on success otherwise error status

Implements Os::FileInterface.

Definition at line 207 of file File.cpp.

◆ size()

PosixFile::Status Os::Posix::File::PosixFile::size ( FwSizeType size_result)
overridevirtual

get size of currently open file

Get the size of the currently open file and fill the size parameter. Return status of the operation.

Parameters
sizeoutput parameter for size.
Returns
OP_OK on success otherwise error status

Implements Os::FileInterface.

Definition at line 116 of file File.cpp.

◆ write()

PosixFile::Status Os::Posix::File::PosixFile::write ( const U8 buffer,
FwSizeType size,
PosixFile::WaitType  wait 
)
overridevirtual

read data from this file into supplied buffer bounded by size

Write data to this file up to the size from the buffer. When wait is set to WAIT, this will block until the requested size has been written successfully to disk. When wait is set to NO_WAIT it will return once the data is sent to the OS.

size will be updated to the count of bytes actually written. Status will reflect the success/failure of the read operation.

It is invalid to pass nullptr to this function call. It is invalid to pass a negative size. It is invalid to supply wait as a non-enumerated value.

Parameters
buffermemory location to store data read from file
sizesize of data to read
waitWAIT to wait for data to write to disk, NO_WAIT to return what is currently available
Returns
OP_OK on success otherwise error status

Implements Os::FileInterface.

Definition at line 273 of file File.cpp.


The documentation for this class was generated from the following files: