F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Os::DirectoryCommon< T > Class Template Reference

Directory class. More...

#include <Os/Directory.hpp>

Inheritance diagram for Os::DirectoryCommon< T >:
Os::DirectoryUserInterface

Public Member Functions

 DirectoryCommon ()
 Constructor. More...
 
 ~DirectoryCommon ()
 Destructor. More...
 
DirectoryHandle * getHandle ()
 return the underlying Directory handle (implementation specific) More...
 
Status open (const char *path, OpenMode mode)
 Open or create a directory. More...
 
bool isOpen ()
 Check if Directory is open or not. More...
 
Status rewind ()
 Rewind directory stream. More...
 
Status read (char *fileNameBuffer, FwSizeType buffSize)
 Get next filename from directory stream. More...
 
void close ()
 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::ExternalArray< Fw::String > &filenameArray, FwSizeType &filenameCount)
 Read the contents of the directory and store filenames in the supplied array. More...
 
 DEPRECATED (Status readDirectory(Fw::String filenameArray[], const FwSizeType arraySize, FwSizeType &filenameCount), "Use readDirectory(Fw::ExternalArray<Fw::String>& filenameArray, FwSizeType& filenameCount) instead")
 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...
 

Additional Inherited Members

- Public Types inherited from Os::DirectoryUserInterface
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 }
 

Detailed Description

template<typename T>
class Os::DirectoryCommon< T >

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 24 of file Directory.hpp.

Constructor & Destructor Documentation

◆ DirectoryCommon()

template<typename T >
Os::DirectoryCommon< T >::DirectoryCommon ( )

Constructor.

Definition at line 160 of file Directory.hpp.

◆ ~DirectoryCommon()

template<typename T >
Os::DirectoryCommon< T >::~DirectoryCommon ( )

Destructor.

Destructor will close the Directory if it is open

Definition at line 163 of file Directory.hpp.

Member Function Documentation

◆ close()

template<typename T >
void Os::DirectoryCommon< T >::close ( )

Close directory.

Definition at line 221 of file Directory.hpp.

◆ DEPRECATED()

template<typename T >
Os::DirectoryCommon< T >::DEPRECATED ( Status   readDirectoryFw::String filenameArray[], const FwSizeType arraySize, FwSizeType &filenameCount,
"Use readDirectory(Fw::ExternalArray<Fw::String>& filenameArray, FwSizeType& filenameCount) instead"   
)

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

◆ getFileCount()

template<typename T >
DirectoryCommon< T >::Status Os::DirectoryCommon< T >::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 231 of file Directory.hpp.

◆ getHandle()

template<typename T >
DirectoryHandle * Os::DirectoryCommon< T >::getHandle ( )

return the underlying Directory handle (implementation specific)

Returns
internal Directory handle representation

Definition at line 173 of file Directory.hpp.

◆ isOpen()

template<typename T >
bool Os::DirectoryCommon< T >::isOpen ( )

Check if Directory is open or not.

Returns
true if Directory is open, false otherwise

Definition at line 189 of file Directory.hpp.

◆ open()

template<typename T >
DirectoryCommon< T >::Status Os::DirectoryCommon< T >::open ( const char *  path,
OpenMode  mode 
)

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

Definition at line 178 of file Directory.hpp.

◆ read() [1/2]

template<typename T >
DirectoryCommon< T >::Status Os::DirectoryCommon< T >::read ( char *  fileNameBuffer,
FwSizeType  buffSize 
)

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

Definition at line 201 of file Directory.hpp.

◆ read() [2/2]

template<typename T >
DirectoryCommon< T >::Status Os::DirectoryCommon< T >::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 213 of file Directory.hpp.

◆ readDirectory()

template<typename T >
DirectoryCommon< T >::Status Os::DirectoryCommon< T >::readDirectory ( Fw::ExternalArray< Fw::String > &  filenameArray,
FwSizeType &  filenameCount 
)

Read the contents of the directory and store filenames in the supplied array.

Reads at most filenameArray.getSize() filenames. 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
filenameCountnumber of filenames written to filenameArray (output)
Returns
status of the operation

Definition at line 262 of file Directory.hpp.

◆ rewind()

template<typename T >
DirectoryCommon< T >::Status Os::DirectoryCommon< T >::rewind ( )

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

Definition at line 193 of file Directory.hpp.


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