F´ Flight Software - C/C++ Documentation
devel
A framework for building embedded system applications to NASA flight quality standards.
|
#include <Os/Directory.hpp>
Public Member Functions | |
Directory () | |
Constructor. More... | |
~Directory () final | |
Destructor. More... | |
DirectoryHandle * | getHandle () override |
return the underlying Directory handle (implementation specific) More... | |
Status | open (const char *path, OpenMode mode) override |
Open or create a directory. More... | |
bool | isOpen () |
Check if Directory is open or not. More... | |
Status | rewind () override |
Rewind directory stream. More... | |
Status | read (char *fileNameBuffer, FwSizeType buffSize) override |
Get next filename from directory stream. More... | |
void | close () override |
Close directory. More... | |
Status | read (Fw::StringBase &filename) |
Get next filename from directory stream and write it to a Fw::StringBase object. More... | |
Status | readDirectory (Fw::String filenameArray[], const FwSizeType arraySize, FwSizeType &filenameCount) |
Read the contents of the directory and store filenames in filenameArray of size arraySize. More... | |
Status | getFileCount (FwSizeType &fileCount) |
Get the number of files in the directory. More... | |
Public Member Functions inherited from Os::DirectoryInterface | |
DirectoryInterface ()=default | |
default constructor More... | |
virtual | ~DirectoryInterface ()=default |
default virtual destructor More... | |
DirectoryInterface (const DirectoryInterface &other)=delete | |
copy constructor is forbidden More... | |
DirectoryInterface & | operator= (const DirectoryInterface &other)=delete |
assignment operator is forbidden More... | |
Additional Inherited Members | |
Public Types inherited from Os::DirectoryInterface | |
enum | Status { OP_OK , DOESNT_EXIST , NO_PERMISSION , NOT_OPENED , NOT_DIR , NO_MORE_FILES , FILE_LIMIT , BAD_DESCRIPTOR , ALREADY_EXISTS , NOT_SUPPORTED , OTHER_ERROR } |
enum | OpenMode { READ , CREATE_IF_MISSING , CREATE_EXCLUSIVE , MAX_OPEN_MODE } |
Static Public Member Functions inherited from Os::DirectoryInterface | |
static DirectoryInterface * | getDelegate (DirectoryHandleStorage &aligned_new_memory) |
provide a pointer to a Directory delegate object More... | |
Directory class.
This class provides a common interface for directory operations, such as reading files in a directory and getting the number of files in a directory.
Definition at line 117 of file Directory.hpp.
Os::Directory::Directory | ( | ) |
Constructor.
Definition at line 10 of file Directory.cpp.
|
final |
Destructor.
Destructor will close the Directory if it is open
Definition at line 14 of file Directory.cpp.
|
overridevirtual |
Directory::Status Os::Directory::getFileCount | ( | FwSizeType & | fileCount | ) |
Get the number of files in the directory.
Counts the number of files in the directory by reading each file entry and writing the count to fileCount.
The function first rewinds the directory stream to ensure counting starts from the beginning. After counting, it rewinds the directory stream again, resetting seek position to beginning.
fileCount | Reference to a variable where the file count will be stored. |
Definition at line 82 of file Directory.cpp.
|
overridevirtual |
return the underlying Directory handle (implementation specific)
Implements Os::DirectoryInterface.
Definition at line 25 of file Directory.cpp.
bool Os::Directory::isOpen | ( | ) |
Check if Directory is open or not.
Definition at line 41 of file Directory.cpp.
|
overridevirtual |
Open or create a directory.
Using the path provided, this function will open or create a directory. Use OpenMode::READ to open an existing directory and error if the directory is not found Use OpenMode::CREATE_IF_MISSING to open a directory, creating the directory if it doesn't exist Use OpenMode::CREATE_EXCLUSIVE to open a directory, creating the directory and erroring if it already exists
It is invalid to pass nullptr
as the path. It is invalid to supply mode
as a non-enumerated value.
path | path of directory to open |
mode | enum (READ, CREATE_IF_MISSING, CREATE_EXCLUSIVE). See notes above for more information |
Implements Os::DirectoryInterface.
Definition at line 30 of file Directory.cpp.
|
overridevirtual |
Get next filename from directory stream.
Write at most buffSize characters of the file name to fileNameBuffer and guarantee null-termination. This function skips the current directory (.) and parent directory (..) entries. Returns NO_MORE_FILES if there are no more files to read from the buffer.
It is invalid to pass nullptr
as fileNameBuffer.
fileNameBuffer | buffer to store filename |
buffSize | size of fileNameBuffer |
Implements Os::DirectoryInterface.
Definition at line 53 of file Directory.cpp.
Directory::Status Os::Directory::read | ( | Fw::StringBase & | filename | ) |
Get next filename from directory stream and write it to a Fw::StringBase object.
filename | Fw::StringBase (or derived) object to store filename in |
Definition at line 64 of file Directory.cpp.
Directory::Status Os::Directory::readDirectory | ( | Fw::String | filenameArray[], |
const FwSizeType | arraySize, | ||
FwSizeType & | filenameCount | ||
) |
Read the contents of the directory and store filenames in filenameArray of size arraySize.
The function first rewinds the directory stream to ensure reading starts from the beginning. After reading, it rewinds the directory stream again, resetting seek position to beginning.
filenameArray | array to store filenames |
arraySize | size of filenameArray |
filenameCount | number of filenames written to filenameArray (output) |
Definition at line 113 of file Directory.cpp.
|
overridevirtual |
Rewind directory stream.
Each read operation moves the seek position forward. This function resets the seek position to the beginning.
Implements Os::DirectoryInterface.
Definition at line 45 of file Directory.cpp.