metrics-ipmi-blobs: Add from gBMC
Tested: ran CI locally.
1/5 ncsid / iface_test OK 0.01s
2/5 ncsid / sock_test OK 0.02s
3/5 ncsid / normalize_ip_test OK 0.02s
4/5 ncsid / normalize_mac_test OK 0.03s
5/5 metrics-ipmi-blobs / gtest test OK 0.01s
Signed-off-by: Sui Chen <suichen@google.com>
Change-Id: Icaf266b170f96b062774c3ef90e59ddec9ea15c6
diff --git a/metrics-ipmi-blobs/handler.hpp b/metrics-ipmi-blobs/handler.hpp
new file mode 100644
index 0000000..d811333
--- /dev/null
+++ b/metrics-ipmi-blobs/handler.hpp
@@ -0,0 +1,48 @@
+#pragma once
+
+#include <blobs-ipmid/blobs.hpp>
+#include <metric.hpp>
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace blobs
+{
+
+class MetricBlobHandler : public GenericBlobInterface
+{
+ public:
+ MetricBlobHandler() = default;
+ ~MetricBlobHandler() = default;
+ MetricBlobHandler(const MetricBlobHandler&) = delete;
+ MetricBlobHandler& operator=(const MetricBlobHandler&) = delete;
+ MetricBlobHandler(MetricBlobHandler&&) = default;
+ MetricBlobHandler& operator=(MetricBlobHandler&&) = default;
+
+ bool canHandleBlob(const std::string& path) override;
+ std::vector<std::string> getBlobIds() override;
+ bool deleteBlob(const std::string& path) override;
+ bool stat(const std::string& path, BlobMeta* meta) override;
+ bool open(uint16_t session, uint16_t flags,
+ const std::string& path) override;
+ std::vector<uint8_t> read(uint16_t session, uint32_t offset,
+ uint32_t requestedSize) override;
+ bool write(uint16_t session, uint32_t offset,
+ const std::vector<uint8_t>& data) override;
+ bool writeMeta(uint16_t session, uint32_t offset,
+ const std::vector<uint8_t>& data) override;
+ bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
+ bool close(uint16_t session) override;
+ bool stat(uint16_t session, BlobMeta* meta) override;
+ bool expire(uint16_t session) override;
+
+ private:
+ bool isReadOnlyOpenFlags(const uint16_t flag);
+ /* Every session gets its own BmcHealthSnapshot instance. */
+ std::unordered_map<uint16_t,
+ std::unique_ptr<metric_blob::BmcHealthSnapshot>>
+ sessions;
+};
+
+} // namespace blobs