xref: /openbmc/phosphor-ipmi-flash/cleanup/cleanup.hpp (revision 42a44c281cce08be0ca6251955f4fb73d30c8ced)
1 #pragma once
2 
3 #include "fs.hpp"
4 
5 #include <blobs-ipmid/blobs.hpp>
6 
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 namespace ipmi_flash
12 {
13 
14 class FileCleanupHandler : public blobs::GenericBlobInterface
15 {
16   public:
17     static std::unique_ptr<blobs::GenericBlobInterface> CreateCleanupHandler(
18         const std::string& blobId, const std::vector<std::string>& files,
19         std::unique_ptr<FileSystemInterface> helper);
20 
FileCleanupHandler(const std::string & blobId,const std::vector<std::string> & files,std::unique_ptr<FileSystemInterface> helper)21     FileCleanupHandler(const std::string& blobId,
22                        const std::vector<std::string>& files,
23                        std::unique_ptr<FileSystemInterface> helper) :
24         supported(blobId), files(files), helper(std::move(helper))
25     {}
26 
27     ~FileCleanupHandler() = default;
28     FileCleanupHandler(const FileCleanupHandler&) = default;
29     FileCleanupHandler& operator=(const FileCleanupHandler&) = default;
30     FileCleanupHandler(FileCleanupHandler&&) = default;
31     FileCleanupHandler& operator=(FileCleanupHandler&&) = default;
32 
33     bool canHandleBlob(const std::string& path) override;
34     std::vector<std::string> getBlobIds() override;
35     bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
36 
37     /* These methods return true without doing anything. */
open(uint16_t,uint16_t,const std::string &)38     bool open(uint16_t, uint16_t, const std::string&) override
39     {
40         return true;
41     }
close(uint16_t)42     bool close(uint16_t) override
43     {
44         return true;
45     }
expire(uint16_t)46     bool expire(uint16_t) override
47     {
48         return true;
49     }
50 
51     /* These methods are unsupported. */
deleteBlob(const std::string &)52     bool deleteBlob(const std::string&) override
53     {
54         return false;
55     }
stat(const std::string &,blobs::BlobMeta *)56     bool stat(const std::string&, blobs::BlobMeta*) override
57     {
58         return false;
59     }
read(uint16_t,uint32_t,uint32_t)60     std::vector<uint8_t> read(uint16_t, uint32_t, uint32_t) override
61     {
62         return {};
63     }
write(uint16_t,uint32_t,const std::vector<uint8_t> &)64     bool write(uint16_t, uint32_t, const std::vector<uint8_t>&) override
65     {
66         return false;
67     }
writeMeta(uint16_t,uint32_t,const std::vector<uint8_t> &)68     bool writeMeta(uint16_t, uint32_t, const std::vector<uint8_t>&) override
69     {
70         return false;
71     }
stat(uint16_t,blobs::BlobMeta *)72     bool stat(uint16_t, blobs::BlobMeta*) override
73     {
74         return false;
75     }
76 
77   private:
78     std::string supported;
79     std::vector<std::string> files;
80     std::unique_ptr<FileSystemInterface> helper;
81 };
82 
83 } // namespace ipmi_flash
84