blob: b97088612d39f34fb097367762e570abac0af92e [file] [log] [blame]
Sampa Misra854e61f2019-08-22 04:36:47 -05001#pragma once
2
3#include "file_io.hpp"
4
5namespace pldm
6{
7
8namespace responder
9{
10
11namespace fs = std::filesystem;
12
13/**
14 * @class FileHandler
15 *
16 * Base class to handle read/write of all oem file types
17 */
18class 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
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060032 /** @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
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060036 * @param[in/out] length - length to be read mentioned by Host
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060037 * @param[in] address - DMA address
38 * @return PLDM status code
39 */
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060040 virtual int readIntoMemory(uint32_t offset, uint32_t& length,
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060041 uint64_t address) = 0;
42
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060043 /** @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
Deepak Kodihalli2da1bfe2019-12-14 08:28:09 -060051 virtual int fileAck(uint8_t fileStatus) = 0;
52
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060053 /** @brief Method to read an oem file type's content into the PLDM response.
54 * @param[in] filePath - file to read from
55 * @param[in] offset - offset to read
56 * @param[in/out] length - length to be read
57 * @param[in] response - PLDM response
58 * @return PLDM status code
59 */
60 virtual int readFile(const std::string& filePath, uint32_t offset,
61 uint32_t& length, Response& response);
62
Sampa Misra854e61f2019-08-22 04:36:47 -050063 /** @brief Method to do the file content transfer ove DMA between host and
64 * bmc. This method is made virtual to be overridden in test case. And need
65 * not be defined in other child classes
66 *
67 * @param[in] path - file system path where read/write will be done
68 * @param[in] upstream - direction of DMA transfer. "false" means a
69 * transfer from host to BMC
70 * @param[in] offset - offset to read/write
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060071 * @param[in/out] length - length to be read/write mentioned by Host
Sampa Misra854e61f2019-08-22 04:36:47 -050072 * @param[in] address - DMA address
73 *
74 * @return PLDM status code
75 */
76 virtual int transferFileData(const fs::path& path, bool upstream,
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060077 uint32_t offset, uint32_t& length,
Sampa Misra854e61f2019-08-22 04:36:47 -050078 uint64_t address);
79
Deepak Kodihalli15211b42019-12-14 02:24:49 -060080 virtual int transferFileData(int fd, bool upstream, uint32_t offset,
81 uint32_t& length, uint64_t address);
82
Sampa Misra854e61f2019-08-22 04:36:47 -050083 /** @brief Constructor to create a FileHandler object
84 */
85 FileHandler(uint32_t fileHandle) : fileHandle(fileHandle)
86 {
87 }
88
89 /** FileHandler destructor
90 */
91 virtual ~FileHandler()
92 {
93 }
94
95 protected:
96 uint32_t fileHandle; //!< file handle indicating name of file or invalid
97};
98
99/** @brief Method to create individual file handler objects based on file type
100 *
101 * @param[in] fileType - type of file
102 * @param[in] fileHandle - file handle
103 */
104
105std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType,
106 uint32_t fileHandle);
107
108} // namespace responder
109} // namespace pldm