blob: 3a3332ad967d22475c8e59ee8bc6f92bc67e4ec4 [file] [log] [blame]
Deepak Kodihallif6d3a832019-11-19 07:00:29 -06001#pragma once
2
3#include "config.h"
4
5#include "file_io_by_type.hpp"
6
7#include <sstream>
8#include <string>
9
10namespace pldm
11{
12namespace responder
13{
14
15using namespace pldm::responder::dma;
16
17/** @class LidHandler
18 *
19 * @brief Inherits and implements FileHandler. This class is used
20 * to read/write LIDs.
21 */
22class LidHandler : public FileHandler
23{
24 public:
25 /** @brief LidHandler constructor
26 */
27 LidHandler(uint32_t fileHandle, bool permSide) : FileHandler(fileHandle)
28 {
29 std::string dir = permSide ? LID_PERM_DIR : LID_TEMP_DIR;
30 std::stringstream stream;
31 stream << std::hex << fileHandle;
32 lidPath = std::move(dir) + '/' + stream.str() + ".lid";
33 }
34
35 virtual int writeFromMemory(uint32_t /*offset*/, uint32_t /*length*/,
36 uint64_t /*address*/)
37 {
38 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
39 }
40
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060041 virtual int readIntoMemory(uint32_t offset, uint32_t& length,
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060042 uint64_t address)
43 {
44 return transferFileData(lidPath, true, offset, length, address);
45 }
46
Deepak Kodihalli75e02f82019-11-20 02:51:05 -060047 virtual int read(uint32_t offset, uint32_t& length, Response& response)
48 {
49 return readFile(lidPath, offset, length, response);
50 }
51
Deepak Kodihalli2da1bfe2019-12-14 08:28:09 -060052 virtual int fileAck(uint8_t /*fileStatus*/)
53 {
54 return PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
55 }
56
Deepak Kodihallif6d3a832019-11-19 07:00:29 -060057 /** @brief LidHandler destructor
58 */
59 ~LidHandler()
60 {
61 }
62
63 protected:
64 std::string lidPath;
65};
66
67} // namespace responder
68} // namespace pldm