| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/Stub/File.hpp | ||
| 3 | // \brief stub file definitions for Os::File | ||
| 4 | // ====================================================================== | ||
| 5 | #include "Os/File.hpp" | ||
| 6 | |||
| 7 | #ifndef OS_STUB_FILE_HPP | ||
| 8 | #define OS_STUB_FILE_HPP | ||
| 9 | namespace Os { | ||
| 10 | namespace Stub { | ||
| 11 | namespace File { | ||
| 12 | |||
| 13 | struct StubFileHandle : public FileHandle {}; | ||
| 14 | |||
| 15 | //! \brief stub implementation of Os::File | ||
| 16 | //! | ||
| 17 | //! Stub implementation of `FileInterface` for use as a delegate class handling error-only file operations. | ||
| 18 | //! | ||
| 19 | class StubFile : public FileInterface { | ||
| 20 | public: | ||
| 21 | //! \brief constructor | ||
| 22 | //! | ||
| 23 | 1 | StubFile() = default; | |
| 24 | |||
| 25 | //! \brief destructor | ||
| 26 | //! | ||
| 27 | 2 | ~StubFile() override = default; | |
| 28 | |||
| 29 | // ------------------------------------ | ||
| 30 | // Functions overrides | ||
| 31 | // ------------------------------------ | ||
| 32 | |||
| 33 | //! \brief open file with supplied path and mode | ||
| 34 | //! | ||
| 35 | //! This implementation does nothing but return NOT_SUPPORTED. | ||
| 36 | //! | ||
| 37 | //! It is invalid to send `nullptr` as the path. | ||
| 38 | //! It is invalid to supply `mode` as a non-enumerated value. | ||
| 39 | //! It is invalid to supply `overwrite` as a non-enumerated value. | ||
| 40 | //! | ||
| 41 | //! \param path: c-string of path to open | ||
| 42 | //! \param mode: file operation mode | ||
| 43 | //! \param overwrite: overwrite existing file on create | ||
| 44 | //! \return: NOT_SUPPORTED | ||
| 45 | //! | ||
| 46 | Os::FileInterface::Status open(const char* path, Mode mode, OverwriteType overwrite) override; | ||
| 47 | |||
| 48 | //! \brief close the file, if not opened then do nothing | ||
| 49 | //! | ||
| 50 | //! This implementation does nothing. | ||
| 51 | //! | ||
| 52 | void close() override; | ||
| 53 | |||
| 54 | //! \brief get size of currently open file | ||
| 55 | //! | ||
| 56 | //! This implementation does nothing but return NOT_SUPPORTED. | ||
| 57 | //! \param size: output parameter for size. | ||
| 58 | //! \return NOT_SUPPORTED | ||
| 59 | //! | ||
| 60 | Status size(FwSizeType& size_result) override; | ||
| 61 | |||
| 62 | //! \brief get file pointer position of the currently open file | ||
| 63 | //! | ||
| 64 | //! This implementation does nothing but return NOT_SUPPORTED. | ||
| 65 | //! \param position: output parameter for size. | ||
| 66 | //! \return NOT_SUPPORTED | ||
| 67 | //! | ||
| 68 | Status position(FwSizeType& position_result) override; | ||
| 69 | |||
| 70 | //! \brief pre-allocate file storage | ||
| 71 | //! | ||
| 72 | //! This implementation does nothing but return NOT_SUPPORTED. | ||
| 73 | //! | ||
| 74 | //! It is invalid to pass a negative `offset`. | ||
| 75 | //! It is invalid to pass a negative `length`. | ||
| 76 | //! | ||
| 77 | //! \param offset: offset into file | ||
| 78 | //! \param length: length after offset to preallocate | ||
| 79 | //! \return NOT_SUPPORTED | ||
| 80 | //! | ||
| 81 | Status preallocate(FwSizeType offset, FwSizeType length) override; | ||
| 82 | |||
| 83 | //! \brief seek the file pointer to the given offset | ||
| 84 | //! | ||
| 85 | //! This implementation does nothing but return NOT_SUPPORTED. | ||
| 86 | //! | ||
| 87 | //! \param offset: offset to seek to | ||
| 88 | //! \param seekType: `ABSOLUTE` for seeking from beginning of file, `RELATIVE` to use current position. | ||
| 89 | //! \return NOT_SUPPORTED | ||
| 90 | //! | ||
| 91 | Status seek(FwSignedSizeType offset, SeekType seekType) override; | ||
| 92 | |||
| 93 | //! \brief flush file contents to storage | ||
| 94 | //! | ||
| 95 | //! This implementation does nothing but return NOT_SUPPORTED. | ||
| 96 | //! | ||
| 97 | //! \return NOT_SUPPORTED | ||
| 98 | //! | ||
| 99 | Status flush() override; | ||
| 100 | |||
| 101 | //! \brief read data from this file into supplied buffer bounded by size | ||
| 102 | //! | ||
| 103 | //! This implementation does nothing but return NOT_SUPPORTED. | ||
| 104 | //! | ||
| 105 | //! It is invalid to pass `nullptr` to this function call. | ||
| 106 | //! It is invalid to pass a negative `size`. | ||
| 107 | //! It is invalid to supply wait as a non-enumerated value. | ||
| 108 | //! | ||
| 109 | //! \param buffer: memory location to store data read from file | ||
| 110 | //! \param size: size of data to read | ||
| 111 | //! \param wait: `WAIT` to wait for data, `NO_WAIT` to return what is currently available | ||
| 112 | //! \return NOT_SUPPORTED | ||
| 113 | //! | ||
| 114 | Status read(U8* buffer, FwSizeType& size, WaitType wait) override; | ||
| 115 | |||
| 116 | //! \brief read data from this file into supplied buffer bounded by size | ||
| 117 | //! | ||
| 118 | //! This implementation does nothing but return NOT_SUPPORTED. | ||
| 119 | //! | ||
| 120 | //! It is invalid to pass `nullptr` to this function call. | ||
| 121 | //! It is invalid to pass a negative `size`. | ||
| 122 | //! It is invalid to supply wait as a non-enumerated value. | ||
| 123 | //! | ||
| 124 | //! \param buffer: memory location to store data read from file | ||
| 125 | //! \param size: size of data to read | ||
| 126 | //! \param wait: `WAIT` to wait for data to write to disk, `NO_WAIT` to return what is currently available | ||
| 127 | //! \return NOT_SUPPORTED | ||
| 128 | //! | ||
| 129 | Status write(const U8* buffer, FwSizeType& size, WaitType wait) override; | ||
| 130 | |||
| 131 | //! \brief returns the raw file handle | ||
| 132 | //! | ||
| 133 | //! Gets the raw file handle from the implementation. Note: users must include the implementation specific | ||
| 134 | //! header to make any real use of this handle. Otherwise it//!must* be passed as an opaque type. | ||
| 135 | //! | ||
| 136 | //! \return raw file handle | ||
| 137 | //! | ||
| 138 | FileHandle* getHandle() override; | ||
| 139 | |||
| 140 | private: | ||
| 141 | //! File handle for PosixFile | ||
| 142 | StubFileHandle m_handle; | ||
| 143 | }; | ||
| 144 | |||
| 145 | } // namespace File | ||
| 146 | } // namespace Stub | ||
| 147 | } // namespace Os | ||
| 148 | #endif // OS_STUB_FILE_HPP | ||
| 149 |