blob: 779eaefa2d8314af823fbb6b3c7e5bb8fc9c5ab1 [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
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
Sampa Misra854e61f2019-08-22 04:36:47 -050061 /** @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
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060069 * @param[in/out] length - length to be read/write mentioned by Host
Sampa Misra854e61f2019-08-22 04:36:47 -050070 * @param[in] address - DMA address
71 *
72 * @return PLDM status code
73 */
74 virtual int transferFileData(const fs::path& path, bool upstream,
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060075 uint32_t offset, uint32_t& length,
Sampa Misra854e61f2019-08-22 04:36:47 -050076 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
100std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType,
101 uint32_t fileHandle);
102
103} // namespace responder
104} // namespace pldm