1 #pragma once 2 3 #include "file_io.hpp" 4 5 namespace pldm 6 { 7 8 namespace responder 9 { 10 11 namespace fs = std::filesystem; 12 13 /** 14 * @class FileHandler 15 * 16 * Base class to handle read/write of all oem file types 17 */ 18 class FileHandler 19 { 20 public: 21 /** @brief Method to write an oem file type from host memory. Individual 22 * file types need to override this method to do the file specific 23 * processing 24 * @param[in] offset - offset to read/write 25 * @param[in] length - length to be read/write mentioned by Host 26 * @param[in] address - DMA address 27 * @return PLDM status code 28 */ 29 virtual int writeFromMemory(uint32_t offset, uint32_t length, 30 uint64_t address) = 0; 31 32 /** @brief Method to read an oem file type into host memory. Individual 33 * file types need to override this method to do the file specific 34 * processing 35 * @param[in] offset - offset to read 36 * @param[in] length - length to be read mentioned by Host 37 * @param[in] address - DMA address 38 * @return PLDM status code 39 */ 40 virtual int readIntoMemory(uint32_t offset, uint32_t length, 41 uint64_t address) = 0; 42 43 /** @brief Method to do the file content transfer ove DMA between host and 44 * bmc. This method is made virtual to be overridden in test case. And need 45 * not be defined in other child classes 46 * 47 * @param[in] path - file system path where read/write will be done 48 * @param[in] upstream - direction of DMA transfer. "false" means a 49 * transfer from host to BMC 50 * @param[in] offset - offset to read/write 51 * @param[in] length - length to be read/write mentioned by Host 52 * @param[in] address - DMA address 53 * 54 * @return PLDM status code 55 */ 56 virtual int transferFileData(const fs::path& path, bool upstream, 57 uint32_t offset, uint32_t length, 58 uint64_t address); 59 60 /** @brief Constructor to create a FileHandler object 61 */ 62 FileHandler(uint32_t fileHandle) : fileHandle(fileHandle) 63 { 64 } 65 66 /** FileHandler destructor 67 */ 68 virtual ~FileHandler() 69 { 70 } 71 72 protected: 73 uint32_t fileHandle; //!< file handle indicating name of file or invalid 74 }; 75 76 /** @brief Method to create individual file handler objects based on file type 77 * 78 * @param[in] fileType - type of file 79 * @param[in] fileHandle - file handle 80 */ 81 82 std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType, 83 uint32_t fileHandle); 84 85 } // namespace responder 86 } // namespace pldm 87