blob: 52d682f8b35703fc45ca991fde310effaef642fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#pragma once
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <vector>
namespace ipmi_flash
{
/**
* Each image update mechanism must implement the ImageHandlerInterface.
*/
class ImageHandlerInterface
{
public:
virtual ~ImageHandlerInterface() = default;
/**
* open the firmware update mechanism.
*
* @param[in] path - the path passed to the handler (the blob_id).
* @return bool - returns true on success.
*/
virtual bool open(const std::string& path) = 0;
/**
* close the image.
*/
virtual void close() = 0;
/**
* write data to the staged file.
*
* @param[in] offset - 0-based offset into the file.
* @param[in] data - the data to write.
* @return bool - returns true on success.
*/
virtual bool write(std::uint32_t offset,
const std::vector<std::uint8_t>& data) = 0;
/**
* return the size of the file (if that notion makes sense).
*
* @return the size in bytes of the image staged.
*/
virtual int getSize() = 0;
};
class HandlerPack
{
public:
HandlerPack(const std::string& name,
std::unique_ptr<ImageHandlerInterface> handler) :
blobName(name),
handler(std::move(handler))
{
}
HandlerPack() = default;
~HandlerPack() = default;
HandlerPack(const HandlerPack&) = delete;
HandlerPack& operator=(const HandlerPack&) = delete;
HandlerPack(HandlerPack&&) = default;
HandlerPack& operator=(HandlerPack&&) = default;
std::string blobName;
std::unique_ptr<ImageHandlerInterface> handler;
};
} // namespace ipmi_flash
|