F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Os::Directory Class Referencefinal

Directory class. More...

#include <Os/Directory.hpp>

Inheritance diagram for Os::Directory:
Os::DirectoryInterface

Public Member Functions

 Directory ()
 Constructor. More...
 
 ~Directory () final
 Destructor. More...
 
DirectoryHandlegetHandle () 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...
 
DirectoryInterfaceoperator= (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 DirectoryInterfacegetDelegate (DirectoryHandleStorage &aligned_new_memory)
 provide a pointer to a Directory delegate object More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Directory()

Os::Directory::Directory ( )

Constructor.

Definition at line 10 of file Directory.cpp.

◆ ~Directory()

Os::Directory::~Directory ( )
final

Destructor.

Destructor will close the Directory if it is open

Definition at line 14 of file Directory.cpp.

Member Function Documentation

◆ close()

void Os::Directory::close ( )
overridevirtual

Close directory.

Implements Os::DirectoryInterface.

Definition at line 72 of file Directory.cpp.

◆ getFileCount()

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.

Parameters
fileCountReference to a variable where the file count will be stored.
Returns
Status indicating the result of the operation.

Definition at line 82 of file Directory.cpp.

◆ getHandle()

DirectoryHandle * Os::Directory::getHandle ( )
overridevirtual

return the underlying Directory handle (implementation specific)

Returns
internal Directory handle representation

Implements Os::DirectoryInterface.

Definition at line 25 of file Directory.cpp.

◆ isOpen()

bool Os::Directory::isOpen ( )

Check if Directory is open or not.

Returns
true if Directory is open, false otherwise

Definition at line 41 of file Directory.cpp.

◆ open()

Directory::Status Os::Directory::open ( const char *  path,
OpenMode  mode 
)
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.

Parameters
pathpath of directory to open
modeenum (READ, CREATE_IF_MISSING, CREATE_EXCLUSIVE). See notes above for more information
Returns
status of the operation

Implements Os::DirectoryInterface.

Definition at line 30 of file Directory.cpp.

◆ read() [1/2]

Directory::Status Os::Directory::read ( char *  fileNameBuffer,
FwSizeType  buffSize 
)
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.

Parameters
fileNameBufferbuffer to store filename
buffSizesize of fileNameBuffer
Returns
status of the operation

Implements Os::DirectoryInterface.

Definition at line 53 of file Directory.cpp.

◆ read() [2/2]

Directory::Status Os::Directory::read ( Fw::StringBase filename)

Get next filename from directory stream and write it to a Fw::StringBase object.

Parameters
filenameFw::StringBase (or derived) object to store filename in
Returns
status of the operation

Definition at line 64 of file Directory.cpp.

◆ readDirectory()

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.

Parameters
filenameArrayarray to store filenames
arraySizesize of filenameArray
filenameCountnumber of filenames written to filenameArray (output)
Returns
status of the operation

Definition at line 113 of file Directory.cpp.

◆ rewind()

Directory::Status Os::Directory::rewind ( )
overridevirtual

Rewind directory stream.

Each read operation moves the seek position forward. This function resets the seek position to the beginning.

Returns
status of the operation

Implements Os::DirectoryInterface.

Definition at line 45 of file Directory.cpp.


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