blob: b7d682bb1a8c205579aff693cf16ad960fa22f2b [file] [log] [blame]
Patrick Venture25528b42018-11-06 18:29:43 -08001#pragma once
2
Patrick Venture400c6362018-11-06 20:06:11 -08003#include <cstdint>
Patrick Venturea78e39f2018-11-06 18:37:06 -08004#include <functional>
5#include <memory>
6#include <string>
Patrick Venture400c6362018-11-06 20:06:11 -08007#include <vector>
Patrick Venturea78e39f2018-11-06 18:37:06 -08008
Patrick Venture1d5a31c2019-05-20 11:38:22 -07009namespace ipmi_flash
Patrick Venture25528b42018-11-06 18:29:43 -080010{
11
12/**
13 * Each image update mechanism must implement the ImageHandlerInterface.
14 */
15class ImageHandlerInterface
16{
17 public:
18 virtual ~ImageHandlerInterface() = default;
19
20 /**
21 * open the firmware update mechanism.
22 *
Patrick Venturea78e39f2018-11-06 18:37:06 -080023 * @param[in] path - the path passed to the handler (the blob_id).
Patrick Venture25528b42018-11-06 18:29:43 -080024 * @return bool - returns true on success.
25 */
Patrick Venturea78e39f2018-11-06 18:37:06 -080026 virtual bool open(const std::string& path) = 0;
Patrick Venture400c6362018-11-06 20:06:11 -080027
28 /**
Patrick Venture68bb1432018-11-09 20:08:48 -080029 * close the image.
30 */
31 virtual void close() = 0;
32
33 /**
Patrick Venture400c6362018-11-06 20:06:11 -080034 * write data to the staged file.
35 *
36 * @param[in] offset - 0-based offset into the file.
37 * @param[in] data - the data to write.
38 * @return bool - returns true on success.
39 */
40 virtual bool write(std::uint32_t offset,
41 const std::vector<std::uint8_t>& data) = 0;
Patrick Venturecc7d1602018-11-15 13:58:33 -080042
43 /**
44 * return the size of the file (if that notion makes sense).
45 *
46 * @return the size in bytes of the image staged.
47 */
48 virtual int getSize() = 0;
Patrick Venturea78e39f2018-11-06 18:37:06 -080049};
50
51struct HandlerPack
52{
53 std::string blobName;
54 ImageHandlerInterface* handler;
Patrick Venture25528b42018-11-06 18:29:43 -080055};
56
Patrick Venture1d5a31c2019-05-20 11:38:22 -070057} // namespace ipmi_flash