blob: c024ec93b76128e2e3e1bafdd56a191dcd7d6d60 [file] [log] [blame]
Patrick Venture25528b42018-11-06 18:29:43 -08001#pragma once
2
Patrick Venture400c6362018-11-06 20:06:11 -08003#include <cstdint>
Jason Lingded66d02020-10-23 14:13:03 -07004#include <fstream>
Patrick Venturea78e39f2018-11-06 18:37:06 -08005#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
Patrick Ventured4e20de2019-07-18 12:48:05 -070051class HandlerPack
Patrick Venturea78e39f2018-11-06 18:37:06 -080052{
Patrick Ventured4e20de2019-07-18 12:48:05 -070053 public:
54 HandlerPack(const std::string& name,
55 std::unique_ptr<ImageHandlerInterface> handler) :
56 blobName(name),
57 handler(std::move(handler))
Patrick Venture9b37b092020-05-28 20:58:57 -070058 {}
Patrick Ventured4e20de2019-07-18 12:48:05 -070059
60 HandlerPack() = default;
61 ~HandlerPack() = default;
62 HandlerPack(const HandlerPack&) = delete;
63 HandlerPack& operator=(const HandlerPack&) = delete;
64 HandlerPack(HandlerPack&&) = default;
65 HandlerPack& operator=(HandlerPack&&) = default;
66
Patrick Venturea78e39f2018-11-06 18:37:06 -080067 std::string blobName;
Patrick Ventured4e20de2019-07-18 12:48:05 -070068 std::unique_ptr<ImageHandlerInterface> handler;
Patrick Venture25528b42018-11-06 18:29:43 -080069};
70
Patrick Venture1d5a31c2019-05-20 11:38:22 -070071} // namespace ipmi_flash