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
Directory.hpp
Go to the documentation of this file.
1// ======================================================================
2// \title Os/Directory.hpp
3// \brief Os::Directory interface definition
4// ======================================================================
5
6#ifndef _OS_DIRECTORY_HPP_
7#define _OS_DIRECTORY_HPP_
8
9#include <FpConfig.hpp>
10#include <Os/Os.hpp>
11#include <Fw/Types/String.hpp>
12
13namespace Os {
14
16
18 public:
32
39
41 DirectoryInterface() = default;
42
44 virtual ~DirectoryInterface() = default;
45
47 DirectoryInterface(const DirectoryInterface& other) = delete;
48
51
54 virtual DirectoryHandle* getHandle() = 0;
55
57 static DirectoryInterface* getDelegate(DirectoryHandleStorage& aligned_new_memory);
58
59
60 // -----------------------------------------------------------------
61 // Directory operations to be implemented by an OSAL implementation
62 // -----------------------------------------------------------------
63 // These functions are to be overridden in each OS implementation
64 // See an example in in Os/Posix/Directory.hpp
65
79 virtual Status open(const char* path, OpenMode mode) = 0;
80
86 virtual Status rewind() = 0;
87
99 virtual Status read(char * fileNameBuffer, FwSizeType buffSize) = 0;
100
105 // virtual Status read(Fw::StringBase& filename) = 0;
106
108 virtual void close() = 0;
109
110
111};
112
117class Directory final : public DirectoryInterface {
118 public:
120 Directory();
121
125 ~Directory() final;
126
129 DirectoryHandle* getHandle() override;
130
131
132 // ------------------------------------------------------------
133 // Implementation-specific Directory member functions
134 // ------------------------------------------------------------
135 // These functions are overridden in each OS implementation (e.g. in Os/Posix/Directory.hpp)
136
150 Status open(const char* path, OpenMode mode) override;
151
154 bool isOpen();
155
161 Status rewind() override;
162
174 Status read(char * fileNameBuffer, FwSizeType buffSize) override;
175
176
178 void close() override;
179
180
181 // ------------------------------------------------------------
182 // Common functions built on top of OS-specific functions
183 // ------------------------------------------------------------
184
189 Status read(Fw::StringBase& filename);
190
200 Status readDirectory(Fw::String filenameArray[], const FwSizeType arraySize, FwSizeType& filenameCount);
201
211 Status getFileCount(FwSizeType& fileCount);
212
213 private:
214 bool m_is_open;
215
216 private:
217 // This section is used to store the implementation-defined Directory handle. To Os::Directory and fprime, this type is
218 // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in
219 // the byte-array here and set `handle` to that address for storage.
220 alignas(FW_HANDLE_ALIGNMENT) DirectoryHandleStorage m_handle_storage;
221 DirectoryInterface& m_delegate;
222};
223
224}
225
226#endif
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Definition FpConfig.h:440
PlatformSizeType FwSizeType
Definition FpConfig.h:35
C++-compatible configuration header for fprime configuration.
U8 DirectoryHandleStorage[FW_DIRECTORY_HANDLE_MAX_SIZE]
Definition Os.hpp:15
Directory class.
Status rewind() override
Rewind directory stream.
Definition Directory.cpp:45
Status getFileCount(FwSizeType &fileCount)
Get the number of files in the directory.
Definition Directory.cpp:82
Status open(const char *path, OpenMode mode) override
Open or create a directory.
Definition Directory.cpp:30
bool isOpen()
Check if Directory is open or not.
Definition Directory.cpp:41
DirectoryHandle * getHandle() override
return the underlying Directory handle (implementation specific)
Definition Directory.cpp:25
Status readDirectory(Fw::String filenameArray[], const FwSizeType arraySize, FwSizeType &filenameCount)
Read the contents of the directory and store filenames in filenameArray of size arraySize.
void close() override
Close directory.
Definition Directory.cpp:72
~Directory() final
Destructor.
Definition Directory.cpp:14
Directory()
Constructor.
Definition Directory.cpp:10
Status read(char *fileNameBuffer, FwSizeType buffSize) override
Get next filename from directory stream.
Definition Directory.cpp:53
static DirectoryInterface * getDelegate(DirectoryHandleStorage &aligned_new_memory)
provide a pointer to a Directory delegate object
virtual Status rewind()=0
Rewind directory stream.
virtual DirectoryHandle * getHandle()=0
return the underlying Directory handle (implementation specific)
virtual Status open(const char *path, OpenMode mode)=0
Open or create a directory.
virtual ~DirectoryInterface()=default
default virtual destructor
virtual void close()=0
Get next filename from directory stream and write it to a Fw::StringBase object.
DirectoryInterface & operator=(const DirectoryInterface &other)=delete
assignment operator is forbidden
DirectoryInterface()=default
default constructor
virtual Status read(char *fileNameBuffer, FwSizeType buffSize)=0
Get next filename from directory stream.
DirectoryInterface(const DirectoryInterface &other)=delete
copy constructor is forbidden
@ READ
Error if directory doesn't exist.
Definition Directory.hpp:34
@ MAX_OPEN_MODE
Maximum value of OpenMode.
Definition Directory.hpp:37
@ CREATE_IF_MISSING
Create directory if it doesn't exist.
Definition Directory.hpp:35
@ CREATE_EXCLUSIVE
Create directory and error if it already exists.
Definition Directory.hpp:36
@ DOESNT_EXIST
Directory doesn't exist.
Definition Directory.hpp:21
@ NO_PERMISSION
No permission to read directory.
Definition Directory.hpp:22
@ OP_OK
Operation was successful.
Definition Directory.hpp:20
@ NO_MORE_FILES
Directory stream has no more files.
Definition Directory.hpp:25
@ NOT_OPENED
Directory hasn't been opened yet.
Definition Directory.hpp:23
@ NOT_SUPPORTED
Operation is not supported by the current implementation.
Definition Directory.hpp:29
@ FILE_LIMIT
Directory has more files than can be read.
Definition Directory.hpp:26
@ BAD_DESCRIPTOR
Directory stream descriptor is invalid.
Definition Directory.hpp:27
@ NOT_DIR
Path is not a directory.
Definition Directory.hpp:24
@ OTHER_ERROR
A catch-all for other errors. Have to look in implementation-specific code.
Definition Directory.hpp:30
@ ALREADY_EXISTS
Directory already exists.
Definition Directory.hpp:28