blob: d3a48a528b5ad0be74960b22287a236e39b223b3 [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 Kodihallif6d3a832019-11-19 07:00:29 -060052 /** @brief LidHandler destructor
53 */
54 ~LidHandler()
55 {
56 }
57
58 protected:
59 std::string lidPath;
60};
61
62} // namespace responder
63} // namespace pldm