blob: 6c3125261384b1ec15ec0750f4c99d295d6c3a7e [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
32 /** @brief Method to do the file content transfer ove DMA between host and
33 * bmc. This method is made virtual to be overridden in test case. And need
34 * not be defined in other child classes
35 *
36 * @param[in] path - file system path where read/write will be done
37 * @param[in] upstream - direction of DMA transfer. "false" means a
38 * transfer from host to BMC
39 * @param[in] offset - offset to read/write
40 * @param[in] length - length to be read/write mentioned by Host
41 * @param[in] address - DMA address
42 *
43 * @return PLDM status code
44 */
45 virtual int transferFileData(const fs::path& path, bool upstream,
46 uint32_t offset, uint32_t length,
47 uint64_t address);
48
49 /** @brief Constructor to create a FileHandler object
50 */
51 FileHandler(uint32_t fileHandle) : fileHandle(fileHandle)
52 {
53 }
54
55 /** FileHandler destructor
56 */
57 virtual ~FileHandler()
58 {
59 }
60
61 protected:
62 uint32_t fileHandle; //!< file handle indicating name of file or invalid
63};
64
65/** @brief Method to create individual file handler objects based on file type
66 *
67 * @param[in] fileType - type of file
68 * @param[in] fileHandle - file handle
69 */
70
71std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType,
72 uint32_t fileHandle);
73
74} // namespace responder
75} // namespace pldm