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/out] 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 read an oem file type's content into the PLDM response. 44 * @param[in] offset - offset to read 45 * @param[in/out] length - length to be read 46 * @param[in] response - PLDM response 47 * @return PLDM status code 48 */ 49 virtual int read(uint32_t offset, uint32_t& length, Response& response) = 0; 50 51 /** @brief Method to read an oem file type's content into the PLDM response. 52 * @param[in] filePath - file to read from 53 * @param[in] offset - offset to read 54 * @param[in/out] length - length to be read 55 * @param[in] response - PLDM response 56 * @return PLDM status code 57 */ 58 virtual int readFile(const std::string& filePath, uint32_t offset, 59 uint32_t& length, Response& response); 60 61 /** @brief Method to do the file content transfer ove DMA between host and 62 * bmc. This method is made virtual to be overridden in test case. And need 63 * not be defined in other child classes 64 * 65 * @param[in] path - file system path where read/write will be done 66 * @param[in] upstream - direction of DMA transfer. "false" means a 67 * transfer from host to BMC 68 * @param[in] offset - offset to read/write 69 * @param[in/out] length - length to be read/write mentioned by Host 70 * @param[in] address - DMA address 71 * 72 * @return PLDM status code 73 */ 74 virtual int transferFileData(const fs::path& path, bool upstream, 75 uint32_t offset, uint32_t& length, 76 uint64_t address); 77 78 /** @brief Constructor to create a FileHandler object 79 */ 80 FileHandler(uint32_t fileHandle) : fileHandle(fileHandle) 81 { 82 } 83 84 /** FileHandler destructor 85 */ 86 virtual ~FileHandler() 87 { 88 } 89 90 protected: 91 uint32_t fileHandle; //!< file handle indicating name of file or invalid 92 }; 93 94 /** @brief Method to create individual file handler objects based on file type 95 * 96 * @param[in] fileType - type of file 97 * @param[in] fileHandle - file handle 98 */ 99 100 std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType, 101 uint32_t fileHandle); 102 103 } // namespace responder 104 } // namespace pldm 105