blob: 7186964789089b947461eb90c91b7b516a09b107 [file] [log] [blame]
Brandon Kimdab96f12021-02-18 11:21:37 -08001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Sui Chen03eba282021-02-11 11:35:56 -080015#pragma once
16
17#include <blobs-ipmid/blobs.hpp>
18#include <metric.hpp>
19
20#include <cstdint>
21#include <string>
22#include <vector>
23
24namespace blobs
25{
26
27class MetricBlobHandler : public GenericBlobInterface
28{
29 public:
30 MetricBlobHandler() = default;
31 ~MetricBlobHandler() = default;
32 MetricBlobHandler(const MetricBlobHandler&) = delete;
33 MetricBlobHandler& operator=(const MetricBlobHandler&) = delete;
34 MetricBlobHandler(MetricBlobHandler&&) = default;
35 MetricBlobHandler& operator=(MetricBlobHandler&&) = default;
36
37 bool canHandleBlob(const std::string& path) override;
38 std::vector<std::string> getBlobIds() override;
39 bool deleteBlob(const std::string& path) override;
40 bool stat(const std::string& path, BlobMeta* meta) override;
41 bool open(uint16_t session, uint16_t flags,
42 const std::string& path) override;
43 std::vector<uint8_t> read(uint16_t session, uint32_t offset,
44 uint32_t requestedSize) override;
45 bool write(uint16_t session, uint32_t offset,
46 const std::vector<uint8_t>& data) override;
47 bool writeMeta(uint16_t session, uint32_t offset,
48 const std::vector<uint8_t>& data) override;
49 bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
50 bool close(uint16_t session) override;
51 bool stat(uint16_t session, BlobMeta* meta) override;
52 bool expire(uint16_t session) override;
53
54 private:
55 bool isReadOnlyOpenFlags(const uint16_t flag);
56 /* Every session gets its own BmcHealthSnapshot instance. */
57 std::unordered_map<uint16_t,
58 std::unique_ptr<metric_blob::BmcHealthSnapshot>>
59 sessions;
60};
61
62} // namespace blobs