Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "fs.hpp" |
| 4 | |
| 5 | #include <blobs-ipmid/blobs.hpp> |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 6 | |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 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> |
| 18 | CreateCleanupHandler(const std::string& blobId, |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame] | 19 | const std::vector<std::string>& files, |
| 20 | std::unique_ptr<FileSystemInterface> helper); |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 21 | |
| 22 | FileCleanupHandler(const std::string& blobId, |
| 23 | const std::vector<std::string>& files, |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame] | 24 | std::unique_ptr<FileSystemInterface> helper) : |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 25 | supported(blobId), |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame] | 26 | files(files), helper(std::move(helper)) |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 27 | {} |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 28 | |
| 29 | ~FileCleanupHandler() = default; |
| 30 | FileCleanupHandler(const FileCleanupHandler&) = default; |
| 31 | FileCleanupHandler& operator=(const FileCleanupHandler&) = default; |
| 32 | FileCleanupHandler(FileCleanupHandler&&) = default; |
| 33 | FileCleanupHandler& operator=(FileCleanupHandler&&) = default; |
| 34 | |
| 35 | bool canHandleBlob(const std::string& path) override; |
| 36 | std::vector<std::string> getBlobIds() override; |
| 37 | bool commit(uint16_t session, const std::vector<uint8_t>& data) override; |
| 38 | |
| 39 | /* These methods return true without doing anything. */ |
| 40 | bool open(uint16_t session, uint16_t flags, |
| 41 | const std::string& path) override |
| 42 | { |
| 43 | return true; |
| 44 | } |
| 45 | bool close(uint16_t session) override |
| 46 | { |
| 47 | return true; |
| 48 | } |
| 49 | bool expire(uint16_t session) override |
| 50 | { |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | /* These methods are unsupported. */ |
| 55 | bool deleteBlob(const std::string& path) override |
| 56 | { |
| 57 | return false; |
| 58 | } |
| 59 | bool stat(const std::string& path, blobs::BlobMeta* meta) override |
| 60 | { |
| 61 | return false; |
| 62 | } |
| 63 | std::vector<uint8_t> read(uint16_t session, uint32_t offset, |
| 64 | uint32_t requestedSize) override |
| 65 | { |
| 66 | return {}; |
| 67 | } |
| 68 | bool write(uint16_t session, uint32_t offset, |
| 69 | const std::vector<uint8_t>& data) override |
| 70 | { |
| 71 | return false; |
| 72 | } |
| 73 | bool writeMeta(uint16_t session, uint32_t offset, |
| 74 | const std::vector<uint8_t>& data) override |
| 75 | { |
| 76 | return false; |
| 77 | } |
| 78 | bool stat(uint16_t session, blobs::BlobMeta* meta) override |
| 79 | { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | std::string supported; |
| 85 | std::vector<std::string> files; |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame] | 86 | std::unique_ptr<FileSystemInterface> helper; |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | } // namespace ipmi_flash |